mirror of
https://github.com/deepseek-ai/DeepGEMM.git
synced 2026-11-05 00:47:26 +00:00
[PR #469] [CLOSED] Fix cross-expert output overwrites in SM90 masked GEMM #472
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
deepseek-ai/DeepGEMM#472
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/deepseek-ai/DeepGEMM/pull/469
Author: @Sunt-ing
Created: 10/12/2026
Status: ❌ Closed
Base:
main← Head:codex/sm90-masked-output-boundaries📝 Commits (1)
2086593Fix SM90 masked GEMM output boundaries📊 Changes
7 files changed (+62 additions, -13 deletions)
View changed files
📝
csrc/jit_kernels/impls/sm90_bf16_gemm.hpp(+5 -3)📝
csrc/jit_kernels/impls/sm90_fp8_gemm_1d2d.hpp(+7 -5)📝
deep_gemm/include/deep_gemm/impls/sm90_bf16_gemm.cuh(+2 -2)📝
deep_gemm/include/deep_gemm/impls/sm90_fp8_gemm_1d2d.cuh(+2 -3)📝
tests/test_bf16.py(+7 -0)📝
tests/test_fp8_fp4.py(+7 -0)📝
tests/utils.py(+32 -0)📄 Description
SM90 masked GEMM flattens the output into a 2D TMA descriptor. When a store tile extends past an expert's capacity, it can overwrite valid rows of the next expert. This affects both BF16 and FP8: capacity 32 reproduces it, and capacity 96 also fails when experts are nearly full.
Keep the expert dimension in the output descriptor and reuse the existing 3D TMA store path. This preserves tile selection and the compute pipeline without adding buffers or synchronization. Boundary regressions are integrated into the existing BF16 and FP8 test suites.
This revisits the limitation discussed in #15 and the small-capacity failure reported in #268. #15 previously fixed small capacities by shrinking the store tile and rejected larger capacities not divisible by the tile size; it also suggested 3D TMA but deferred support for those cases. This change handles both small and non-tile-aligned capacities through the same output path.
On H200, the median paired latency changes across six rounds were between −0.17% and +0.16% for the larger tested shapes. The smallest shape was about 1.9% slower for BF16 and 1.5% slower for FP8, roughly 0.06–0.08 µs. The uniform 3D path avoids maintaining separate aligned and unaligned implementations, at that small measured cost.
Reproduction and validation
Requires an SM90 GPU and a source build of DeepGEMM. Save the following as
repro.pyoutside the source checkout and runpython repro.pyagainst the installed baseline or patched package:Running this exact script against the baseline failed with
AssertionError: diff=tensor(0.1456, device='cuda:0', dtype=torch.float64); the patched wheel completed all 16 checks. Only valid rows are checked; padding values are unspecified.Run the included regressions from the checkout after building and installing the patched package:
Both passed with the final built wheel, including a fresh-JIT-cache run. Both fail at capacity 16 when run against the baseline package. A separate timed run with the JIT cache populated took 0.23 s for the BF16 test body and 0.09 s for FP8; this excludes process startup and imports, and does not estimate cold compilation time.
Supplemental validation, using separate local harnesses not included in this PR:
057ca5964aae0879ff2e0eb71ee05a3cb0ba3df7; candidate:20865936a058d55c4c583cc2b0c2bcf3bc319a2f. H200, PyTorch2.13.0+cu130, CUDA 13.0.python setup.py bdist_wheelpassed with setuptools75.8.0.Performance used six paired rounds with alternating arm order. Each measurement took the median of seven CUDA-event samples, each containing 1,000 Graph calls. Input generation and quantization were outside timing; FP8 API scale conversion was included. Positive values below mean slower; values are medians of paired latency changes.
Clocks were not locked; sampled SM clocks ranged from 1305 to 1980 MHz. Small differences on the larger shapes should not be interpreted as established speedups. CPU launch latency, model-level impact, other GPU architectures, and the full build matrix were not evaluated.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.