[blackwell][draft] sm100: FP8 blockwise GEMM -> torch._scaled_mm (#226) - #234
Draft
Andrewxu313 wants to merge 2 commits into
Draft
[blackwell][draft] sm100: FP8 blockwise GEMM -> torch._scaled_mm (#226)#234Andrewxu313 wants to merge 2 commits into
Andrewxu313 wants to merge 2 commits into
Conversation
Placeholder commit for draft PR. Implementation tracked in: batchgen-agent-metadata/batchgen_design/blackwell/blackwell-kernel-port-v1.md Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The compiled SM90a CuTe FP8 blockwise kernel is unavailable on Blackwell, and cuBLAS in torch 2.9+cu129 rejects 1x128/128x128 blockwise FP8 scaling (heuristic returns CUBLAS_STATUS_NOT_SUPPORTED; fast-accum unsupported for 1x128). Only row-wise/tensor-wise FP8 GEMM is available. Add an sm100 branch in grouped_fp8_blockwise_gemm() that emulates deepseek blockwise scaling exactly: split the K contraction into 128-wide blocks and issue one row-wise torch._scaled_mm per block, accumulating partials in fp32. Within a K-block the act scale is constant per row (1x128) and the weight scale is constant per 128-output-row block (128x128, expanded to per-column), so the row-wise GEMM is numerically identical to true blockwise for that block. - Processes the full uniform mtp reserved rows per expert -> static control flow, CUDA-graph compatible (no host sync on seqlens, no data-dependent shapes). Padding-row outputs are ignored by downstream gather. - Covers s1 (gate+up), s3 (down) and fused_s1 automatically since all route through grouped_fp8_blockwise_gemm (fused_s1 falls back to s1_silu on sm100 as its _C kernel is absent). - Dim asserts (K,N multiples of 128; scale shapes) guard silent mis-scaling. Verified on B200 (GLM-5 / MiniMax-M2.5 style dims, E=4, mtp=64, K=2048, N=1536, incl. a zero-token expert): GEMM max rel 0.0039, S1+SiLU 0.0056, fused_s1 matches s1_silu (< 1e-2 acceptance). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Closes #226. Part of #204 (Blackwell Phase 2).
Summary
Add arch=='sm100' branch in grouped_fp8_blockwise_moe.py calling torch._scaled_mm(a_fp8, b_fp8, scale_a, scale_b, out_dtype=bfloat16).
Spec
blackwell-kernel-port-v1.md § Sub-task 3