Skip to content

[Draft] [GPU] DSv4 Support for TE MoE Block - #5487

Draft
dinodeep wants to merge 1 commit into
AI-Hypercomputer:mainfrom
dinodeep:dinodeep/te-moe-block-dsv4-support
Draft

dinodeep wants to merge 1 commit into
AI-Hypercomputer:mainfrom
dinodeep:dinodeep/te-moe-block-dsv4-support

Conversation

@dinodeep

@dinodeep dinodeep commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This PR integrates the updated support for TE MoE block for supporting DSv4. It does the following

  • pipes hash routing through TE MoE block's moe(...) call so that hash routing layers can correctly use TE MoE block
  • uses the expert counts returned from TE MoE block to support updating the routed bias via routed_bias_update_rate
  • change the default initialization (not checkpointed) of DSv4's hash routing self.tid2eid from zero array to randomly initialized experts, preventing (1) a single token going to the same expert multiple times (2) having a balanced distribution of tokens to experts (3) prevent infinite gradients when all tokens go to the same expert

This is a useful change so that TE MoE block can work with DSv4 out of the box.

Tests

Tested by integrating a end-to-end train test to validate full execution.

Checklist

Before submitting this PR, please make sure (put X in square brackets):

  • I have performed a self-review of my code. For an optional AI review, add the gemini-review label.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests tests and provided workload links above if applicable.
  • I have made or will make corresponding changes to the doc if needed, including adding new documentation pages to the relevant Table of Contents (toctree directive) as explained in our documentation.

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

Copy link
Copy Markdown

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 adds support for hash routing and routed bias updates in TransformerEngine MoE blocks, particularly for DeepSeek-V4. It introduces the moe_from_routing path when hash routing is enabled, handles routed bias updates, and adds a corresponding integration test. However, a critical issue was identified where input_ids (which is required for hash routing) is not forwarded by the caller DeepSeekMoELayer in src/maxtext/models/deepseek.py to self.mlp_op or self.DeepSeekMoeBlock_0, which will cause a runtime ValueError.

Comment thread src/maxtext/layers/moe.py
Comment thread src/maxtext/configs/models/deepseek4-284b.yml
Comment thread src/maxtext/layers/moe.py Outdated
@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 31.81818% with 30 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/maxtext/layers/moe.py 30.00% 28 Missing ⚠️
src/maxtext/models/deepseek.py 50.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@dinodeep
dinodeep force-pushed the dinodeep/te-moe-block-dsv4-support branch 2 times, most recently from 335a81d to 852bc73 Compare October 1, 2026 23:06
Comment thread src/maxtext/layers/moe.py Outdated
@dinodeep
dinodeep force-pushed the dinodeep/te-moe-block-dsv4-support branch from 852bc73 to 1791d6c Compare October 4, 2026 16:55
@dinodeep
dinodeep force-pushed the dinodeep/te-moe-block-dsv4-support branch 3 times, most recently from a97e92a to 0e1ced1 Compare October 22, 2026 21:08
@dinodeep
dinodeep force-pushed the dinodeep/te-moe-block-dsv4-support branch from 0e1ced1 to 7c100e1 Compare October 22, 2026 22:01

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants