Decode Step Capacity
Each active request is [id, cached_tokens]; generating its next token requires one more KV position. Implement fit_decode_step(active, max_total_tokens). Return IDs accepted in input order while the sum of (cached_tokens + 1) stays within the total capacity. Skip requests that do not fit and continue. All counts are nonnegative. This simplified model treats each selected request as generating exactly one token.
Explore the underlying concept with illustrative inputs. This experiment is separate from the problem’s test cases.
Continuous batching
Compare fixed batches with a scheduler that refills slots as requests finish.
Fixed batches · 9 ticks total
Continuous batching · 6 ticks total
All five requests arrive at tick 0. Two slots each decode one token per tick. Request lengths: 2, 4, 1, 3, 2. Bars show scheduled work; the vertical cursor marks the current tick.
Change the experiment
for each decoding_tick:
decode_one_token(active_requests)
remove_finished_requests()
fill_free_slots(queue)Try it yourself
Increase the last request length. Compare the two completion times and locate idle slots in fixed batching.
Tick 0. Fixed batches completed 0 requests; continuous batching completed 0.
Refilling free slots can improve utilization. This idealized model excludes prefill, memory limits and shared GPU contention.
Playback pauses in hidden tabs and offscreen. With reduced motion enabled, use the timeline or Next step.Examples
A guided view of the published example, not a trace of your code.
[[["a",3],["b",8],["c",1]],7]["a","c"]Start with the input values shown in this example.
Input: active = [["a",3],["b",8],["c",1]], max_total_tokens = 7
Output: ["a","c"]
Explanation: skip long sequence
Input: active = [["a",0],["b",0]], max_total_tokens = 2
Output: ["a","b"]
Explanation: first decode
Hint 1
A selected sequence costs its cached length plus one.