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
5 changes: 5 additions & 0 deletions scripts/models/minimax-m3.1-flash-4layer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from model_args_utils import load_sibling_model_args


def model_args() -> str:
return load_sibling_model_args(__file__, "minimax-m3.1-flash", nlayers=4, first_k_dense_replace=2)
5 changes: 5 additions & 0 deletions scripts/models/minimax-m3.1-flash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from model_args_utils import load_sibling_model_args


def model_args(**kwargs) -> str:
return load_sibling_model_args(__file__, "minimax-m3", rotary_base=10000000, **kwargs)
36 changes: 29 additions & 7 deletions scripts/run_minimax_m3.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""MiniMax-M3 DAPO training (bf16 train, bf16 rollout).
"""MiniMax-M3 / MiniMax-M3.1-Flash DAPO training (bf16 train, bf16 rollout).

`prepare` downloads the release to `<model-dir>/<repo name>` and, unless `<model-dir>/<model-name>` is
that download, converts it with tools/convert_minimax_m3_to_bf16.py. It then converts the model into
the Megatron `<model-dir>/<megatron-model-type>_torch_dist` used as the reference model, unless they
already exist:
MiniMax-M3 the full model (854 GB), 8 nodes x 4 GPUs
MiniMax-M3-4layer `--layers 0,1,3,4`: two dense-attention dense-MLP and two sparse MoE layers, 4 GPUs
that download, converts it with tools/convert_minimax_m3_to_bf16.py (MiniMax-M3.1-Flash ships MXFP8
linears and NVFP4 routed experts; MiniMax-M3 ships BF16). It then converts the model into the Megatron
`<model-dir>/<megatron-model-type>_torch_dist` used as the reference model, unless they already exist:
MiniMax-M3 the full model (854 GB), 8 nodes x 4 GPUs
MiniMax-M3-4layer `--layers 0,1,3,4`: two dense-attention dense-MLP and two sparse MoE layers, 4 GPUs
MiniMax-M3.1-Flash-bf16 the full model (852 GB), 8 nodes x 4 GPUs
MiniMax-M3.1-Flash-4layer-bf16 `--layers 0,1,3,4` (36 GB), two dense and two MoE layers, 4 GPUs

Args:
--model-name: checkpoint directory under `--model-dir`; selects the matching recipe.
Expand Down Expand Up @@ -67,12 +69,32 @@ class _Recipe:
rollout_num_gpus_per_engine=4,
layers="0,1,3,4",
),
"MiniMax-M3.1-Flash-bf16": _Recipe(
hf_repo="MiniMaxAI/MiniMax-M3.1-Flash",
megatron_model_type="minimax-m3.1-flash",
num_gpus=32,
parallel=(4, 4, 8),
rollout_num_gpus_per_engine=8,
stream_optimizer_state=True,
check_weight_update_equal=False,
convert_args="--pipeline-model-parallel-size 4 --expert-model-parallel-size 8",
),
"MiniMax-M3.1-Flash-4layer-bf16": _Recipe(
hf_repo="MiniMaxAI/MiniMax-M3.1-Flash",
megatron_model_type="minimax-m3.1-flash-4layer",
num_gpus=4,
parallel=(2, 1, 2),
rollout_num_gpus_per_engine=4,
layers="0,1,3,4",
),
}


@dataclass
class ScriptArgs(U.ExecuteTrainConfig):
model_name: Literal["MiniMax-M3", "MiniMax-M3-4layer"] = "MiniMax-M3-4layer"
model_name: Literal[
"MiniMax-M3", "MiniMax-M3-4layer", "MiniMax-M3.1-Flash-bf16", "MiniMax-M3.1-Flash-4layer-bf16"
] = "MiniMax-M3-4layer"
num_gpus_per_node: int = 4
run_id: str = U.create_run_id()
model_dir: str = "/root/models"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import os

from scripts.run_minimax_m3 import _RECIPES, ScriptArgs, execute
from tests.ci.ci_register import register_cuda_ci
from tests.ci.metric_history import register_ci_gate

register_cuda_ci(
est_time=1500,
suite="stage-c-4-gpu-h200",
labels=["megatron", "model-scripts"],
hardware=["hopper", "blackwell"],
num_gpus=4,
)

register_ci_gate(metric_key="train/grad_norm")
register_ci_gate(metric_key="train/ppo_kl")
register_ci_gate(metric_key="train/train_rollout_logprob_abs_diff")
register_ci_gate(metric_key="train/train_rollout_kl")
# deterministic_random scores each sample by a hash bit, so raw_reward has nothing to regress; track it
register_ci_gate(metric_key="rollout/raw_reward", constraint=None)
register_ci_gate(metric_key="perf/actor_train_mfu")

_MODEL_ORG = "CharyZeng"


def _args() -> ScriptArgs:
return ScriptArgs(
model_name="MiniMax-M3.1-Flash-4layer-bf16",
num_nodes=1,
num_gpus_per_node=4,
num_rollout=3,
rollout_max_response_len=512,
extra_args=(
"--ci-test "
"--ci-disable-logprobs-checker "
# the pruned model scores 0 on math, which zeroes every advantage; a pseudo-random
# reward keeps the weights moving so each weight sync carries real deltas
"--rm-type deterministic_random "
"--offload-train-target cpu "
),
)


def prepare(args: ScriptArgs):
U = args.create_backend()
recipe = _RECIPES[args.model_name]
hf_checkpoint = f"{args.model_dir}/{args.model_name}"
U.exec_command_cpu(f"mkdir -p {args.model_dir} {args.data_dir}")
U.exec_command_cpu(f"hf download {_MODEL_ORG}/{args.model_name} --local-dir {hf_checkpoint}")
U.hf_download_dataset("zhuzilin/dapo-math-17k", data_dir=args.data_dir)
U.convert_checkpoint(
model_name=recipe.megatron_model_type,
megatron_model_type=recipe.megatron_model_type,
num_gpus_per_node=args.num_gpus_per_node,
dir_dst=args.model_dir,
hf_checkpoint=hf_checkpoint,
megatron_path=args.megatron_path,
)


if __name__ == "__main__":
args = _args()
prepare(args)
for proxy_var in ("http_proxy", "https_proxy", "HTTP_PROXY", "HTTPS_PROXY"):
os.environ.pop(proxy_var, None)
execute(args)
60 changes: 60 additions & 0 deletions tests/snapshots/model_args/minimax-m3.1-flash-4layer.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"--spec"
"miles_plugins.models.minimax_m3.minimax_m3"
"get_minimax_m3_spec"
"--num-layers"
"4"
"--hidden-size"
"6144"
"--ffn-hidden-size"
"12288"
"--num-attention-heads"
"64"
"--group-query-attention"
"--num-query-groups"
"4"
"--kv-channels"
"128"
"--qk-layernorm"
"--moe-layer-freq"
"[0,0,1,1]"
"--num-experts"
"128"
"--moe-router-topk"
"4"
"--moe-router-score-function"
"sigmoid"
"--moe-router-enable-expert-bias"
"--moe-router-bias-update-rate"
"0"
"--moe-router-topk-scaling-factor"
"2.0"
"--moe-ffn-hidden-size"
"3072"
"--moe-shared-expert-intermediate-size"
"3072"
"--moe-router-dtype"
"fp32"
"--moe-grouped-gemm"
"--moe-permute-fusion"
"--vocab-size"
"200064"
"--rotary-base"
"10000000"
"--rotary-percent"
"0.5"
"--position-embedding-type"
"rope"
"--no-rope-fusion"
"--normalization"
"RMSNorm"
"--norm-epsilon"
"1e-6"
"--apply-layernorm-1p"
"--quick-geglu"
"--activation-func-clamp-value"
"7"
"--disable-bias-linear"
"--untie-embeddings-and-output-weights"
"--make-vocab-size-divisible-by"
"64"
"--enable-experimental"
60 changes: 60 additions & 0 deletions tests/snapshots/model_args/minimax-m3.1-flash.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"--spec"
"miles_plugins.models.minimax_m3.minimax_m3"
"get_minimax_m3_spec"
"--num-layers"
"60"
"--hidden-size"
"6144"
"--ffn-hidden-size"
"12288"
"--num-attention-heads"
"64"
"--group-query-attention"
"--num-query-groups"
"4"
"--kv-channels"
"128"
"--qk-layernorm"
"--moe-layer-freq"
"[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]"
"--num-experts"
"128"
"--moe-router-topk"
"4"
"--moe-router-score-function"
"sigmoid"
"--moe-router-enable-expert-bias"
"--moe-router-bias-update-rate"
"0"
"--moe-router-topk-scaling-factor"
"2.0"
"--moe-ffn-hidden-size"
"3072"
"--moe-shared-expert-intermediate-size"
"3072"
"--moe-router-dtype"
"fp32"
"--moe-grouped-gemm"
"--moe-permute-fusion"
"--vocab-size"
"200064"
"--rotary-base"
"10000000"
"--rotary-percent"
"0.5"
"--position-embedding-type"
"rope"
"--no-rope-fusion"
"--normalization"
"RMSNorm"
"--norm-epsilon"
"1e-6"
"--apply-layernorm-1p"
"--quick-geglu"
"--activation-func-clamp-value"
"7"
"--disable-bias-linear"
"--untie-embeddings-and-output-weights"
"--make-vocab-size-divisible-by"
"64"
"--enable-experimental"
Loading