mstar.engine.resources.kv.bounded.manager#
A pool of fixed-size per-request KV slots with sink + window retention.
Unlike the paged KVManager there is nothing to reserve per step and
nothing to release: a request takes a slot when it first runs and keeps it,
the window is a ring overwritten in place, and a step’s layout is a small
integer table computed on the host from positions the step declares.
Classes
|
|
|
- class mstar.engine.resources.kv.bounded.manager.BoundedKVManager(config, device, kv_dtype=None)[source]#
Bases:
Resource- Parameters:
config (BoundedKVConfig)
device (torch.device)
kv_dtype (torch.dtype | None)
- admit(step, ctx)[source]#
Reserve space for the given step. In the case where requests in a batch must be executed sequentially, this may be called for all requests in a loop before the per-request plan -> forward -> commit cycle.
- Parameters:
step (BoundedKVStep)
ctx (StepContext)
- Return type:
- attend(layer_idx, q, k, v, source=None, plan=None, rel_bias=None, ieee=False, row_source=None)[source]#
Attention for
q, k, v [B * rows, H, T, D]over each row’s retained keys (source [sources, rows, H, L, 2D]is this layer’s source prefixes, each row’s picked by itsStreamPosition.source) and this step’s own, then this step’s keys into the slots.[B * rows, T, H, D].plandefaults to the step’s.rel_biasis a per-distance score term (kernels.bounded_attention), for relative-position attention; with a per-query window (BoundedKVConfig.query_window) it is indexed by distance,[B * rows, H, T, window + 1]. Rows whose source is -1 read theirs fromrow_source = (storage [slots, rows, H, L, 2D], slots [>= B]), e.g. another resource’s per-request entries.
- classmethod build(spec, info)[source]#
- Parameters:
spec (BoundedKVSpec)
info (EngineResourceInfo)
- Return type:
- build_accelerator_graph_buffers(slots, max_bs, max_seq_len)[source]#
Size whatever the captured replays will read.
Called once per runner that captures against this node — the whole forward’s, and one per piecewise region — so it must tolerate repeated calls: grow to the largest shape asked for, never clobber what an earlier call already sized.
- Parameters:
slots (list[CGSlotSpec])
max_bs (int)
max_seq_len (int)
- Return type:
None
- commit(step, ctx)[source]#
record step consumption
- Parameters:
step (BoundedKVStep)
ctx (StepContext)
- Return type:
None
- property current: BoundedPlan#
- ingest_request(rid, overrides=None)[source]#
Must be idempotent: the conductor sends one NewRequest per partition, so a worker serving several partitions of a request ingests it once for each, possibly after a node has already run a step for it.
- Parameters:
rid (str)
overrides (ResourceReqConfig | None)
- plan(step, ctx)[source]#
ret is immutable and opaque to runner; only gives to ctx.plan_results
- Parameters:
step (BoundedKVStep)
ctx (StepContext)
- Return type:
- post_warmup_validate()[source]#
For, e.g., the KV cache to check that num_free_pages is identical across TP ranks after cuda graph capture.
Raises an error (fails loudly) if invalid.
- reset_request(rid, free=False)[source]#
Nothing to zero: a slot’s contents are only read where a later position says they were written.
- rollback_admit(step, ctx)[source]#
Free the slots this step’s admit took fresh; a slot a request already held stays with it.
- Parameters:
step (BoundedKVStep)
ctx (StepContext)
- Return type:
None
- class mstar.engine.resources.kv.bounded.manager.BoundedPlan(table, rows, max_retained, max_span, reads_source, reads_row_source)[source]#
Bases:
NamedTuple- Parameters: