Skip to content

Deterministic MoE Router Kernel By Removing Global Atomic Ops - #3587

Open
zhongbozhu wants to merge 2 commits into
NVIDIA:mainfrom
zhongbozhu:fix/deterministic-moe-aux-loss
Open

zhongbozhu wants to merge 2 commits into
NVIDIA:mainfrom
zhongbozhu:fix/deterministic-moe-aux-loss

Conversation

@zhongbozhu

@zhongbozhu zhongbozhu commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Please include a brief summary of the changes, relevant motivation and context.

Fixes NVIDIA/Megatron-LM#7221

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

Please list the changes introduced in this PR:

  • Change A
  • Change B

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@github-actions github-actions Bot added the community-contribution PRs from external contributor outside the core maintainers, representing community-driven work. label Sep 29, 2026
@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge; no actionable issues were found.

Summary

Adds an optional fixed-order reduction for MoE auxiliary loss while preserving the existing atomic path by default.

  • MoE aux-loss callers can now choose a fixed-order reduction.
  • PyTorch's aux-loss call offers deterministic mode for eager and graph calls.
  • The fused MLA module keeps its extension import with the package imports.

No actionable issues were found. CUDA tests were not run.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["fused_moe_aux_loss"] --> B{"deterministic?"}
  B -->|No| C["Existing atomic reduction"]
  B -->|Yes| D["Get workspace"]
  D --> E["Each block writes one partial sum"]
  E --> F["Sum partials in a fixed order"]
  C --> G["Loss and saved coefficient"]
  F --> G
  G --> H["Existing backward kernel"]
Loading

Reviews (3) · Last reviewed commit: "Align deterministic MoE aux-loss workspa..." · Reviewed by Greptile

*
* \return Maximum required workspace size in bytes.
*/
size_t nvte_get_moe_aux_loss_workspace_size();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The way we handle the workspace in the other APIs is similar to CUB - we run the APIs with the nullptr arguments for the workspace once (which populates the other fields), then run it again with the proper workspace. Please align this API to that.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor

Thanks a lot @zhongbozhu.

The kernel is deterministic on one GPU. For multi-node runs, does determinism also hold with multi-node job, do we need the same placement and a fixed NCCL algorithm? Good to put it in the docs if there's anything worth noting.

Signed-off-by: Zhongbo Zhu <zhongboz@nvidia.com>
Signed-off-by: zhongboz <zhongboz@nvidia.com>
Query workspace shape and dtype through the deterministic forward APIs, retain stream and CUDA Graph isolation, and cover metadata queries and invalid scratch buffers. Fix the stream cache-key lint warning and upstream import ordering.

Validated on GB200: 201 TE tests passed (12 invalid top-k cases skipped), 6 C API tests passed, and 40 MCore checks passed with 1 expected atomic negative-control XPASS. Full PyTorch QA lint, pre-commit, and license checks passed.

Signed-off-by: zhongboz <zhongboz@nvidia.com>
@zhongbozhu
zhongbozhu force-pushed the fix/deterministic-moe-aux-loss branch from 17c35fa to 07887f8 Compare October 15, 2026 07:29
@zhongbozhu

Copy link
Copy Markdown
Collaborator Author

/te-ci pytorch

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.21 community-contribution PRs from external contributor outside the core maintainers, representing community-driven work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Determinism] Add deterministic TE fused loss support

3 participants