|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# for rerun the task |
| 4 | +pkill -9 sglang |
| 5 | +sleep 3 |
| 6 | +ray stop --force |
| 7 | +pkill -9 ray |
| 8 | +pkill -9 python |
| 9 | +sleep 3 |
| 10 | +pkill -9 ray |
| 11 | +pkill -9 python |
| 12 | + |
| 13 | +set -ex |
| 14 | + |
| 15 | +# if base folder not set raise error |
| 16 | +if [ -z "${BASE_FOLDER}" ]; then |
| 17 | + echo "BASE_FOLDER is not set. Please set it to the base directory of your checkpoints." |
| 18 | + exit 1 |
| 19 | +fi |
| 20 | + |
| 21 | +if [ -z "${MASTER_ADDR}" ]; then |
| 22 | + echo "MASTER_ADDR is not set. Please set it to the master node address." |
| 23 | + exit 1 |
| 24 | +fi |
| 25 | + |
| 26 | +# will prevent ray from buffering stdout/stderr |
| 27 | +export PYTHONBUFFERED=16 |
| 28 | + |
| 29 | +NVLINK_COUNT=$(nvidia-smi topo -m 2>/dev/null | grep -o 'NV[0-9][0-9]*' | wc -l) |
| 30 | +if [ "$NVLINK_COUNT" -gt 0 ]; then |
| 31 | + HAS_NVLINK=1 |
| 32 | +else |
| 33 | + HAS_NVLINK=0 |
| 34 | +fi |
| 35 | +echo "HAS_NVLINK: $HAS_NVLINK (detected $NVLINK_COUNT NVLink references)" |
| 36 | + |
| 37 | +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" |
| 38 | +source "${SCRIPT_DIR}/models/qwen3-next-80B-A3B.sh" |
| 39 | + |
| 40 | +CKPT_ARGS=( |
| 41 | + --hf-checkpoint ${BASE_FOLDER}/Qwen3-Next-80B-A3B-Thinking |
| 42 | + --ref-load ${BASE_FOLDER}/Qwen3-Next-80B-A3B-Thinking_torch_dist |
| 43 | + --load ${BASE_FOLDER}/Qwen3-Next-80B-A3B-Thinking_slime/ |
| 44 | + --save ${BASE_FOLDER}/Qwen3-Next-80B-A3B-Thinking_slime/ |
| 45 | + --save-interval 20 |
| 46 | +) |
| 47 | + |
| 48 | +ROLLOUT_ARGS=( |
| 49 | + --prompt-data ${BASE_FOLDER}/dapo-math-17k/dapo-math-17k.jsonl |
| 50 | + --input-key prompt |
| 51 | + --label-key label |
| 52 | + --apply-chat-template |
| 53 | + --rollout-shuffle |
| 54 | + --rm-type deepscaler |
| 55 | + --num-rollout 300 |
| 56 | + --rollout-batch-size 16 |
| 57 | + --n-samples-per-prompt 4 |
| 58 | + --rollout-max-response-len 8192 |
| 59 | + --rollout-temperature 0.8 |
| 60 | + |
| 61 | + --global-batch-size 64 |
| 62 | + --balance-data |
| 63 | +) |
| 64 | + |
| 65 | +EVAL_ARGS=( |
| 66 | + --eval-interval 20 |
| 67 | + --eval-prompt-data aime ${BASE_FOLDER}/aime-2024/aime-2024.jsonl |
| 68 | + --n-samples-per-eval-prompt 2 |
| 69 | + --eval-max-response-len 16384 |
| 70 | + --eval-top-p 0.7 |
| 71 | +) |
| 72 | + |
| 73 | +PERF_ARGS=( |
| 74 | + --tensor-model-parallel-size 1 |
| 75 | + --sequence-parallel |
| 76 | + --pipeline-model-parallel-size 6 |
| 77 | + --context-parallel-size 1 |
| 78 | + --expert-model-parallel-size 1 |
| 79 | + --expert-tensor-parallel-size 1 |
| 80 | + |
| 81 | + --recompute-granularity full |
| 82 | + --recompute-method uniform |
| 83 | + --recompute-num-layers 1 |
| 84 | + |
| 85 | + # --micro-batch-size 1 |
| 86 | + --use-dynamic-batch-size |
| 87 | + --max-tokens-per-gpu 2048 |
| 88 | +) |
| 89 | + |
| 90 | +GRPO_ARGS=( |
| 91 | + --advantage-estimator gspo |
| 92 | + #--use-kl-loss |
| 93 | + --kl-loss-coef 0.00 |
| 94 | + --kl-loss-type low_var_kl |
| 95 | + --kl-coef 0.00 |
| 96 | + --entropy-coef 0.00 |
| 97 | + --eps-clip 4e-4 |
| 98 | +) |
| 99 | + |
| 100 | +OPTIMIZER_ARGS=( |
| 101 | + --optimizer adam |
| 102 | + --lr 1e-6 |
| 103 | + --lr-decay-style constant |
| 104 | + --weight-decay 0.1 |
| 105 | + --adam-beta1 0.9 |
| 106 | + --adam-beta2 0.98 |
| 107 | + |
| 108 | + --optimizer-cpu-offload |
| 109 | + --overlap-cpu-optimizer-d2h-h2d |
| 110 | + --use-precision-aware-optimizer |
| 111 | +) |
| 112 | + |
| 113 | +WANDB_ARGS=( |
| 114 | +# --use-wandb |
| 115 | +# --wandb-project slime-dev |
| 116 | +# --wandb-group qwen3-next-80B-A3B-test |
| 117 | +# --wandb-key ${WANDB_KEY} |
| 118 | +) |
| 119 | + |
| 120 | +SGLANG_ARGS=( |
| 121 | + --rollout-num-gpus-per-engine 2 |
| 122 | + --rollout-num-gpus 2 |
| 123 | + --sglang-mem-fraction-static 0.8 |
| 124 | + --sglang-ep-size 1 |
| 125 | + |
| 126 | + --sglang-cuda-graph-bs 1 2 4 8 $(seq 16 8 128) |
| 127 | + |
| 128 | + # mtp |
| 129 | +# --sglang-speculative-algorithm EAGLE |
| 130 | +# --sglang-speculative-num-steps 2 |
| 131 | +# --sglang-speculative-eagle-topk 1 |
| 132 | +# --sglang-speculative-num-draft-tokens 3 |
| 133 | +# --sglang-enable-draft-weights-cpu-backup |
| 134 | +# |
| 135 | +# --sglang-max-running-requests 512 |
| 136 | +) |
| 137 | + |
| 138 | +MISC_ARGS=( |
| 139 | + # default dropout in megatron is 0.1 |
| 140 | + --attention-dropout 0.0 |
| 141 | + --hidden-dropout 0.0 |
| 142 | + # should be good for model performance |
| 143 | + --accumulate-allreduce-grads-in-fp32 |
| 144 | +# --grad-reduce-in-bf16 |
| 145 | + --attention-softmax-in-fp32 |
| 146 | + # need to comment this when using model with MLA |
| 147 | + --attention-backend flash |
| 148 | + |
| 149 | + --moe-token-dispatcher-type alltoall |
| 150 | +# --moe-enable-deepep |
| 151 | +# --debug-rollout-only |
| 152 | +) |
| 153 | + |
| 154 | +# launch the master node of ray in container |
| 155 | +export no_proxy="127.0.0.1,${MASTER_ADDR}" |
| 156 | +ray start --head --node-ip-address ${MASTER_ADDR} --num-gpus 8 --disable-usage-stats --dashboard-host=0.0.0.0 --dashboard-port=8265 |
| 157 | +for WORKER_IP in $(awk '{print $1}' /root/mpi_rack_hostfile); do |
| 158 | + if [[ "$WORKER_IP" == "$MLP_WORKER_0_HOST" ]]; then |
| 159 | + continue |
| 160 | + fi |
| 161 | + echo "Starting Ray worker on ${WORKER_IP}" |
| 162 | + ssh root@"${WORKER_IP}" \ |
| 163 | + "pkill -9 sglang ; ray stop --force ; pkill -9 python ; ray start --address=${MASTER_ADDR}:6379 --num-gpus 8 --node-ip-address ${WORKER_IP} --disable-usage-stats --dashboard-host=0.0.0.0 --dashboard-port=8265" & |
| 164 | +done |
| 165 | +wait |
| 166 | + |
| 167 | +# Build the runtime environment JSON with proper variable substitution |
| 168 | +RUNTIME_ENV_JSON="{ |
| 169 | + \"env_vars\": { |
| 170 | + \"PYTHONPATH\": \"/root/Megatron-LM/\", |
| 171 | + \"CUDA_DEVICE_MAX_CONNECTIONS\": \"1\", |
| 172 | + \"NCCL_NVLS_ENABLE\": \"${HAS_NVLINK}\", |
| 173 | + \"no_proxy\": \"${no_proxy}\", |
| 174 | + \"MASTER_ADDR\": \"${MASTER_ADDR}\" |
| 175 | + } |
| 176 | +}" |
| 177 | + |
| 178 | +ray job submit --address="http://127.0.0.1:8265" \ |
| 179 | + --runtime-env-json="${RUNTIME_ENV_JSON}" \ |
| 180 | + -- python3 train.py \ |
| 181 | + --actor-num-nodes 1 \ |
| 182 | + --actor-num-gpus-per-node 6 \ |
| 183 | + ${MODEL_ARGS[@]} \ |
| 184 | + ${CKPT_ARGS[@]} \ |
| 185 | + ${ROLLOUT_ARGS[@]} \ |
| 186 | + ${OPTIMIZER_ARGS[@]} \ |
| 187 | + ${GRPO_ARGS[@]} \ |
| 188 | + ${WANDB_ARGS[@]} \ |
| 189 | + ${PERF_ARGS[@]} \ |
| 190 | + ${EVAL_ARGS[@]} \ |
| 191 | + ${SGLANG_ARGS[@]} \ |
| 192 | + ${MISC_ARGS[@]} |
0 commit comments