Repository navigation
[DeepSeek] Integrate M*G Group Gemm - #1046
Merged
Merged
Conversation
xrsrke
pushed a commit
to NousResearch/torchtitan
that referenced
this pull request
Feb 13, 2026
### Summary Integrating the M*G Group GEMM kernel by @lessw2020 in pytorch#967. This kernel requires tokens for the same expert to reside together. So we need to permute the received tokens before the GEMM. We also need to make sure each token group's length (i.e. `m_sizes`) meet the alignment requirement of the Group GEMM. This requires padding some unused index (like `-1`) into the permutation indices. With this integration, we remove a few CPU sync points in the original program, for example, getting the `received` length, and slicing the chunk of tokens for each expert. And most obviously, we removed the for loop needed to perform matmul for all local experts. ### TODO The generation of permutation indices are in CPU right now. We should write a kernel for it. ### Test ``` $ torchrun --standalone --nproc-per-node 4 generate.py Combining expert weights for Group GEMM Combining expert weights for Group GEMM Combining expert weights for Group GEMM ...... Output: You are a helpful assistant. User: What is 2+2? Assistant: 2 + 2 equals 4. ```
xrsrke
pushed a commit
to NousResearch/torchtitan
that referenced
this pull request
Feb 25, 2026
### Summary Integrating the M*G Group GEMM kernel by @lessw2020 in pytorch#967. This kernel requires tokens for the same expert to reside together. So we need to permute the received tokens before the GEMM. We also need to make sure each token group's length (i.e. `m_sizes`) meet the alignment requirement of the Group GEMM. This requires padding some unused index (like `-1`) into the permutation indices. With this integration, we remove a few CPU sync points in the original program, for example, getting the `received` length, and slicing the chunk of tokens for each expert. And most obviously, we removed the for loop needed to perform matmul for all local experts. ### TODO The generation of permutation indices are in CPU right now. We should write a kernel for it. ### Test ``` $ torchrun --standalone --nproc-per-node 4 generate.py Combining expert weights for Group GEMM Combining expert weights for Group GEMM Combining expert weights for Group GEMM ...... Output: You are a helpful assistant. User: What is 2+2? Assistant: 2 + 2 equals 4. ```
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Integrating the M*G Group GEMM kernel by @lessw2020 in #967. This kernel requires tokens for the same expert to reside together. So we need to permute the received tokens before the GEMM.
We also need to make sure each token group's length (i.e.
m_sizes) meet the alignment requirement of the Group GEMM. This requires padding some unused index (like-1) into the permutation indices.With this integration, we remove a few CPU sync points in the original program, for example, getting the
receivedlength, and slicing the chunk of tokens for each expert.And most obviously, we removed the for loop needed to perform matmul for all local experts.
TODO
The generation of permutation indices are in CPU right now. We should write a kernel for it.
Test