|
| 1 | +# work_path: PaddleLLM/llm/alignment/ppo |
| 2 | +# reinforce_plus_plus 训练 |
| 3 | +model_name=$1 |
| 4 | +ngpus=${2:-8} |
| 5 | +steps=${3:-2} |
| 6 | +ext_args="" |
| 7 | + |
| 8 | +# 1. 模型准备 |
| 9 | +echo "清理显存" |
| 10 | +# fuser -v /dev/nvidia* 2>/dev/null | awk '{for(i=1;i<=NF;i++) if ($i ~ /^[0-9]+$/) print $i}' | xargs kill -9 2>/dev/null |
| 11 | +sleep 3s |
| 12 | +echo "清理Checkpoints" |
| 13 | +rm -rf ../../checkpoints/${model_name}/reinforce_plus_plus/* 2>/dev/null |
| 14 | + |
| 15 | +if [[ ${model_name} == "qwen" ]]; then |
| 16 | + model_name_or_path="Qwen/Qwen2.5-1.5B" |
| 17 | +elif [[ ${model_name} == "llama" ]]; then |
| 18 | + model_name_or_path="meta-llama/Meta-Llama-3-8B" |
| 19 | +fi |
| 20 | + |
| 21 | +output_dir="../../checkpoints/${model_name}/reinforce_plus_plus" # 以llm为根目录 |
| 22 | + |
| 23 | +# 2. 数据准备 |
| 24 | +if [ ! -d "ppo-kk" ]; then |
| 25 | + wget https://paddlenlp.bj.bcebos.com/datasets/examples/ppo-kk.tgz && tar zxf ppo-kk.tgz |
| 26 | +fi |
| 27 | + |
| 28 | +# 3. 设置环境变量 |
| 29 | +if [ $ngpus -eq 0 ]; then |
| 30 | + DEVICE="0" |
| 31 | +elif [ $ngpus -eq 1 ]; then |
| 32 | + DEVICE="1" |
| 33 | +elif [ $ngpus -eq 2 ]; then |
| 34 | + DEVICE="2,3" |
| 35 | +elif [ $ngpus -eq 4 ]; then |
| 36 | + DEVICE="4,5,6,7" |
| 37 | +elif [ $ngpus -eq 8 ]; then |
| 38 | + DEVICE="0,1,2,3,4,5,6,7" |
| 39 | +else |
| 40 | + echo "Unsupported number of GPUs" |
| 41 | + exit 1 |
| 42 | +fi |
| 43 | +export CUDA_VISIBLE_DEVICES=${DEVICE} |
| 44 | +current_path=$(pwd) |
| 45 | +repo_path=${current_path%%PaddleLLM*}PaddleLLM |
| 46 | +llm_path=${repo_path}/llm |
| 47 | +export PYTHONPATH=$repo_path:$PYTHONPATH |
| 48 | +export PYTHONPATH=$llm_path:$PYTHONPATH |
| 49 | + |
| 50 | +# 4. 启动训练脚本 |
| 51 | +echo "启动reward服务" |
| 52 | +cd reward |
| 53 | +python reward_server.py > reward_server.log 2>&1 & |
| 54 | +cd .. |
| 55 | +echo "开始训练:" |
| 56 | + |
| 57 | +python -u -m paddle.distributed.launch --devices "0,1,2,3,4,5,6,7" run_ppo.py ../../config/${model_name}/grpo_argument.json \ |
| 58 | + --train_datasets "ppo-kk/34567ppl/train.jsonl" \ |
| 59 | + --eval_datasets "ppo-kk/5ppl/test.jsonl" \ |
| 60 | + --label_key tgt \ |
| 61 | + --rl_algorithm reinforce_plus_plus \ |
| 62 | + --normalize_advantage 0 \ |
| 63 | + --normalize_reward 1 \ |
| 64 | + --actor_model_name_or_path ${model_name_or_path} \ |
| 65 | + --reward_model_name_or_path "" \ |
| 66 | + --output_dir ${output_dir} \ |
| 67 | + --max_steps ${steps} \ |
| 68 | + --save_steps ${steps} \ |
| 69 | + --tensor_parallel_degree 2 \ |
| 70 | + --per_device_prompt_batch_size 1 \ |
| 71 | + --per_device_train_batch_size 8 \ |
| 72 | + --max_length 1024 \ |
| 73 | + --max_prompt_len 512 \ |
| 74 | + --pipeline_parallel_degree 1 \ |
| 75 | + --sharding_parallel_degree 4 \ |
| 76 | + --sharding "stage1" \ |
| 77 | + --recompute 1 \ |
| 78 | + ${ext_args} |
| 79 | + |
| 80 | +echo "热启" |
| 81 | +python -u -m paddle.distributed.launch --devices "0,1,2,3,4,5,6,7" run_ppo.py ../../config/${model_name}/grpo_argument.json \ |
| 82 | + --train_datasets "ppo-kk/34567ppl/train.jsonl" \ |
| 83 | + --eval_datasets "ppo-kk/5ppl/test.jsonl" \ |
| 84 | + --label_key tgt \ |
| 85 | + --rl_algorithm reinforce_plus_plus \ |
| 86 | + --normalize_advantage 0 \ |
| 87 | + --normalize_reward 1 \ |
| 88 | + --actor_model_name_or_path ${model_name_or_path} \ |
| 89 | + --reward_model_name_or_path "" \ |
| 90 | + --output_dir ${output_dir} \ |
| 91 | + --max_steps 1 \ |
| 92 | + --save_steps 11 \ |
| 93 | + --tensor_parallel_degree 2 \ |
| 94 | + --per_device_prompt_batch_size 1 \ |
| 95 | + --per_device_train_batch_size 8 \ |
| 96 | + --max_length 1024 \ |
| 97 | + --max_prompt_len 512 \ |
| 98 | + --pipeline_parallel_degree 1 \ |
| 99 | + --sharding_parallel_degree 4 \ |
| 100 | + --sharding "stage1" \ |
| 101 | + --recompute 1 \ |
| 102 | + ${ext_args} |
| 103 | + |
| 104 | +echo "kill reward 服务" |
| 105 | +pkill -9 -f reward_server.py |
0 commit comments