Created
March 18, 2026 21:58
-
-
Save rodrigobaron/f7b88658b11e732e71200b8e01c4b64d to your computer and use it in GitHub Desktop.
Slime ReTool recipe for a single 24GB GPU
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # for rerun the task | |
| pkill -9 sglang | |
| sleep 3 | |
| ray stop --force | |
| pkill -9 ray | |
| pkill -9 python | |
| sleep 3 | |
| pkill -9 ray | |
| pkill -9 python | |
| set -ex | |
| # will prevent ray from buffering stdout/stderr | |
| export PYTHONBUFFERED=16 | |
| # Model configuration for Qwen3-0.6B | |
| MODEL_NAME="Qwen3-0.6B" | |
| MODEL_TYPE="qwen3-0.6B" | |
| # Download model and dataset | |
| hf download --repo-type dataset zhuzilin/dapo-math-17k --local-dir /root/datasets/dapo-math-17k | |
| hf download --repo-type dataset zhuzilin/aime-2024 --local-dir /root/datasets/aime-2024 | |
| NVLINK_COUNT=$(nvidia-smi topo -m 2>/dev/null | grep -o 'NV[0-9][0-9]*' | wc -l) | |
| if [ "$NVLINK_COUNT" -gt 0 ]; then | |
| HAS_NVLINK=1 | |
| else | |
| HAS_NVLINK=0 | |
| fi | |
| echo "HAS_NVLINK: $HAS_NVLINK (detected $NVLINK_COUNT NVLink references)" | |
| SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" | |
| source "/root/slime/scripts/models/qwen3-0.6B.sh" | |
| CKPT_ARGS=( | |
| --hf-checkpoint /root/models/${MODEL_NAME}/ | |
| --ref-load /root/models/${MODEL_NAME}_slime/ | |
| # --load /root/models/${MODEL_NAME}_slime_rl/ | |
| --load /root/slime/recipes/retool/${MODEL_NAME}_slime_rl/ | |
| --save /root/slime/recipes/retool/${MODEL_NAME}_slime_rl/ | |
| --save-interval 20 | |
| ) | |
| ROLLOUT_ARGS=( | |
| --prompt-data /root/datasets/dapo-math-17k/dapo-math-17k.jsonl | |
| --input-key prompt | |
| --label-key label | |
| --apply-chat-template | |
| --rollout-shuffle | |
| --reward-key score | |
| --num-rollout 3000 | |
| --rollout-batch-size 2 | |
| --n-samples-per-prompt 4 | |
| --rollout-max-response-len 2048 | |
| --rollout-max-context-len 3000 | |
| --rollout-temperature 1 | |
| --global-batch-size 8 | |
| --balance-data | |
| ) | |
| EVAL_ARGS=( | |
| --eval-interval 20 | |
| --eval-prompt-data aime /root/datasets/aime-2024/aime-2024.jsonl | |
| --n-samples-per-eval-prompt 1 | |
| --eval-max-response-len 2048 | |
| --eval-top-p 1 | |
| ) | |
| PERF_ARGS=( | |
| --tensor-model-parallel-size 1 | |
| --sequence-parallel | |
| --pipeline-model-parallel-size 1 | |
| --context-parallel-size 1 | |
| --expert-model-parallel-size 1 | |
| --expert-tensor-parallel-size 1 | |
| --recompute-granularity full | |
| --recompute-method uniform | |
| --recompute-num-layers 1 | |
| # --micro-batch-size 1 | |
| --use-dynamic-batch-size | |
| --max-tokens-per-gpu 4096 | |
| --train-memory-margin-bytes 68435456 | |
| ) | |
| GRPO_ARGS=( | |
| --advantage-estimator grpo | |
| --use-kl-loss | |
| --kl-loss-coef 0.00 | |
| --kl-loss-type low_var_kl | |
| --entropy-coef 0.00 | |
| --eps-clip 0.2 | |
| --eps-clip-high 0.28 | |
| ) | |
| OPTIMIZER_ARGS=( | |
| --optimizer adam | |
| --lr 1e-6 | |
| --lr-decay-style constant | |
| --weight-decay 0.1 | |
| --adam-beta1 0.9 | |
| --adam-beta2 0.98 | |
| ) | |
| WANDB_ARGS=( | |
| --use-wandb | |
| --wandb-project slime-dapo | |
| --wandb-group qwen3-0.6B-test-multi-turn | |
| --wandb-key ${WANDB_KEY} | |
| ) | |
| SGLANG_ARGS=( | |
| --rollout-num-gpus-per-engine 1 | |
| --sglang-mem-fraction-static 0.6 | |
| --sglang-enable-metrics | |
| --sglang-cuda-graph-max-bs 8 | |
| ) | |
| MISC_ARGS=( | |
| # default dropout in megatron is 0.1 | |
| --attention-dropout 0.0 | |
| --hidden-dropout 0.0 | |
| # should be good for model performance | |
| --accumulate-allreduce-grads-in-fp32 | |
| --attention-softmax-in-fp32 | |
| # need to comment this when using model with MLA | |
| --attention-backend flash | |
| ) | |
| CUSTOM_ARGS=( | |
| --custom-generate-function-path generate_with_retool.generate | |
| --custom-rm-path generate_with_retool.reward_func | |
| ) | |
| # launch the master node of ray in container | |
| export MASTER_ADDR=${MASTER_ADDR:-"127.0.0.1"} | |
| ray start --head --node-ip-address ${MASTER_ADDR} --num-gpus 1 --disable-usage-stats --dashboard-host=0.0.0.0 --dashboard-port=8265 | |
| # Build the runtime environment JSON with proper variable substitution | |
| RUNTIME_ENV_JSON="{ | |
| \"env_vars\": { | |
| \"PYTHONPATH\": \"/root/Megatron-LM/:${SCRIPT_DIR}:/root/slime\", | |
| \"CUDA_DEVICE_MAX_CONNECTIONS\": \"1\", | |
| \"NCCL_NVLS_ENABLE\": \"${HAS_NVLINK}\", | |
| \"PYTORCH_CUDA_ALLOC_CONF\": \"max_split_size_mb:1024\" | |
| } | |
| }" | |
| ray job submit --address="http://127.0.0.1:8265" \ | |
| --runtime-env-json="${RUNTIME_ENV_JSON}" \ | |
| -- python3 train.py \ | |
| --actor-num-nodes 1 \ | |
| --actor-num-gpus-per-node 1 \ | |
| --colocate \ | |
| ${MODEL_ARGS[@]} \ | |
| ${CKPT_ARGS[@]} \ | |
| ${ROLLOUT_ARGS[@]} \ | |
| ${OPTIMIZER_ARGS[@]} \ | |
| ${GRPO_ARGS[@]} \ | |
| ${WANDB_ARGS[@]} \ | |
| ${PERF_ARGS[@]} \ | |
| ${EVAL_ARGS[@]} \ | |
| ${SGLANG_ARGS[@]} \ | |
| ${MISC_ARGS[@]} \ | |
| ${CUSTOM_ARGS[@]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # for rerun the task | |
| pkill -9 sglang | |
| sleep 3 | |
| ray stop --force | |
| pkill -9 ray | |
| pkill -9 python | |
| sleep 3 | |
| pkill -9 ray | |
| pkill -9 python | |
| set -ex | |
| # Prevent Ray from buffering stdout/stderr | |
| export PYTHONBUFFERED=16 | |
| # Model configuration for Qwen3-0.6B | |
| MODEL_NAME="Qwen3-0.6B" | |
| MODEL_TYPE="qwen3-0.6B" | |
| # Create directories | |
| mkdir -p /root/models /root/datasets | |
| # Download model and dataset | |
| hf download Qwen/${MODEL_NAME} --local-dir /root/models/${MODEL_NAME} | |
| hf download --repo-type dataset JoeYing/ReTool-SFT --local-dir /root/datasets/ReTool-SFT | |
| # Convert Data | |
| python recipes/retool/sft_data_processing.py | |
| SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" | |
| source scripts/models/qwen3-0.6B.sh | |
| PYTHONPATH=/root/Megatron-LM/ python tools/convert_hf_to_torch_dist.py \ | |
| ${MODEL_ARGS[@]} \ | |
| --hf-checkpoint /root/models/${MODEL_NAME} \ | |
| --save /root/models/${MODEL_NAME}_torch_dist | |
| # Checkpoint arguments | |
| CKPT_ARGS=( | |
| --hf-checkpoint /root/models/${MODEL_NAME}/ | |
| --ref-load /root/models/${MODEL_NAME}_torch_dist | |
| # --load /root/models/${MODEL_NAME}_slime/ | |
| --save /root/models/${MODEL_NAME}_slime/ | |
| --save-interval 100 | |
| ) | |
| # SFT-specific arguments | |
| SFT_ARGS=( | |
| --rollout-function-path slime.rollout.sft_rollout.generate_rollout | |
| --prompt-data /root/datasets/ReTool-SFT/ReTool-SFT-converted.parquet | |
| --input-key messages | |
| --rollout-shuffle | |
| --num-epoch 3 | |
| --rollout-batch-size 16 | |
| --global-batch-size 16 | |
| --loss-type sft_loss | |
| --calculate-per-token-loss | |
| --disable-compute-advantages-and-returns | |
| --debug-train-only | |
| ) | |
| # Performance arguments for single GPU | |
| PERF_ARGS=( | |
| --tensor-model-parallel-size 1 | |
| --sequence-parallel | |
| --pipeline-model-parallel-size 1 | |
| --context-parallel-size 1 | |
| --recompute-granularity full | |
| --recompute-method uniform | |
| --recompute-num-layers 1 | |
| --use-dynamic-batch-size | |
| --max-tokens-per-gpu 4098 | |
| # --micro-batch-size 1 | |
| ) | |
| # Optimizer arguments | |
| OPTIMIZER_ARGS=( | |
| --optimizer adam | |
| --lr 1e-5 | |
| --lr-decay-style cosine | |
| --min-lr 1e-6 | |
| --lr-warmup-fraction 0.1 | |
| --weight-decay 0.1 | |
| --adam-beta1 0.9 | |
| --adam-beta2 0.95 | |
| ) | |
| WANDB_ARGS=( | |
| --use-wandb | |
| --wandb-project slime-dev | |
| --wandb-group qwen3-0.6B-sft | |
| --wandb-key ${WANDB_KEY} | |
| ) | |
| # Miscellaneous arguments | |
| MISC_ARGS=( | |
| --attention-dropout 0.0 | |
| --hidden-dropout 0.0 | |
| --accumulate-allreduce-grads-in-fp32 | |
| --attention-softmax-in-fp32 | |
| --attention-backend flash | |
| ) | |
| # launch the master node of ray in container | |
| export MASTER_ADDR=${MASTER_ADDR:-"127.0.0.1"} | |
| export no_proxy="127.0.0.1,${MASTER_ADDR}" | |
| ray start --head --node-ip-address ${MASTER_ADDR} --num-gpus 1 --disable-usage-stats | |
| # Build the runtime environment JSON with proper variable substitution | |
| RUNTIME_ENV_JSON="{ | |
| \"env_vars\": { | |
| \"PYTHONPATH\": \"/root/Megatron-LM/\", | |
| \"CUDA_DEVICE_MAX_CONNECTIONS\": \"1\", | |
| \"NCCL_NVLS_ENABLE\": \"${HAS_NVLINK}\", | |
| \"PYTORCH_CUDA_ALLOC_CONF\": \"expandable_segments:True\" | |
| } | |
| }" | |
| ray job submit --address="http://127.0.0.1:8265" \ | |
| --runtime-env-json="${RUNTIME_ENV_JSON}" \ | |
| -- python3 train_async.py \ | |
| --actor-num-nodes 1 \ | |
| --actor-num-gpus-per-node 1 \ | |
| ${MODEL_ARGS[@]} \ | |
| ${CKPT_ARGS[@]} \ | |
| ${SFT_ARGS[@]} \ | |
| ${OPTIMIZER_ARGS[@]} \ | |
| ${WANDB_ARGS[@]} \ | |
| ${PERF_ARGS[@]} \ | |
| ${EVAL_ARGS[@]} \ | |
| ${MISC_ARGS[@]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from datasets import load_dataset | |
| ds = load_dataset("JoeYing/ReTool-SFT")["train"] | |
| def convert(sample): | |
| conversations = sample["messages"] | |
| def convert_role(role): | |
| if role == "user": | |
| return "user" | |
| elif role == "assistant": | |
| return "assistant" | |
| elif role == "system": | |
| return "system" | |
| else: | |
| raise ValueError(f"Unknown role: {role}") | |
| messages = [ | |
| { | |
| "role": convert_role(turn["role"]), | |
| "content": turn["content"], | |
| } | |
| for turn in conversations | |
| ] | |
| return {"messages": messages} | |
| ds = ds.map(convert) | |
| ds.to_parquet("./data/retool/ReTool-SFT.parquet") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment