Repository navigation
Add fused DeepSeek-V3.2 indexer cache kernel - #3185
Merged
Merged
Conversation
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a fused DeepSeek-V3.2 indexer kernel that combines Q/K RoPE, K RMSNorm, Q FP8 per-1x128 quantization, indexer weight scaling, and K-cache insertion in a single HIP kernel, replacing a multi-step path used by the companion ATOM integration.
Changes:
- Add
indexer_qk_rope_quant_and_cache_kerneland its host wrapper (with shape/layout/device validation) incsrc/kernels/cache_kernels.cu, plus a dispatch macro for the FP8 e4m3 cache type. - Declare the new op in
csrc/include/cache.hand bind it via pybind incsrc/include/rocm_ops.hpp. - Expose the new op in the Python cache ops API via
aiter/ops/cache.py.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| csrc/kernels/cache_kernels.cu | New fused indexer kernel, dispatch macro, and host entry with validation. |
| csrc/include/cache.h | Function declaration for the new op. |
| csrc/include/rocm_ops.hpp | Pybind binding exposing the op to Python. |
| aiter/ops/cache.py | Python-side compile_ops declaration matching the new C++ signature. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| q_amax = block_reduce<float, decltype(max_func), HEAD_DIM, true>(q_amax, max_func); | ||
|
|
||
| const float q_fp8_max = static_cast<float>(opus::finfo<cache_t>::max()); | ||
| const float q_scale = fmaxf(q_amax, 1e-10f) / q_fp8_max; |
Co-authored-by: Cursor <[email protected]>
valarLip
approved these changes
May 15, 2026
This was referenced May 28, 2026
Closed
frida-andersson
added a commit
to frida-andersson/aiter
that referenced
this pull request
Jun 1, 2026
…kernel The fused `indexer_qk_rope_quant_and_cache_kernel` (added in ROCm#3185) diverged numerically from the unfused vLLM path it replaces, causing a catastrophic GSM8K accuracy regression on DeepSeek-V3.2 (0.95 -> 0.49 strict-match, 20-shot) when fusion was enabled. Two independent bugs in this kernel: 1. Q quant skipped UE8M0 rounding and used direct division by a constexpr fp8_max. The unfused path is `per_token_group_quant_fp8` in vllm/.../fp8_utils.py which (a) multiplies by the reciprocal of fp8_max and (b) applies UE8M0 (`scale = 2^ceil(log2(scale))`) when the caller passes `scale_fmt = "ue8m0"`. DSv3.2's indexer always passes ue8m0, so the fused kernel disagreed with the unfused one on ~94% of Q values per call. The K-quant block in the same kernel already applied UE8M0 correctly (lines ~1429); only the Q block was missing it. Direct division also triggers GPU fast-division which adds 1-ULP noise that flips the rounded fp8 value at representable boundaries. 2. `norm_weight` and `norm_bias` were typed `scalar_t*`, which in production is bf16. vLLM stores `LayerNorm.weight`/`bias` as fp32 and `F.layer_norm` consumes them as fp32 in the unfused path. The implicit fp32 -> bf16 cast at the call site lost ~16 mantissa bits per element, causing K to drift from the unfused reference by 1+ fp8 ULP on ~3% of values per call. Both drifts compounded across the 58 indexer layers in DSv3.2 and broke long-context accuracy. With both fixes applied (and a separate cache-layout fix on the vLLM call site), GSM8K strict-match recovered to 0.95. Changes: - Apply UE8M0 + multiply-by-reciprocal to the Q scale, mirroring the unfused Triton `per_token_group_quant_fp8`. - Hard-type `norm_weight` and `norm_bias` as `float*` in the kernel signature and the launch macro, drop the `static_cast<float>` on each load, and assert `dtype == fp32` on the host so the bf16 footgun cannot be reintroduced. ABI note: this tightens the dtype contract for `norm_weight`/`norm_bias` from "match q.dtype" to "must be fp32". vLLM is the only known caller of this kernel today and already has fp32 LN params natively, so the change is benign for it. Any future caller passing bf16 will get a loud host check failure rather than silent ~3% K drift.
valarLip
pushed a commit
that referenced
this pull request
Jul 28, 2026
…kernel (#3451) * Fix Q UE8M0 quant and require fp32 LN params in fused DSv3.2 indexer kernel The fused `indexer_qk_rope_quant_and_cache_kernel` (added in #3185) diverged numerically from the unfused vLLM path it replaces, causing a catastrophic GSM8K accuracy regression on DeepSeek-V3.2 (0.95 -> 0.49 strict-match, 20-shot) when fusion was enabled. Two independent bugs in this kernel: 1. Q quant skipped UE8M0 rounding and used direct division by a constexpr fp8_max. The unfused path is `per_token_group_quant_fp8` in vllm/.../fp8_utils.py which (a) multiplies by the reciprocal of fp8_max and (b) applies UE8M0 (`scale = 2^ceil(log2(scale))`) when the caller passes `scale_fmt = "ue8m0"`. DSv3.2's indexer always passes ue8m0, so the fused kernel disagreed with the unfused one on ~94% of Q values per call. The K-quant block in the same kernel already applied UE8M0 correctly (lines ~1429); only the Q block was missing it. Direct division also triggers GPU fast-division which adds 1-ULP noise that flips the rounded fp8 value at representable boundaries. 2. `norm_weight` and `norm_bias` were typed `scalar_t*`, which in production is bf16. vLLM stores `LayerNorm.weight`/`bias` as fp32 and `F.layer_norm` consumes them as fp32 in the unfused path. The implicit fp32 -> bf16 cast at the call site lost ~16 mantissa bits per element, causing K to drift from the unfused reference by 1+ fp8 ULP on ~3% of values per call. Both drifts compounded across the 58 indexer layers in DSv3.2 and broke long-context accuracy. With both fixes applied (and a separate cache-layout fix on the vLLM call site), GSM8K strict-match recovered to 0.95. Changes: - Apply UE8M0 + multiply-by-reciprocal to the Q scale, mirroring the unfused Triton `per_token_group_quant_fp8`. - Hard-type `norm_weight` and `norm_bias` as `float*` in the kernel signature and the launch macro, drop the `static_cast<float>` on each load, and assert `dtype == fp32` on the host so the bf16 footgun cannot be reintroduced. ABI note: this tightens the dtype contract for `norm_weight`/`norm_bias` from "match q.dtype" to "must be fp32". vLLM is the only known caller of this kernel today and already has fp32 LN params natively, so the change is benign for it. Any future caller passing bf16 will get a loud host check failure rather than silent ~3% K drift. * Add dim/contiguity guards for norm_weight and norm_bias The kernel indexes norm_weight[dim] / norm_bias[dim] as a flat array; a non-1D or non-contiguous view would silently produce wrong results. Add explicit dim() == 1 and is_contiguous() checks before launch so a bad input is caught immediately rather than corrupting K values.
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
indexer_qk_rope_quant_and_cache, a fused DeepSeek-V3.2 indexer helper that applies Q/K RoPE, K RMSNorm, Q FP8 per-1x128 quantization, indexer weight scaling, and K cache insertion in one kernel path.Validation
+5.6%, CON=8+5.7%, CON=16+3.5%.gsm8k, 3-shot: flexible-extract0.9462, strict-match0.9469.Notes
ATOM_ENABLE_DS_INDEXER_QK_ROPE_CACHE_FUSIONwith fallback to the original path when disabled or unsupported.Made with Cursor