[DeepSeek-V4] Implement MoE routing primitives#3871
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
37ee811 to
31329c5
Compare
1ab79e5 to
c025463
Compare
31329c5 to
22a57ff
Compare
c025463 to
68c44a6
Compare
22a57ff to
32869e5
Compare
72a92a7 to
e81f52d
Compare
32869e5 to
c92f2e0
Compare
|
🤖 Hi @parambole, I've received your request, and I'm working on it now! You can track my progress in the logs for more details. |
0cac1e1 to
fa01c9c
Compare
dc34263 to
41e3f67
Compare
dipakg-lang
left a comment
There was a problem hiding this comment.
Looks like this change wrongly has attention related changes instead of MOE routing related ones?
6c801b1 to
cb89739
Compare
Ah! That was just an artifact of the base branch I selected. I recently changed the PR's base branch to deepseek_v4_compressed_attention, which should isolate the diff to show only the MoE routing changes going forward. Let me know if the diff still looks noisy! |
cb89739 to
eb9de77
Compare
eb9de77 to
0167a4e
Compare
RissyRan
left a comment
There was a problem hiding this comment.
Thanks for the change! Please note that we have DS v2, and a few if condition may break the functionality.
There was a problem hiding this comment.
Thanks for refactoring and reusing MoE logic! Further comments:
- Perhaps we can use
is_hash_routinginsteadlayer_idxto indicate hash router for clarify. Decoder can use idx to determine. - Perhaps can use
nnx.Variableinstead ofnnx.Paramfor register_buffer counterpart
RissyRan
left a comment
There was a problem hiding this comment.
Thanks for the change! Please add an assertion in types.py.
|
Note sure why |
Description
Implement Mixture of Experts (MoE) routing primitives and infrastructural updates required for DeepSeek-V4 integration into MaxText.
moe.py'sget_topkfunction.RoutedMoEandRoutedAndSharedMoEto acceptlayer_idxandinput_idsvia optional keyword arguments. This allows DeepSeek to pipe these variables down into the hashing logic, while safely defaulting to0andNoneso existing callers are entirely unimpacted.fused_moe_matmul(via thevllm_rpablock) specifically for hash-routed layers where it is unsupported.sqrtsoftpluscustom activation function inlinears.pyrequired by the DeepSeek V4 MoE router.tests/unit/deepseek_v4_vs_reference_test.py): Validates MoE routing parity against PyTorch reference implementations.Tests
Tested on CPU. All DeepSeek V4 and core MoE unit tests pass successfully.
Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.