Repository navigation
[TRTLLM-16622][perf] DeepSeek-V4.1: derive the DSpark ring window in the attention kernel and load whole ring tiles - #22365
Closed
ziyixiong-nv wants to merge 1 commit into
Conversation
…the attention kernel and load whole ring tiles The embedded DeepSeek-V4/V4.1 DSpark draft keeps each request's rolling 128-row captured-context window in one page of a worker-owned ring. The paged DSpark attention read it through per-forward metadata that a Triton launch built: a two-column page table aliasing the page, shifted positions, valid lengths and capacities. With a partial window (valid_len < 128) the kernel also split each 64-row tile into 16-, 4- and 1-row TMA copies issued by one thread. A disaggregated generation server starts every request with an empty window that fills with about 3.5 accepted tokens per step, so the first ~36 decode steps of each request paid the split loads in all three draft stages. - trtllm::fused_dsv4_dspark_ring_attention takes each request's slot, start position and valid length. A ring specialization of the paged kernel derives the window end and capacity from the start position, stages only the slot and loads whole 64-row tiles. The softmax mask drops the rows past valid_len, so unwritten rows must hold finite values; the worker zero-initializes its windows. - The batched and attention-TP draft paths call the ring op. The Triton metadata launch (speculative/dspark_ring_metadata.py), its helper and its plumbing through the draft stages are removed. - fused_dsv4_dspark_attention keeps its signature and kernel; the input checks both ops share move into one helper. GB300, TEP8 decode shapes (8 and 16 heads), kernel time per launch: 7.5-7.8 us for every valid_len, was 13.7-16.8 us below 128 and 7.4-7.7 us at 128; the non-paged kernel used before NVIDIA#21067 took 7.2-7.7 us. On the low-latency TEP8 GEN step with the rest of the DS-V4.1 decode stack, deriving the window in the kernel cut each draft attention launch from 11.1 to 9.9 us and removed a 1.4 us launch. Disaggregated low-latency TEP8 serving (batch 1, DSpark k=5, same stack): 1,484.2 -> 1,504.8 tokens/s per user, GEN step p50 2.220 -> 2.206 ms, acceptance length 3.517 in both. Test: test_ring_attention_matches_aliased_page_table checks the ring op bit for bit against the generic op over the equivalent aliased page table (wrapped starts, partial and empty windows). The DSpark attention tests that patched the generic op or built the metadata now use the ring op. Signed-off-by: ziyixiong-nv <[email protected]>
ziyixiong-nv
requested review from
YihuiLu512,
farazkh80,
pengbowang-nv,
pranav-nvidia,
ruocheng-nv and
zhaoyuanh-nvidia
November 16, 2026 15:04
Contributor
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. Next included review available in 57 minutes. View limit details
|
1 task done
Collaborator
|
@kris1025, could you help to review this PR as trt-llm-torch-attention-devs? Thanks~ Assignment explanation
Affinity and workload are snapshots at selection, not live counters. Existing reservations on this PR are counted once. |
yuxianq
requested review from
kris1025
and removed request for
farazkh80 and
pengbowang-nv
November 16, 2026 16:05
Collaborator
Author
|
Closing as we're going to enable ctx DSpark in disagg mode. |
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.
@coderabbitai summary
Description
Summary
The embedded DeepSeek-V4/V4.1 DSpark draft (
DSv4DSparkDraftModel) attends each request's rolling 128-rowcaptured-context window. The draft worker keeps that window in one page of a ring it owns. #21067 made the DSpark
window attention paged. To read these windows through it, the draft built per-forward metadata with a separate
Triton launch: a two-column page table aliasing the request's page, shifted positions, valid lengths and capacities.
With a partial window (
valid_len< 128) the paged kernel also split each 64-row tile into 16-, 4- and 1-row TMAcopies issued by one thread, plus a one-row copy per unwritten row, so a partial window cost about twice a full one.
Partial windows are the common case on a disaggregated generation server. The draft's windows are not transferred
from the context server, so every request starts there with an empty window and fills it with its accepted tokens,
about 3.5 per step at the measured point. For the first ~36 decode steps of every request, all three draft stages
paid the split loads.
This PR adds
trtllm::fused_dsv4_dspark_ring_attention, which takes each request's slot, start position and validlength. A ring specialization of the paged kernel derives the window end and capacity from the start position, stages
only the slot and loads whole 64-row tiles; the softmax mask already drops the rows past
valid_len. Partial windowsnow cost what full ones do, and the metadata launch is gone.
Changes
attention/kernels/blackwell/dspark/attention.py,attention_kernel.py): a compile-timeringspecialization.
window_endmaps the start position into the ring's second alias (start % 128 + 129), andwindow_capacityisthe constant
2 * 128.history_tile_sizes = (64,)): rowrof the window is rowrof the page.them.
custom_ops/dspark_attention_custom_op.py):trtllm::fused_dsv4_dspark_ring_attention(q, draft_block, kv_pages, slots, start_pos, valid_len, attn_sink, inverse_rope_freqs, softmax_scale), with contiguous INT64[G]slots, start positions and valid lengths, itsown kernel cache and a fake.
_check_dspark_attention_inputs.fused_dsv4_dspark_attentionkeeps itssignature and compiles the same kernel.
models/modeling_dspark.py):dspark_attention_forward_batchedanddspark_attention_forward_tpcall the ring op._dspark_ring_attention_metadataand thering_attention_metadataarguments of both paths,_forward_stageandforward_batchedare removed.speculative/dspark_ring_metadata.py(the Triton metadata launch) is removed.Performance
All numbers are on GB300.
Kernel time per launch at the TEP8 decode shapes (8 and 16 heads):
valid_lenvalid_len.kernel cut each of the three draft attention launches from 11.1 to 9.9 us and removed the 1.4 us metadata launch:
4.2-4.8 us per step off the attention's critical path.
Disaggregated low-latency TEP8 serving (attention TP8 generation, batch 1, DSpark k=5), 30-minute windows. This was
measured with the rest of the DS-V4.1 decode stack (the other PRs of this set), not on main alone:
kernel. With split loads they took 26 us more.
Compatibility
(including Kimi-K3-DSpark) use the DFlash paged-KV decode and do not call these ops. There is no LLM API or
configuration change.
the existing support checks accept). Other GPUs and shapes keep the PyTorch reference path.
fused_dsv4_dspark_attentionkeeps its signature and kernel; the ring branches are compile-time specializations.The draft worker allocates and clears its windows with zeros, so draft outputs do not change.
Dependencies
None. One commit on main, independent of the other PRs of this set.
#22371 (DSpark draft) is stacked on this PR: its attention-TP path passes
pdl=Trueto the ring op, and its commitsits on this one.
Test Coverage
test_dspark_cute_dsl_attention.py::test_ring_attention_matches_aliased_page_table(SM100/SM103/SM107). Thering op equals the generic op over the equivalent aliased page table bit for bit, with wrapped start positions and
empty, partial and full windows, at 64 and 128 heads.
test_dspark_cute_dsl_attention.py: the warmup, production-ring and batched scalar-reference tests.test_tp_attention_shards_sum_to_replicatednow runs through the ring op unchanged.hw_agnostic/test_dspark_attention.py: the batched-preparation test patches the ring op. The two tests of theremoved metadata helper are dropped.
GPU run on this branch (GB300): the DSpark unit tests, including the new one, and the
hw_agnostictests pass; theonly failures are 6
test_spec_sampler_step_fold.pycases that fail on main as well. GSM8K with DSpark passes atattention TP4 (NVFP4, the attention-TP path) and DP4 (NVFP4, the batched path). With the rest of the DS-V4.1 decode
stack, the same tests and GSM8K with DSpark MXFP4 at TP4 pass too.
PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.