Repository navigation
[megatron] update cross_entropy_fusion_impl default value 'te' -> 'native' (#9578) #9578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Jintao-Huang
merged 2 commits into
modelscope:main
from
Jintao-Huang:fix_cross_entropy_fusion_impl
Jun 17, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -440,7 +440,7 @@ class MegatronArguments(RLHFMegatronArgumentsMixin, MegatronTunerMixin): | |||||||||||||
| apply_rope_fusion: bool = False | ||||||||||||||
| gradient_accumulation_fusion: bool = True | ||||||||||||||
| cross_entropy_loss_fusion: bool = True | ||||||||||||||
| cross_entropy_fusion_impl: Optional[Literal['native', 'te']] = None | ||||||||||||||
| cross_entropy_fusion_impl: Literal['native', 'te'] = 'native' | ||||||||||||||
| calculate_per_token_loss: Optional[bool] = None | ||||||||||||||
| attention_backend: str = 'flash' # flash, fused, unfused, local, auto | ||||||||||||||
| optimizer: Literal['adam', 'sgd', 'muon', 'dist_muon'] = 'adam' | ||||||||||||||
|
|
@@ -720,15 +720,6 @@ def __post_init__(self): | |||||||||||||
| self._init_vpp_size() | ||||||||||||||
| if self.vit_gradient_checkpointing is None: | ||||||||||||||
| self.vit_gradient_checkpointing = not self.freeze_vit | ||||||||||||||
| if self.cross_entropy_fusion_impl is None: | ||||||||||||||
| if is_torch_npu_available(): | ||||||||||||||
| self.cross_entropy_fusion_impl = 'native' | ||||||||||||||
| else: | ||||||||||||||
| import transformer_engine | ||||||||||||||
| if version.parse(transformer_engine.__version__) >= version.parse('2.8.0'): | ||||||||||||||
| self.cross_entropy_fusion_impl = 'te' | ||||||||||||||
| else: | ||||||||||||||
| self.cross_entropy_fusion_impl = 'native' | ||||||||||||||
| if isinstance(self.report_to, str): | ||||||||||||||
| self.report_to = [self.report_to] | ||||||||||||||
|
Comment on lines
723
to
724
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To prevent potential runtime issues when
Suggested change
|
||||||||||||||
| self.model_info, self.model_meta = get_model_info_meta( | ||||||||||||||
|
|
||||||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the type of
cross_entropy_fusion_impltoLiteral['native', 'te'](non-optional) and removing theNonecheck in__post_init__can lead to runtime errors if the argument is explicitly passed asNoneor deserialized asNonefrom older configurations or external parsers. Keeping it asOptionaland adding a fallback to'native'in__post_init__is safer and more robust.