Skip to content

[WIP] N*G Triton group gemm for MoE - #960

Closed
lessw2020 wants to merge 6 commits into
mainfrom
lessw2020/triton_group_gemm
Closed

lessw2020 wants to merge 6 commits into
mainfrom
lessw2020/triton_group_gemm

Conversation

@lessw2020

@lessw2020 lessw2020 commented Mar 14, 2025 •

Copy link
Copy Markdown
Contributor

This PR adds a Triton Group GEMM with full backwards pass support, for integration with MoE training.
The forward pass is from FBGemm experimental:
https://github.com/pytorch/FBGEMM/blob/main/fbgemm_gpu/experimental/gemm/triton_gemm/grouped_gemm.py

A. - Forward unit tests expanded and refactored. now includes DeepSeek v3 main shapes:

Testing BF16 N*G GroupGeMM with G=1, M=64
Testing BF16 N*G GroupGeMM with G=1, M=512
Testing BF16 N*G GroupGeMM with G=1, M=2048
Testing BF16 N*G GroupGeMM with G=4, M=64
Testing BF16 N*G GroupGeMM with G=4, M=512
Testing BF16 N*G GroupGeMM with G=4, M=2048
Testing BF16 N*G GroupGeMM with G=16, M=64
Testing BF16 N*G GroupGeMM with G=16, M=512
Testing BF16 N*G GroupGeMM with G=16, M=2048
.Testing BF16 N*G Deepseek shape: G=4, M=8192, N=4096, K=7168
Testing BF16 N*G Deepseek shape: G=4, M=8192, N=7168, K=2048
Testing BF16 N*G Deepseek shape: G=8, M=4096, N=4096, K=7168
Testing BF16 N*G Deepseek shape: G=8, M=4096, N=7168, K=2048
.
----------------------------------------------------------------------
Ran 2 tests in 75.435s

OK

1 - Backward Numerics with BF16 have been verified on sample sizes and the core DeepSeek v3 shapes.

2025-03-13 16:40:08,294 - INFO - Gradient shapes - grad_x: torch.Size([1024, 256]), grad_w: torch.Size([10240, 256])
2025-03-13 16:40:08,294 - INFO - Running PyTorch reference implementation
2025-03-13 16:40:08,591 - INFO - Comparing gradients with PyTorch reference
2025-03-13 16:40:08,602 - INFO - Maximum gradient error - grad_x: 0.125, grad_w: 0.125
2025-03-13 16:40:08,641 - INFO - ✓ SUCCESS! grad_X matches the PyTorch reference (allclose check passed)
2025-03-13 16:40:08,641 - INFO - ✓ SUCCESS! grad_W matches the PyTorch reference (allclose check passed)
2025-03-13 16:40:08,641 - INFO - Gradients allclose check - grad_x: True, grad_w: True
2025-03-13 16:40:08,641 - INFO - ✓ SUCCESS: Gradients match the PyTorch reference (allclose check passed)

2 - Todos:
a - fp8 support
b - TMA (used in forward now but not in backward)
c - WS
d - Perf and auto-tuning

3 - Integration - ready now for BF16 though may want to do perf work first.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 14, 2025
@lessw2020 lessw2020 mentioned this pull request Mar 14, 2025
@lessw2020 lessw2020 self-assigned this Mar 14, 2025
@lessw2020 lessw2020 changed the title [WIP] Triton group gemm for MoE [WIP] N*G Triton group gemm for MoE Mar 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants