Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions docs/en/examples/glm4.7-30B-A3B.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@

The environment setup, data, and checkpoint conversion are the same as for the Qwen3-4B model. You can refer to [Example: Qwen3-4B Model](qwen3-4B.md), replacing mentions of Qwen3-4B with GLM-4.7-Flash.

### Prerequisites

GLM-4.7-Flash requires **transformers ≥ 5.0** for the `Glm4MoeLiteForCausalLM` architecture. Install or upgrade:

```bash
pip install "transformers>=5.0"
```

### Download Model

```bash
Expand Down Expand Up @@ -119,9 +127,9 @@ SPEC_ARGS=(
- `--enable-mtp-training`: Enables gradient computation for MTP layers. Without this flag, the MTP layer is loaded but frozen.
- `--mtp-loss-scaling-factor 0.2`: Weight of the MTP loss relative to the main policy loss. Default is 0.2.

> ⚠️ **Note**: MTP training for GLM-4.7-Flash is not yet supported because the deepseek_v3 checkpoint bridge does not include MTP weight conversion (`# TODO: mtp` in upstream mbridge). You can still use MTP for speculative decoding during inference — SGLang handles MTP layers internally.
> **Note**: MTP training requires the MTP checkpoint bridge to properly convert weights between HuggingFace and Megatron formats. The `GLM4MoELiteBridge` (in `slime_plugins/mbridge/glm4moe_lite.py`) extends the DeepSeek V3 bridge with dynamic MTP layer indexing to support GLM-4.7-Flash's 47-layer architecture.
>
> For models with full MTP training support (e.g., MiMo), see `scripts/run-mimo-7B-rl-eagle.sh` as a reference.
> For other models with MTP training support (e.g., MiMo), see `scripts/run-mimo-7B-rl-eagle.sh` as a reference.

### Multi-Node Support

Expand Down
12 changes: 10 additions & 2 deletions docs/zh/examples/glm4.7-30B-A3B.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

搭建环境、数据与 ckpt 转换均与 Qwen3-4B 模型相同,可以参考 [示例:Qwen3-4B](qwen3-4B.md),将文中 Qwen3-4B 的部分转换为 GLM-4.7-Flash 即可。

### 前置条件

GLM-4.7-Flash 需要 **transformers ≥ 5.0** 以支持 `Glm4MoeLiteForCausalLM` 架构。请安装或升级:

```bash
pip install "transformers>=5.0"
```

### 下载模型

```bash
Expand Down Expand Up @@ -118,9 +126,9 @@ SPEC_ARGS=(
- `--enable-mtp-training`:启用 MTP 层的梯度计算。不设置此标志时,MTP 层会被加载但冻结。
- `--mtp-loss-scaling-factor 0.2`:MTP loss 相对于主策略 loss 的权重,默认为 0.2。

> ⚠️ **注意**:GLM-4.7-Flash 的 MTP 训练目前尚不支持,因为 deepseek_v3 的 checkpoint bridge 尚未实现 MTP 权重转换(上游 mbridge 中标注为 `# TODO: mtp`)。但推理时的投机解码仍然可用 — SGLang 会内部处理 MTP
> **注意**:MTP 训练需要 MTP checkpoint bridge 正确转换 HuggingFace 和 Megatron 格式之间的权重。`GLM4MoELiteBridge`(位于 `slime_plugins/mbridge/glm4moe_lite.py`)扩展了 DeepSeek V3 bridge,实现了动态 MTP 层索引以支持 GLM-4.7-Flash 的 47 层架构
>
> 对于完整支持 MTP 训练的模型(如 MiMo),可参考 `scripts/run-mimo-7B-rl-eagle.sh`。
> 对于其他支持 MTP 训练的模型(如 MiMo),可参考 `scripts/run-mimo-7B-rl-eagle.sh`。

### 多机支持

Expand Down
175 changes: 0 additions & 175 deletions scripts/run-glm4.7-30B-A3B-8gpus.sh

This file was deleted.

72 changes: 23 additions & 49 deletions scripts/run-glm4.7-30B-A3B.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ ROLLOUT_ARGS=(

--num-rollout 3000
--rollout-batch-size 128
#--over-sampling-batch-size 256
--n-samples-per-prompt 8
--rollout-max-response-len 32768
--rollout-temperature 1.0
Expand All @@ -56,14 +55,14 @@ EVAL_ARGS=(
--eval-prompt-data aime24 $BASE_DIR/rl_data/aime-2024.jsonl
--n-samples-per-eval-prompt 2
--eval-max-response-len 16384
--eval-temperature 0.6
--eval-temperature 1.0
--eval-top-p 0.95
)

PERF_ARGS=(
--tensor-model-parallel-size 4
--sequence-parallel
--pipeline-model-parallel-size 2
--pipeline-model-parallel-size 1
--context-parallel-size 2
--expert-model-parallel-size 8
--expert-tensor-parallel-size 1
Expand All @@ -77,6 +76,12 @@ PERF_ARGS=(
--max-tokens-per-gpu 32768
)

MTP_ARGS=(
--mtp-num-layers 1
--enable-mtp-training
--mtp-loss-scaling-factor 0.2
)

GRPO_ARGS=(
--advantage-estimator grpo
--use-kl-loss
Expand Down Expand Up @@ -139,56 +144,24 @@ MISC_ARGS=(
)

# launch the master node of ray in container
export MASTER_ADDR=${MLP_WORKER_0_HOST}
export no_proxy="127.0.0.1,${MASTER_ADDR}"
ray start --head --node-ip-address ${MASTER_ADDR} --num-gpus 8 --disable-usage-stats

for WORKER_IP in $(awk '{print $1}' /root/mpi_rack_hostfile); do
if [[ "$WORKER_IP" == "$MLP_WORKER_0_HOST" ]]; then
continue
fi
echo "Starting Ray worker on ${WORKER_IP}"
ssh root@"${WORKER_IP}" \
"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" &
done
wait
export MASTER_ADDR=${MASTER_ADDR:-"127.0.0.1"}
ray start --head --node-ip-address ${MASTER_ADDR} --num-gpus 8 --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/\",
\"CUDA_DEVICE_MAX_CONNECTIONS\": \"1\",
\"NCCL_NVLS_ENABLE\": \"${HAS_NVLINK}\"
}
}"

ray job submit --address="http://127.0.0.1:8265" \
--runtime-env-json='{
"env_vars": {
"no_proxy": "localhost,127.0.0.1,0.0.0.0,${MASTER_ADDR}",
"GLOO_SOCKET_IFNAME": "${MLP_SOCKET_IFNAME}",
"TP_SOCKET_IFNAME": "${MLP_SOCKET_IFNAME}",
"MASTER_ADDR": "${MLP_WORKER_0_HOST}",
"PYTHONPATH": "/root/Megatron-LM/",
"NCCL_CUMEM_ENABLE": "0",
"CUDA_DEVICE_MAX_CONNECTIONS": "1",
"NVTE_BWD_LAYERNORM_SM_MARGIN": "20",
"NCCL_IB_TC": "160",
"NCCL_PXN_DISABLE": "0",
"NCCL_IB_GID_INDEX": "3",
"NCCL_NET_GDR_LEVEL": "4",
"NCCL_IB_RETRY_CNT": "7",
"NCCL_IB_TIMEOUT": "32",
"NCCL_IB_QPS_PER_CONNECTION": "8",
"NCCL_P2P_LEVEL": "NVL",
"TORCH_NCCL_AVOID_RECORD_STREAMS": "1",
"NCCL_NVLS_ENABLE": "0",
"NCCL_MIN_CTAS": "4",
"OMPI_MCA_pml": "ob1",
"OMPI_MCA_btl": "^openib",
"OMPI_MCA_routed": "direct",
"OMPI_MCA_routed_radix": "1024",
"OMPI_MCA_plm_rsh_no_tree_spawn": "1",
"OMPI_MCA_oob_tcp_if_include": "${MLP_SOCKET_IFNAME}",
"OMPI_MCA_btl_tcp_if_include": "${MLP_SOCKET_IFNAME}"
}
}' \
--runtime-env-json="${RUNTIME_ENV_JSON}" \
-- python3 train.py \
--actor-num-nodes 2 \
--actor-num-nodes 1 \
--actor-num-gpus-per-node 8 \
--colocate \
--save-debug-rollout-data "data.pt" \
${MODEL_ARGS[@]} \
${CKPT_ARGS[@]} \
${ROLLOUT_ARGS[@]} \
Expand All @@ -198,4 +171,5 @@ ray job submit --address="http://127.0.0.1:8265" \
${PERF_ARGS[@]} \
${EVAL_ARGS[@]} \
${SGLANG_ARGS[@]} \
${MISC_ARGS[@]}
${MISC_ARGS[@]} \
${MTP_ARGS[@]}
14 changes: 14 additions & 0 deletions slime/backends/megatron_utils/model_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ def wrapped_model_provider(
if getattr(args, "decoder_last_pipeline_num_layers", None) is not None:
provider.num_layers_in_last_pipeline_stage = args.decoder_last_pipeline_num_layers
provider.finalize()

if role == "critic":
_original_provide = provider.provide

def _critic_provide(pre_process=True, post_process=True, vp_stage=None):
model = _original_provide(pre_process=pre_process, post_process=post_process, vp_stage=vp_stage)
if post_process:
model.output_layer = LinearForLastLayer(
input_size=model.config.hidden_size, output_size=1, config=model.config
)
return model

return _critic_provide

return provider.provide

def model_provider(pre_process: bool = True, post_process: bool = True, vp_stage: int | None = None) -> GPTModel:
Expand Down
Loading