advanced28 min studyLesson 705 in Engineering

Eviction releases reusable storage only when the required state remains recoverable

Separate idle-prefix eviction from active-request preemption, identify replay dependencies, and compare recovery costs without changing the model's attention semantics.

On this page

What you’ll understand

  • Distinguish evictable idle prefixes from live or asynchronously held state.
  • List the model and request state required for correct KV reconstruction.
  • Calculate reclaimed capacity and measured resume latency under explicit assumptions.

A KV cache can be discarded because its values are derived from other state, but derivability does not make every eviction safe or cheap. Reclaiming an idle completed prefix is different from preempting a running request whose attention still needs those values. Define what survives, who still owns the block, and how the state will be reconstructed. Memory pressure should change scheduling and recomputation policy, not silently change a full-context model into one that forgets arbitrary earlier tokens.

Idle cache eviction and active preemption are different transitions

An idle full-prefix block with zero active references may remain in a lookup structure for future reuse. Evicting it removes that reusable identity before the physical slot is repurposed. A later compatible request can recompute the missing state, so eviction changes future work rather than the current output of a request that no longer owns it. Active or in-flight references require protection. Reusing the bytes while another kernel still reads them is a lifetime error, even if a scheduler has already marked the corresponding request canceled.

A live request can be preempted through an explicit protocol that stops its further launches, resolves outstanding access, retains its reconstruction inputs, and releases or offloads its KV allocation. The original PagedAttention system discusses recomputation and swapping as recovery choices under memory pressure. That original design should not be treated as a statement that every current engine uses the same policy or supports all combinations. Separate a block-pool admission failure from a device allocation failure: a pool may be full while the underlying GPU tensor remains fixed in size.

E={b:rb=0 ∧ hb=0},Creclaim≤∣E∣mB\mathcal E=\{b:r_b=0\ \land\ h_b=0\},\qquad C_{\rm reclaim}\le |\mathcal E|m_B
E contains blocks with no active request references r_b and no additional outstanding-operation holds h_b under the declared ownership model. m_B is equal block payload bytes. The bound concerns reclaimable pool capacity, not bytes necessarily returned to CUDA; policies and metadata can restrict which eligible blocks are actually reused.↔ Scroll wide equations horizontally.

Reconstruct the same effective state, not just the visible text

To replay a dense prefix, retain the exact token history and every other input that affects the state: model and adapter revisions, positions, attention-mask semantics, multimodal features or reproducible inputs, and relevant configuration. Restoring token strings through a changed tokenizer is not equivalent to restoring token IDs. If exact continuation is required, preserve sampling and stopping state as well; rebuilding KV alone does not restore a random generator's position or an already streamed output boundary. Replay under compatible numerical execution can reproduce the mathematical state while still differing at floating-point roundoff level.

Do not drop arbitrary old KV positions and continue as if the full state remained available. A model explicitly designed for a sliding attention window can have a different valid retention policy, but that is an architectural contract rather than an eviction shortcut. If compressed or quantized state is reconstructed differently, define the accepted numerical and quality tolerance. Tests should compare replayed continuations with a controlled nonpreempted reference and include cancellation, multimodal inputs, changed adapters, and prefix identity. Recovery correctness needs evidence beyond a successful allocation after the pause.

KV⁡1:T=Fθ(x1:T,z)\operatorname{KV}_{1:T}=F_{\theta}(x_{1:T},z)
This mathematical definition treats KV state as a function of fixed model state theta, exact token sequence x, and all additional effective inputs z. T is retained token count. It supports recomputation only when the required inputs and semantics survive; bitwise floating-point reproducibility and sampler-state restoration are separate contracts.↔ Scroll wide equations horizontally.

Measure recovery work and avoid repeated preemption loops

A cheap-to-recompute prefix can be a better eviction candidate than an equally sized expensive one, but reuse probability, queue pressure, and fairness also matter. Measure prefill and transfer latency at the actual batch and context shapes. A policy that repeatedly admits work then preempts the same long requests can waste capacity and violate latency goals despite high instantaneous utilization. Track bytes reclaimed, replay tokens, repeated victims, and time-to-first-token or inter-token stalls. An idle cache hit rate alone does not describe the cost imposed on active requests.

The probability lab isolates a hypothetical independent reuse count after eviction. Reset, explicitly set BOTH reuse probability p=0.25 and n=20, predict five reuses on average, then Play or Step. Reset and re-set BOTH p=0.75 and n=20; predict fifteen. Edits retain t; playback highlights exact binomial counts without replaying a model. The toy has no cache capacity, prefix lengths, recovery times, ownership, or scheduler. Its stipulated reuse probability cannot be inferred from an eviction event itself, and correlated conversations would violate the independent identical-trial assumption.

Reclaim idle capacity and account for a later miss

A twenty-block pool has twelve actively referenced blocks, six idle evictable cached blocks, and two unused blocks. A new request needs five blocks. Assume no outstanding extra holds. One later compatible prefix miss has measured prefill latency twenty-four milliseconds plus six milliseconds of serial scheduling delay.

  1. The new request is short by 5−2=3 blocks. Reclaim three of the six eligible idle blocks; the twelve actively referenced blocks remain protected.

  2. After admission, live use becomes 12+5=17 blocks, three idle cached blocks remain, and no unused blocks remain. Reclamation reused pool slots rather than necessarily reducing the device allocation.

  3. For the later miss under the stated measurements, resume work takes 24+6=30 milliseconds before subsequent decode. This cost is specific to that shape and delay; it does not establish that recomputation always beats offload.

The result

A safe idle eviction can enable admission while creating a future recomputation cost that needs explicit measurement and policy.

Explore the model

Interactive lab

Interactive lab · probability

Expected future reuse is an input to eviction cost

For EACH run Reset, set BOTH p and n, predict, then Play or Step. At n=20 compare stipulated reuse p=0.25, mean 5, with p=0.75, mean 15. Edits retain t. This exact iid count model has no actual prefixes, eviction policy, GPU blocks, reconstruction work, or latency prediction.

Expected future reuse is an input to eviction costThese are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Current readings: Mean · np: 5; Variance · np(1−p): 2.5; Total probability: 1. All parameters are adjustable with the labeled controls below.03581000.070.150.220.3Successes kP(X = k)k = 0 · P = 9.77e-4
Exact probabilityHighlighted outcomeMean np
Mean · np
5
Variance · np(1−p)
2.5
Total probability
1
t = 0 s

These are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. 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 forReclaimability, recoverability, and expected reuse cost are separate questions.

Check your understanding

A full-context decoder loses an active request's old KV blocks. Which recovery preserves the intended semantics?

Try it yourself

A pool has eight active blocks, four eligible idle cached blocks, and one unused block. A new request needs three blocks. Calculate minimum idle evictions and the remaining idle count. Does this operation prove that GPU driver usage falls?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Cover the shortfall using eligible slots, then distinguish pool reuse from releasing its backing allocation.

Compare with the solution

The shortfall is 3−1=2 blocks, so two idle blocks must be reclaimed and two remain cached. The operation does not imply lower driver-level usage: the pool's backing device allocation can stay fixed while ownership of its slots changes.

Take it with you

  • Idle-prefix eviction and active-request preemption have different ownership transitions.
  • Recomputation needs exact effective inputs and compatible model semantics.
  • Pool capacity savings and recovery latency must be measured at their own boundaries.

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.