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 megatron/core/model_parallel_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,11 @@ def __post_init__(self):
if self.autocast_dtype is None:
self.autocast_dtype = self.params_dtype

assert not (self.cross_entropy_loss_fusion and self.cross_entropy_fusion_impl == 'te'), (
"Transformer Engine cross entropy loss fusion is disabled due to stability issues. "
"Use cross_entropy_fusion_impl='native', or disable cross_entropy_loss_fusion."
)

if self.defer_embedding_wgrad_compute and self.pipeline_model_parallel_size == 1:
raise ValueError(
"Cannot defer embedding wgrad compute when pipeline model parallel is not used"
Expand Down
2 changes: 1 addition & 1 deletion megatron/core/transformer/moe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ The following flags are general performance flags that can help to achieve highe
--moe-router-fusion
--moe-permute-fusion
--cross-entropy-loss-fusion
--cross-entropy-fusion-impl te
--cross-entropy-fusion-impl native

## Communication optimization
--use-distributed-optimizer
Expand Down
7 changes: 7 additions & 0 deletions megatron/training/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,13 @@ def validate_args(args, defaults={}):
assert args.fim_spm_rate, "--fim-spm-rate should be specified."
assert all(token is not None for token in extra_tokens), "FIM extra tokens should be specified."

assert not (
args.cross_entropy_loss_fusion and args.cross_entropy_fusion_impl == 'te'
), (
"Transformer Engine cross entropy loss fusion is disabled due to stability issues. "
"Use --cross-entropy-fusion-impl native, or omit --cross-entropy-loss-fusion."
)

# Deterministic mode
if args.deterministic_mode:
assert not args.use_flash_attn, "Flash attention can not be used in deterministic mode."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ MODEL_ARGS:
--train-samples: 19531250
--manual-gc: true
--cross-entropy-loss-fusion: true
--cross-entropy-fusion-impl: te
--cross-entropy-fusion-impl: native
# Transformer Engine args
--transformer-impl: transformer_engine
# Data args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ MODEL_ARGS:
--train-samples: 19531250
--manual-gc: true
--cross-entropy-loss-fusion: true
--cross-entropy-fusion-impl: te
--cross-entropy-fusion-impl: native
# Transformer Engine args
--transformer-impl: transformer_engine
# Data args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ MODEL_ARGS:
--exit-duration-in-mins: 220
--no-check-for-nan-in-loss-and-grad: true
--cross-entropy-loss-fusion: true
--cross-entropy-fusion-impl: te
--cross-entropy-fusion-impl: native
--manual-gc: true
--manual-gc-interval: 10

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ MODEL_ARGS:
--exit-duration-in-mins: 220
--no-check-for-nan-in-loss-and-grad: true
--cross-entropy-loss-fusion: true
--cross-entropy-fusion-impl: te
--cross-entropy-fusion-impl: native
--manual-gc: true
--manual-gc-interval: 10

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ MODEL_ARGS:
--exit-duration-in-mins: 220
--no-check-for-nan-in-loss-and-grad: true
--cross-entropy-loss-fusion: true
--cross-entropy-fusion-impl: te
--cross-entropy-fusion-impl: native
--manual-gc: true
--manual-gc-interval: 10

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ MODEL_ARGS:
--exit-duration-in-mins: 220
--no-check-for-nan-in-loss-and-grad: true
--cross-entropy-loss-fusion: true
--cross-entropy-fusion-impl: te
--cross-entropy-fusion-impl: native
--manual-gc: true
--manual-gc-interval: 10

Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/models/test_mimo_1f1b_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def get_language_model_spec(
pipeline_dtype=pipeline_dtype,
bf16=bf16,
cross_entropy_loss_fusion=True,
cross_entropy_fusion_impl='te',
cross_entropy_fusion_impl='native',
calculate_per_token_loss=per_token_loss,
**extra_kwargs,
)
Expand Down
17 changes: 17 additions & 0 deletions tests/unit_tests/test_model_parallel_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

import pytest

from megatron.core.model_parallel_config import ModelParallelConfig


def test_te_cross_entropy_loss_fusion_is_disabled():
with pytest.raises(AssertionError, match="Transformer Engine cross entropy loss fusion"):
ModelParallelConfig(cross_entropy_loss_fusion=True, cross_entropy_fusion_impl='te')


def test_native_cross_entropy_loss_fusion_is_allowed():
config = ModelParallelConfig(cross_entropy_loss_fusion=True, cross_entropy_fusion_impl='native')

assert config.cross_entropy_loss_fusion
assert config.cross_entropy_fusion_impl == 'native'
Loading