Choose prompt chunks at real interruption boundaries
Quantify a fictional chunk-size latency tradeoff while preserving prompt dependencies, decode service, and implementation-specific scheduling boundaries.
On this page
The question for today
What you’ll understand
- Calculate chunk count, repeated overhead, and one bounded interference interval.
- Distinguish iteration-boundary scheduling from arbitrary kernel preemption.
- Explain how decode protection can trade against prompt completion and first-token delay.
A long prompt can occupy execution long enough to delay active streams. Chunked prefill divides that prompt into supported pieces so the scheduler can reconsider eligible work between pieces. Smaller chunks can reduce one source of blocking while adding launches, coordination, and less efficient computation. The right size depends on the actual engine, batch mix, and latency contract. A chunk-size setting is a policy lever, not a universal guarantee that every stream gap stays below a chosen threshold.
Preserve prompt context while exposing scheduling opportunities
Later prompt chunks depend on earlier prompt context. An implementation must retain or reconstruct the appropriate state and apply correct causal attention to the prefix. Treating chunks as unrelated documents would change the model computation. The scheduler's opportunity occurs where the engine returns control or supports an explicit boundary; choosing a small logical chunk does not imply a running GPU kernel can be interrupted at any instruction. Include in-flight work and synchronization when measuring how quickly a new priority can take effect.
Sarathi-Serve studies chunked prompt work and mixed batches as a way to balance throughput and latency. Pinned vLLM 0.10.2 documentation describes its own V1 decode-prioritized chunking policy and iteration token budget. Those designs motivate experiments but do not justify copying a reported gain or a default chunk size to another workload. Also distinguish a chunk's raw prompt-token count from its actual time when growing context changes attention work and when mixed decode work changes batch efficiency.
Account for repeated overhead and competing service
In a deliberately simple serial model, a prompt costs α milliseconds per token and h milliseconds of fixed overhead per chunk. Its total prompt work is αP+h·ceil(P/c). This model exposes repeated overhead but deliberately ignores changing attention cost, batching, transfer, and overlapping execution. It can compare a stated scheduling idea without pretending to predict an accelerator. Measurements should then replace its coefficients or reject the model where it fails.
If decode can be reconsidered between chunks, one chunk contributes at most its modeled nonpreemptive interval before that opportunity under the simple assumptions. That is not the full inter-token latency: waiting for other work, decode duration, host handling, and transport remain. Very small chunks can also postpone a new prompt's completion and time to first token through repeated overhead or deprioritization. A policy that protects existing streams indefinitely can starve new prompts unless admission and aging address that outcome.
Inspect the whole tradeoff rather than one percentile
Measure prompt completion, first-token delay, stream gaps, completed-request goodput, memory occupancy, and fairness under the same offered workload. Include short prompts, long prompts, and bursts, and preserve the exact chunking policy and serving version. A mean decode rate can hide a single long gap, while a favorable stream percentile can hide prompt starvation. Record which boundary timestamps the profiler and client use so a shorter kernel is not confused with a shorter user-visible response.
The queue lab adds only a fluid overload comparison. Reset, set both arrival λ=4 and service μ=3, predict backlog eight after four seconds, then Play or take eight Steps. Reset and set both λ=2,μ=3 for a separate run that drains its initial four units at four seconds. Control edits retain elapsed time, so these are fresh comparisons rather than live rate switches. This fluid model contains no chunks, kernels, priorities, latency distribution, or measured p99; it shows why chunk tuning alone cannot eliminate sustained excess offered work.
Work it through
Compare two fictional chunk sizes
A prompt has 1,000 tokens. In a stipulated serial model α=0.02 ms/token and fixed overhead h=1 ms per chunk. Compare maximum chunk sizes 250 and 100, with scheduling reconsidered only between chunks.
With c=250 there are four chunks. Total prompt work is 0.02×1000+4×1=24 ms, and one full chunk's modeled interval is 0.02×250+1=6 ms.
With c=100 there are ten chunks. Total prompt work is 20+10=30 ms, while the full-chunk interval falls to 0.02×100+1=3 ms.
The smaller chunks add six milliseconds of total modeled prompt work while halving this one blocking interval. They do not alone guarantee a three-millisecond inter-token gap or a faster first token because other waiting and execution terms remain.
The toy tradeoff is 24 versus 30 ms of prompt work and six versus three ms per full chunk. Actual mixed-batch timings must test whether this model applies.
The living notebook
Explore the model
Interactive lab · queue
Separate chunk policy from sustained offered-work imbalance
Fresh Reset → set both λ=4,μ=3 predicts backlog 8 at t=4 s; Reset → set both λ=2,μ=3 predicts backlog 0 then. Play or take eight half-second Steps. Edits retain time. This fluid queue has no chunks, kernels, latency distribution, or measured tail percentile.
- Fluid backlog
- 4
- Net rate · λ − μ
- −1 /s
- M/M/1 mean residence
- 1 s
Fluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forMore scheduling opportunities cannot remove a sustained capacity deficit by themselves.
Pause & reason
Check your understanding
Your turn
Try it yourself
For the same α=0.02 ms/token and h=1 ms model, choose c=200 for a 1,000-token prompt. Calculate total prompt work and the full-chunk interval. What additional evidence is needed before claiming an ITL objective of five milliseconds?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Count five chunks, then keep the modeled chunk interval separate from decode, queueing, and delivery terms.
Compare with the solution
There are five chunks, giving total prompt work 20+5=25 ms and full-chunk interval 0.02×200+1=5 ms. A five-millisecond chunk interval alone leaves no budget for decode or other waiting and transport, so it does not establish a five-millisecond ITL objective. Measure the complete client-visible gap under the declared workload and verify the scheduler's actual interruption boundary and competing work.
Keep the idea
Take it with you
- Chunking preserves prompt dependencies while exposing supported scheduling boundaries.
- Smaller chunks can reduce one blocking term and increase total overhead or prompt delay.
- Evaluate stream latency, prompt progress, goodput, and overload under the same workload.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.