Repository navigation
[Fix] Use cached prefix lengths for FlashInfer full-attention ragged prefill - #40796
Merged
Fridge003 merged 3 commits intoSep 24, 2026
Merged
Conversation
Fridge003
reviewed
Sep 23, 2026
| if extend_prefix_lens_cpu is not None: | ||
| paged_kernel_lens_sum = sum(extend_prefix_lens_cpu) | ||
| else: | ||
| paged_kernel_lens_sum = prefix_lens.sum().item() |
Collaborator
There was a problem hiding this comment.
Line 2001 will cause severe performance degradation, since .item() is a synchronized operations. Can we make sure this branch is not hit?
Collaborator
Author
There was a problem hiding this comment.
This branch doesnt get hit in most use-cases, only one that I can see that hits this branch is dllm metadata caller, but removing this .item() or changing this branch requires alot of changes elsewhere in this file, which requires a lot of validation and might be a seperate PR.
Jiminator
marked this pull request as ready for review
September 23, 2026 05:14
Jiminator
requested review from
Qiaolin-Yu,
ispobock and
merrymercy
as code owners
September 23, 2026 05:14
Collaborator
Author
|
/tag-and-rerun-ci |
Fridge003
approved these changes
Sep 23, 2026
This was referenced Sep 26, 2026
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.
Motivation
In a mixed sliding-window/full-attention model, FlashInfer ragged prefill plans the full-attention layer's paged read over
seq_lens. The new K/V is not written to the cache until after attention, and the ragged wrapper already handles those tokens. Reading their cache slots can therefore mix stale K/V into the result.Modifications
prefix_lenswhen ragged prefill is active. Use the host prefix total when available, retaining the existing device-sum fallback pattern.Paged-only execution is unchanged. Two files; eight backend lines added.
Accuracy Tests
On NVIDIA B300, using upstream
7b977ce5dcce6e61f0a5f8ef8b4235e42eb00299, Torch 2.13.0+cu130, FlashInfer 0.6.18, and sglang-kernel 0.4.7+cu130:unsloth/gemma-3-1b-itat5b11413a10db4e486ef16a20101fd028f8f2499c, BF16, TP1, FlashInfer, page size 1, eager execution. Actual full-attention forwards use the ragged path. With a 384-token prompt and 257 cached tokens, the full wrapper plans 384 cache slots before the fix and 257 afterward.Reproduce the regression:
Changed-file pre-commit hooks pass. The all-files run passes its non-Rust hooks; four Rust hooks could not execute because the local host lacks cargo/rustup. No Rust files are changed.
Speed Tests and Profiling
No throughput improvement is claimed. The normal ragged-prefill path uses the existing CPU prefix lengths without adding a device-to-host scalar read.
CI States
Latest PR Test (Base): ⏳ Run #35834018141⚠️ Not enabled -- add
Latest PR Test (Extra):
run-ci-extralabel to opt in.Latest PR Test (AMD ROCm 10): ❌ Run #35834018015