Skip to content

Commit 020041f

Browse files
committed
feat(nemotron): add NVFP4 mixed precision configurations for Ultra pretraining on GB200 and GB300
- Introduced new mixed precision configuration for Nemotron 3 Ultra using BF16 with NVFP4. - Added NVFP4 pretraining configurations for 256 GPUs on both GB200 and GB300. - Updated existing functions to incorporate new precision settings and ensure compatibility with the latest architecture. Signed-off-by: Ravi Ghadia <ghadiaravi13@users.noreply.github.com>
1 parent a67b573 commit 020041f

5 files changed

Lines changed: 218 additions & 2 deletions

File tree

src/megatron/bridge/perf_recipes/nemotronh/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
nemotron_3_super_pretrain_64gpu_gb200_fp8mx_config,
3131
nemotron_3_super_pretrain_64gpu_gb200_nvfp4_config,
3232
nemotron_3_ultra_pretrain_256gpu_gb200_fp8mx_config,
33+
nemotron_3_ultra_pretrain_256gpu_gb200_nvfp4_config,
3334
nemotronh_56b_pretrain_64gpu_gb200_fp8cs_config,
3435
)
3536
from megatron.bridge.perf_recipes.nemotronh.gb300.nemotronh import (
@@ -40,6 +41,7 @@
4041
nemotron_3_super_pretrain_64gpu_gb300_fp8mx_config,
4142
nemotron_3_super_pretrain_64gpu_gb300_nvfp4_config,
4243
nemotron_3_ultra_pretrain_256gpu_gb300_fp8mx_config,
44+
nemotron_3_ultra_pretrain_256gpu_gb300_nvfp4_config,
4345
nemotronh_56b_pretrain_64gpu_gb300_fp8cs_config,
4446
nemotronh_56b_pretrain_256gpu_gb300_bf16_config,
4547
nemotronh_56b_pretrain_256gpu_gb300_fp8cs_config,

src/megatron/bridge/perf_recipes/nemotronh/common.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
from megatron.bridge.recipes.nemotronh.nemotron_3_ultra import nemotron_3_ultra_pretrain_config
2828
from megatron.bridge.recipes.nemotronh.nemotronh import nemotronh_56b_pretrain_config
2929
from megatron.bridge.training.config import ConfigContainer
30-
from megatron.bridge.training.mixed_precision import MixedPrecisionConfig, nemotron_3_super_bf16_with_nvfp4_mixed
30+
from megatron.bridge.training.mixed_precision import (
31+
MixedPrecisionConfig,
32+
nemotron_3_super_bf16_with_nvfp4_mixed,
33+
nemotron_3_ultra_bf16_with_nvfp4_mixed,
34+
)
3135

3236

3337
_TE_QUANT_CFG_PATH = Path(__file__).with_name("te_quant.cfg")
@@ -65,7 +69,19 @@ def _with_global_batch_size(cfg: ConfigContainer, global_batch_size: int) -> Con
6569
def _nemotron_3_super_nvfp4_precision() -> MixedPrecisionConfig:
6670
"""Return the NVFP4 precision config used by Nemotron 3 Super perf recipes."""
6771
cfg = nemotron_3_super_bf16_with_nvfp4_mixed()
68-
# Disabled until MCore PR 4358 lands.
72+
# Although MCore PR 4358 is merged,
73+
# Megatron-FSDP's ParamAndGradBuffer has no NVFP4 packed-storage support, unlike the
74+
# legacy DDP buffer, so FP4 primary weights fault during buffer init.
75+
cfg.fp4_param_gather = False
76+
return cfg
77+
78+
79+
def _nemotron_3_ultra_nvfp4_precision() -> MixedPrecisionConfig:
80+
"""Return the NVFP4 precision config used by Nemotron 3 Ultra perf recipes."""
81+
cfg = nemotron_3_ultra_bf16_with_nvfp4_mixed()
82+
# Although MCore PR 4358 is merged,
83+
# Megatron-FSDP's ParamAndGradBuffer has no NVFP4 packed-storage support, unlike the
84+
# legacy DDP buffer, so FP4 primary weights fault during buffer init.
6985
cfg.fp4_param_gather = False
7086
return cfg
7187

src/megatron/bridge/perf_recipes/nemotronh/gb200/nemotronh.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
_apply_nemotron_3_ultra_perf_defaults,
2424
_benchmark_common,
2525
_nemotron_3_super_nvfp4_precision,
26+
_nemotron_3_ultra_nvfp4_precision,
2627
_perf_precision,
2728
load_quantization_recipe,
2829
nemotron_3_nano_pretrain_config,
@@ -303,6 +304,93 @@ def nemotron_3_ultra_pretrain_256gpu_gb200_fp8mx_config() -> ConfigContainer:
303304
return cfg
304305

305306

307+
def nemotron_3_ultra_pretrain_256gpu_gb200_nvfp4_config() -> ConfigContainer:
308+
"""Nemotron 3 Ultra (550B-A55B LatentMoE) pretrain: 256× GB200, NVFP4, Megatron-FSDP (HSDP).
309+
310+
TP2 + SP (due to smaller GB200 HBM) / PP1 / CP1 / EP64 / ETP1, GBS 256 / MBS 1, seq 8192, BF16 + NVFP4 mixed
311+
precision, HybridEP flex dispatcher, CuteDSL fused grouped MLP, selective recompute +
312+
fine-grained activation offload of the expert MLP, MTP=2.
313+
"""
314+
315+
num_gpus = 256
316+
expert_model_parallel_size = 64
317+
global_batch_size = 256
318+
hybrid_ep_ranks_per_nvlink_domain = 64
319+
320+
cfg = nemotron_3_ultra_pretrain_config()
321+
cfg.mixed_precision = _nemotron_3_ultra_nvfp4_precision()
322+
323+
_apply_nemotron_3_ultra_perf_defaults(cfg)
324+
325+
# Apply HSDP / FSDP dtype overrides last so they win over the generic defaults.
326+
_apply_nemotron_3_ultra_fsdp_hsdp(cfg, num_gpus=num_gpus)
327+
328+
# Parallelism
329+
cfg.model.tensor_model_parallel_size = 2
330+
cfg.model.pipeline_model_parallel_size = 1
331+
cfg.model.virtual_pipeline_model_parallel_size = None
332+
cfg.model.context_parallel_size = 1
333+
cfg.model.sequence_parallel = True
334+
cfg.model.expert_tensor_parallel_size = 1
335+
cfg.model.pipeline_model_parallel_layout = None
336+
cfg.model.seq_length = 8192
337+
338+
# Only tensors larger than 350M elements are offloaded, which
339+
# approximates offloading the moe_act (pre-activation input) for seq 8192/2 (due to SP) / MBS 1.
340+
cfg.model.min_offloaded_tensor_size = 350_000_000
341+
342+
# MXFP8 requires router padding for quantization.
343+
cfg.model.moe_router_padding_for_quantization = True
344+
345+
# GPU-count specific overrides of the canonical (256-GPU / EP64) defaults.
346+
cfg.model.expert_model_parallel_size = expert_model_parallel_size
347+
cfg.train.global_batch_size = global_batch_size
348+
349+
# Fine-grained activation offloading. Requires NVTE_CPU_OFFLOAD_V1=1 in the
350+
# launch environment (set in this recipe's env_vars).
351+
# NOTE: also requires setting the min_offloaded_tensor_size to selectively offload moe_act of the fused_group_mlp, to avoid CPU OOM issues
352+
cfg.model.fine_grained_activation_offloading = True
353+
cfg.model.offload_modules = ["fused_group_mlp"]
354+
cfg.model.fine_grained_offloading_max_inflight_offloads = 1
355+
356+
# Selective recompute of the MoE activation
357+
# recomputes the activation output of the MoE expert MLP, while FC1 output (activation input) is saved and offloaded to cpu
358+
cfg.model.recompute_granularity = "selective"
359+
cfg.model.recompute_modules = ["moe_act"]
360+
361+
# Keep process settings next to the recipe so users can see the exact benchmark environment.
362+
cfg.env_vars = {
363+
**COMMON_PERF_ENV_VARS,
364+
# CUDA stream scheduling for this model and parallel layout.
365+
"CUDA_DEVICE_MAX_CONNECTIONS": 32,
366+
# CUDA graph and allocator behavior for this recipe.
367+
"NCCL_GRAPH_REGISTER": 0,
368+
# TODO: graph_capture_record_stream_reuse might be potentially useful
369+
# when enabling CG, because it allows the freed-up memory buffers of the offloaded tensors
370+
# to be reused during the CG capture, thus keeping the peak memory usage lower.
371+
"PYTORCH_CUDA_ALLOC_CONF": ("expandable_segments:True,graph_capture_record_stream_reuse:True"),
372+
"TORCH_NCCL_AVOID_RECORD_STREAMS": 1,
373+
# NCCL user-buffer and launch settings.
374+
"NCCL_NVLS_ENABLE": 0,
375+
# HybridEP topology for the target system.
376+
"NUM_OF_HYBRID_EP_RANKS_PER_NVLINK_DOMAIN": hybrid_ep_ranks_per_nvlink_domain,
377+
"NUM_OF_TOKENS_PER_CHUNK_COMBINE_API": 128,
378+
"NVLINK_DOMAIN_SIZE": 72,
379+
"USE_MNNVL": 1,
380+
# Transformer Engine overlap settings for this model.
381+
"NVTE_BWD_LAYERNORM_SM_MARGIN": 20,
382+
"NVTE_FWD_LAYERNORM_SM_MARGIN": 20,
383+
# Required by fine_grained_activation_offloading (TE >= 2.10.0) to avoid
384+
# offloading weights;
385+
"NVTE_CPU_OFFLOAD_V1": 1,
386+
# Enable TE's CuteDSL fused grouped MLP kernel (sm100+). Required by the
387+
# op fuser + fused weighted squared-ReLU with moe_act activation recompute
388+
# (ScaledSReLU(activation_recompute_in_mlp=True) only runs on this path).
389+
"NVTE_CUTEDSL_FUSED_GROUPED_MLP": 1,
390+
}
391+
return cfg
392+
393+
306394
def nemotron_3_nano_pretrain_8gpu_gb200_bf16_config() -> ConfigContainer:
307395
"""Nemotron 3 Nano pretrain: 8× GB200, BF16."""
308396
cfg = nemotron_3_nano_pretrain_config()

src/megatron/bridge/perf_recipes/nemotronh/gb300/nemotronh.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
_apply_nemotron_3_ultra_perf_defaults,
2424
_benchmark_common,
2525
_nemotron_3_super_nvfp4_precision,
26+
_nemotron_3_ultra_nvfp4_precision,
2627
_perf_precision,
2728
_with_global_batch_size,
2829
load_quantization_recipe,
@@ -308,6 +309,102 @@ def nemotron_3_ultra_pretrain_256gpu_gb300_fp8mx_config() -> ConfigContainer:
308309
return cfg
309310

310311

312+
def _nemotron_3_ultra_gb300_nvfp4_config(
313+
*, num_gpus: int, expert_model_parallel_size: int, global_batch_size: int
314+
) -> ConfigContainer:
315+
"""Shared builder for Nemotron 3 Ultra GB300 NVFP4 Megatron-FSDP perf recipes."""
316+
cfg = nemotron_3_ultra_pretrain_config()
317+
cfg.mixed_precision = _nemotron_3_ultra_nvfp4_precision()
318+
319+
"""
320+
Uses TP1 / PP1 / CP1 / EP64 / ETP1, GBS 256 / MBS 1,
321+
seq 8192, HybridEP flex dispatcher, CuteDSL fused grouped MLP, selective
322+
recompute + activation offload of the expert MLP, MTP=2. The MoE architecture
323+
(512 experts, latent MoE, MTP, squared-relu, hybrid Mamba/attention pattern,
324+
...) is inherited from the base recipe via ``AutoBridge``.
325+
"""
326+
# Parallelism
327+
cfg.model.tensor_model_parallel_size = 1
328+
cfg.model.pipeline_model_parallel_size = 1
329+
cfg.model.virtual_pipeline_model_parallel_size = None
330+
cfg.model.context_parallel_size = 1
331+
cfg.model.sequence_parallel = False
332+
cfg.model.expert_tensor_parallel_size = 1
333+
cfg.model.pipeline_model_parallel_layout = None
334+
cfg.model.seq_length = 8192
335+
336+
# Only tensors larger than 500MB are offloaded, which
337+
# approximates offloading the moe_act input for seq 8192 / MBS 1.
338+
cfg.model.min_offloaded_tensor_size = 500_000_000
339+
340+
# MXFP8 requires router padding for quantization.
341+
cfg.model.moe_router_padding_for_quantization = True
342+
343+
# GPU-count specific overrides of the canonical (256-GPU / EP64) defaults.
344+
cfg.model.expert_model_parallel_size = expert_model_parallel_size
345+
cfg.train.global_batch_size = global_batch_size
346+
347+
# Fine-grained activation offloading. Requires NVTE_CPU_OFFLOAD_V1=1 in the
348+
# launch environment (set in this recipe's env_vars).
349+
# NOTE: also requires setting the min_offloaded_tensor_size to avoid CPU OOM issues
350+
cfg.model.fine_grained_activation_offloading = True
351+
cfg.model.offload_modules = ["fused_group_mlp"]
352+
353+
# Selective recompute of the MoE activation
354+
# recomputes the activation output of the MoE expert MLP, while FC1 output (activation input) is saved and offloaded to cpu
355+
cfg.model.recompute_granularity = "selective"
356+
cfg.model.recompute_modules = ["moe_act"]
357+
358+
_apply_nemotron_3_ultra_perf_defaults(cfg)
359+
360+
# Apply HSDP / FSDP dtype overrides last so they win over the generic defaults.
361+
_apply_nemotron_3_ultra_fsdp_hsdp(cfg, num_gpus=num_gpus)
362+
363+
return cfg
364+
365+
366+
def nemotron_3_ultra_pretrain_256gpu_gb300_nvfp4_config() -> ConfigContainer:
367+
"""Nemotron 3 Ultra (550B-A55B LatentMoE) pretrain: 256× GB300, NVFP4, Megatron-FSDP (HSDP).
368+
369+
TP1 / PP1 / CP1 / EP64 / ETP1, GBS 256 / MBS 1, seq 8192, BF16 + NVFP4 mixed
370+
precision, HybridEP flex dispatcher, CuteDSL fused grouped MLP, selective
371+
recompute + fine-grained activation offload of the expert MLP, MTP=2.
372+
"""
373+
cfg = _nemotron_3_ultra_gb300_nvfp4_config(
374+
num_gpus=256,
375+
expert_model_parallel_size=64,
376+
global_batch_size=256,
377+
)
378+
# Keep process settings next to the recipe so users can see the exact benchmark environment.
379+
cfg.env_vars = {
380+
**COMMON_PERF_ENV_VARS,
381+
# CUDA stream scheduling for this model and parallel layout.
382+
"CUDA_DEVICE_MAX_CONNECTIONS": 32,
383+
# CUDA graph and allocator behavior for this recipe.
384+
"NCCL_GRAPH_REGISTER": 0,
385+
"PYTORCH_CUDA_ALLOC_CONF": "expandable_segments:True",
386+
"TORCH_NCCL_AVOID_RECORD_STREAMS": 1,
387+
# NCCL user-buffer and launch settings.
388+
"NCCL_NVLS_ENABLE": 0,
389+
# HybridEP topology for the target system.
390+
"NUM_OF_HYBRID_EP_RANKS_PER_NVLINK_DOMAIN": 64,
391+
"NUM_OF_TOKENS_PER_CHUNK_COMBINE_API": 128,
392+
"NVLINK_DOMAIN_SIZE": 72,
393+
"USE_MNNVL": 1,
394+
# Transformer Engine overlap settings for this model.
395+
"NVTE_BWD_LAYERNORM_SM_MARGIN": 20,
396+
"NVTE_FWD_LAYERNORM_SM_MARGIN": 20,
397+
# Required by fine_grained_activation_offloading (TE >= 2.10.0) to avoid
398+
# offloading weights;
399+
"NVTE_CPU_OFFLOAD_V1": 1,
400+
# Enable TE's CuteDSL fused grouped MLP kernel (sm100+). Required by the
401+
# op fuser + fused weighted squared-ReLU with moe_act activation recompute
402+
# (ScaledSReLU(activation_recompute_in_mlp=True) only runs on this path).
403+
"NVTE_CUTEDSL_FUSED_GROUPED_MLP": 1,
404+
}
405+
return cfg
406+
407+
311408
def nemotron_3_nano_pretrain_8gpu_gb300_bf16_config() -> ConfigContainer:
312409
"""Nemotron 3 Nano pretrain: 8× GB300, BF16."""
313410
cfg = nemotron_3_nano_pretrain_config()

src/megatron/bridge/training/mixed_precision.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,19 @@ def nemotron_3_super_bf16_with_nvfp4_mixed() -> MixedPrecisionConfig:
429429
return cfg
430430

431431

432+
@register
433+
def nemotron_3_ultra_bf16_with_nvfp4_mixed() -> MixedPrecisionConfig:
434+
"""Create a MixedPrecisionConfig for mixed precision training using BF16 with NVFP4
435+
Returns:
436+
MixedPrecisionConfig: Configuration for BF16 with NVFP4 mixed precision training
437+
"""
438+
cfg = bf16_with_nvfp4_mixed()
439+
cfg.first_last_layers_bf16 = True
440+
cfg.num_layers_at_start_in_bf16 = 0
441+
cfg.num_layers_at_end_in_bf16 = 16 # last 15% of layers in BF16
442+
return cfg
443+
444+
432445
def get_mixed_precision_config(name: str | MixedPrecisionConfig) -> MixedPrecisionConfig:
433446
"""Return a :class:`MixedPrecisionConfig` for *name*.
434447

0 commit comments

Comments
 (0)