Skip to content

Commit ffa5b7b

Browse files
perf(recipe): llama3 8B GB200 NVFP4 — run DPA in FP8 current scaling (#5394)
Signed-off-by: Nitin Vegesna <nvegesna@nvidia.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
1 parent 09bd5c9 commit ffa5b7b

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎src/megatron/bridge/perf_recipes/llama/gb200/llama3.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ def llama3_8b_pretrain_8gpu_gb200_nvfp4_config() -> ConfigContainer:
160160
"""Llama3 8B pretrain: 8× GB200, NVFP4."""
161161
cfg = llama3_8b_pretrain_config()
162162
cfg.mixed_precision = _perf_precision("nvfp4")
163+
# NVFP4BlockScaling takes fp8_dpa from this field, so DPA runs in FP8 under the FP4 recipe.
164+
cfg.mixed_precision.fp8_dot_product_attention = True
163165
cfg.tokenizer.vocab_size = 128256
164166
cfg.model.should_pad_vocab = True
165167

@@ -193,6 +195,8 @@ def llama3_8b_pretrain_8gpu_gb200_nvfp4_config() -> ConfigContainer:
193195
"NVTE_FWD_LAYERNORM_SM_MARGIN": 20,
194196
# NVFP4 fast-math path.
195197
"NVTE_USE_FAST_MATH": 1,
198+
# FP8 recipe TE uses for the DPA enabled above.
199+
"NVTE_DPA_FP8_RECIPE": "Float8CurrentScaling",
196200
}
197201
return cfg
198202

‎tests/unit_tests/recipes/test_llama_perf_recipes.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import pytest
2121

2222
from megatron.bridge.perf_recipes.llama.gb200.llama3 import (
23+
llama3_8b_pretrain_8gpu_gb200_nvfp4_config,
2324
llama3_70b_pretrain_64gpu_gb200_nvfp4_config,
2425
)
2526
from megatron.bridge.perf_recipes.llama.h100.llama3 import (
@@ -139,3 +140,28 @@ def test_llama3_70b_gb200_nvfp4_captures_whole_transformer_layer(monkeypatch: py
139140
assert cfg.model.pipeline_model_parallel_size == 4
140141
assert cfg.model.virtual_pipeline_model_parallel_size == 5
141142
assert cfg.train.global_batch_size == 256
143+
144+
145+
@pytest.mark.unit
146+
def test_llama3_8b_gb200_nvfp4_runs_dpa_in_fp8_current_scaling(monkeypatch: pytest.MonkeyPatch) -> None:
147+
"""The 8-GPU GB200 NVFP4 recipe runs dot-product attention in FP8 current scaling.
148+
149+
NVFP4BlockScaling takes ``fp8_dpa`` from ``fp8_dot_product_attention`` independently of
150+
``config.fp8``, so the flag is live under the FP4 recipe rather than inert.
151+
``NVTE_DPA_FP8_RECIPE`` selects the FP8 recipe TE uses for that attention path, and must be
152+
part of the inline ``env_vars`` dict so the recipe-environment test sees it.
153+
"""
154+
patch_recipe_construction_dependencies(monkeypatch)
155+
156+
cfg = llama3_8b_pretrain_8gpu_gb200_nvfp4_config()
157+
158+
assert cfg.mixed_precision.fp8_dot_product_attention is True
159+
assert cfg.mixed_precision.fp4 == "e2m1"
160+
assert cfg.mixed_precision.fp4_recipe == "nvfp4"
161+
assert cfg.env_vars["NVTE_DPA_FP8_RECIPE"] == "Float8CurrentScaling"
162+
163+
# Parallelism and batch are unchanged by this setting.
164+
assert cfg.model.tensor_model_parallel_size == 1
165+
assert cfg.model.pipeline_model_parallel_size == 1
166+
assert cfg.train.global_batch_size == 128
167+
assert cfg.train.micro_batch_size == 4

0 commit comments

Comments
 (0)