Practice in Lab: Reserve KV-cache memory with explicit grouped-query dimensions →
Reserve KV-cache memory with explicit grouped-query dimensions
An admission limit expressed only as request count ignores ragged context lengths. KV-cache reservation should depend on the actual key/value head count, which can be smaller than the query-head count in grouped-query attention. This planner reserves each request's maximum output up front and shows how memory assumptions affect admission. It is an unpaged arithmetic model, not a GPU allocator. Its greedy policy may skip a large request to admit a smaller later one; the separate scheduling project uses a declared FIFO policy instead.
layers, kv_heads, head_dim, element_bytes = 2,1,4,2
per_token = 2*layers*kv_heads*head_dim*element_bytes
reserved_tokens = 4
print(per_token, reserved_tokens*per_token)Review the design
Compare the estimate with real accelerator measurements and paged-cache behavior. Treat memory reservation, throughput, fairness and latency as separate constraints.
Your task
Compute unpaged KV bytes per token as 2*layers*kv_heads*head_dim*bytes_per_element. Reserve each request's prompt+maximum-output tokens. In input order admit requests that fit remaining byte capacity, skipping those that do not fit. Return admitted,rejected,reserved_bytes,bytes_per_token. IDs are unique. Dimensions are positive integers; capacity and token counts are nonnegative integers. This estimate excludes model weights, activations, allocator/page overhead and tensor parallel replication.
The explanation opens here once every check passes.