已合并
下线GPRO入口配置 #2523
AtomGit-Bot创建于 2025年4月10日
下线GPRO入口配置 #2523
已合并
从refs/pull/2523/head合入到2.0.0
共 5 个文件变更+0-502
| @@ -1,84 +0,0 @@ | |||
| 1 | -defaults: | ||
| 2 | - - model: | ||
| 3 | - - llama32-1b | ||
| 4 | - | ||
| 5 | -training: | ||
| 6 | - global_batch_size: 4 | ||
| 7 | - seq_length: 512 | ||
| 8 | - tokenizer_type: PretrainedFromHF | ||
| 9 | - tokenizer_name_or_path: ./models/llama-3.2-1b-instruct/ | ||
| 10 | - train_iters: 1000 | ||
| 11 | - distributed_backend: nccl | ||
| 12 | - no_shared_storage: true | ||
| 13 | - save_interval: 10000 | ||
| 14 | - no_load_optim: true | ||
| 15 | - no_load_rng: true | ||
| 16 | - bf16: true | ||
| 17 | - is_instruction_dataset: true | ||
| 18 | - variable_seq_lengths: true | ||
| 19 | - no_shuffle: true | ||
| 20 | - stage: ray_grpo | ||
| 21 | - sequence_parallel: False | ||
| 22 | - | ||
| 23 | -actor_rollout_ref: | ||
| 24 | - actor_rollout: | ||
| 25 | - model: llama32-1b | ||
| 26 | - do_sample: true | ||
| 27 | - micro_batch_size: 1 | ||
| 28 | - ppo_mini_batch_size: 1 | ||
| 29 | - num_samples_per_step: 1 | ||
| 30 | - max_prompt_length: 256 | ||
| 31 | - ppo_epochs: 1 | ||
| 32 | - clip_ratio: 0.2 | ||
| 33 | - entropy_coeff: 0.001 | ||
| 34 | - shuffle_minibatch: false | ||
| 35 | - use_kv_cache: true | ||
| 36 | - tensor_model_parallel_size: 1 | ||
| 37 | - pipeline_model_parallel_size: 1 | ||
| 38 | - lr: 1e-7 | ||
| 39 | - lr_decay_style: constant | ||
| 40 | - min_lr: 0.0 | ||
| 41 | - weight_decay: 0.0 | ||
| 42 | - lr_warmup_fraction: 0.0 | ||
| 43 | - clip_grad: 10000.0 | ||
| 44 | - adam_beta1: 0.9 | ||
| 45 | - adam_beta2: 0.999 | ||
| 46 | - initial_loss_scale: 4096 | ||
| 47 | - finetune: true | ||
| 48 | - load: ./models/llama-3.2-1b-instruct-tp1-pp1 | ||
| 49 | - save: ./ckpt | ||
| 50 | - num_gpus_for_train: 1 | ||
| 51 | - num_gpus_for_infer: 1 | ||
| 52 | - pad_to_multiple_of: 1 | ||
| 53 | - data_path: ./dataset/descriptiveness/descriptiveness | ||
| 54 | - split: 100,0,0 | ||
| 55 | - n_samples_per_prompt: 4 | ||
| 56 | - | ||
| 57 | - ref: | ||
| 58 | - model: llama32-1b | ||
| 59 | - tensor_model_parallel_size: 1 | ||
| 60 | - pipeline_model_parallel_size: 1 | ||
| 61 | - micro_batch_size: 4 | ||
| 62 | - load: ./models/llama-3.2-1b-instruct-tp1-pp1 | ||
| 63 | - | ||
| 64 | -reward: | ||
| 65 | - model: llama32-1b | ||
| 66 | - tensor_model_parallel_size: 1 | ||
| 67 | - pipeline_model_parallel_size: 1 | ||
| 68 | - micro_batch_size: 4 | ||
| 69 | - load: ./models/llama-3.2-1b-rm-mcore-tp1-pp1 | ||
| 70 | - | ||
| 71 | -algorithm: | ||
| 72 | - gamma: 1.0 | ||
| 73 | - lam: 0.95 | ||
| 74 | - adv_estimator: group_norm | ||
| 75 | - kl_penalty: kl | ||
| 76 | - kl_ctrl: | ||
| 77 | - type: fixed | ||
| 78 | - kl_coef: 0.05 | ||
| 79 | - missing_eos_penalty: 0.0 | ||
| 80 | - | ||
| 81 | -resource_pool: | ||
| 82 | - actor_rollout: [2] | ||
| 83 | - ref: [1] | ||
| 84 | - reward: [1] | ||
| @@ -1,88 +0,0 @@ | |||
| 1 | -defaults: | ||
| 2 | - - model: | ||
| 3 | - - qwen25-7b | ||
| 4 | - | ||
| 5 | -training: | ||
| 6 | - global_batch_size: 12 | ||
| 7 | - seq_length: 4096 | ||
| 8 | - tokenizer_type: PretrainedFromHF | ||
| 9 | - tokenizer_name_or_path: ./models/Qwen2.5-Math-7B | ||
| 10 | - train_iters: 100 | ||
| 11 | - distributed_backend: nccl | ||
| 12 | - no_shared_storage: true | ||
| 13 | - save_interval: 10 | ||
| 14 | - no_load_optim: true | ||
| 15 | - no_load_rng: true | ||
| 16 | - bf16: true | ||
| 17 | - is_instruction_dataset: true | ||
| 18 | - variable_seq_lengths: true | ||
| 19 | - no_shuffle: false | ||
| 20 | - stage: ray_grpo | ||
| 21 | - sequence_parallel: true | ||
| 22 | - dataset_additional_keys: labels | ||
| 23 | - | ||
| 24 | -actor_rollout_ref: | ||
| 25 | - actor_rollout: | ||
| 26 | - model: qwen25-7b | ||
| 27 | - do_sample: true | ||
| 28 | - micro_batch_size: 2 | ||
| 29 | - ppo_mini_batch_size: 12 | ||
| 30 | - num_samples_per_step: 2 | ||
| 31 | - temperature: 1.0 | ||
| 32 | - max_prompt_length: 2048 | ||
| 33 | - max-tokens-to-oom: 1000000 | ||
| 34 | - ppo_epochs: 1 | ||
| 35 | - clip_ratio: 0.2 | ||
| 36 | - entropy_coeff: 0.001 | ||
| 37 | - shuffle_minibatch: false | ||
| 38 | - use_kv_cache: true | ||
| 39 | - tensor_model_parallel_size: 2 | ||
| 40 | - pipeline_model_parallel_size: 4 | ||
| 41 | - lr: 1e-6 | ||
| 42 | - lr_decay_style: constant | ||
| 43 | - min_lr: 0.0 | ||
| 44 | - weight_decay: 0.0 | ||
| 45 | - lr_warmup_fraction: 0.0 | ||
| 46 | - clip_grad: 10000.0 | ||
| 47 | - initial_loss_scale: 4096 | ||
| 48 | - finetune: true | ||
| 49 | - load: ./ckpt | ||
| 50 | - save: ./ckpt | ||
| 51 | - num_gpus_for_train: 8 | ||
| 52 | - num_gpus_for_infer: 6 | ||
| 53 | - data_path: ./dataset/pe-nlp/data | ||
| 54 | - split: 100,0,0 | ||
| 55 | - n_samples_per_prompt: 4 | ||
| 56 | - | ||
| 57 | - ref: | ||
| 58 | - model: qwen25-7b | ||
| 59 | - tensor_model_parallel_size: 2 | ||
| 60 | - pipeline_model_parallel_size: 1 | ||
| 61 | - micro_batch_size: 4 | ||
| 62 | - load: ./ckpt | ||
| 63 | - | ||
| 64 | -reward: | ||
| 65 | - model: qwen25-7b | ||
| 66 | - verifier: true | ||
| 67 | - tensor_model_parallel_size: 2 | ||
| 68 | - pipeline_model_parallel_size: 1 | ||
| 69 | - micro_batch_size: 4 | ||
| 70 | - load: ./ckpt | ||
| 71 | - | ||
| 72 | -algorithm: | ||
| 73 | - gamma: 1.0 | ||
| 74 | - lam: 0.95 | ||
| 75 | - adv_estimator: group_norm | ||
| 76 | - kl_penalty: kl | ||
| 77 | - kl_ctrl: | ||
| 78 | - type: fixed | ||
| 79 | - kl_coef: 0.05 | ||
| 80 | - missing_eos_penalty: 0.0 | ||
| 81 | - verifier_function: ["acc", "format"] | ||
| 82 | - verifier_weight: [0.5, 0.5] | ||
| 83 | - advantage_whiten: False | ||
| 84 | - | ||
| 85 | -resource_pool: | ||
| 86 | - actor_rollout: [8, 6] | ||
| 87 | - ref: [2] | ||
| 88 | - reward: [] | ||
| @@ -1,92 +0,0 @@ | |||
| 1 | -defaults: | ||
| 2 | - - model: | ||
| 3 | - - qwen25-7b | ||
| 4 | - | ||
| 5 | -training: | ||
| 6 | - global_batch_size: 80 | ||
| 7 | - seq_length: 4096 | ||
| 8 | - tokenizer_type: PretrainedFromHF | ||
| 9 | - tokenizer_name_or_path: ./models/Qwen2.5-7B-Instruct | ||
| 10 | - train_iters: 100 | ||
| 11 | - distributed_backend: nccl | ||
| 12 | - no_shared_storage: true | ||
| 13 | - save_interval: 10 | ||
| 14 | - no_load_optim: true | ||
| 15 | - no_load_rng: true | ||
| 16 | - no_save_optim: true | ||
| 17 | - no_save_rng: true | ||
| 18 | - bf16: true | ||
| 19 | - is_instruction_dataset: true | ||
| 20 | - variable_seq_lengths: true | ||
| 21 | - no_shuffle: false | ||
| 22 | - stage: ray_grpo | ||
| 23 | - sequence_parallel: true | ||
| 24 | - dataset_additional_keys: labels categories | ||
| 25 | - | ||
| 26 | -actor_rollout_ref: | ||
| 27 | - actor_rollout: | ||
| 28 | - model: qwen25-7b | ||
| 29 | - do_sample: true | ||
| 30 | - micro_batch_size: 2 | ||
| 31 | - ppo_mini_batch_size: 80 | ||
| 32 | - num_samples_per_step: 1 | ||
| 33 | - temperature: 1.0 | ||
| 34 | - max_prompt_length: 2048 | ||
| 35 | - max-tokens-to-oom: 999999 | ||
| 36 | - ppo_epochs: 1 | ||
| 37 | - clip_ratio: 0.2 | ||
| 38 | - entropy_coeff: 0.001 | ||
| 39 | - shuffle_minibatch: false | ||
| 40 | - use_kv_cache: true | ||
| 41 | - tensor_model_parallel_size: 2 | ||
| 42 | - pipeline_model_parallel_size: 4 | ||
| 43 | - lr: 1e-6 | ||
| 44 | - lr_decay_style: constant | ||
| 45 | - min_lr: 0.0 | ||
| 46 | - weight_decay: 0.0 | ||
| 47 | - lr_warmup_fraction: 0.0 | ||
| 48 | - clip_grad: 10000.0 | ||
| 49 | - initial_loss_scale: 4096 | ||
| 50 | - finetune: true | ||
| 51 | - load: ./models/Qwen2.5-7B-Instruct-tp2-pp4 | ||
| 52 | - save: ./models/Qwen2.5-7B-Instruct-R1-Zero | ||
| 53 | - num_gpus_for_train: 8 | ||
| 54 | - num_gpus_for_infer: 40 | ||
| 55 | - data_path: 1,./dataset/pe_nlp,1,./dataset/dpo_en_zh | ||
| 56 | - dataset_category: 1,0 | ||
| 57 | - split: 100,0,0 | ||
| 58 | - n_samples_per_prompt: 4 | ||
| 59 | - | ||
| 60 | - ref: | ||
| 61 | - model: qwen25-7b | ||
| 62 | - tensor_model_parallel_size: 2 | ||
| 63 | - pipeline_model_parallel_size: 4 | ||
| 64 | - micro_batch_size: 8 | ||
| 65 | - load: ./models/Qwen2.5-7B-Instruct-tp2-pp4/ | ||
| 66 | - | ||
| 67 | -reward: | ||
| 68 | - model: qwen25-7b | ||
| 69 | - verifier: true | ||
| 70 | - tensor_model_parallel_size: 4 | ||
| 71 | - pipeline_model_parallel_size: 2 | ||
| 72 | - micro_batch_size: 8 | ||
| 73 | - load: ./models/Qwen2.5-7B-reward_tp4pp2/ | ||
| 74 | - | ||
| 75 | -algorithm: | ||
| 76 | - gamma: 1.0 | ||
| 77 | - lam: 0.95 | ||
| 78 | - adv_estimator: group_norm | ||
| 79 | - kl_penalty: kl | ||
| 80 | - kl_ctrl: | ||
| 81 | - type: fixed | ||
| 82 | - kl_coef: 0.05 | ||
| 83 | - missing_eos_penalty: 0.0 | ||
| 84 | - verifier_function: [ "acc"] | ||
| 85 | - verifier_weight: [ 1.0 ] | ||
| 86 | - advantage_whiten: False | ||
| 87 | - | ||
| 88 | -resource_pool: | ||
| 89 | - actor_rollout: [8,8,8,8,8,8] | ||
| 90 | - ref: [8] | ||
| 91 | - reward: [8] | ||
| 92 | - | ||
| @@ -1,91 +0,0 @@ | |||
| 1 | -defaults: | ||
| 2 | - - model: | ||
| 3 | - - qwen25-7b | ||
| 4 | - | ||
| 5 | -training: | ||
| 6 | - global_batch_size: 4 | ||
| 7 | - seq_length: 4096 | ||
| 8 | - tokenizer_type: PretrainedFromHF | ||
| 9 | - tokenizer_name_or_path: ./models/Qwen2.5-7B-Instruct | ||
| 10 | - train_iters: 100 | ||
| 11 | - distributed_backend: nccl | ||
| 12 | - no_shared_storage: true | ||
| 13 | - save_interval: 10 | ||
| 14 | - no_load_optim: true | ||
| 15 | - no_load_rng: true | ||
| 16 | - no_save_optim: true | ||
| 17 | - no_save_rng: true | ||
| 18 | - bf16: true | ||
| 19 | - is_instruction_dataset: true | ||
| 20 | - variable_seq_lengths: true | ||
| 21 | - no_shuffle: false | ||
| 22 | - stage: ray_grpo | ||
| 23 | - sequence_parallel: true | ||
| 24 | - dataset_additional_keys: labels categories | ||
| 25 | - | ||
| 26 | -actor_rollout_ref: | ||
| 27 | - actor_rollout: | ||
| 28 | - model: qwen25-7b | ||
| 29 | - do_sample: true | ||
| 30 | - micro_batch_size: 2 | ||
| 31 | - ppo_mini_batch_size: 4 | ||
| 32 | - num_samples_per_step: 2 | ||
| 33 | - temperature: 1.0 | ||
| 34 | - max_prompt_length: 2048 | ||
| 35 | - max-tokens-to-oom: 999999 | ||
| 36 | - ppo_epochs: 1 | ||
| 37 | - clip_ratio: 0.2 | ||
| 38 | - entropy_coeff: 0.001 | ||
| 39 | - shuffle_minibatch: false | ||
| 40 | - use_kv_cache: true | ||
| 41 | - tensor_model_parallel_size: 1 | ||
| 42 | - pipeline_model_parallel_size: 4 | ||
| 43 | - lr: 1e-6 | ||
| 44 | - lr_decay_style: constant | ||
| 45 | - min_lr: 0.0 | ||
| 46 | - weight_decay: 0.0 | ||
| 47 | - lr_warmup_fraction: 0.0 | ||
| 48 | - clip_grad: 10000.0 | ||
| 49 | - initial_loss_scale: 4096 | ||
| 50 | - finetune: true | ||
| 51 | - load: ./models/Qwen2.5-7B-Instruct-tp1-pp4 | ||
| 52 | - save: ./models/Qwen2.5-7B-Instruct-R1-Zero | ||
| 53 | - num_gpus_for_train: 4 | ||
| 54 | - num_gpus_for_infer: 2 | ||
| 55 | - data_path: ./pe_nlp/pe_nlp | ||
| 56 | - dataset_category: 1 | ||
| 57 | - split: 100,0,0 | ||
| 58 | - n_samples_per_prompt: 2 | ||
| 59 | - | ||
| 60 | - ref: | ||
| 61 | - model: qwen25-7b | ||
| 62 | - tensor_model_parallel_size: 1 | ||
| 63 | - pipeline_model_parallel_size: 1 | ||
| 64 | - micro_batch_size: 2 | ||
| 65 | - load: ./models/Qwen2.5-7B-Instruct-tp1-pp1/ | ||
| 66 | - | ||
| 67 | -reward: | ||
| 68 | - model: qwen25-7b | ||
| 69 | - verifier: true | ||
| 70 | - tensor_model_parallel_size: 1 | ||
| 71 | - pipeline_model_parallel_size: 1 | ||
| 72 | - micro_batch_size: 2 | ||
| 73 | - load: ./models/Qwen2.5-7B-reward_500iter_tp1pp1/ | ||
| 74 | - | ||
| 75 | -algorithm: | ||
| 76 | - gamma: 1.0 | ||
| 77 | - lam: 0.95 | ||
| 78 | - adv_estimator: group_norm | ||
| 79 | - kl_penalty: kl | ||
| 80 | - kl_ctrl: | ||
| 81 | - type: fixed | ||
| 82 | - kl_coef: 0.05 | ||
| 83 | - missing_eos_penalty: 0.0 | ||
| 84 | - verifier_function: [ "acc"] | ||
| 85 | - verifier_weight: [ 1.0 ] | ||
| 86 | - advantage_whiten: False | ||
| 87 | - | ||
| 88 | -resource_pool: | ||
| 89 | - actor_rollout: [6] | ||
| 90 | - ref: [1] | ||
| 91 | - reward: [] | ||
| @@ -1,147 +0,0 @@ | |||
| 1 | -# 后训练方法 Ray GRPO | ||
| 2 | - | ||
| 3 | -[Group Relative Policy Optimization (GRPO) ](https://arxiv.org/pdf/2402.03300)是 DeepSeek V2中提出的训练方法,它移除了 PPO 中对 Critic模型的依赖,而是使用对同一问题产生的多个采样输出的平均值作为奖励,从而大大减少了显存占用。 | ||
| 4 | - | ||
| 5 | -GRPO方法中包含了三个模型:Actor,Reference,Reward。其中Actor/Reference模型是经过预训练和指令微调(Supervised Fine-Tuning,SFT)得到的大语言模型,Reward是训练得到的奖励模型。GRPO 的训练目标是使得 Actor 模型的回答可以更加符合人类偏好。 | ||
| 6 | - | ||
| 7 | -# 使用说明 | ||
| 8 | - | ||
| 9 | -## 环境配置 | ||
| 10 | - | ||
| 11 | -配置MindSpeed-LLM基础环境: 参考[安装指南](./install_guide.md) | ||
| 12 | - | ||
| 13 | -## 数据预处理 | ||
| 14 | - | ||
| 15 | -数据集转换参考脚本:MindSpeed-LLM/examples/mcore/llama3/data_convert_llama3_ppo.sh | ||
| 16 | -以 [descriptiveness 数据集](https://huggingface.co/datasets/trl-internal-testing/descriptiveness-sentiment-trl-style/tree/main/data) 为例。 | ||
| 17 | - | ||
| 18 | -```bash | ||
| 19 | -source /usr/local/Ascend/ascend-toolkit/set_env.sh | ||
| 20 | -mkdir ./dataset/llama3-hf/ | ||
| 21 | - | ||
| 22 | -python ./preprocess_data.py \ | ||
| 23 | - --input ./dataset/descriptiveness-00000-of-00001.parquet \ | ||
| 24 | - --tokenizer-name-or-path ./model_from_hf/llama3-hf/ \ | ||
| 25 | - --output-prefix ./dataset/llama3-hf/descriptiveness \ | ||
| 26 | - --workers 16 \ | ||
| 27 | - --log-interval 1000 \ | ||
| 28 | - --tokenizer-type PretrainedFromHF \ | ||
| 29 | - --handler-name PPOAlpacaStyleInstructionHandler \ | ||
| 30 | - --prompt-type llama3 \ | ||
| 31 | - --map-keys '{"prompt":"prompt", "query":"", "response": "prompt", "system":""}' | ||
| 32 | -``` | ||
| 33 | - | ||
| 34 | -## 模型权重转换 | ||
| 35 | - | ||
| 36 | -根据 GRPO 算法要求,Actor 和 Reference 模型应该使用 SFT 微调后的模型进行初始化,Reward 模型应该使用奖励模型训练后的模型进行初始化。GRPO 算法模型权重均使用Megatron-mcore格式,其他格式的权重需要进行模型权重转换,具体可参考[权重转换](./checkpoint.md)。 | ||
| 37 | - | ||
| 38 | -下面以llama3.2-1b模型作为示例参考: | ||
| 39 | - | ||
| 40 | -actor_rollout_ref 涉及到的actor_rollout 与 ref 均需要 SFT 微调后的模型,涉及到的权重转换操作与 SFT 阶段的一致。权重转换示例脚本: | ||
| 41 | -<a href="../../examples/mcore/llama32/ckpt_convert_llama32_hf2mcore.sh">llama32-1b</a> | ||
| 42 | - | ||
| 43 | -reward 模型需要使用奖励模型训练后的模型,权重转换示例脚本:<td><a href="../../examples/mcore/llama32/ckpt_convert_llama32_hf2mcore_orm.sh">llama32-1b-orm</a></td> | ||
| 44 | - | ||
| 45 | - | ||
| 46 | -相应的ppo_trainer_llama32_1b.yaml配置如下 | ||
| 47 | -``` | ||
| 48 | - actor_rollout_ref: | ||
| 49 | - actor_rollout: | ||
| 50 | - ... | ||
| 51 | - load: ./model_weights/llama32-mcore/ | ||
| 52 | - save: ./model_weights/llama32-mcore-save/ | ||
| 53 | - | ||
| 54 | - ref: | ||
| 55 | - ... | ||
| 56 | - load: ./model_weights/llama32-mcore/ | ||
| 57 | - | ||
| 58 | - reward: | ||
| 59 | - ... | ||
| 60 | - load: ./model_weights/llama32-mcore-orm/ | ||
| 61 | -``` | ||
| 62 | - | ||
| 63 | -## 启动方式 | ||
| 64 | - | ||
| 65 | -### 单机 | ||
| 66 | - | ||
| 67 | -通过 --config-name 传递选取的 config 文件名(不添加.yaml后缀),可以通过下列命令直接启动训练(Llama32 1B 模型可单机运行)。 | ||
| 68 | -目前已支持的配置文件放置在 configs/rlxf/ 文件夹下。配置文件的具体说明见下文。 | ||
| 69 | - | ||
| 70 | -```bash | ||
| 71 | -python ray_gpt.py --config-name grpo_trainer_llama32_1b | ||
| 72 | -``` | ||
| 73 | - | ||
| 74 | -### 多机 | ||
| 75 | - | ||
| 76 | -多机运行程序时,需要首先进入对应目录,并激活conda或docker环境: | ||
| 77 | - | ||
| 78 | -```bash | ||
| 79 | -cd MindSpeed-LLM | ||
| 80 | -conda activate xxx | ||
| 81 | -``` | ||
| 82 | - | ||
| 83 | -然后,在主节点上启动 Ray 集群: | ||
| 84 | - | ||
| 85 | -```bash | ||
| 86 | -# 创建一个集群,端口6344,dashboard端口8260,有8个NPU | ||
| 87 | -ray start --head --port 6344 --dashboard-host=0.0.0.0 --dashboard-port=8260 --resources='{"NPU": 8}' | ||
| 88 | -``` | ||
| 89 | - | ||
| 90 | -随后,在其他节点加入主节点的集群 | ||
| 91 | - | ||
| 92 | -```bash | ||
| 93 | -# IP_ADDRESS 处填写主节点 IP 地址 | ||
| 94 | -ray start --address="IP_ADDRESS:6344" --resources='{"NPU": 8}' | ||
| 95 | -``` | ||
| 96 | - | ||
| 97 | -在完成 Ray 集群构建后,在主节点启动运行程序即可(Llama3 8B 模型可双机运行) | ||
| 98 | - | ||
| 99 | -```bash | ||
| 100 | -python ray_gpt.py --config-name grpo_trainer_llama3_8b | ||
| 101 | -``` | ||
| 102 | - | ||
| 103 | -## 配置文件 | ||
| 104 | - | ||
| 105 | -由于 GRPO 训练过程中涉及 3 个模型,通过将模型参数和训练配置解耦的层级化参数配置,来简化 GRPO 训练的参数配置过程。RLXF 训练涉及到的所有配置文件均存储在 configs/rlxf 路径下,其中 model 文件夹下存储了模型结构相关的配置文件,GRPO训练相关的模型参数文件以grpo_{模型名}.yaml方式命名。 | ||
| 106 | - | ||
| 107 | -在每个 grpo_trainer 配置文件中,需要包含defaults,training,resource_pool,algorithm等字段,以及 GRPO 训练过程中涉及到的 3 个角色 actor,reward,ref的配置。其中: | ||
| 108 | - | ||
| 109 | -1. defaults 负责引入模型配置文件,在 defaults 中应列举本配置文件中所需要用到的所有模型配置,模型配置可以在下方3个角色的具体配置中通过 model 字段进行选择。 | ||
| 110 | -2. training 字段设置的参数为所有 3 个角色通用的默认参数,这些参数可以在下方进一步被角色的单独配置所覆盖。 | ||
| 111 | -3. resource_pool 字段指定了各个角色所需的 NPU 资源数量。 | ||
| 112 | -4. actor,reward,ref 字段分别指定了GRPO算法中三个角色训练相关的参数配置。 | ||
| 113 | - | ||
| 114 | -## 参数解析 | ||
| 115 | - | ||
| 116 | -相较于普通模型训练,GRPO增加一些特殊参数: | ||
| 117 | - | ||
| 118 | -### `training:` | ||
| 119 | - | ||
| 120 | -* `stage`:用于指定训练算法,使用 Ray GRPO 训练须设置为`ray_grpo`; | ||
| 121 | - | ||
| 122 | -### `actor_rollout:` | ||
| 123 | - | ||
| 124 | -* `do_sample`:控制 Actor 模型进行推理时是否采样,默认为 False,GRPO 需要设置为True ; | ||
| 125 | -* `ppo_mini_batch_size`:Actor 模型的 mini_batch_size,默认为1; | ||
| 126 | -* `max_prompt_length`:GRPO 训练中最大 prompt 长度,默认为512; | ||
| 127 | -* `num_samples_per_step`:Actor 推理时每个step的推理样本数量,默认为1; | ||
| 128 | -* `ppo_epochs`:Actor 训练对同一批经验数据的重复次数,默认为1; | ||
| 129 | -* `clip_ratio`:Actor模型训练计算损失函数时的clip比例,默认为0.2 一般取值范围 [0.1,0.3] 最大取值范围[0,1] 该数值越大允许策略更新的幅度越大,反之不然; | ||
| 130 | -* `shuffle_minibatch`:Actor 训练时是否对 minibatch 进行 shuffle,默认为 False; | ||
| 131 | -* `num_gpus_for_train` :Actor 模型分配给训练部分的显卡数量; | ||
| 132 | -* `num_gpus_for_infer` :Actor 模型分配给推理部分的显卡数量; | ||
| 133 | -* `missing_eos_penalty`:缺少序列结束符EOS时的惩罚系数; | ||
| 134 | -* `n_samples_per_prompt`:每条prompt的重用次数,代表GRPO训练流程里每个Group的数据量,默认为1; | ||
| 135 | - | ||
| 136 | -### `resource_pool:` | ||
| 137 | - | ||
| 138 | -* `actor_rollout`:给 Actor 模型训练和推理总共分配的显卡数量; | ||
| 139 | -* `ref`:给 Reference 模型分配的显卡数量; | ||
| 140 | -* `reward`:给 Reward 模型分配的显卡数量; | ||
| 141 | - | ||
| 142 | -# 精度对比 | ||
| 143 | - | ||
| 144 | -我们与强化学习开源仓库 [OpenRLHF](https://github.com/OpenRLHF/OpenRLHF) 进行了精度对比,来辅助验证算法实现的正确性。因为 GRPO group_norm的特性需求,推理状态do sample 设置为 True,为了与基准方法进行精度对齐,在 Actor 推理时固定 responses 方式进行精度对齐的实验。可以看到,固定 responses 后 loss 能够较好地实现对齐。 | ||
| 145 | - | ||
| 146 | - | ||
| 147 | - | ||