Skip to content

Fix per-tier cached-token re-count for chunked prefill#1

Open
ishandhanani wants to merge 14 commits into
hxieustc:add-fine-grain-prefill-cached-token-infofrom
sgl-project:idhanani/fix-26976-chunked-tier-split
Open

Fix per-tier cached-token re-count for chunked prefill#1
ishandhanani wants to merge 14 commits into
hxieustc:add-fine-grain-prefill-cached-token-infofrom
sgl-project:idhanani/fix-26976-chunked-tier-split

Conversation

@ishandhanani

@ishandhanani ishandhanani commented Jun 4, 2026

Copy link
Copy Markdown

Follow-up to sgl-project#26976 — re-tested the updated branch on 1x L40S (Qwen3-0.6B, HiCache, write_through, page_size 64). All previously-flagged issues are fixed and the tier split is correct for host/device hits. One remaining bug found, fixed here.

Chunked prefill re-counts the tier split

Continuation chunks re-enter can_run_list via add_chunked_req with prefix_len=0, but PrefillStats.from_adder re-reads the full req.cached_tokens_* split on every chunk. With --chunked-prefill-size 512 and a 1344-token cached prefix (4-chunk request):

chunk 1: #cached-token: 1344, #cached-token-device: 1344
chunk 2: #cached-token: 0,    #cached-token-device: 1344
chunk 3: #cached-token: 0,    #cached-token-device: 1344
chunk 4: #cached-token: 0,    #cached-token-device: 1344

This breaks the invariant documented on PrefillStats (log_hit_tokens == device + host + storage) and re-counts the split once per chunk for anyone aggregating the log lines. Default chunked_prefill_size is 4096, so any prompt longer than that hits this in production.

Fix

Track continuation chunks on the adder (continuation_chunk_reqs) and credit the split only on the chunk where the prefix is credited — mirroring log_hit_tokens semantics. Also reverts the formatting-only hunks in schedule_policy.py so the PR diff stays scoped.

Verification (same box/config)

Check Before fix After fix
Chunked tier split (4-chunk req, 1344-token cached prefix) chunks 2-4 log #cached-token: 0, #cached-token-device: 1344 chunk 1: 1344 / 1344; chunks 2-4: 0 / 0
Aggregate invariant over the full server log, incl. aiperf load (c=16, 256 reqs, 1024-token prompts vs 512 chunk size, live host hits) broken (split re-counted per chunk) sum #cached-token = 133952 == sum device 121536 + sum host 12416
Host-tier attribution (evict to host, re-send) correct unchanged: #cached-token: 1536, device: 0, host: 1536 on load-back; device: 1536, host: 0 after promotion
Mismatch / new warnings 0 0 across all runs
aiperf load (c=16, 256 reqs) 256/256, 0 errors 256/256, 0 errors

CI States

Latest PR Test (Base): ❌ Run #26969001224
Latest PR Test (Extra): ❌ Run #26969001003

github-actions Bot and others added 14 commits May 5, 2026 02:43
Continuation chunks of a chunked prefill re-enter can_run_list via
add_chunked_req with prefix_len=0, but from_adder re-read the full
req.cached_tokens_* split on every chunk. A 4-chunk request with a
1344-token cached prefix logged:

  chunk 1: #cached-token: 1344, #cached-token-device: 1344
  chunk 2: #cached-token: 0,    #cached-token-device: 1344
  chunk 3: #cached-token: 0,    #cached-token-device: 1344
  chunk 4: #cached-token: 0,    #cached-token-device: 1344

breaking log_hit_tokens == device + host + storage and re-counting the
tier split once per chunk. Track continuation chunks on the adder and
credit the split only on the chunk where the prefix is credited.

Also drop the formatting-only hunks in schedule_policy.py to keep the
diff scoped.
@hxieustc
hxieustc force-pushed the add-fine-grain-prefill-cached-token-info branch from 77394e6 to a4be49d Compare June 4, 2026 21:35
@hxieustc hxieustc added the run-ci label Jun 8, 2026
@hxieustc
hxieustc force-pushed the add-fine-grain-prefill-cached-token-info branch 11 times, most recently from f520b04 to 0e6b21c Compare June 17, 2026 01:20
@hxieustc
hxieustc force-pushed the add-fine-grain-prefill-cached-token-info branch 2 times, most recently from 516d152 to d45be44 Compare June 23, 2026 21:03
@hxieustc
hxieustc force-pushed the add-fine-grain-prefill-cached-token-info branch 2 times, most recently from 6ae79bb to 68c830b Compare June 26, 2026 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants