Skip to content

[megatron] update cross_entropy_fusion_impl default value 'te' -> 'native' (#9578)#9578

Merged
Jintao-Huang merged 2 commits into
modelscope:mainfrom
Jintao-Huang:fix_cross_entropy_fusion_impl
Jun 17, 2026
Merged

[megatron] update cross_entropy_fusion_impl default value 'te' -> 'native' (#9578)#9578
Jintao-Huang merged 2 commits into
modelscope:mainfrom
Jintao-Huang:fix_cross_entropy_fusion_impl

Conversation

@Jintao-Huang

Copy link
Copy Markdown
Collaborator

No description provided.

@Jintao-Huang Jintao-Huang changed the title [bugfix] fix cross_entropy_fusion_impl [bugfix] fix cross_entropy_fusion_impl 'te' -> 'native' Jun 16, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request changes the default implementation of cross-entropy loss fusion (cross_entropy_fusion_impl) from dynamic resolution to a static default of 'native', updating both the code and documentation. The feedback suggests keeping the field type as Optional and adding a defensive fallback to 'native' in post_init to prevent runtime errors if None is explicitly passed or deserialized.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

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'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Changing the type of cross_entropy_fusion_impl to Literal['native', 'te'] (non-optional) and removing the None check in __post_init__ can lead to runtime errors if the argument is explicitly passed as None or deserialized as None from older configurations or external parsers. Keeping it as Optional and adding a fallback to 'native' in __post_init__ is safer and more robust.

Suggested change
cross_entropy_fusion_impl: Literal['native', 'te'] = 'native'
cross_entropy_fusion_impl: Optional[Literal['native', 'te']] = 'native'

Comment on lines 723 to 724
if isinstance(self.report_to, str):
self.report_to = [self.report_to]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To prevent potential runtime issues when cross_entropy_fusion_impl is explicitly set or parsed as None, we should add a defensive check in __post_init__ to default it to 'native' if it is None.

Suggested change
if isinstance(self.report_to, str):
self.report_to = [self.report_to]
if self.cross_entropy_fusion_impl is None:
self.cross_entropy_fusion_impl = 'native'
if isinstance(self.report_to, str):
self.report_to = [self.report_to]

@Jintao-Huang

Copy link
Copy Markdown
Collaborator Author

NVIDIA/Megatron-LM#5115

@Jintao-Huang Jintao-Huang merged commit 7cb73c1 into modelscope:main Jun 17, 2026
2 of 3 checks passed
@Jintao-Huang Jintao-Huang changed the title [bugfix] fix cross_entropy_fusion_impl 'te' -> 'native' [megatron] update cross_entropy_fusion_impl default value 'te' -> 'native' (#9578) Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants