Repository navigation
fix(attention): include cached prefixes in chunked prefill - #642
Merged
Merged
Conversation
xsuler
force-pushed
the
fix/chunked-prefill-prefix
branch
from
October 30, 2026 03:19
9f2d292 to
c931f4c
Compare
xsuler
force-pushed
the
fix/chunked-prefill-prefix
branch
from
October 30, 2026 03:27
c931f4c to
ac6b06f
Compare
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 does this PR do?
When a prompt spans multiple prefill chunks, later queries must attend to the cached prefix as well as their current chunk. Carry prefix and total-KV lengths through scheduler metadata and use paged extend attention with bottom-right causal alignment. The zero-score regression now produces
[1, 2, 3, 4]across chunks rather than[1, 2, 5, 6].Related issue
Fixes #635
Type of change
How was it tested?
Real NVIDIA H20-3e CUDA validation with PyTorch 2.8 and FlashAttention 2.7.4:
The initial combined run passed 62 tests. After adding three Ling KDA cases, the CUDA suite passed all 20 tests, covering:
Ling-3.0-tiny checkpoint diagnostics also record full-prefill batch-shape sensitivity alongside chunk-partition measurements. These measurements are separate from the attention/state regressions; bitwise equality of BF16 MoE logits is not assumed.
Performance
Paired alternating measurements on the same Ling checkpoint, one ongoing 32-token prompt plus one incoming long prompt, 32 generated tokens per request, eager decode and fixed tokens. Model/scheduler timings exclude HTTP, tokenization and sampling.
Both workloads meet the predefined unchanged-budget throughput floor of 90% of baseline. For the 4097-token workload, a 256-token budget reduced the longest ongoing-decode gap from 189 ms to 115 ms, while throughput changed from 47.69 to 20.76 tok/s and incoming-prompt TTFT from 152 ms to 1792 ms. This PR preserves the default budget and makes no aggregate throughput-improvement claim for smaller chunks.
Reproduce with
scripts/validation/chunked_prefill_perf.py, passing the original backend file frome17794cas--baseline.A Tic-Tac-Toe GSPO run used Ling-3.0-tiny, LR
1e-5, batch size32,8samples per prompt, concurrency256, TP4, world size8, and mini batch size8. It was stopped at the user's request. TensorBoard recorded reward means-0.903125,-0.710938, and-0.275000for steps 0–2; the requested 10-step limit was not reached.Long-prompt selected-token logprobs
Tested the original BF16 Ling checkpoint with TP=4, eager decode, temperature 1, and the same 128 fixed continuation tokens for every comparison. Means exclude prompt tokens and cover selected next-token logprobs, in nats. The train comparison uses packed
model.train()forward without gradients or optimizer updates, with sequence parallelism disabled and the same one-token LM-head projection shape as rollout.Full-rollout vs train mean abs diff: 0.015572 (4097 prompt tokens), 0.012157 (8193 prompt tokens). Full-prefill repeat controls had zero difference for both prompt lengths. Individual-token differences are also recorded: the largest full-vs-chunked value was 0.983284 nats.
Reproduce with
torchrun --standalone --nproc-per-node=4 scripts/validation/ling_long_prompt_logprobs.py --model /path/to/Ling-3.0-tiny --output results.json. The output preserves token-level logprobs, token hashes, mean, median, p95 and maximum deltas.Checklist