Repository navigation
[SM100] Let the FP8 einsum epilogue and Mega mHC write FlashInfer's 128x4 SF layout - #136
Merged
Merged
Conversation
…28x4 SF layout A 4D int32 SF output [ceil(rows / 128), K / 128, 32, 4] selects FlashInfer's 128x4 swizzle; its flat uint8 view is FlashInfer's mm_mxfp8 a_descale, so a FlashInfer consumer needs no layout conversion. 2D outputs are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Compute the FlashInfer 128x4 row offset in 32 bits, and derive the shifted task's second token from the first (+4 words, since the first index is even). The 2D instantiation is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
In the FlashInfer 128x4 layout a 32 B SF sector holds token pairs p, p+16, p+32 and p+48 of a 128-token tile, so the shifted-norm task order had four CTAs writing each sector. Permute token pairs inside the tile so a CTA takes p and p+16, matching the two writers per sector of the MN-major layout. Only the swizzled instance changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Jzz1943
pushed a commit
to Jzz1943/DeepGEMM
that referenced
this pull request
Dec 1, 2026
The upstream merge (sgl-project#177) added a 2D-only `check_sf_layout` to `FP8CastWithClampEpilogue::check`, which rejects the 4D `[ceil(m / 128), n / 128, 32, 4]` SFD that `fp8_einsum` accepts since sgl-project#136. DeepSeek V4.1's FP8 `wo_a` einsum (FlashInfer `wo_b` handoff) asserted at server warmup. Validate the 4D shape there as `fp8_einsum` does, and add the 4D case to the sgl einsum test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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
The FP8
(d, sfd)output offp8_einsum("bhr,hdr->bhd", ...)and Mega mHC'sy_gemm_sfcan now be written directly in FlashInfer's 128x4 swizzled UE8M0 layout. A consumer running FlashInfer'smm_mxfp8then needs no scale conversion.[ceil(rows / 128), K / 128, 32, 4]instead of the 2D MN-major one.[t, w, i, j]packs the four SFs of row128 t + 32 j + ifor K wordsw..view(torch.uint8).view(-1)is exactly FlashInfer's swizzleda_descale.EpilogueOperatorArgs::sfd_mn_tile_stride(0 = MN-major) selects the row offset instore_sf.kSwizzledPrimarySFtemplate argument plusNormArgs::y_primary_sf_stride_mtileselect the layout at compile time.Motivation
In DeepSeek-V4.1 prefill, two dense projections take DeepGEMM-packed
(fp8, sf)pairs from these producers:On sm_107 (CC 10.7), FlashInfer's cute-dsl MXFP8 GEMM is faster than the DeepGEMM 1D1D GEMM for these shapes. Today the pair has to be permuted into FlashInfer's layout first, and that copy is 4-22% of the FlashInfer call. It erases the GEMM win for wqkv_a and for small-row wo_b.
FlashInfer cannot read the MN-major layout itself without a kernel change:
tcgen05.cp 32x128b.warpx4) row holds rows i, i+32, i+64 and i+96.Validation
Correctness (bitwise equal to the 2D path followed by the pad + permute conversion):
test_einsum.py: the FP8bhr,hdr->bhdcase now also checks the 4D SFD.test_mega_mhc.py: newtest_mega_mhc_flashinfer_sf, normal and shifted, T = 1, 200, 1025, 4096.mm_mxfp8output (cute-dsl backend).tests/test_einsum.pypasses on sm_103 at bcf8ec5, andtests/test_mega_mhc.pyat the current head (8b4cc78). The later Mega mHC commits are also bitwise-checked at production shapes: sm_103 rows 1 to 16384 (including 127, 128, 129), sm_107 rows 1, 129, 1000, 4100 and 16384.Performance, sm_107 (FlashInfer cute-dsl
mm_mxfp8, autotuned). The DeepGEMM side is the 1D1D GEMM at #133. Each arm is one CUDA graph; arms are interleaved over 5 rounds, and the table gives the median of per-round ratios. "e2e" = producer + GEMM (+ conversion), compared with producer + DeepGEMM GEMM.Producer cost of the 4D layout:
🤖 Generated with Claude Code