Skip to content

Commit 5d6d2e5

Browse files
authored
Merge branch 'main' into pr4_omni3_packseq_sequence_utils
2 parents d18b410 + c705936 commit 5d6d2e5

202 files changed

Lines changed: 7865 additions & 2429 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docker/Dockerfile.ci‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,12 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
9191
# the uv sync below. Point the compilers at the CCCL/libcu++ headers (under cccl/ in this base
9292
# image, not the default CUDA include path) and scope the build to the target archs.
9393
export FLASH_MLA_DISABLE_SM90=1 NVCC_THREADS=16 \
94-
CFLAGS="-I/usr/local/cuda/include/cccl${CFLAGS:+ $CFLAGS}" \
95-
CXXFLAGS="-I/usr/local/cuda/include/cccl${CXXFLAGS:+ $CXXFLAGS}" && \
94+
CFLAGS="-I/usr/local/cuda/include/cccl${CFLAGS:+ $CFLAGS} -DNDEBUG" \
95+
CXXFLAGS="-I/usr/local/cuda/include/cccl${CXXFLAGS:+ $CXXFLAGS} -DNDEBUG" && \
9696
# Reinstall nvidia-cutlass-dsl in system site packages
9797
# uv install can run into non-deterministic install issues
98+
# Keep this pin compatible with cuDNN Frontend; mismatched versions can break
99+
# its CUTLASS-backed kernels.
98100
pip uninstall -y nvidia-cutlass-dsl nvidia-cutlass-dsl-libs-base nvidia-cutlass-dsl-libs-cu13 && \
99101
pip install nvidia-cutlass-dsl[cu13]==4.5.0 && \
100102
if [ "$MCORE_TRIGGERED_TESTING" = "true" ]; then \
@@ -110,4 +112,4 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
110112
ln -sf "$(ldconfig -p | awk '/libcudart\.so\.[0-9]+ /{print $NF; exit}')" /opt/venv/lib/python3.12/site-packages/tilelang/lib/libcudart_stub.so && \
111113
uv cache prune ${UV_CACHE_PRUNE_ARGS}
112114

113-
COPY --chmod=644 . /opt/Megatron-Bridge
115+
COPY --chmod=644 . /opt/Megatron-Bridge

‎docker/common/fw_pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ override-dependencies = [
103103
"nvidia-cusparse-cu12; sys_platform == 'never'",
104104
"nvidia-cusparselt-cu12; sys_platform == 'never'",
105105
"nvidia-nccl-cu12; sys_platform == 'never'",
106-
"nvidia-cudnn-frontend==1.24.0",
106+
"nvidia-cudnn-frontend==1.26.0",
107107
"nvidia-cutlass-dsl[cu13]; sys_platform == 'never'", # Rely on system site packages install
108108
"tensorrt-llm; sys_platform == 'never'",
109109
"tensorrt; sys_platform == 'never'",

‎docker/common/import_check_skip.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ deep_ep_cpp
2323
hybrid_ep_cpp
2424
torch_tensorrt
2525
quack # imports nvidia-cutlass-dsl MLIR libs, which dlopen libcuda at import
26+
peft # transitively imports optional CUDA-backed modules that dlopen libcuda
27+
transformer_engine # dlopens libcuda at import
2628

2729
# Requires the libfuse system library (multi-storage-client FUSE backend; optional):
2830
mfusepy

‎docs/fern/versions/_nav_order.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"./versions/nightly/pages/models/llama/llama2.mdx": 1
1818
"./versions/nightly/pages/models/mimo/mimo.mdx": 1
1919
"./versions/nightly/pages/models/minimax/minimax-m2.mdx": 1
20+
"./versions/nightly/pages/models/minimax/minimax-m3.mdx": 2
2021
"./versions/nightly/pages/models/mistral/mistral.mdx": 1
2122
"./versions/nightly/pages/models/moonlight/moonlight.mdx": 1
2223
"./versions/nightly/pages/models/nemotron/llama-nemotron.mdx": 1

‎docs/fern/versions/nightly.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ navigation:
9090
- contents:
9191
- page: MiniMax-M2
9292
path: ./nightly/pages/models/minimax/minimax-m2.mdx
93+
- page: MiniMax-M3
94+
path: ./nightly/pages/models/minimax/minimax-m3.mdx
9395
section: MiniMax
9496
- contents:
9597
- page: Mistral

‎docs/fern/versions/nightly/pages/models/minimax/index.mdx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ MiniMax model documentation is organized by model variant.
55
| Variant | Guide |
66
|---------|-------|
77
| MiniMax-M2 / M2.5 / M2.7 | [minimax-m2.md](minimax-m2.md) |
8+
| MiniMax-M3 | [minimax-m3.md](minimax-m3.md) |
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# MiniMax-M3
2+
3+
[MiniMax-M3](https://huggingface.co/MiniMaxAI/MiniMax-M3) is a natively multimodal sparse MoE model from MiniMaxAI (428B total, ~23B active parameters). Megatron Bridge supports the M3 *language model* through the `MiniMaxM3Bridge`: the text backbone of the `MiniMaxM3SparseForConditionalGeneration` checkpoint is converted to a Megatron-Core `GPTModel`.
4+
5+
## Supported Variants
6+
7+
| Variant | Hugging Face ID | Notes |
8+
|---------|-----------------|-------|
9+
| MiniMax-M3 | `MiniMaxAI/MiniMax-M3` | Language model only (bf16 weights) |
10+
11+
## Architecture Notes
12+
13+
- Mixed dense/MoE decoder: 60 layers, the first 3 dense, the rest with 128 routed experts (top-4) plus one shared expert.
14+
- Sigmoid router with expert-bias correction and `routed_scaling_factor` applied to the normalized top-k weights (DeepSeek-V3-style routing); the checkpoint's FP32 router weights remain FP32 during import.
15+
- SwiGLU-OAI activation in every MLP and expert: clamped gate/up projections with a `+1` linear offset, mapped to `activation_func_clamp_value` / `glu_linear_offset` (same mechanism as GPT-OSS).
16+
- Gemma-style RMSNorm (`x * (1 + w)`) on every norm, mapped to `layernorm_zero_centered_gamma`.
17+
- GQA attention (64 query heads, 4 KV heads) with per-head QK RMSNorm and partial RoPE (64 of 128 head channels rotated, theta 5e6).
18+
19+
## Known Limitations
20+
21+
- **Language model only.** The CLIP-style vision tower, multimodal projector, and patch-merge MLP are not mapped.
22+
- **Full attention only.** The lightning-indexer block-sparse attention branch (`self_attn.index_*` weights) is not mapped; the Megatron model runs full causal attention on every layer. Block selection keeps `index_topk_blocks * index_block_size` (2048) key tokens per query, so full attention is mathematically identical up to that sequence length and an approximation beyond it.
23+
- **MTP modules are not mapped.** The released checkpoint advertises `num_nextn_predict_layers` in its config but ships no `mtp.*` weights.
24+
- **Auxiliary-loss scoring differs for training.** The recipes use MCore's token-global load-balancing loss over normalized sigmoid scores. Hugging Face leaves its optional router loss disabled by default and uses softmax scores when enabled.
25+
- The MXFP8 variant (`MiniMaxAI/MiniMax-M3-MXFP8`) is not supported; use the bf16 checkpoint.
26+
27+
## Conversion
28+
29+
```python
30+
from megatron.bridge import AutoBridge
31+
32+
bridge = AutoBridge.from_hf_pretrained("MiniMaxAI/MiniMax-M3", trust_remote_code=True)
33+
provider = bridge.to_megatron_provider()
34+
```
35+
36+
The bridge imports the language backbone from the multimodal checkpoint.
37+
Standalone Hugging Face checkpoint export is not supported because the vision,
38+
projector, lightning-indexer, and MTP weights are intentionally not mapped;
39+
native Megatron checkpoints and in-memory weight round-trip verification are
40+
supported.
41+
42+
## Examples
43+
44+
For real-checkpoint Slurm conversion, inference, hardware requirements, and
45+
validated parallelism settings, see the [MiniMax-M3 examples README](https://github.com/NVIDIA-NeMo/Megatron-Bridge/blob/main/examples/models/minimax/minimax_m3/README.md).
46+
47+
## Recipes
48+
49+
Pretraining and packed-sequence (THD) SFT recipes are available under [`src/megatron/bridge/recipes/minimax`](https://github.com/NVIDIA-NeMo/Megatron-Bridge/tree/main/src/megatron/bridge/recipes/minimax) (`minimax_m3_pretrain_256gpu_h100_bf16_config`, `minimax_m3_sft_128gpu_h100_bf16_config`), using a TP=2 / PP=4 / EP=32 baseline layout.
50+
51+
## Related Implementation
52+
53+
- Bridge implementation: [`src/megatron/bridge/models/minimax_m3`](https://github.com/NVIDIA-NeMo/Megatron-Bridge/tree/main/src/megatron/bridge/models/minimax_m3)
54+
- Examples: [`examples/models/minimax/minimax_m3`](https://github.com/NVIDIA-NeMo/Megatron-Bridge/tree/main/examples/models/minimax/minimax_m3)

‎docs/fern/versions/nightly/pages/models/qwen/qwen2.5-vl.mdx‎

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -61,29 +61,25 @@ Before training, ensure the following environment variables are set.
6161

6262
### Full Finetuning
6363

64-
Example usage for full parameter finetuning:
64+
Example usage for 3B full-parameter finetuning on one H100:
6565

6666
```bash
67-
uv run python -m torch.distributed.run --nproc-per-node=8 examples/models/qwen/qwen_vl/finetune_qwen25_vl.py \
68-
--pretrained-checkpoint $MEGATRON_MODEL_PATH \
69-
--recipe qwen25_vl_3b_finetune_config \
70-
--dataset-type hf \
71-
dataset.source.dataset_name=cord_v2 \
72-
train.global_batch_size=<batch size> \
73-
train.train_iters=<number of iterations> \
74-
logger.wandb_project=<optional wandb project name> \
75-
logger.wandb_save_dir=$SAVE_DIR \
76-
checkpoint.save=$SAVE_DIR/<experiment name>
67+
uv run python -m torch.distributed.run --standalone --nproc_per_node=1 \
68+
scripts/training/run_recipe.py \
69+
--recipe qwen25_vl_3b_sft_config \
70+
--dataset vlm-hf \
71+
--step_func vlm_step \
72+
checkpoint.pretrained_checkpoint=$MEGATRON_MODEL_PATH \
73+
checkpoint.save=$SAVE_DIR/qwen25-vl-3b-sft \
74+
dataset.source.dataset_name=cord_v2 \
75+
train.global_batch_size=2 \
76+
train.train_iters=NUM_ITERATIONS
7777
```
7878

7979
Note:
80-
- The `--recipe` parameter selects the model size configuration. Available options:
81-
- `qwen25_vl_3b_finetune_config` - for 3B model
82-
- `qwen25_vl_7b_finetune_config` - for 7B model
83-
- `qwen25_vl_32b_finetune_config` - for 32B model
84-
- `qwen25_vl_72b_finetune_config` - for 72B model
80+
- Full-SFT recipes are `qwen25_vl_{3b,7b,32b,72b}_sft_config`; their defaults require 1, 2, 16, and 32 GPUs respectively.
8581
- The config file `examples/models/qwen/qwen_vl/conf/qwen25_vl_pretrain_override_example.yaml` contains a list of arguments
86-
that can be overridden in the command. For example, you can set `train.global_batch_size=&lt;batch size&gt;` in the command.
82+
that can be overridden in the command. For example, you can set `train.global_batch_size=BATCH_SIZE` in the command.
8783
- The dataset format should be JSONL with conversation format (see dataset section below).
8884
- After training, you can run inference with `hf_to_megatron_generate_vlm.py` by supplying the trained megatron checkpoint.
8985
You can also export the trained checkpoint to Hugging Face format.
@@ -92,14 +88,15 @@ Note:
9288
Parameter-efficient finetuning (PEFT) using LoRA or DoRA is supported. You can use the `--peft_scheme` argument to enable PEFT training:
9389

9490
```bash
95-
uv run python -m torch.distributed.run --nproc-per-node=8 examples/models/qwen/qwen_vl/finetune_qwen25_vl.py \
96-
--pretrained-checkpoint $MEGATRON_MODEL_PATH \
97-
--recipe qwen25_vl_3b_finetune_config \
98-
--peft_scheme lora \
99-
--dataset-type hf \
100-
dataset.source.dataset_name=cord_v2 \
101-
train.global_batch_size=<batch size> \
102-
checkpoint.save=$SAVE_DIR/<experiment name>
91+
uv run python -m torch.distributed.run --standalone --nproc_per_node=1 \
92+
scripts/training/run_recipe.py \
93+
--recipe qwen25_vl_3b_peft_config \
94+
--dataset vlm-hf \
95+
--step_func vlm_step \
96+
--peft_scheme lora \
97+
checkpoint.pretrained_checkpoint=$MEGATRON_MODEL_PATH \
98+
checkpoint.save=$SAVE_DIR/qwen25-vl-3b-lora \
99+
dataset.source.dataset_name=cord_v2
103100
```
104101

105102
PEFT options:
@@ -112,16 +109,21 @@ You can also combine PEFT with freeze options to control which components are tr
112109

113110
Example with LoRA and freeze options:
114111
```bash
115-
uv run python -m torch.distributed.run --nproc-per-node=8 examples/models/qwen/qwen_vl/finetune_qwen25_vl.py \
116-
--pretrained-checkpoint $MEGATRON_MODEL_PATH \
117-
--recipe qwen25_vl_3b_finetune_config \
118-
--peft_scheme lora \
119-
model.freeze_language_model=True \
120-
model.freeze_vision_model=False \
121-
model.freeze_vision_projection=False \
122-
checkpoint.save=$SAVE_DIR/<experiment name>
112+
uv run python -m torch.distributed.run --standalone --nproc_per_node=1 \
113+
scripts/training/run_recipe.py \
114+
--recipe qwen25_vl_3b_peft_config \
115+
--dataset vlm-hf \
116+
--step_func vlm_step \
117+
--peft_scheme lora \
118+
checkpoint.pretrained_checkpoint=$MEGATRON_MODEL_PATH \
119+
model.freeze_language_model=True \
120+
model.freeze_vision_model=False \
121+
model.freeze_vision_projection=False \
122+
checkpoint.save=$SAVE_DIR/qwen25-vl-3b-lora
123123
```
124124

125+
For local processor-native image JSONL and sharded Energon preparation patterns, see the [multimodal data tutorials](https://github.com/NVIDIA-NeMo/Megatron-Bridge/blob/main/tutorials/data/README.md).
126+
125127
## Example Datasets
126128

127129
Megatron Bridge supports various vision-language dataset examples which can be used to finetune Qwen 2.5 VL:

‎docs/fern/versions/nightly/pages/recipe-usage.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Training mode follows the recipe and dataset type:
2323
| LLM pretraining or continued pretraining | `GPTDatasetConfig` | `pretrain()` | No checkpoint for from-scratch runs; use `checkpoint.load` for full resume or `checkpoint.pretrained_checkpoint` for model-weight initialization |
2424
| Full SFT | `GPTSFTDatasetConfig` for local JSONL or Hugging Face source data | `finetune()` | Use `checkpoint.pretrained_checkpoint` for the base model, or `checkpoint.load` for a full native Megatron resume |
2525
| PEFT / LoRA / DoRA | Same as SFT, plus `cfg.peft` | `finetune()` | `checkpoint.pretrained_checkpoint` is required for the frozen base model; `checkpoint.load` resumes adapter training |
26-
| VLM SFT or PEFT | `DirectHFSFTDatasetConfig` + builder, Energon, or a specialized/preloaded provider | `finetune()` with a VLM step function | Use the model-specific checkpoint guidance in the recipe or model docs |
26+
| VLM SFT or PEFT | `DirectHFSFTDatasetConfig` with a Hugging Face source, including its JSON loader, or Energon | `finetune()` with a VLM step function | Use the model-specific checkpoint guidance in the recipe or model docs |
2727

2828
For dataset fields, prefer `seq_length` in Bridge examples. LLM pretraining uses `GPTDatasetConfig` with `data_path`, `blend`, or `blend_per_split`; SFT and PEFT use `dataset_root` for local JSONL data. Do not use `data_path` for SFT/PEFT JSONL roots.
2929

0 commit comments

Comments
 (0)