|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# usage: bash examples/on_policy_distillation/run-qwen3-8B-opd.sh |
| 4 | + |
| 5 | +set -ex |
| 6 | + |
| 7 | + |
| 8 | +# Start the teacher model server |
| 9 | +TEACHER_IP="127.0.0.1" # Use localhost here, you can change it to your IP |
| 10 | +TEACHER_PORT=13141 |
| 11 | +LOG_FILE="/tmp/sglang_$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 6).log" |
| 12 | + |
| 13 | +## Launch the teacher model server in the background |
| 14 | +CUDA_VISIBLE_DEVICES=7 python3 -m sglang.launch_server \ |
| 15 | + --model-path /root/Qwen3-32B \ |
| 16 | + --host 0.0.0.0 \ |
| 17 | + --port $TEACHER_PORT \ |
| 18 | + --tp 1 \ |
| 19 | + --chunked-prefill-size 4096 \ |
| 20 | + --mem-fraction-static 0.6 \ |
| 21 | + > "$LOG_FILE" 2>&1 & |
| 22 | + |
| 23 | +echo "Starting teacher model server..." |
| 24 | + |
| 25 | +## Wait for the teacher model server to be ready |
| 26 | +until curl -sf http://$TEACHER_IP:$TEACHER_PORT/health_generate > /dev/null; do |
| 27 | + echo "Waiting for the teacher model server to start..." |
| 28 | + tail -n 10 "$LOG_FILE" |
| 29 | + sleep 5 |
| 30 | +done |
| 31 | + |
| 32 | +echo "Teacher model server is up and running at $TEACHER_IP:$TEACHER_PORT." |
| 33 | +sleep 10 |
| 34 | + |
| 35 | + |
| 36 | +export PYTHONBUFFERED=16 |
| 37 | + |
| 38 | +NVLINK_COUNT=$(nvidia-smi topo -m 2>/dev/null | grep -o 'NV[0-9][0-9]*' | wc -l) |
| 39 | +if [ "$NVLINK_COUNT" -gt 0 ]; then |
| 40 | + HAS_NVLINK=1 |
| 41 | +else |
| 42 | + HAS_NVLINK=0 |
| 43 | +fi |
| 44 | +echo "HAS_NVLINK: $HAS_NVLINK (detected $NVLINK_COUNT NVLink references)" |
| 45 | + |
| 46 | +source "/root/slime/scripts/models/qwen3-8B.sh" |
| 47 | + |
| 48 | + |
| 49 | +CKPT_ARGS=( |
| 50 | + --hf-checkpoint /root/Qwen3-8B |
| 51 | + --ref-load /root/Qwen3-8B_torch_dist |
| 52 | + --load /root/Qwen3-8B_slime/ |
| 53 | + --save /root/Qwen3-8B_slime/ |
| 54 | + --save-interval 20 |
| 55 | +) |
| 56 | + |
| 57 | +ROLLOUT_ARGS=( |
| 58 | + --prompt-data /root/dapo-math-17k/dapo-math-17k.jsonl |
| 59 | + --input-key prompt |
| 60 | + --apply-chat-template |
| 61 | + --rollout-shuffle |
| 62 | + --num-rollout 300 |
| 63 | + --rollout-batch-size 16 |
| 64 | + --n-samples-per-prompt 4 |
| 65 | + --rollout-max-response-len 16384 |
| 66 | + --rollout-temperature 0.8 |
| 67 | + |
| 68 | + --global-batch-size 64 |
| 69 | + --balance-data |
| 70 | +) |
| 71 | + |
| 72 | +RM_ARGS=( |
| 73 | + --custom-rm-path examples.on_policy_distillation.on_policy_distillation.reward_func |
| 74 | + --custom-reward-post-process-path examples.on_policy_distillation.on_policy_distillation.post_process_rewards |
| 75 | + --rm-url http://$TEACHER_IP:$TEACHER_PORT/generate |
| 76 | +) |
| 77 | + |
| 78 | +EVAL_ARGS=( |
| 79 | + # --eval-interval 20 |
| 80 | + # --eval-prompt-data aime ${DATA_DIR}/aime-2024/aime-2024.jsonl |
| 81 | + # --n-samples-per-eval-prompt 16 |
| 82 | + # --eval-max-response-len 16384 |
| 83 | + # --eval-top-p 0.7 |
| 84 | +) |
| 85 | + |
| 86 | +PERF_ARGS=( |
| 87 | + --tensor-model-parallel-size 2 |
| 88 | + --sequence-parallel |
| 89 | + --pipeline-model-parallel-size 1 |
| 90 | + --context-parallel-size 1 |
| 91 | + --expert-model-parallel-size 1 |
| 92 | + --expert-tensor-parallel-size 1 |
| 93 | + |
| 94 | + --recompute-granularity full |
| 95 | + --recompute-method uniform |
| 96 | + --recompute-num-layers 1 |
| 97 | + |
| 98 | + # --micro-batch-size 1 |
| 99 | + --use-dynamic-batch-size |
| 100 | + --max-tokens-per-gpu 16384 |
| 101 | +) |
| 102 | + |
| 103 | +GRPO_ARGS=( |
| 104 | + --advantage-estimator on_policy_distillation |
| 105 | + --use-kl-loss |
| 106 | + --kl-loss-coef 0.00 |
| 107 | + --kl-loss-type low_var_kl |
| 108 | + --entropy-coef 0.00 |
| 109 | +) |
| 110 | + |
| 111 | +OPTIMIZER_ARGS=( |
| 112 | + --optimizer adam |
| 113 | + --lr 1e-6 |
| 114 | + --lr-decay-style constant |
| 115 | + --weight-decay 0.1 |
| 116 | + --adam-beta1 0.9 |
| 117 | + --adam-beta2 0.98 |
| 118 | +) |
| 119 | + |
| 120 | +WANDB_ARGS=( |
| 121 | + #--use-wandb |
| 122 | + # --wandb-project slime-dev |
| 123 | + # --wandb-group qwen3-8B-test |
| 124 | + # --wandb-key ${WANDB_KEY} |
| 125 | +) |
| 126 | + |
| 127 | +SGLANG_ARGS=( |
| 128 | + --rollout-num-gpus-per-engine 1 |
| 129 | + --sglang-mem-fraction-static 0.4 |
| 130 | +) |
| 131 | + |
| 132 | + |
| 133 | +MISC_ARGS=( |
| 134 | + --attention-dropout 0.0 |
| 135 | + --hidden-dropout 0.0 |
| 136 | + --accumulate-allreduce-grads-in-fp32 |
| 137 | + --attention-softmax-in-fp32 |
| 138 | + --attention-backend flash |
| 139 | +) |
| 140 | + |
| 141 | + |
| 142 | + |
| 143 | + |
| 144 | +# launch the master node of ray in container |
| 145 | +export MASTER_ADDR=${MASTER_ADDR:-"127.0.0.1"} |
| 146 | +ray start --head --node-ip-address ${MASTER_ADDR} --num-gpus 8 --disable-usage-stats --dashboard-host=0.0.0.0 --dashboard-port=8265 |
| 147 | + |
| 148 | + |
| 149 | +ray job submit --address="http://127.0.0.1:8265" \ |
| 150 | + --runtime-env-json='{ |
| 151 | + "env_vars": { |
| 152 | + "PYTHONPATH": "/root/Megatron-LM/", |
| 153 | + "CUDA_DEVICE_MAX_CONNECTIONS": "1" |
| 154 | + } |
| 155 | + }' \ |
| 156 | + -- python3 train.py \ |
| 157 | + --actor-num-nodes 1 \ |
| 158 | + --actor-num-gpus-per-node 2 \ |
| 159 | + --rollout-num-gpus 4 \ |
| 160 | + ${MODEL_ARGS[@]} \ |
| 161 | + ${CKPT_ARGS[@]} \ |
| 162 | + ${ROLLOUT_ARGS[@]} \ |
| 163 | + ${OPTIMIZER_ARGS[@]} \ |
| 164 | + ${GRPO_ARGS[@]} \ |
| 165 | + ${WANDB_ARGS[@]} \ |
| 166 | + ${PERF_ARGS[@]} \ |
| 167 | + ${EVAL_ARGS[@]} \ |
| 168 | + ${SGLANG_ARGS[@]} \ |
| 169 | + ${MISC_ARGS[@]} \ |
| 170 | + ${RM_ARGS[@]} |
| 171 | + |
| 172 | + |
| 173 | + |
| 174 | +####clear after training |
| 175 | +pkill -9 sglang |
| 176 | +sleep 3 |
| 177 | +ray stop --force |
| 178 | +pkill -9 ray |
| 179 | +pkill -9 python |
| 180 | +sleep 3 |
| 181 | +pkill -9 ray |
| 182 | +pkill -9 python |
| 183 | + |
| 184 | + |
| 185 | + |
| 186 | + |
| 187 | + |
| 188 | + |
| 189 | + |
| 190 | + |
| 191 | + |
| 192 | + |
0 commit comments