Repository navigation
[Bugfix][XPU] Apply attn_sink in the DeepSeek-V4 sparse MLA Triton kernel - #76
Draft
afierka-intel wants to merge 1 commit into
Draft
afierka-intel wants to merge 1 commit into
afierka-intel wants to merge 1 commit into
Conversation
…rnel The XPU DeepSeek-V4 path passed attn_sink to xpu_sparse_decode_fp8 but never applied it, and the prefill call did not pass it at all, so the per-head sink logit was silently ignored (NVIDIA/ROCm/CPU backends apply it). The error is largest for rows with few valid keys (start of a sequence, SWA window). Add an optional attn_sink pointer to _bf16_mla_sparse_kernel (HAS_ATTN_SINK): the sink joins the softmax denominator, lse is still reported over the selected keys only, and -inf is a no-op. Pass attn_sink[: num_heads] from the V4 prefill and decode call sites. Adds kernel tests against reference_mla_sparse_prefill (DSv4 shape, sinks in the range of the released checkpoints, 1..512 valid keys) and a -inf no-op test. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Artur Fierka <artur.fierka@intel.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.
What
Apply DeepSeek-V4
attn_sinkin the XPU sparse-MLA Triton kernel (_bf16_mla_sparse_kernel) and pass it from both V4 call sites on XPU (prefill inxpu_sparse.py, decode inxpu_sparse_decode_fp8.py). Add kernel tests.Why
On XPU the V4 path never applied the per-head sink logit:
xpu_sparse_decode_fp8()acceptedattn_sinkbut did not use it, and the prefill call did not pass it at all. NVIDIA (FlashMLA / FlashInfer), ROCm and CPU backends all apply it, so XPU silently computed a different softmax.The sink is not small in the released checkpoint: the 44
*.attn.attn_sinktensors ofdeepseek-ai/DeepSeek-V4-Flashspan [-2.20, +2.49]. Error of the XPU kernel ignoring the sink vs. an fp32 reference with the sink (Intel Arc Pro B70, bf16, sinks drawn from that range, worst over seeds/scales):Rows with few valid keys are exactly the start of every sequence / the SWA window.
Implementation: optional
attn_sink_ptr+HAS_ATTN_SINKconstexpr; after the key loop,m = max(e_max, sink·log2e), rescaleaccande_sum,e_sum += 2^(sink·log2e − m). The returnedlsestays over the selected keys only (same convention asreference_mla_sparse_prefill);-infis a bitwise no-op. Callers that do not passattn_sink(V3.2 / GLM-5 backend) compile the same kernel as before.Not a duplicate: vllm-project#57798 changes how V4 sinks are loaded (all platforms), not how the XPU kernel applies them; no open PR touches
vllm/v1/attention/ops/xpu_mla_sparse.py.Test plan
On Intel Arc Pro B60: 10 passed, base
187a0eb98a(6 new: DSv4 shape with 1/4/16/128/512 valid keys vs.reference_mla_sparse_prefill(attn_sink=...), and the-infno-op test; the new tests also require the no-sink result to differ for short rows).End to end:
yujiepan/deepseek-v4-fp4-fp8-tiny-randomwithq_lora_rank256 and sinks from the V4-Flash range), XPU vs. NVIDIA H200 on identical weights/prompts: rel. L2 of layer-0 attention output 0.22 (main) → 0.09 (this PR). Re-checked on base187a0eb98a, prompt-logprob distance to H200 (1500 / 6000 / 16-token prompts): max |Δ| 1.57 / 1.76 / 2.14 nats onmain→ 0.38 / 0.52 / 0.41 with this PR; mean |Δ| 0.111 / 0.109 / 0.79 → 0.079 / 0.096 / 0.16.deepseek-ai/DeepSeek-V4-Flashreal weights, TP=8 on 8× Intel Arc Pro B60 (with this PR and fix: avoid overlapping stores in XPU KV cache kernel vllm-project/vllm#52582): coherent answers; first 16 GSM8K test questions, greedy, 700 new tokens: 13/16, every question whose reasoning finished in the budget was correct. At n=16 the A/B againstmainshows no accuracy gap (both 8/16 at a 256-token budget) — the case for this PR is fidelity to the reference, not a headline accuracy change.XPU-only change:
triton_bf16_mla_sparse_interfaceis imported only byvllm/v1/attention/backends/mla/xpu_mla_sparse.pyandvllm/models/deepseek_v4/xpu/.AI-assisted (Claude Code / Opus).