feat(report): flag chunk-granular ITL when the server batches tokens#150
Merged
Merged
Conversation
ITL is recorded per streamed chunk (one inter-token-latency sample = the gap between consecutive SSE content chunks). When a server emits one token per chunk (the common case) that equals true per-token ITL. When it batches multiple tokens into one chunk (under load, speculative decoding, chunked streaming), each ITL sample is one inter-chunk gap covering several tokens — biased high and under-sampled. Rather than tokenize each chunk delta inline (which would add work to the very timing path being measured), detect batching cheaply from data already collected: count streamed content chunks and compare to the server-reported content token total. The mean tokens-per-chunk is reported as `latency.itl_tokens_per_chunk`, and the console prints a note when it exceeds 1.5 so users know ITL is chunk-granular for that run. Detection only fires when the server reports usage; without it the ratio is ~1 and no note is shown. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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.
Summary
Design-limitation #4, option (b): detect + label, rather than change the ITL math.
ITL is recorded per streamed chunk — one inter-token-latency sample is the gap between consecutive SSE content chunks. When a server emits one token per chunk (the common case for vLLM/TGI/llama-server at normal load), that equals true per-token ITL. When it batches multiple tokens into one chunk (under load, speculative decoding, chunked streaming), each ITL sample is one inter-chunk gap covering several tokens — biased high and under-sampled.
Rather than tokenize each chunk's delta inline (which would add work to the very timing path being measured, perturbing the numbers), this detects batching cheaply from data already collected: count streamed content chunks and compare to the server-reported content token total.
streamed_content_chunkscounter; mean tokens-per-chunk surfaced aslatency.itl_tokens_per_chunkin the JSON.usage; without it the ratio is ~1 and no note appears.This keeps ITL correct-and-unlabeled for the common 1-token-per-chunk case and makes the one failure mode (batching) visible, without touching the measurement path.
Test plan
cargo test— 99 lib + 16 integration tests pass, 0 failures.cargo clippy --all-targets— cleancargo fmt --check— cleansafe_divguard, and the chunk counter accumulates per non-warmup content stream in both the single-turn and conversation paths.Generated with Claude Code