Repository navigation
Restore FP32 MQA logits and the logits_dtype switch - #46
Merged
Merged
Conversation
The 26/09/30 release merge (15c02c8) dropped the `logits_dtype` argument of `fp8_fp4_mqa_logits` and `fp8_fp4_paged_mqa_logits`, so SM100 always returned BF16 logits and SM90/SM120 always FP32. Bring the argument back with its original default, `torch.float32`. The SM90 and SM120 kernels are still templated on the logits type, so they only need the argument passed through. The SM100 kernel gains a `logits_dtype_t` template parameter: FP32 logits reduce in FP32 (ReLU as `x + |x|` with packed FADD2/FFMA2, BF16 weights widened in registers), while the BF16 path is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…uction Before the 26/09/30 release, the SM100 indexer chose its reduction from the weights dtype: FP32 weights reduced in FP32 and emitted FP32 or BF16 logits, while BF16 weights reduced in BF16 and required BF16 logits. Restore that instead of widening BF16 weights to FP32 inside the kernel. The release kernel runs three math warpgroups, so FP32 weights no longer fit in registers, and widening BF16 weights per use spilled. FP32 weights are now TMA-loaded as FP32 and read in place from shared memory with warp-uniform 16-byte loads, feeding `FADD2` (`x + |x|`) and `FFMA2`. The shared-memory layout takes the weights dtype; the BF16 path is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
5 of 6 tasks
RayWang96
pushed a commit
to deepseek-ai/DeepGEMM
that referenced
this pull request
Nov 19, 2026
* Public Release 26/09 (#432) * Public release 26/09 * Update News * Fix Mega MoE task info slot release ordering (#441) * Public release 26/09/30 (#462) Add locality-aware Mega MoE execution, GEMM epilogue classes with BF16 stochastic rounding, wider sparse MQA head support, and packed SF strides. Improve Indexer and Mega MoE pipelines, update attention and Mega Gate interfaces, and include runtime and correctness fixes. Export the current source through the OSS filter while retaining public release history and the Mega MoE task-info release-ordering fix. Co-authored-by: Anyi Xu <[email protected]> Co-authored-by: huahuaquq <[email protected]> Co-authored-by: TwenTy_ <[email protected]> Co-authored-by: xyf007 <[email protected]> Co-authored-by: Yongqi Zhuo <[email protected]> Co-authored-by: yukuai26 <[email protected]> Co-authored-by: Zhean Xu <[email protected]> * Update FP8 epilogues and paged sparse MQA alignment (#471) Add FP8CastWithClamp with optional clamped-element counts, consolidate GEMM epilogue conversions, and accept 128-byte paged sparse KV strides. Keep the Mega MoE localizer alive until test teardown and bump the package version to 2.8.2. Co-authored-by: xyf007 <[email protected]> Co-authored-by: yukuai26 <[email protected]> Co-authored-by: Zhean Xu <[email protected]> * Fix mega_mhc split barriers under CUDA graph replay (#478) A CUDA graph kernel node keeps the same %gridid on every replay. The mega_mhc split barriers tag each execution with %gridid, so after a replay a barrier line still holds encode_state(grid_idx, kNumSplits), which is exactly the state the next replay waits for. A Mix or Norm waiter whose m-block init CTA has not started yet proceeds immediately and reads the previous replay's split partials. Tag executions with an epoch instead. The epoch and an exit count live in the unused tail of the first barrier line, so the host-side buffer is unchanged. Every CTA reads the epoch after cudaGridDependencySynchronize, and the last CTA to retire resets the exit count and advances the epoch. Signed-off-by: lightseek-bot <[email protected]> * Restore FP32 weights/logits in SM100 MQA logits (port of vllm-project#46) Upstream 26/09/30 made the SM100 dense and paged MQA logits kernels take BF16 weights and write BF16 logits only. nv_dev callers pass FP32 weights and read FP32 logits, so port vllm-project#46: the SM100 kernel is templated on the weights and logits types again, and the host accepts FP32 or BF16 weights on SM100 (MX inputs). `logits_dtype` now defaults to the weights' precision: BF16 weights reduce in BF16 and require (and default to) BF16 logits; FP32 and FP16 weights default to FP32 logits. This is the same default on every architecture. Non-MX FP8 inputs on SM100 still take the FP16-weight path only. Tests: test_nv_attention_restoration.py checks the SM100 unified dense kernel with MXFP8 inputs and FP32/BF16 weights, eager against scheduled, bitwise. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Pin the sparse MQA metadata layout in the SM120 kernel The SM120 sparse MQA kernel reads `layout/sparse_mqa_logits.cuh`, which is shared with SM100 and follows upstream. Assert the parts of it the kernel reads (struct sizes and field offsets, slot packing, KV split flag mask), so a future upstream format change fails to compile instead of producing wrong logits. The device file matches DeepGEMM-sm120 v0.2.0. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Drop stale clean_logits notes from the README The MQA logits APIs no longer take `clean_logits`. Also note that the SM100 FP16-weight path is the only non-MX FP8 MQA logits path on SM100. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Signed-off-by: lightseek-bot <[email protected]> Co-authored-by: Zhean Xu <[email protected]> Co-authored-by: Chenggang Zhao <[email protected]> Co-authored-by: Anyi Xu <[email protected]> Co-authored-by: huahuaquq <[email protected]> Co-authored-by: TwenTy_ <[email protected]> Co-authored-by: xyf007 <[email protected]> Co-authored-by: Yongqi Zhuo <[email protected]> Co-authored-by: yukuai26 <[email protected]> Co-authored-by: LightSeek Foundation <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
RayWang96
pushed a commit
to deepseek-ai/DeepGEMM
that referenced
this pull request
Nov 19, 2026
) Upstream 26/09/30 made the SM100 dense and paged MQA logits kernels take BF16 weights and write BF16 logits only. nv_dev callers pass FP32 weights and read FP32 logits, so port vllm-project#46: the SM100 kernel is templated on the weights and logits types again, and the host accepts FP32 or BF16 weights on SM100 (MX inputs). `logits_dtype` now defaults to the weights' precision: BF16 weights reduce in BF16 and require (and default to) BF16 logits; FP32 and FP16 weights default to FP32 logits. This is the same default on every architecture. Non-MX FP8 inputs on SM100 still take the FP16-weight path only. Tests: test_nv_attention_restoration.py checks the SM100 unified dense kernel with MXFP8 inputs and FP32/BF16 weights, eager against scheduled, bitwise. 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.
The 26/09/30 release merge (15c02c8) removed FP32 logits from the indexer APIs
fp8_fp4_mqa_logitsandfp8_fp4_paged_mqa_logits. Since then SM100 only takes BF16 weights and only returns BF16 logits, and SM90/SM120 always return FP32. This PR restores the original behavior and the originallogits_dtypeargument:As before the release, the weights dtype picks the reduction and
logits_dtypepicks the output:devlogits_dtype=torch.bfloat16is requiredclean_logitsis not restored.Change
logits_dtypeis added to the C++ entry points, theTORCH_LIBRARYschemas (ScalarType logits_dtype=float) and the Python wrappers. SM100 accepts FP32 weights again, and BF16 weights with FP32 logits are rejected, as they were originally. The logits row-stride alignment follows the chosen dtype.sm100_mqa_logitsandsm100_paged_mqa_logitstakelogits_dtype_tandweights_dtype_t, andMQALogitsSharedStoragetakes the weights dtype.cvt.rn.relu.bf16x2+HFMA2).FADD2(ReLU asx + |x|, as in the pre-release kernel) andFFMA2.Behavior change for current callers
vLLM's
vllm/utils/deep_gemm.pycasts the indexer weights to BF16 on SM100 and does not passlogits_dtype. Against this PR that call fails the "BF16 weights require BF16 logits" check, because the default is FP32 again. When vLLM bumps, it needs one of these:weights.to(torch.bfloat16)inmqa_logits_mx_inputs. The weights already come out offused_qas FP32, so this also removes a cast.logits_dtype=torch.bfloat16.SM90 and SM120 already took FP32 weights and returned FP32 logits, so they are unaffected.
Accuracy
Each output is compared against an FP64 reference that uses FP32 weights. Inputs are random, with weights built the way vLLM builds them. Shape: H=64, D=128, top-2048 of 32768 keys.
calc_diff(MXFP8 / MXFP4)These numbers match the pre-release kernel (64d096c) on the same inputs.
Performance (GB200, exclusive Slurm node, us)
Contiguous: 4096 queries x 65536 keys.
devBF16dev, within run-to-run noise.Test
tests/test_attention.pynow enumerates(weights, logits)pairs: FP32→FP32 and FP32→BF16 on every architecture, plus BF16→BF16 on SM100. It checkslogits.dtype. For the FP8 format, the simulated-reference tolerance is 3e-5 when either dtype is BF16, and 5e-6 otherwise. The sparse test passeslogits_dtype=torch.bfloat16, because it compares against the full kernel bit for bit.Validated on GB200 (SM100):
DG_MQA_NUM_CASES=48 python tests/test_attention.pypassed (48 prefill, 48 paged and 48 sparse cases).dev.git diff --checkpassed.SM90 and SM120 were not run, because no such GPUs were available.
AI assistance: Claude Code assisted with investigation, implementation, and validation.
🤖 Generated with Claude Code