Conversation
ormandj
requested review from
Fridge003,
HaiShaw,
Qiaolin-Yu,
hebiao064,
ispobock and
merrymercy
as code owners
September 8, 2026 06:19
This was referenced Sep 8, 2026
Open
36 tasks
ormandj
force-pushed
the
kda-host-prefill-lengths
branch
from
September 8, 2026 21:44
bf412b3 to
eb71d35
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.
Motivation
This change targets a shorter wait for the first response token, especially for long prompts. KDA prefill currently waits for a sequence-length read from the GPU in every layer of every chunk, even though the scheduler already has that length on the CPU.
Reusing the host lengths removes those repeated waits without changing the attention computation or generation settings. The profile below shows 1,122 device scalar reads eliminated for a 131,158-token prompt. That establishes reduced synchronization work; an isolated time-to-first-token improvement has not yet been measured.
Modifications
Use the sum of
extend_seq_lens_cpuwhen available. Keep the device-offset fallback when host lengths are absent, and preserve input trimming, output padding, cached-state handling and target verification.Accuracy Tests
Author CPU validation at
c0a43f8c19: 24 tests passed, with CUDA hidden. Its Python runtime and test trees are unchanged at refreshed headeb71d35924on mainafe90a8bc9. Earlier GPU and serving results retain their stated source scope.Author-run result: 24 CPU cases pass in
test/registered/unit/layers/attention/test_kda_extend_host_lengths.py. They cover host lengths and the device fallback, padding and state tracking. The host-metadata cases raise if the code reads device offsets, and check exact output values, shape and padding with stubbed numerical kernels. These tests validate the metadata change, not GPU kernel numerics.Speed Tests and Profiling
Author-reported CPU/CUDA profiling of GLM-5.3-Flash W4A16 with FP8 KV on two RTX PRO 6000 Blackwell Max-Q 96 GB GPUs at 300 W, TP2 over PCIe. One cold 131,158-token prompt was traced for each path, using 4,096-token prefill chunks and stopping after one generated token. The table counts KDA sequence-length scalar reads on rank 0 across the 33 target prefill chunks.
These are operation counts from the profiled paths. The surrounding builds also differed in KV layout, so they do not establish an isolated serving speedup for this PR. The device-offset fallback still synchronizes when host lengths are absent.
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciDeveloped with AI assistance.
CI States
Latest PR Test (Base): ❌ Run #34282262308
Latest PR Test (Extra): ❌ Run #34282261977
Latest PR Test (AMD ROCm 7.2): ❌ Run #34282262293