Skip to content

Restore FP32 MQA logits and the logits_dtype switch - #46

Merged
zyongye merged 2 commits into
vllm-project:devfrom
zyongye:restore-mqa-logits-dtype
Oct 29, 2026
Merged

zyongye merged 2 commits into
vllm-project:devfrom
zyongye:restore-mqa-logits-dtype

Conversation

@zyongye

@zyongye zyongye commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

The 26/09/30 release merge (15c02c8) removed FP32 logits from the indexer APIs fp8_fp4_mqa_logits and fp8_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 original logits_dtype argument:

fp8_fp4_mqa_logits(q, kv, weights, cu_seq_len_k_start, cu_seq_len_k_end, max_seqlen_k,
                   logits_dtype=torch.float32, schedule_meta=None)
fp8_fp4_paged_mqa_logits(q, kv_cache, weights, context_lens, block_table, schedule_meta, max_context_len,
                         logits_dtype=torch.float32, indices=None)

As before the release, the weights dtype picks the reduction and logits_dtype picks the output:

Weights Reduction Logits
FP32 (all architectures) FP32 FP32 (default) or BF16
BF16 (SM100 only) packed BF16, unchanged from dev BF16 only, so logits_dtype=torch.bfloat16 is required

clean_logits is not restored.

Change

  • API. logits_dtype is added to the C++ entry points, the TORCH_LIBRARY schemas (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.
  • SM90 / SM120. These kernels are still templated on the logits type, so they only need the argument passed through.
  • SM100 kernel. sm100_mqa_logits and sm100_paged_mqa_logits take logits_dtype_t and weights_dtype_t, and MQALogitsSharedStorage takes the weights dtype.
    • BF16 weights: the path is unchanged (cvt.rn.relu.bf16x2 + HFMA2).
    • FP32 weights: the weights are TMA-loaded as FP32 and read in place from shared memory with warp-uniform 16-byte loads. These feed FADD2 (ReLU as x + |x|, as in the pre-release kernel) and FFMA2.
    • Why not registers: the pre-release kernel kept FP32 weights in registers, which fit with 2 math warpgroups. The release kernel runs 3, so 128 FP32 weights per thread would spill. Widening BF16 weights per use was tried too: it spilled and was 2–3x slower than BF16.

Behavior change for current callers

vLLM's vllm/utils/deep_gemm.py casts the indexer weights to BF16 on SM100 and does not pass logits_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:

  • Exact FP32 logits: drop the weights.to(torch.bfloat16) in mqa_logits_mx_inputs. The weights already come out of fused_q as FP32, so this also removes a cast.
  • Today's behavior: pass 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.

Weights Logits calc_diff (MXFP8 / MXFP4) Top-k recall (MXFP8 / MXFP4)
FP32 FP32 2.33e-15 / 2.11e-15 100.000% / 100.000%
FP32 BF16 1.38e-6 / 1.38e-6 99.735% / 99.746%
BF16 BF16 1.18e-5 / 1.17e-5 99.467% / 99.469%

These numbers match the pre-release kernel (64d096c) on the same inputs.

Performance (GB200, exclusive Slurm node, us)

Contiguous: 4096 queries x 65536 keys.

Format H D dev BF16 PR BF16 PR FP32 -> FP32 PR FP32 -> BF16 Pre-release FP32 -> FP32
MXFP4 32 128 537 546 766 (1.40x) 788 958
MXFP4 64 128 977 987 1438 (1.46x) 1458 1652
MXFP4 16 64 364 364 526 (1.44x) 540 686
MXFP8 32 128 733–814 733 964 (1.32x) 1007 1049
MXFP8 64 128 1543 1605 2043 (1.27x) 2029 1829
MXFP8 16 64 396 396 589 (1.49x) 602 699
  • BF16: the same speed as dev, within run-to-run noise.
  • FP32: costs 1.27–1.49x of BF16 in prefill. That is faster than the pre-release FP32 path in 5 of the 6 shapes; MXFP8 H64 is 12% slower.
  • Paged decode (varlen, 512 requests x 32768 context, page 64): every mode is within 2–4% of BF16.
  • Pre-release column: built from 64d096c and measured in an earlier run on the same hardware.

Test

tests/test_attention.py now enumerates (weights, logits) pairs: FP32→FP32 and FP32→BF16 on every architecture, plus BF16→BF16 on SM100. It checks logits.dtype. For the FP8 format, the simulated-reference tolerance is 3e-5 when either dtype is BF16, and 5e-6 otherwise. The sparse test passes logits_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.py passed (48 prefill, 48 paged and 48 sparse cases).
  • FP32 path check: FP32 weights holding BF16 values give the same FP32 logits, bit for bit, as widening BF16 weights inside the kernel. This held over 20 contiguous and paged cases, including H=8/12/20 and ragged paged requests.
  • BF16 output check: FP32→BF16 output equals the FP32 result rounded to BF16, bit for bit.
  • BF16 path check: BF16→BF16 output is bit-identical to dev.
  • Rejection check: BF16 weights with FP32 logits are rejected.
  • git diff --check passed.

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

zyongye and others added 2 commits October 28, 2026 21:32
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]>
@zyongye zyongye changed the title Restore the logits_dtype switch for MQA logits Restore FP32 MQA logits and the logits_dtype switch Oct 28, 2026
@zyongye
zyongye merged commit c5b78ac into vllm-project:dev Oct 29, 2026
1 check failed
@zyongye
zyongye deleted the restore-mqa-logits-dtype branch October 29, 2026 17:35
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant