Expand description
Per-sequence device state the serve must RESERVE, computed before the model exists.
§Why this is config-keyed and not a layer-trait sum
preflight_reserve(args, config, free_mem) runs long before build_model, and the model
builder consumes the reserve it returns. There is no layer list, no proposer, and no
GpuBackend at that point, so a per-sequence term cannot be Σ_layers layer.some_method().
Every sibling reserve term (ssm_reserve::*) is a free function over config-derived scalars
for exactly this reason; this module follows that precedent.
§What is charged, and what deliberately is not
Charged — device memory a sequence OWNS, that no other reserve term covers:
- the target stack’s DSA indexer caches (
Glm5NextDsaState), one per text DSA layer; - the draft proposer’s own per-sequence state (
Glm5NextMtpHead::alloc_state).
The proposer is a SEPARATE OWNER — it is not a TransformerLayer and never appears in the
layer list, so a layer-side sum cannot see it. It is returned separately and must not be
folded into the target-layer term.
NOT charged, each because something else already accounts for it:
- KDA recurrent + conv state — pool-owned, covered by
ssm_reserve::ssm_pool_reserve_bytes(andmeta.rsnever callsalloc_statefor a pool-backed mixer); - the paged KV pool — it is the KV budget this reserve is subtracted from; charging it here would be circular;
- the buffer arena — sized by
max_batch_tokens, not per sequence (buffer_arena_bytes); - SSM snapshot / replay-ring / h-stage — already reserve terms, and the snapshot term
already scales by
max_batch_size; - CUDA-graph exec memory — per SLOT, not per sequence, and LRU-bounded;
- pad-row dummy states — transient per step, and GLM declines every batched path.
🔴 The indexer cache is REPLICATED across ranks. EP does not halve it, so this returns per-rank bytes directly and callers must not divide again.
Structs§
- PerSequence
State - Per-sequence, per-rank device state, split by OWNER.
Functions§
- per_
sequence_ state_ bytes - Per-sequence owned device state for
config, at a context ofmax_seq_lentokens.