|
| 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 | +# will prevent ray from buffering stdout/stderr |
| 16 | +export PYTHONBUFFERED=16 |
| 17 | + |
| 18 | +# unset proxy to avoid issues |
| 19 | +unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY |
| 20 | + |
| 21 | +NVLINK_COUNT=$(nvidia-smi topo -m 2>/dev/null | grep -o 'NV[0-9][0-9]*' | wc -l) |
| 22 | +if [ "$NVLINK_COUNT" -gt 0 ]; then |
| 23 | + HAS_NVLINK=1 |
| 24 | +else |
| 25 | + HAS_NVLINK=0 |
| 26 | +fi |
| 27 | +echo "HAS_NVLINK: $HAS_NVLINK (detected $NVLINK_COUNT NVLink references)" |
| 28 | + |
| 29 | +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" |
| 30 | +source "${SCRIPT_DIR}/models/qwen3.5-27B.sh" |
| 31 | + |
| 32 | +CKPT_ARGS=( |
| 33 | + --hf-checkpoint /root/Qwen3.5-27B |
| 34 | + --ref-load /root/Qwen3.5-27B_torch_dist/ |
| 35 | + --load /root/Qwen3.5-27B_slime |
| 36 | + --save /root/Qwen3.5-27B_slime |
| 37 | + --save-interval 20 |
| 38 | +) |
| 39 | + |
| 40 | +ROLLOUT_ARGS=( |
| 41 | + --prompt-data /root/dapo-math-17k/dapo-math-17k.jsonl |
| 42 | + --input-key prompt |
| 43 | + --label-key label |
| 44 | + --apply-chat-template |
| 45 | + --rollout-shuffle |
| 46 | + --rm-type deepscaler |
| 47 | + --num-rollout 3000 |
| 48 | + --rollout-batch-size 32 |
| 49 | + --n-samples-per-prompt 8 |
| 50 | + --rollout-max-response-len 8192 |
| 51 | + --rollout-temperature 1 |
| 52 | + |
| 53 | + --global-batch-size 256 |
| 54 | + --balance-data |
| 55 | +) |
| 56 | + |
| 57 | +EVAL_ARGS=( |
| 58 | + --eval-interval 20 |
| 59 | + --eval-prompt-data aime /root/aime-2024/aime-2024.jsonl |
| 60 | + --n-samples-per-eval-prompt 16 |
| 61 | + --eval-max-response-len 16384 |
| 62 | + --eval-top-p 1 |
| 63 | +) |
| 64 | + |
| 65 | +PERF_ARGS=( |
| 66 | + --tensor-model-parallel-size 4 |
| 67 | + --sequence-parallel |
| 68 | + --pipeline-model-parallel-size 1 |
| 69 | + --context-parallel-size 1 |
| 70 | + --expert-model-parallel-size 1 |
| 71 | + --expert-tensor-parallel-size 1 |
| 72 | + |
| 73 | + --recompute-granularity full |
| 74 | + --recompute-method uniform |
| 75 | + --recompute-num-layers 1 |
| 76 | + |
| 77 | + # --micro-batch-size 1 |
| 78 | + --use-dynamic-batch-size |
| 79 | + --max-tokens-per-gpu 20480 |
| 80 | +) |
| 81 | + |
| 82 | +GRPO_ARGS=( |
| 83 | + --advantage-estimator grpo |
| 84 | + --use-kl-loss |
| 85 | + --kl-loss-coef 0.00 |
| 86 | + --kl-loss-type low_var_kl |
| 87 | + --entropy-coef 0.00 |
| 88 | + --eps-clip 0.2 |
| 89 | + --eps-clip-high 0.28 |
| 90 | +) |
| 91 | + |
| 92 | +OPTIMIZER_ARGS=( |
| 93 | + --optimizer adam |
| 94 | + --lr 1e-6 |
| 95 | + --lr-decay-style constant |
| 96 | + --weight-decay 0.1 |
| 97 | + --adam-beta1 0.9 |
| 98 | + --adam-beta2 0.98 |
| 99 | + |
| 100 | + --optimizer-cpu-offload |
| 101 | + --overlap-cpu-optimizer-d2h-h2d |
| 102 | + --use-precision-aware-optimizer |
| 103 | +) |
| 104 | + |
| 105 | +WANDB_ARGS=( |
| 106 | + #--use-wandb |
| 107 | + # --wandb-project slime-dev |
| 108 | + # --wandb-group qwen3.5-27B-test |
| 109 | + # --wandb-key ${WANDB_KEY} |
| 110 | +) |
| 111 | + |
| 112 | +SGLANG_ARGS=( |
| 113 | + --rollout-num-gpus-per-engine 8 |
| 114 | + --sglang-mem-fraction-static 0.7 |
| 115 | + --sglang-cuda-graph-bs 1 2 4 8 $(seq 16 8 256) |
| 116 | +) |
| 117 | + |
| 118 | +MISC_ARGS=( |
| 119 | + # default dropout in megatron is 0.1 |
| 120 | + --attention-dropout 0.0 |
| 121 | + --hidden-dropout 0.0 |
| 122 | + # should be good for model performance |
| 123 | + --accumulate-allreduce-grads-in-fp32 |
| 124 | + --attention-softmax-in-fp32 |
| 125 | + # need to comment this when using model with MLA |
| 126 | + --attention-backend flash |
| 127 | +) |
| 128 | + |
| 129 | +# launch the master node of ray in container |
| 130 | +export MASTER_ADDR=${MASTER_ADDR:-"127.0.0.1"} |
| 131 | +export no_proxy="127.0.0.1,${MASTER_ADDR}" |
| 132 | +ray start --head --node-ip-address ${MASTER_ADDR} --num-gpus 8 --disable-usage-stats --dashboard-host=0.0.0.0 --dashboard-port=8265 |
| 133 | + |
| 134 | +# Build the runtime environment JSON with proper variable substitution |
| 135 | +RUNTIME_ENV_JSON="{ |
| 136 | + \"env_vars\": { |
| 137 | + \"PYTHONPATH\": \"/root/Megatron-LM/\", |
| 138 | + \"CUDA_DEVICE_MAX_CONNECTIONS\": \"1\", |
| 139 | + \"NCCL_NVLS_ENABLE\": \"${HAS_NVLINK}\", |
| 140 | + \"no_proxy\": \"${no_proxy}\" |
| 141 | + } |
| 142 | +}" |
| 143 | + |
| 144 | +ray job submit --address="http://127.0.0.1:8265" \ |
| 145 | + --runtime-env-json="${RUNTIME_ENV_JSON}" \ |
| 146 | + -- python3 train.py \ |
| 147 | + --actor-num-nodes 1 \ |
| 148 | + --actor-num-gpus-per-node 8 \ |
| 149 | + --colocate \ |
| 150 | + ${MODEL_ARGS[@]} \ |
| 151 | + ${CKPT_ARGS[@]} \ |
| 152 | + ${ROLLOUT_ARGS[@]} \ |
| 153 | + ${OPTIMIZER_ARGS[@]} \ |
| 154 | + ${GRPO_ARGS[@]} \ |
| 155 | + ${WANDB_ARGS[@]} \ |
| 156 | + ${PERF_ARGS[@]} \ |
| 157 | + ${EVAL_ARGS[@]} \ |
| 158 | + ${SGLANG_ARGS[@]} \ |
| 159 | + ${MISC_ARGS[@]} |
0 commit comments