mstar.engine.resources.kv.ring.manager#
The paged KVManager reserves pages per step and hands them back;
this one reserves nothing. Every layer’s ring is allocated once at
build and reused for the life of the process,.
Classes
|
Per-layer ring caches holding |
|
Host facts downstream resources need to stage this fixed ring view, one entry per row of the step batch, in |
- class mstar.engine.resources.kv.ring.manager.RingKVManager(config, name, device, dtype=torch.bfloat16)[source]#
Bases:
AttentionResourcePer-layer ring caches holding
num_sessionssessions, one per request.- Parameters:
config (RingKVConfig)
name (str)
device (device)
dtype (dtype)
- admit(step, ctx)[source]#
Claim a session for this step’s request. A full pool is retried; a malformed step is refused terminally. Does not support eviction for now
- Parameters:
step (ResourceStep)
ctx (StepContext)
- Return type:
- classmethod build(spec, info)[source]#
- Parameters:
spec (KVSpec)
info (EngineResourceInfo)
- Return type:
- build_accelerator_graph_buffers(slots, max_bs, max_seq_len)[source]#
No-op: every buffer a replay touches was allocated at
build,_static_session_idxincluded.- Parameters:
slots (list[CGSlotSpec])
max_bs (int)
max_seq_len (int)
- Return type:
None
- capacity(layer_idx)[source]#
Token slots ONE session owns in
layer_idx’s ring, scratch frame included.total_slotsis the whole buffer.
- commit(step, ctx)[source]#
Record the frame each request just committed. Metadata only.
- Parameters:
step (ResourceStep)
ctx (StepContext)
- Return type:
None
- get_state(rid)[source]#
Snapshot one request’s session. Cloned, so the caller can hold it across further rollout steps that mutate the rings in place.
- ingest_request(rid, overrides=None)[source]#
Register
rid. Deliberately does not claim a session.- Parameters:
rid (str)
overrides (ResourceReqConfig | None)
- Return type:
None
- plan(step, ctx)[source]#
Stage the padded batch’s session indices, one per row. Ring addresses stay in the graph.
A replay pads the batch to its capture bucket with dummy rids that hold no session. Those rows still write and attend (their output is dropped downstream), so every one is parked on
_padding_session– the shared scratch session outside the resident pool. The flex mask scopes each row to its own session, so a padding row’s read and its commit both stay on that session and never reach a real request’s history; no request is ever admitted to it, so the tail it leaves behind is never read.- Parameters:
step (ResourceStep)
ctx (StepContext)
- Return type:
- post_warmup_validate()[source]#
Capture must leave every session exactly as it found it.
- Return type:
None
- remove_request(rid)[source]#
The request is gone: drop its session, its claim, and its registration.
- Parameters:
rid (str)
- Return type:
None
- reset_request(rid, free=False)[source]#
Zero
rid’s session and release its claim.freeis ignored, there is no physical allocation to hand back.
- session_of(rid)[source]#
rid’s session index, or None if it holds none. Host-side introspection; the forward reads the staged tensor, never this.
- total_slots(layer_idx)[source]#
Token slots in
layer_idx’s buffer across every session – the length of the KV viewupsertreturns and of its visibility row.
- upsert(k, v, layer_idx, frame_pos, *, commit, build_visibility=True)[source]#
Write one step’s K/V for
layer_idxand return what to attend to.k/vare[B, H_kv, tokens_per_frame, D], one frame per resident session in the step batch.kis already RoPE’d and RMS-normed andvis post value-residual lerp: the cache stores post-RoPE keys, so replayed history is never re-rotated. Returns(k_all, v_all, visible), the first two spanning the whole buffer, every resident session and the third a[total_slots]bool row that is False everywhere outside the calling request’s own session.frame_posandcommitare both arguments rather than resource state, for the same reason.frame_posis the[B]int64 ring clock – not a slot id – and alone determines the slot written and the visibility row;
- class mstar.engine.resources.kv.ring.manager.RingPlan(request_ids, session_idx, frame_pos)[source]#
Bases:
NamedTupleHost facts downstream resources need to stage this fixed ring view, one entry per row of the step batch, in
ctx.request_idsorder.