Text Generation
Transformers
Safetensors
qwen3
llama-factory
full
Generated from Trainer
conversational
text-generation-inference
Instructions to use ayh015/myLightningOPD with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ayh015/myLightningOPD with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ayh015/myLightningOPD") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("ayh015/myLightningOPD") model = AutoModelForCausalLM.from_pretrained("ayh015/myLightningOPD", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use ayh015/myLightningOPD with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ayh015/myLightningOPD" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ayh015/myLightningOPD", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/ayh015/myLightningOPD
- SGLang
How to use ayh015/myLightningOPD with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "ayh015/myLightningOPD" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ayh015/myLightningOPD", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "ayh015/myLightningOPD" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ayh015/myLightningOPD", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use ayh015/myLightningOPD with Docker Model Runner:
docker model run hf.co/ayh015/myLightningOPD
Upload folder using huggingface_hub
Browse files- .gitattributes +1 -0
- configs/lightning_opd/qwen3-30b-a3b-lightning-opd.py +145 -0
- configs/lightning_opd/qwen3-4b-lightning-opd.py +140 -0
- configs/lightning_opd/qwen3-8b-lightning-opd.py +139 -0
- configs/models/qwen3-30B-A3B.sh +49 -0
- configs/models/qwen3-4B.sh +20 -0
- configs/models/qwen3-8B.sh +21 -0
- configs/opd/qwen3-4b-opd.py +190 -0
- configs/opd/qwen3-8b-opd.py +190 -0
- configs/sft/data/sft_data/openthoughts3_300k_qwen3-8b.jsonl +3 -0
- configs/sft/dataset_info.json +23 -0
- configs/sft/dataset_info_ori_Fri_5_Jun.json +16 -0
- configs/sft/qwen3-4b-base-open-thoughts3-qwen3-8b.yaml +42 -0
- configs/sft/qwen3-8b-base-open-thoughts3-qwen3-32b.yaml +41 -0
- configs/sft/run_sft.sh +49 -0
.gitattributes
CHANGED
|
@@ -36,3 +36,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 36 |
assets/intuitive.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
assets/main-results.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
assets/overview.png filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 36 |
assets/intuitive.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
assets/main-results.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
assets/overview.png filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
configs/sft/data/sft_data/openthoughts3_300k_qwen3-8b.jsonl filter=lfs diff=lfs merge=lfs -text
|
configs/lightning_opd/qwen3-30b-a3b-lightning-opd.py
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
import os
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
import slime.utils.external_utils.command_utils as U
|
| 8 |
+
|
| 9 |
+
# Lightning OPD: response tokens + teacher logprobs are pre-computed in parquet.
|
| 10 |
+
# No teacher server needed at training time -> all 8 GPUs go to the actor.
|
| 11 |
+
#
|
| 12 |
+
# Required env vars:
|
| 13 |
+
# SFT_CHECKPOINT - path to the SFT checkpoint (HF format)
|
| 14 |
+
# LIGHTNING_OPD_DATA - path to the precomputed parquet
|
| 15 |
+
|
| 16 |
+
MODEL_NAME = "Qwen3-30B-A3B-Base-Open-Thoughts-Qwen3-30B-A3B-Thinking-2507-sft"
|
| 17 |
+
MODEL_TYPE = "qwen3-30B-A3B"
|
| 18 |
+
NUM_GPUS = 8
|
| 19 |
+
SFT_CHECKPOINT = os.environ["SFT_CHECKPOINT"]
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def prepare():
|
| 23 |
+
U.convert_checkpoint(
|
| 24 |
+
model_name=MODEL_NAME,
|
| 25 |
+
megatron_model_type=MODEL_TYPE,
|
| 26 |
+
num_gpus_per_node=NUM_GPUS,
|
| 27 |
+
hf_checkpoint=SFT_CHECKPOINT,
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def execute(rerun=True):
|
| 32 |
+
load_save_path = f"/root/models/{MODEL_NAME}_ckpt__{Path(__file__).stem}/"
|
| 33 |
+
|
| 34 |
+
ckpt_args = (
|
| 35 |
+
f"--hf-checkpoint {SFT_CHECKPOINT} "
|
| 36 |
+
f"--ref-load /root/models/{MODEL_NAME}_torch_dist "
|
| 37 |
+
f"--load {load_save_path} "
|
| 38 |
+
f"--save {load_save_path} "
|
| 39 |
+
"--save-interval 10 "
|
| 40 |
+
"--save-retain-interval 100 "
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
rollout_args = (
|
| 44 |
+
f"--prompt-data {os.environ['LIGHTNING_OPD_DATA']} "
|
| 45 |
+
"--input-key prompt "
|
| 46 |
+
"--label-key label "
|
| 47 |
+
"--rollout-shuffle "
|
| 48 |
+
"--num-rollout 3000 "
|
| 49 |
+
"--rollout-batch-size 256 "
|
| 50 |
+
"--n-samples-per-prompt 1 "
|
| 51 |
+
"--rollout-max-response-len 4096 "
|
| 52 |
+
"--global-batch-size 256 "
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
rm_args = (
|
| 56 |
+
"--custom-rm-path slime.rollout.on_policy_distillation.reward_func "
|
| 57 |
+
"--custom-reward-post-process-path slime.rollout.on_policy_distillation.post_process_rewards "
|
| 58 |
+
"--include-verifiable-reward "
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
perf_args = (
|
| 62 |
+
"--tensor-model-parallel-size 4 "
|
| 63 |
+
"--sequence-parallel "
|
| 64 |
+
"--pipeline-model-parallel-size 1 "
|
| 65 |
+
"--context-parallel-size 1 "
|
| 66 |
+
"--expert-model-parallel-size 8 "
|
| 67 |
+
"--expert-tensor-parallel-size 1 "
|
| 68 |
+
"--recompute-granularity full "
|
| 69 |
+
"--recompute-method uniform "
|
| 70 |
+
"--recompute-num-layers 1 "
|
| 71 |
+
"--use-dynamic-batch-size "
|
| 72 |
+
"--max-tokens-per-gpu 12288 "
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
grpo_args = (
|
| 76 |
+
"--advantage-estimator on_policy_distillation "
|
| 77 |
+
"--use-kl-loss "
|
| 78 |
+
"--kl-loss-coef 0.00 "
|
| 79 |
+
"--kl-loss-type low_var_kl "
|
| 80 |
+
"--entropy-coef 0.00 "
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
optimizer_args = (
|
| 84 |
+
"--optimizer adam "
|
| 85 |
+
"--lr 2e-6 "
|
| 86 |
+
"--lr-decay-style constant "
|
| 87 |
+
"--weight-decay 0.1 "
|
| 88 |
+
"--adam-beta1 0.9 "
|
| 89 |
+
"--adam-beta2 0.98 "
|
| 90 |
+
"--optimizer-cpu-offload "
|
| 91 |
+
"--overlap-cpu-optimizer-d2h-h2d "
|
| 92 |
+
"--use-precision-aware-optimizer "
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
wandb_args = ""
|
| 96 |
+
if os.environ.get("WANDB_KEY"):
|
| 97 |
+
wandb_args = (
|
| 98 |
+
"--use-wandb "
|
| 99 |
+
"--wandb-project lightning-opd "
|
| 100 |
+
f"--wandb-group {Path(__file__).stem} "
|
| 101 |
+
f"--wandb-key {os.environ['WANDB_KEY']} "
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
sglang_args = (
|
| 105 |
+
"--rollout-num-gpus-per-engine 8 "
|
| 106 |
+
"--sglang-mem-fraction-static 0.8 "
|
| 107 |
+
"--sglang-cuda-graph-max-bs 32 "
|
| 108 |
+
"--sglang-max-running-requests 512 "
|
| 109 |
+
"--sglang-enable-metrics "
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
misc_args = (
|
| 113 |
+
"--attention-dropout 0.0 "
|
| 114 |
+
"--hidden-dropout 0.0 "
|
| 115 |
+
"--accumulate-allreduce-grads-in-fp32 "
|
| 116 |
+
"--attention-softmax-in-fp32 "
|
| 117 |
+
"--attention-backend flash "
|
| 118 |
+
"--actor-num-nodes 1 "
|
| 119 |
+
"--actor-num-gpus-per-node 8 "
|
| 120 |
+
"--rollout-num-gpus 0 "
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
train_args = (
|
| 124 |
+
f"{ckpt_args} "
|
| 125 |
+
f"{rollout_args} "
|
| 126 |
+
f"{rm_args} "
|
| 127 |
+
f"{grpo_args} "
|
| 128 |
+
f"{optimizer_args} "
|
| 129 |
+
f"{wandb_args} "
|
| 130 |
+
f"{perf_args} "
|
| 131 |
+
f"{sglang_args} "
|
| 132 |
+
f"{misc_args} "
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
U.execute_train(
|
| 136 |
+
rerun=rerun,
|
| 137 |
+
train_args=train_args,
|
| 138 |
+
num_gpus_per_node=NUM_GPUS,
|
| 139 |
+
megatron_model_type=MODEL_TYPE,
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
if __name__ == "__main__":
|
| 144 |
+
prepare()
|
| 145 |
+
execute(rerun=False)
|
configs/lightning_opd/qwen3-4b-lightning-opd.py
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
import os
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
import slime.utils.external_utils.command_utils as U
|
| 8 |
+
|
| 9 |
+
# Lightning OPD: response tokens + teacher logprobs are pre-computed in parquet.
|
| 10 |
+
# No teacher server needed at training time -> all 8 GPUs go to the actor.
|
| 11 |
+
#
|
| 12 |
+
# Required env vars:
|
| 13 |
+
# SFT_CHECKPOINT - path to the SFT checkpoint (HF format)
|
| 14 |
+
# LIGHTNING_OPD_DATA - path to the precomputed parquet
|
| 15 |
+
|
| 16 |
+
MODEL_NAME = "Qwen3-4B-Base-Open-Thoughts-Qwen3-8B-sft-3k"
|
| 17 |
+
MODEL_TYPE = "qwen3-4B"
|
| 18 |
+
NUM_GPUS = 4
|
| 19 |
+
SFT_CHECKPOINT = os.environ["SFT_CHECKPOINT"]
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def prepare():
|
| 23 |
+
U.convert_checkpoint(
|
| 24 |
+
model_name=MODEL_NAME,
|
| 25 |
+
megatron_model_type=MODEL_TYPE,
|
| 26 |
+
num_gpus_per_node=NUM_GPUS,
|
| 27 |
+
hf_checkpoint=SFT_CHECKPOINT,
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def execute(rerun=True):
|
| 32 |
+
load_save_path = f"/root/models/{MODEL_NAME}_ckpt__{Path(__file__).stem}/"
|
| 33 |
+
|
| 34 |
+
ckpt_args = (
|
| 35 |
+
f"--hf-checkpoint {SFT_CHECKPOINT} "
|
| 36 |
+
f"--ref-load /root/models/{MODEL_NAME}_torch_dist "
|
| 37 |
+
f"--load {load_save_path} "
|
| 38 |
+
f"--save {load_save_path} "
|
| 39 |
+
"--save-interval 10 "
|
| 40 |
+
"--save-retain-interval 100 "
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
rollout_args = (
|
| 44 |
+
f"--prompt-data {os.environ['LIGHTNING_OPD_DATA']} "
|
| 45 |
+
"--input-key prompt "
|
| 46 |
+
"--label-key label "
|
| 47 |
+
"--rollout-shuffle "
|
| 48 |
+
"--num-rollout 150 "
|
| 49 |
+
"--rollout-batch-size 256 "
|
| 50 |
+
"--n-samples-per-prompt 1 "
|
| 51 |
+
"--rollout-max-response-len 4096 "
|
| 52 |
+
"--global-batch-size 256 "
|
| 53 |
+
"--rollout-temperature 0.8"
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
rm_args = (
|
| 57 |
+
"--custom-rm-path slime.rollout.on_policy_distillation.reward_func "
|
| 58 |
+
"--custom-reward-post-process-path slime.rollout.on_policy_distillation.post_process_rewards "
|
| 59 |
+
"--include-verifiable-reward "
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
perf_args = (
|
| 63 |
+
"--tensor-model-parallel-size 2 "
|
| 64 |
+
"--sequence-parallel "
|
| 65 |
+
"--pipeline-model-parallel-size 1 "
|
| 66 |
+
"--context-parallel-size 1 "
|
| 67 |
+
"--expert-model-parallel-size 1 "
|
| 68 |
+
"--expert-tensor-parallel-size 1 "
|
| 69 |
+
"--recompute-granularity full "
|
| 70 |
+
"--recompute-method uniform "
|
| 71 |
+
"--recompute-num-layers 1 "
|
| 72 |
+
"--use-dynamic-batch-size "
|
| 73 |
+
"--max-tokens-per-gpu 16384 "
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
grpo_args = (
|
| 77 |
+
"--advantage-estimator on_policy_distillation "
|
| 78 |
+
"--use-kl-loss "
|
| 79 |
+
"--kl-loss-coef 0.00 "
|
| 80 |
+
"--kl-loss-type low_var_kl "
|
| 81 |
+
"--entropy-coef 0.00 "
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
optimizer_args = (
|
| 85 |
+
"--optimizer adam "
|
| 86 |
+
"--lr 2e-6 "
|
| 87 |
+
"--lr-decay-style constant "
|
| 88 |
+
"--weight-decay 0.1 "
|
| 89 |
+
"--adam-beta1 0.9 "
|
| 90 |
+
"--adam-beta2 0.98 "
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
wandb_args = ""
|
| 94 |
+
if os.environ.get("WANDB_KEY"):
|
| 95 |
+
wandb_args = (
|
| 96 |
+
"--use-wandb "
|
| 97 |
+
"--wandb-project lightning-opd "
|
| 98 |
+
f"--wandb-group {Path(__file__).stem} "
|
| 99 |
+
f"--wandb-key {os.environ['WANDB_KEY']} "
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
sglang_args = (
|
| 103 |
+
"--rollout-num-gpus-per-engine 1 "
|
| 104 |
+
"--sglang-mem-fraction-static 0.4 "
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
misc_args = (
|
| 108 |
+
"--attention-dropout 0.0 "
|
| 109 |
+
"--hidden-dropout 0.0 "
|
| 110 |
+
"--accumulate-allreduce-grads-in-fp32 "
|
| 111 |
+
"--attention-softmax-in-fp32 "
|
| 112 |
+
"--attention-backend flash "
|
| 113 |
+
"--actor-num-nodes 1 "
|
| 114 |
+
"--actor-num-gpus-per-node 4 "
|
| 115 |
+
"--rollout-num-gpus 0 "
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
train_args = (
|
| 119 |
+
f"{ckpt_args} "
|
| 120 |
+
f"{rollout_args} "
|
| 121 |
+
f"{rm_args} "
|
| 122 |
+
f"{grpo_args} "
|
| 123 |
+
f"{optimizer_args} "
|
| 124 |
+
f"{wandb_args} "
|
| 125 |
+
f"{perf_args} "
|
| 126 |
+
f"{sglang_args} "
|
| 127 |
+
f"{misc_args} "
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
U.execute_train(
|
| 131 |
+
rerun=rerun,
|
| 132 |
+
train_args=train_args,
|
| 133 |
+
num_gpus_per_node=NUM_GPUS,
|
| 134 |
+
megatron_model_type=MODEL_TYPE,
|
| 135 |
+
)
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
if __name__ == "__main__":
|
| 139 |
+
prepare()
|
| 140 |
+
execute(rerun=False)
|
configs/lightning_opd/qwen3-8b-lightning-opd.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
import os
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
import slime.utils.external_utils.command_utils as U
|
| 8 |
+
|
| 9 |
+
# Lightning OPD: response tokens + teacher logprobs are pre-computed in parquet.
|
| 10 |
+
# No teacher server needed at training time -> all 8 GPUs go to the actor.
|
| 11 |
+
#
|
| 12 |
+
# Required env vars:
|
| 13 |
+
# SFT_CHECKPOINT - path to the SFT checkpoint (HF format)
|
| 14 |
+
# LIGHTNING_OPD_DATA - path to the precomputed parquet
|
| 15 |
+
|
| 16 |
+
MODEL_NAME = "Qwen3-8B-Base-Open-Thoughts-Qwen3-32B-sft-3k"
|
| 17 |
+
MODEL_TYPE = "qwen3-8B"
|
| 18 |
+
NUM_GPUS = 8
|
| 19 |
+
SFT_CHECKPOINT = os.environ["SFT_CHECKPOINT"]
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def prepare():
|
| 23 |
+
U.convert_checkpoint(
|
| 24 |
+
model_name=MODEL_NAME,
|
| 25 |
+
megatron_model_type=MODEL_TYPE,
|
| 26 |
+
num_gpus_per_node=NUM_GPUS,
|
| 27 |
+
hf_checkpoint=SFT_CHECKPOINT,
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def execute(rerun=True):
|
| 32 |
+
load_save_path = f"/root/models/{MODEL_NAME}_ckpt__{Path(__file__).stem}/"
|
| 33 |
+
|
| 34 |
+
ckpt_args = (
|
| 35 |
+
f"--hf-checkpoint {SFT_CHECKPOINT} "
|
| 36 |
+
f"--ref-load /root/models/{MODEL_NAME}_torch_dist "
|
| 37 |
+
f"--load {load_save_path} "
|
| 38 |
+
f"--save {load_save_path} "
|
| 39 |
+
"--save-interval 10 "
|
| 40 |
+
"--save-retain-interval 100 "
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
rollout_args = (
|
| 44 |
+
f"--prompt-data {os.environ['LIGHTNING_OPD_DATA']} "
|
| 45 |
+
"--input-key prompt "
|
| 46 |
+
"--label-key label "
|
| 47 |
+
"--rollout-shuffle "
|
| 48 |
+
"--num-rollout 3000 "
|
| 49 |
+
"--rollout-batch-size 256 "
|
| 50 |
+
"--n-samples-per-prompt 1 "
|
| 51 |
+
"--rollout-max-response-len 4096 "
|
| 52 |
+
"--global-batch-size 256 "
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
rm_args = (
|
| 56 |
+
"--custom-rm-path slime.rollout.on_policy_distillation.reward_func "
|
| 57 |
+
"--custom-reward-post-process-path slime.rollout.on_policy_distillation.post_process_rewards "
|
| 58 |
+
"--include-verifiable-reward "
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
perf_args = (
|
| 62 |
+
"--tensor-model-parallel-size 4 "
|
| 63 |
+
"--sequence-parallel "
|
| 64 |
+
"--pipeline-model-parallel-size 1 "
|
| 65 |
+
"--context-parallel-size 1 "
|
| 66 |
+
"--expert-model-parallel-size 1 "
|
| 67 |
+
"--expert-tensor-parallel-size 1 "
|
| 68 |
+
"--recompute-granularity full "
|
| 69 |
+
"--recompute-method uniform "
|
| 70 |
+
"--recompute-num-layers 1 "
|
| 71 |
+
"--use-dynamic-batch-size "
|
| 72 |
+
"--max-tokens-per-gpu 16384 "
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
grpo_args = (
|
| 76 |
+
"--advantage-estimator on_policy_distillation "
|
| 77 |
+
"--use-kl-loss "
|
| 78 |
+
"--kl-loss-coef 0.00 "
|
| 79 |
+
"--kl-loss-type low_var_kl "
|
| 80 |
+
"--entropy-coef 0.00 "
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
optimizer_args = (
|
| 84 |
+
"--optimizer adam "
|
| 85 |
+
"--lr 2e-6 "
|
| 86 |
+
"--lr-decay-style constant "
|
| 87 |
+
"--weight-decay 0.1 "
|
| 88 |
+
"--adam-beta1 0.9 "
|
| 89 |
+
"--adam-beta2 0.98 "
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
wandb_args = ""
|
| 93 |
+
if os.environ.get("WANDB_KEY"):
|
| 94 |
+
wandb_args = (
|
| 95 |
+
"--use-wandb "
|
| 96 |
+
"--wandb-project lightning-opd "
|
| 97 |
+
f"--wandb-group {Path(__file__).stem} "
|
| 98 |
+
f"--wandb-key {os.environ['WANDB_KEY']} "
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
sglang_args = (
|
| 102 |
+
"--rollout-num-gpus-per-engine 1 "
|
| 103 |
+
"--sglang-mem-fraction-static 0.4 "
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
misc_args = (
|
| 107 |
+
"--attention-dropout 0.0 "
|
| 108 |
+
"--hidden-dropout 0.0 "
|
| 109 |
+
"--accumulate-allreduce-grads-in-fp32 "
|
| 110 |
+
"--attention-softmax-in-fp32 "
|
| 111 |
+
"--attention-backend flash "
|
| 112 |
+
"--actor-num-nodes 1 "
|
| 113 |
+
"--actor-num-gpus-per-node 8 "
|
| 114 |
+
"--rollout-num-gpus 0 "
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
train_args = (
|
| 118 |
+
f"{ckpt_args} "
|
| 119 |
+
f"{rollout_args} "
|
| 120 |
+
f"{rm_args} "
|
| 121 |
+
f"{grpo_args} "
|
| 122 |
+
f"{optimizer_args} "
|
| 123 |
+
f"{wandb_args} "
|
| 124 |
+
f"{perf_args} "
|
| 125 |
+
f"{sglang_args} "
|
| 126 |
+
f"{misc_args} "
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
U.execute_train(
|
| 130 |
+
rerun=rerun,
|
| 131 |
+
train_args=train_args,
|
| 132 |
+
num_gpus_per_node=NUM_GPUS,
|
| 133 |
+
megatron_model_type=MODEL_TYPE,
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
if __name__ == "__main__":
|
| 138 |
+
prepare()
|
| 139 |
+
execute(rerun=False)
|
configs/models/qwen3-30B-A3B.sh
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
NLAYERS=48
|
| 2 |
+
FIRST_K_DENSE_REPLACE=0
|
| 3 |
+
|
| 4 |
+
arr=()
|
| 5 |
+
for ((i=0; i<NLAYERS; i++)); do
|
| 6 |
+
if (( i < FIRST_K_DENSE_REPLACE )); then
|
| 7 |
+
arr+=(0)
|
| 8 |
+
else
|
| 9 |
+
arr+=(1)
|
| 10 |
+
fi
|
| 11 |
+
done
|
| 12 |
+
|
| 13 |
+
printf -v MOE_LAYER_FREQ "[%s]" "$(IFS=', '; echo "${arr[*]}")"
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
MODEL_ARGS=(
|
| 17 |
+
--disable-bias-linear
|
| 18 |
+
--qk-layernorm
|
| 19 |
+
--group-query-attention
|
| 20 |
+
--num-attention-heads 32
|
| 21 |
+
--num-query-groups 4
|
| 22 |
+
--kv-channels 128
|
| 23 |
+
--num-layers 48
|
| 24 |
+
--hidden-size 2048
|
| 25 |
+
--ffn-hidden-size 6144
|
| 26 |
+
|
| 27 |
+
--normalization RMSNorm
|
| 28 |
+
--position-embedding-type rope
|
| 29 |
+
--norm-epsilon 1e-6
|
| 30 |
+
--rotary-percent 1.0
|
| 31 |
+
--swiglu
|
| 32 |
+
--untie-embeddings-and-output-weights
|
| 33 |
+
--vocab-size 151936
|
| 34 |
+
|
| 35 |
+
--rotary-base 1000000
|
| 36 |
+
|
| 37 |
+
# moe
|
| 38 |
+
--moe-ffn-hidden-size 768
|
| 39 |
+
--moe-router-score-function softmax
|
| 40 |
+
--moe-token-dispatcher-type alltoall
|
| 41 |
+
--moe-router-topk 8
|
| 42 |
+
--moe-layer-freq $MOE_LAYER_FREQ
|
| 43 |
+
--num-experts 128
|
| 44 |
+
--moe-grouped-gemm
|
| 45 |
+
--moe-token-drop-policy probs
|
| 46 |
+
--moe-router-dtype fp32
|
| 47 |
+
--moe-permute-fusion
|
| 48 |
+
--moe-aux-loss-coeff 0
|
| 49 |
+
)
|
configs/models/qwen3-4B.sh
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
MODEL_ARGS=(
|
| 5 |
+
--swiglu
|
| 6 |
+
--num-layers 36
|
| 7 |
+
--hidden-size 2560
|
| 8 |
+
--ffn-hidden-size 9728
|
| 9 |
+
--num-attention-heads 32
|
| 10 |
+
--group-query-attention
|
| 11 |
+
--num-query-groups 8
|
| 12 |
+
--use-rotary-position-embeddings
|
| 13 |
+
--disable-bias-linear
|
| 14 |
+
--normalization "RMSNorm"
|
| 15 |
+
--norm-epsilon 1e-6
|
| 16 |
+
--rotary-base "${MODEL_ARGS_ROTARY_BASE:-1000000}"
|
| 17 |
+
--vocab-size 151936
|
| 18 |
+
--kv-channels 128
|
| 19 |
+
--qk-layernorm
|
| 20 |
+
)
|
configs/models/qwen3-8B.sh
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
MODEL_ARGS=(
|
| 5 |
+
--swiglu
|
| 6 |
+
--num-layers 36
|
| 7 |
+
--hidden-size 4096
|
| 8 |
+
--ffn-hidden-size 12288
|
| 9 |
+
--num-attention-heads 32
|
| 10 |
+
--group-query-attention
|
| 11 |
+
--num-query-groups 8
|
| 12 |
+
--use-rotary-position-embeddings
|
| 13 |
+
--disable-bias-linear
|
| 14 |
+
--normalization "RMSNorm"
|
| 15 |
+
--norm-epsilon 1e-6
|
| 16 |
+
--rotary-base 1000000
|
| 17 |
+
--vocab-size 151936
|
| 18 |
+
--kv-channels 128
|
| 19 |
+
--qk-layernorm
|
| 20 |
+
--untie-embeddings-and-output-weights
|
| 21 |
+
)
|
configs/opd/qwen3-4b-opd.py
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
import os
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
import slime.utils.external_utils.command_utils as U
|
| 8 |
+
from slime.utils.external_utils.command_utils import get_bool_env_var
|
| 9 |
+
|
| 10 |
+
# Standard OPD: requires a live teacher server during training.
|
| 11 |
+
# 2 GPUs for actor (TP=2), 4 GPUs for rollout, 2 GPUs for teacher server.
|
| 12 |
+
#
|
| 13 |
+
# Required env vars:
|
| 14 |
+
# SFT_CHECKPOINT - path to the SFT checkpoint (HF format)
|
| 15 |
+
|
| 16 |
+
MODEL_NAME = "Qwen3-4B-Base-Open-Thoughts-Qwen3-8B-sft-3k"
|
| 17 |
+
TEACHER_MODEL_NAME = "Qwen3-8B"
|
| 18 |
+
TEACHER_IP = os.environ.get("MASTER_ADDR", "127.0.0.1")
|
| 19 |
+
TEACHER_PORT = 13141
|
| 20 |
+
MODEL_TYPE = "qwen3-4B"
|
| 21 |
+
NUM_GPUS = 8
|
| 22 |
+
SFT_CHECKPOINT = os.environ["SFT_CHECKPOINT"]
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def deploy_teacher_model():
|
| 26 |
+
import random, string
|
| 27 |
+
random_suffix = ''.join(random.choices(string.ascii_letters + string.digits, k=6))
|
| 28 |
+
LOG_FILE = f"/tmp/sglang_{random_suffix}.log"
|
| 29 |
+
external_ray = get_bool_env_var("SLIME_SCRIPT_EXTERNAL_RAY")
|
| 30 |
+
|
| 31 |
+
U.exec_command(
|
| 32 |
+
"pkill -9 sglang; "
|
| 33 |
+
"sleep 3; "
|
| 34 |
+
f"{'' if external_ray else 'ray stop --force; '}"
|
| 35 |
+
f"{'' if external_ray else 'pkill -9 ray; '}"
|
| 36 |
+
"pkill -9 slime; "
|
| 37 |
+
"sleep 3; "
|
| 38 |
+
f"{'' if external_ray else 'pkill -9 ray; '}"
|
| 39 |
+
"pkill -9 slime; "
|
| 40 |
+
"pkill -9 redis; "
|
| 41 |
+
"true;"
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
U.exec_command(
|
| 45 |
+
f"CUDA_VISIBLE_DEVICES=6,7 python3 -m sglang.launch_server "
|
| 46 |
+
f"--model-path /root/models/{TEACHER_MODEL_NAME} "
|
| 47 |
+
f"--host 0.0.0.0 "
|
| 48 |
+
f"--port {TEACHER_PORT} "
|
| 49 |
+
f"--tp 2 "
|
| 50 |
+
f"--chunked-prefill-size 4096 "
|
| 51 |
+
f"--mem-fraction-static 0.6 "
|
| 52 |
+
f"--context-length 32768 "
|
| 53 |
+
f"> {LOG_FILE} 2>&1 & "
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
U.exec_command(
|
| 57 |
+
f"until curl -sf http://{TEACHER_IP}:{TEACHER_PORT}/health_generate > /dev/null; do "
|
| 58 |
+
f" echo 'Waiting for teacher model...'; "
|
| 59 |
+
f" tail -n 10 {LOG_FILE}; sleep 5; done; "
|
| 60 |
+
f"echo 'Teacher model ready at {TEACHER_IP}:{TEACHER_PORT}.'; sleep 10;"
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def prepare():
|
| 65 |
+
U.exec_command("mkdir -p /root/models /root/datasets")
|
| 66 |
+
U.exec_command(f"huggingface-cli download Qwen/{TEACHER_MODEL_NAME} --local-dir /root/models/{TEACHER_MODEL_NAME}")
|
| 67 |
+
|
| 68 |
+
U.convert_checkpoint(
|
| 69 |
+
model_name=MODEL_NAME,
|
| 70 |
+
megatron_model_type=MODEL_TYPE,
|
| 71 |
+
num_gpus_per_node=NUM_GPUS,
|
| 72 |
+
hf_checkpoint=SFT_CHECKPOINT,
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
deploy_teacher_model()
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def execute(rerun=True):
|
| 79 |
+
load_save_path = f"/root/models/{MODEL_NAME}_ckpt__{Path(__file__).stem}/"
|
| 80 |
+
|
| 81 |
+
ckpt_args = (
|
| 82 |
+
f"--hf-checkpoint {SFT_CHECKPOINT} "
|
| 83 |
+
f"--ref-load /root/models/{MODEL_NAME}_torch_dist "
|
| 84 |
+
f"--load {load_save_path} "
|
| 85 |
+
f"--save {load_save_path} "
|
| 86 |
+
"--save-interval 10 "
|
| 87 |
+
"--save-retain-interval 10 "
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
rollout_args = (
|
| 91 |
+
"--prompt-data /root/datasets/dapo-math-17k/dapo-math-17k.jsonl "
|
| 92 |
+
"--input-key prompt "
|
| 93 |
+
"--label-key label "
|
| 94 |
+
"--apply-chat-template "
|
| 95 |
+
"--rollout-shuffle "
|
| 96 |
+
"--num-rollout 3000 "
|
| 97 |
+
"--rollout-batch-size 64 "
|
| 98 |
+
"--n-samples-per-prompt 4 "
|
| 99 |
+
"--rollout-max-response-len 4096 "
|
| 100 |
+
"--rollout-temperature 0.8 "
|
| 101 |
+
"--global-batch-size 256 "
|
| 102 |
+
"--balance-data "
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
rm_args = (
|
| 106 |
+
"--custom-rm-path slime.rollout.on_policy_distillation.reward_func "
|
| 107 |
+
"--custom-reward-post-process-path slime.rollout.on_policy_distillation.post_process_rewards "
|
| 108 |
+
f"--rm-url http://{TEACHER_IP}:{TEACHER_PORT}/generate "
|
| 109 |
+
"--include-verifiable-reward "
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
perf_args = (
|
| 113 |
+
"--tensor-model-parallel-size 2 "
|
| 114 |
+
"--sequence-parallel "
|
| 115 |
+
"--pipeline-model-parallel-size 1 "
|
| 116 |
+
"--context-parallel-size 1 "
|
| 117 |
+
"--expert-model-parallel-size 1 "
|
| 118 |
+
"--expert-tensor-parallel-size 1 "
|
| 119 |
+
"--recompute-granularity full "
|
| 120 |
+
"--recompute-method uniform "
|
| 121 |
+
"--recompute-num-layers 1 "
|
| 122 |
+
"--use-dynamic-batch-size "
|
| 123 |
+
"--max-tokens-per-gpu 16384 "
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
grpo_args = (
|
| 127 |
+
"--advantage-estimator on_policy_distillation "
|
| 128 |
+
"--use-kl-loss "
|
| 129 |
+
"--kl-loss-coef 0.00 "
|
| 130 |
+
"--kl-loss-type low_var_kl "
|
| 131 |
+
"--entropy-coef 0.00 "
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
optimizer_args = (
|
| 135 |
+
"--optimizer adam "
|
| 136 |
+
"--lr 2e-6 "
|
| 137 |
+
"--lr-decay-style constant "
|
| 138 |
+
"--weight-decay 0.1 "
|
| 139 |
+
"--adam-beta1 0.9 "
|
| 140 |
+
"--adam-beta2 0.98 "
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
wandb_args = ""
|
| 144 |
+
if os.environ.get("WANDB_KEY"):
|
| 145 |
+
wandb_args = (
|
| 146 |
+
"--use-wandb "
|
| 147 |
+
"--wandb-project lightning-opd "
|
| 148 |
+
f"--wandb-group {Path(__file__).stem} "
|
| 149 |
+
f"--wandb-key {os.environ['WANDB_KEY']} "
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
sglang_args = (
|
| 153 |
+
"--rollout-num-gpus-per-engine 1 "
|
| 154 |
+
"--sglang-mem-fraction-static 0.4 "
|
| 155 |
+
)
|
| 156 |
+
|
| 157 |
+
misc_args = (
|
| 158 |
+
"--attention-dropout 0.0 "
|
| 159 |
+
"--hidden-dropout 0.0 "
|
| 160 |
+
"--accumulate-allreduce-grads-in-fp32 "
|
| 161 |
+
"--attention-softmax-in-fp32 "
|
| 162 |
+
"--attention-backend flash "
|
| 163 |
+
"--actor-num-nodes 1 "
|
| 164 |
+
"--actor-num-gpus-per-node 2 "
|
| 165 |
+
"--rollout-num-gpus 4 "
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
train_args = (
|
| 169 |
+
f"{ckpt_args} "
|
| 170 |
+
f"{rollout_args} "
|
| 171 |
+
f"{rm_args} "
|
| 172 |
+
f"{grpo_args} "
|
| 173 |
+
f"{optimizer_args} "
|
| 174 |
+
f"{wandb_args} "
|
| 175 |
+
f"{perf_args} "
|
| 176 |
+
f"{sglang_args} "
|
| 177 |
+
f"{misc_args} "
|
| 178 |
+
)
|
| 179 |
+
|
| 180 |
+
U.execute_train(
|
| 181 |
+
rerun=rerun,
|
| 182 |
+
train_args=train_args,
|
| 183 |
+
num_gpus_per_node=NUM_GPUS,
|
| 184 |
+
megatron_model_type=MODEL_TYPE,
|
| 185 |
+
)
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
if __name__ == "__main__":
|
| 189 |
+
prepare()
|
| 190 |
+
execute(rerun=False)
|
configs/opd/qwen3-8b-opd.py
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
import os
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
import slime.utils.external_utils.command_utils as U
|
| 8 |
+
from slime.utils.external_utils.command_utils import get_bool_env_var
|
| 9 |
+
|
| 10 |
+
# Standard OPD: requires a live teacher server during training.
|
| 11 |
+
# 4 GPUs for actor (TP=4), 2 GPUs for rollout, 2 GPUs for teacher server.
|
| 12 |
+
#
|
| 13 |
+
# Required env vars:
|
| 14 |
+
# SFT_CHECKPOINT - path to the SFT checkpoint (HF format)
|
| 15 |
+
|
| 16 |
+
MODEL_NAME = "Qwen3-8B-Base-Open-Thoughts-Qwen3-32B-sft-3.5k"
|
| 17 |
+
TEACHER_MODEL_NAME = "Qwen3-32B"
|
| 18 |
+
TEACHER_IP = os.environ.get("MASTER_ADDR", "127.0.0.1")
|
| 19 |
+
TEACHER_PORT = 13141
|
| 20 |
+
MODEL_TYPE = "qwen3-8B"
|
| 21 |
+
NUM_GPUS = 8
|
| 22 |
+
SFT_CHECKPOINT = os.environ["SFT_CHECKPOINT"]
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def deploy_teacher_model():
|
| 26 |
+
import random, string
|
| 27 |
+
random_suffix = ''.join(random.choices(string.ascii_letters + string.digits, k=6))
|
| 28 |
+
LOG_FILE = f"/tmp/sglang_{random_suffix}.log"
|
| 29 |
+
external_ray = get_bool_env_var("SLIME_SCRIPT_EXTERNAL_RAY")
|
| 30 |
+
|
| 31 |
+
U.exec_command(
|
| 32 |
+
"pkill -9 sglang; "
|
| 33 |
+
"sleep 3; "
|
| 34 |
+
f"{'' if external_ray else 'ray stop --force; '}"
|
| 35 |
+
f"{'' if external_ray else 'pkill -9 ray; '}"
|
| 36 |
+
"pkill -9 slime; "
|
| 37 |
+
"sleep 3; "
|
| 38 |
+
f"{'' if external_ray else 'pkill -9 ray; '}"
|
| 39 |
+
"pkill -9 slime; "
|
| 40 |
+
"pkill -9 redis; "
|
| 41 |
+
"true;"
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
U.exec_command(
|
| 45 |
+
f"CUDA_VISIBLE_DEVICES=6,7 python3 -m sglang.launch_server "
|
| 46 |
+
f"--model-path /root/models/{TEACHER_MODEL_NAME} "
|
| 47 |
+
f"--host 0.0.0.0 "
|
| 48 |
+
f"--port {TEACHER_PORT} "
|
| 49 |
+
f"--tp 2 "
|
| 50 |
+
f"--chunked-prefill-size 4096 "
|
| 51 |
+
f"--mem-fraction-static 0.6 "
|
| 52 |
+
f"--context-length 32768 "
|
| 53 |
+
f"> {LOG_FILE} 2>&1 & "
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
U.exec_command(
|
| 57 |
+
f"until curl -sf http://{TEACHER_IP}:{TEACHER_PORT}/health_generate > /dev/null; do "
|
| 58 |
+
f" echo 'Waiting for teacher model...'; "
|
| 59 |
+
f" tail -n 10 {LOG_FILE}; sleep 5; done; "
|
| 60 |
+
f"echo 'Teacher model ready at {TEACHER_IP}:{TEACHER_PORT}.'; sleep 10;"
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def prepare():
|
| 65 |
+
U.exec_command("mkdir -p /root/models /root/datasets/dapo-math-17k")
|
| 66 |
+
U.exec_command(f"huggingface-cli download Qwen/{TEACHER_MODEL_NAME} --local-dir /root/models/{TEACHER_MODEL_NAME}")
|
| 67 |
+
|
| 68 |
+
U.convert_checkpoint(
|
| 69 |
+
model_name=MODEL_NAME,
|
| 70 |
+
megatron_model_type=MODEL_TYPE,
|
| 71 |
+
num_gpus_per_node=NUM_GPUS,
|
| 72 |
+
hf_checkpoint=SFT_CHECKPOINT,
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
deploy_teacher_model()
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def execute(rerun=True):
|
| 79 |
+
load_save_path = f"/root/models/{MODEL_NAME}_ckpt__{Path(__file__).stem}/"
|
| 80 |
+
|
| 81 |
+
ckpt_args = (
|
| 82 |
+
f"--hf-checkpoint {SFT_CHECKPOINT} "
|
| 83 |
+
f"--ref-load /root/models/{MODEL_NAME}_torch_dist "
|
| 84 |
+
f"--load {load_save_path} "
|
| 85 |
+
f"--save {load_save_path} "
|
| 86 |
+
"--save-interval 5 "
|
| 87 |
+
"--save-retain-interval 5 "
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
rollout_args = (
|
| 91 |
+
"--prompt-data /root/datasets/dapo-math-17k/dapo-math-17k.jsonl "
|
| 92 |
+
"--input-key prompt "
|
| 93 |
+
"--label-key label "
|
| 94 |
+
"--apply-chat-template "
|
| 95 |
+
"--rollout-shuffle "
|
| 96 |
+
"--num-rollout 3000 "
|
| 97 |
+
"--rollout-batch-size 64 "
|
| 98 |
+
"--n-samples-per-prompt 4 "
|
| 99 |
+
"--rollout-max-response-len 4096 "
|
| 100 |
+
"--rollout-temperature 0.8 "
|
| 101 |
+
"--global-batch-size 256 "
|
| 102 |
+
"--balance-data "
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
rm_args = (
|
| 106 |
+
"--custom-rm-path slime.rollout.on_policy_distillation.reward_func "
|
| 107 |
+
"--custom-reward-post-process-path slime.rollout.on_policy_distillation.post_process_rewards "
|
| 108 |
+
f"--rm-url http://{TEACHER_IP}:{TEACHER_PORT}/generate "
|
| 109 |
+
"--include-verifiable-reward "
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
perf_args = (
|
| 113 |
+
"--tensor-model-parallel-size 4 "
|
| 114 |
+
"--sequence-parallel "
|
| 115 |
+
"--pipeline-model-parallel-size 1 "
|
| 116 |
+
"--context-parallel-size 1 "
|
| 117 |
+
"--expert-model-parallel-size 1 "
|
| 118 |
+
"--expert-tensor-parallel-size 1 "
|
| 119 |
+
"--recompute-granularity full "
|
| 120 |
+
"--recompute-method uniform "
|
| 121 |
+
"--recompute-num-layers 1 "
|
| 122 |
+
"--use-dynamic-batch-size "
|
| 123 |
+
"--max-tokens-per-gpu 8192 "
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
grpo_args = (
|
| 127 |
+
"--advantage-estimator on_policy_distillation "
|
| 128 |
+
"--use-kl-loss "
|
| 129 |
+
"--kl-loss-coef 0.00 "
|
| 130 |
+
"--kl-loss-type low_var_kl "
|
| 131 |
+
"--entropy-coef 0.00 "
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
optimizer_args = (
|
| 135 |
+
"--optimizer adam "
|
| 136 |
+
"--lr 2e-6 "
|
| 137 |
+
"--lr-decay-style constant "
|
| 138 |
+
"--weight-decay 0.1 "
|
| 139 |
+
"--adam-beta1 0.9 "
|
| 140 |
+
"--adam-beta2 0.98 "
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
wandb_args = ""
|
| 144 |
+
if os.environ.get("WANDB_KEY"):
|
| 145 |
+
wandb_args = (
|
| 146 |
+
"--use-wandb "
|
| 147 |
+
"--wandb-project lightning-opd "
|
| 148 |
+
f"--wandb-group {Path(__file__).stem} "
|
| 149 |
+
f"--wandb-key {os.environ['WANDB_KEY']} "
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
sglang_args = (
|
| 153 |
+
"--rollout-num-gpus-per-engine 1 "
|
| 154 |
+
"--sglang-mem-fraction-static 0.4 "
|
| 155 |
+
)
|
| 156 |
+
|
| 157 |
+
misc_args = (
|
| 158 |
+
"--attention-dropout 0.0 "
|
| 159 |
+
"--hidden-dropout 0.0 "
|
| 160 |
+
"--accumulate-allreduce-grads-in-fp32 "
|
| 161 |
+
"--attention-softmax-in-fp32 "
|
| 162 |
+
"--attention-backend flash "
|
| 163 |
+
"--actor-num-nodes 1 "
|
| 164 |
+
"--actor-num-gpus-per-node 4 "
|
| 165 |
+
"--rollout-num-gpus 2 "
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
train_args = (
|
| 169 |
+
f"{ckpt_args} "
|
| 170 |
+
f"{rollout_args} "
|
| 171 |
+
f"{rm_args} "
|
| 172 |
+
f"{grpo_args} "
|
| 173 |
+
f"{optimizer_args} "
|
| 174 |
+
f"{wandb_args} "
|
| 175 |
+
f"{perf_args} "
|
| 176 |
+
f"{sglang_args} "
|
| 177 |
+
f"{misc_args} "
|
| 178 |
+
)
|
| 179 |
+
|
| 180 |
+
U.execute_train(
|
| 181 |
+
rerun=rerun,
|
| 182 |
+
train_args=train_args,
|
| 183 |
+
num_gpus_per_node=NUM_GPUS,
|
| 184 |
+
megatron_model_type=MODEL_TYPE,
|
| 185 |
+
)
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
if __name__ == "__main__":
|
| 189 |
+
prepare()
|
| 190 |
+
execute(rerun=False)
|
configs/sft/data/sft_data/openthoughts3_300k_qwen3-8b.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:66cf6cffd11dd523d28cd449afcd5500c62ab47e6617a977039e931d22ae2689
|
| 3 |
+
size 13944494336
|
configs/sft/dataset_info.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"openthoughts3_300k_qwen3-8b": {
|
| 3 |
+
"file_name": "data/sft_data/openthoughts3_300k_qwen3-8b.jsonl",
|
| 4 |
+
"formatting": "sharegpt",
|
| 5 |
+
"columns": {
|
| 6 |
+
"messages": "messages"
|
| 7 |
+
},
|
| 8 |
+
"tags": {
|
| 9 |
+
"role_tag": "role",
|
| 10 |
+
"content_tag": "content",
|
| 11 |
+
"user_tag": "user",
|
| 12 |
+
"assistant_tag": "assistant",
|
| 13 |
+
"system_tag": "system"
|
| 14 |
+
}
|
| 15 |
+
},
|
| 16 |
+
"openthoughts3_300k_qwen3-32b": {
|
| 17 |
+
"file_name": "data/sft_data/openthoughts3_300k_qwen3-32b.parquet",
|
| 18 |
+
"formatting": "sharegpt",
|
| 19 |
+
"columns": {
|
| 20 |
+
"messages": "messages"
|
| 21 |
+
}
|
| 22 |
+
}
|
| 23 |
+
}
|
configs/sft/dataset_info_ori_Fri_5_Jun.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"openthoughts3_300k_qwen3-8b": {
|
| 3 |
+
"file_name": "data/sft_data/openthoughts3_300k_qwen3-8b.jsonl",
|
| 4 |
+
"formatting": "sharegpt",
|
| 5 |
+
"columns": {
|
| 6 |
+
"messages": "messages"
|
| 7 |
+
}
|
| 8 |
+
},
|
| 9 |
+
"openthoughts3_300k_qwen3-32b": {
|
| 10 |
+
"file_name": "data/sft_data/openthoughts3_300k_qwen3-32b.parquet",
|
| 11 |
+
"formatting": "sharegpt",
|
| 12 |
+
"columns": {
|
| 13 |
+
"messages": "messages"
|
| 14 |
+
}
|
| 15 |
+
}
|
| 16 |
+
}
|
configs/sft/qwen3-4b-base-open-thoughts3-qwen3-8b.yaml
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### model
|
| 2 |
+
model_name_or_path: model_weights/qwen3-4b-base
|
| 3 |
+
|
| 4 |
+
### method
|
| 5 |
+
stage: sft
|
| 6 |
+
do_train: true
|
| 7 |
+
finetuning_type: full
|
| 8 |
+
deepspeed: examples/deepspeed/ds_z0_config.json
|
| 9 |
+
enable_liger_kernel: true
|
| 10 |
+
packing: true
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
### dataset
|
| 14 |
+
dataset: openthoughts3_300k_qwen3-8b
|
| 15 |
+
template: qwen3
|
| 16 |
+
cutoff_len: 16384
|
| 17 |
+
overwrite_cache: true
|
| 18 |
+
preprocessing_num_workers: 16
|
| 19 |
+
dataloader_persistent_workers: true
|
| 20 |
+
dataloader_pin_memory: true
|
| 21 |
+
dataloader_num_workers: 4
|
| 22 |
+
|
| 23 |
+
### output
|
| 24 |
+
logging_steps: 1
|
| 25 |
+
save_steps: 100
|
| 26 |
+
save_total_limit: 10
|
| 27 |
+
plot_loss: true
|
| 28 |
+
overwrite_output_dir: false
|
| 29 |
+
save_only_model: false
|
| 30 |
+
#report_to: wandb
|
| 31 |
+
report_to: none
|
| 32 |
+
run_name: qwen3-4b-base-open-thoughts3-qwen3-8b
|
| 33 |
+
|
| 34 |
+
### train
|
| 35 |
+
per_device_train_batch_size: 4
|
| 36 |
+
gradient_accumulation_steps: 2
|
| 37 |
+
learning_rate: 0.00008
|
| 38 |
+
max_steps: 3000
|
| 39 |
+
lr_scheduler_type: cosine
|
| 40 |
+
warmup_ratio: 0.1
|
| 41 |
+
bf16: true
|
| 42 |
+
ddp_timeout: 180000000
|
configs/sft/qwen3-8b-base-open-thoughts3-qwen3-32b.yaml
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### model
|
| 2 |
+
model_name_or_path: Qwen/Qwen3-8B-Base
|
| 3 |
+
|
| 4 |
+
### method
|
| 5 |
+
stage: sft
|
| 6 |
+
do_train: true
|
| 7 |
+
finetuning_type: full
|
| 8 |
+
deepspeed: examples/deepspeed/ds_z1_config.json
|
| 9 |
+
enable_liger_kernel: true
|
| 10 |
+
packing: true
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
### dataset
|
| 14 |
+
dataset: openthoughts3_300k_qwen3-32b
|
| 15 |
+
template: qwen3
|
| 16 |
+
cutoff_len: 16384
|
| 17 |
+
overwrite_cache: true
|
| 18 |
+
preprocessing_num_workers: 16
|
| 19 |
+
dataloader_persistent_workers: true
|
| 20 |
+
dataloader_pin_memory: true
|
| 21 |
+
dataloader_num_workers: 4
|
| 22 |
+
|
| 23 |
+
### output
|
| 24 |
+
logging_steps: 1
|
| 25 |
+
save_steps: 100
|
| 26 |
+
save_total_limit: 10
|
| 27 |
+
plot_loss: true
|
| 28 |
+
overwrite_output_dir: false
|
| 29 |
+
save_only_model: false
|
| 30 |
+
report_to: wandb
|
| 31 |
+
run_name: qwen3-8b-base-open-thoughts3-qwen3-32b
|
| 32 |
+
|
| 33 |
+
### train
|
| 34 |
+
per_device_train_batch_size: 2
|
| 35 |
+
gradient_accumulation_steps: 2
|
| 36 |
+
learning_rate: 8e-5
|
| 37 |
+
max_steps: 3000
|
| 38 |
+
lr_scheduler_type: cosine
|
| 39 |
+
warmup_ratio: 0.1
|
| 40 |
+
bf16: true
|
| 41 |
+
ddp_timeout: 180000000
|
configs/sft/run_sft.sh
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 3 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 4 |
+
|
| 5 |
+
# Step 2: Run SFT training with LlamaFactory.
|
| 6 |
+
#
|
| 7 |
+
# Required environment variables:
|
| 8 |
+
# CONFIG_YAML - Name of the SFT config file in configs/sft/ (e.g. qwen3-4b-base-sft-qwen3-8b.yaml)
|
| 9 |
+
# OUTPUT_DIR - Directory for the SFT checkpoint output
|
| 10 |
+
#
|
| 11 |
+
# Optional:
|
| 12 |
+
# NUM_NODES - Number of nodes (default: 4)
|
| 13 |
+
# NUM_GPUS - GPUs per node (default: 8)
|
| 14 |
+
# MASTER_ADDR - Master node address (default: localhost)
|
| 15 |
+
#
|
| 16 |
+
# Prerequisites:
|
| 17 |
+
# - LlamaFactory installed (pip install llamafactory)
|
| 18 |
+
# - SFT data generated by Step 1 and registered in LlamaFactory's dataset_info.json
|
| 19 |
+
|
| 20 |
+
set -euo pipefail
|
| 21 |
+
|
| 22 |
+
: "${CONFIG_YAML:?Set CONFIG_YAML (e.g. qwen3-4b-base-sft-qwen3-8b.yaml)}"
|
| 23 |
+
: "${OUTPUT_DIR:?Set OUTPUT_DIR for SFT checkpoint output}"
|
| 24 |
+
|
| 25 |
+
NUM_NODES="${NUM_NODES:-4}"
|
| 26 |
+
NUM_GPUS="${NUM_GPUS:-8}"
|
| 27 |
+
MASTER_ADDR="${MASTER_ADDR:-localhost}"
|
| 28 |
+
MASTER_PORT="${MASTER_PORT:-29500}"
|
| 29 |
+
|
| 30 |
+
# torchrun \
|
| 31 |
+
# --nnodes "${NUM_NODES}" \
|
| 32 |
+
# --nproc_per_node="${NUM_GPUS}" \
|
| 33 |
+
# --rdzv_id $RANDOM \
|
| 34 |
+
# --rdzv_backend c10d \
|
| 35 |
+
# --rdzv_endpoint "${MASTER_ADDR}:29500" \
|
| 36 |
+
# -m llamafactory.cli.train \
|
| 37 |
+
# "configs/sft/${CONFIG_YAML}" \
|
| 38 |
+
# "dataset_dir=configs/sft" \
|
| 39 |
+
# "output_dir=${OUTPUT_DIR}"
|
| 40 |
+
|
| 41 |
+
FORCE_TORCHRUN=1 \
|
| 42 |
+
NNODES="${NUM_NODES}" \
|
| 43 |
+
NPROC_PER_NODE="${NUM_GPUS}" \
|
| 44 |
+
MASTER_ADDR="${MASTER_ADDR}" \
|
| 45 |
+
MASTER_PORT="${MASTER_PORT}" \
|
| 46 |
+
llamafactory-cli train \
|
| 47 |
+
"configs/sft/${CONFIG_YAML}" \
|
| 48 |
+
"dataset_dir=configs/sft" \
|
| 49 |
+
"output_dir=${OUTPUT_DIR}"
|