Repository navigation
Conversation
The SM90 layout heuristic adds block M candidates of 16 and 32 for small M, but the SM90 FP8 1D1D kernel (FP32-output / k-grouped GEMMs) only supports block M of 64 or 128 (single or double math warpgroups). For M <= 32, the cost model prefers the smaller tile and the JIT compilation then fails on the kernel's static assertion, so e.g. `fp8_gemm_nt` with an FP32 accumulator and `k_grouped_fp8_gemm_nt_contiguous` cannot run for M <= 32 on Hopper. Restrict the 16/32 candidates to the kernels that support them (1D2D and BF16), and add small-M weight-gradient shapes to the test enumeration. Signed-off-by: RunguoLi <[email protected]>
| # Wgrad with small M (e.g., narrow weights), where the heuristic may pick small block M | ||
| for small_m in (16, 32): | ||
| yield emit(override_kernel_type, quant_config, small_m, 4096, 7168, override_major, override_major, True, torch.float) # Wgrad | ||
|
|
There was a problem hiding this comment.
🔵 suggestion: The comment says the heuristic "may pick small block M" for these wgrad shapes, but after this fix the SM90 1D1D kernel will never see block M < 64 — that is the point of the regression test. Consider rewording to something like: "Wgrad with small M: regression test for the 1D1D kernel, which only supports block M 64/128 (the heuristic must not pick 16/32 here)".
🤖 v5
| for small_m in (16, 32): | ||
| yield emit(override_kernel_type, quant_config, small_m, 4096, 7168, override_major, override_major, True, torch.float) # Wgrad | ||
|
|
||
| if collect_cublas_scores and scores: |
There was a problem hiding this comment.
🔵 suggestion: The issue also reports k_grouped_fp8_gemm_nt_contiguous failing for m <= 32 on SM90, but the added coverage only exercises the fp8_gemm_nt FP32-accumulate path. Since KGroupedContiguous goes through the same block_m_candidates branch it is fixed by the same change, but adding a small-M entry (e.g. m=16 or m=32) to enumerate_k_grouped_contiguous would keep that path covered too. Non-blocking.
🤖 v5
| if dtype == torch.bfloat16 or get_arch_major() == 10: | ||
| yield emit(override_kernel_type, quant_config, n, m, k, override_major, override_major, False, torch.float) # Wgrad | ||
| # Wgrad with small M (e.g., narrow weights), where the heuristic may pick small block M | ||
| for small_m in (16, 32): |
There was a problem hiding this comment.
🔵 suggestion: The new small-M weight-gradient cases hardcode n=4096, k=7168. This covers the reported regression, but the literals duplicate shape information that is otherwise centralized in nk_list. Consider naming these constants or deriving them from the existing shape tables so the small-M path stays in sync if the canonical shapes change.
🤖 v4
🤖 ds-review-bot Code Reviewv6未发现本次变更引入的缺陷。新增条件与 SM90 1D1D 内核的块尺寸约束一致,不影响其他内核的小块候选;新增测试也保留了全部既有用例。已静态检查 SM100 相关路径,但当前环境缺少 PyTorch/CUDA,未能执行 GPU 验证。 v5The change is correct and minimal. v4This MR fixes a real SM90 JIT failure. The layout heuristic in csrc/jit_kernels/heuristics/sm90.hpp unconditionally offered block M candidates of 16/32 for small M, but the FP8 1D1D kernel (FP32-output weight-gradient and k-grouped paths) only supports BLOCK_M of 64 or 128 and fails its static assertions. The fix correctly scopes the small-tile candidates behind 'desc.kernel_type != KernelType::Kernel1D1D', preserving the small tiles for the 1D2D and BF16 kernels that do support them. This matches the kernel's static asserts exactly and the explanatory comment is valuable for maintenance. The test change adds small-M weight-gradient coverage to enumerate_normal, and hoisting override_major / override_kernel_type out of the inner 'for n, k in nk_list' loop is a clean, behavior-preserving refactor (these values depend only on arch and dtype). On SM100 the new shapes exercise the swap-AB path, as intended. The change is small, well-commented, and I found no functional concerns. Files reviewed: 2 |
…case - Name the small-M weight-gradient shape next to the other shape tables and reword its comment (the heuristic must not pick block M 16/32). - Add a small-M (m=16) shape to the k-grouped enumeration on SM90, with 8 groups so that TMA multicast stays disabled. Signed-off-by: RunguoLi <[email protected]>
|
Thanks for the review. Pushed 95880a3 to address the suggestions:
Re-ran the SM90 suites at the PR head on an H200 (CUDA 13.0): |
|
@LyricZhao @zheanxu Could you take a look at this when you have time? It only limits the block M 16/32 candidates in the SM90 heuristic to the kernels that support them, so FP32-output |
|
Hi @RayWang96, a friendly follow-up on this one. The SM90 heuristic on main is unchanged since this PR was opened, so FP32-output |
|
Hi @LyricZhao, could you review this when you have time? It changes the SM90 heuristic lines you last updated: the block-M 16/32 candidates are now restricted to kernels that support them. The PR merges cleanly, and the SM90 test suites pass at the PR head on an H200. Thanks! |
SM90 grouped 1D2D heuristics, thread-local alignment, MoE precompile, and deepseek-ai#455/deepseek-ai#478
Problem
On SM90, the layout heuristic (
csrc/jit_kernels/heuristics/sm90.hpp) adds block M candidates of 16 and 32 whenm <= 32forNormal,BatchedandKGroupedContiguousGEMMs. The SM90 FP8 1D2D and BF16 kernels support these small tiles, but the SM90 FP8 1D1D kernel (used for FP32-output / weight-gradient GEMMs and for the k-grouped GEMM) only supportsBLOCK_Mof 64 or 128:For
m <= 32the cost model always prefers the smaller tile (e.g. it picksblock_m=32, block_n=56form=27, n=5744, k=7936), so JIT compilation fails and the call raises. This affects, on Hopper:fp8_gemm_nt(a, b, d, c=d)with an FP32d(the 1D1D wgrad path) wheneverm <= 32k_grouped_fp8_gemm_nt_contiguouswheneverm <= 32Neither shape was covered by the tests (the wgrad shapes only use
mfromnk_list, all>= 576, and the k-grouped shapes all havem >= 768). Found with a randomized shape fuzzer on an H200.Fix
Only offer the 16/32 candidates to kernels that support them (
kernel_type != Kernel1D1D). With the fix, the heuristic picksblock_m=64for these shapes. Shapes withm > 32are unaffected, since the candidate list only changes whenm <= 32.Tests (
tests/generators.py):m in {16, 32},n=4096, k=7168, FP32 accumulate) inenumerate_normal. On SM90 they use the FP8 1D1D kernel and the BF16 kernel. On SM100 they should go through swap-AB.num_groups=8, m=16, n=2048) inenumerate_k_grouped_contiguous, enabled on SM90 only. 8 groups keep TMA multicast disabled, so this shape does not depend on the separate k-grouped multicast fix in Fix SM90 k-grouped GEMM hang and silent corruption when TMA multicast clusters straddle group boundaries #415 / [BUG] Fix sm90 grouped multicast deadlock #429.Testing (H200, CUDA 13.0, PyTorch 2.11.0+cu130, at the PR head)
tests/test_fp8_fp4.pytests/test_bf16.pytests/test_layout.pytests/test_einsum.pytests/test_legacy.pytests/test_attention.pyNew test lines:
Before the fix, the same shapes fail at JIT compile time with the static assertions quoted above.
I could only test on SM90. The k-grouped shape is gated to SM90 because I could not check whether the SM100 k-grouped kernel accepts the swap-AB layout its heuristic picks for small M. It could be enabled there if it does.