mstar.engine.resources.kv.manager#
Classes
|
|
|
(request, label) cache stream metadata |
|
A stream an in-progress offload has taken ownership of, and the state its host copy was made from. |
|
|
|
|
|
|
|
physical storage and free list management |
|
|
|
fifo retention of context_budget |
- class mstar.engine.resources.kv.manager.AllocResult(success: bool = True, error: mstar.engine.resources.step.AdmitFailedReason | None = None)[source]#
Bases:
object- Parameters:
success (bool)
error (AdmitFailedReason | None)
- error: AdmitFailedReason | None = None#
- class mstar.engine.resources.kv.manager.CacheStream(page_indices=<factory>, stored_len=0, position=0, released=0, retention=None, read_pending=False, read_future=None, read_error=None, offloaded=False, generation=0, step_in_flight=False)[source]#
Bases:
object(request, label) cache stream metadata
- Parameters:
- read_error: BaseException | None = None#
- retention: RetentionPolicy | None = None#
- class mstar.engine.resources.kv.manager.ClaimedStream(label, pages, generation, stored_len, position, released)[source]#
Bases:
objectA stream an in-progress offload has taken ownership of, and the state its host copy was made from.
- Parameters:
- class mstar.engine.resources.kv.manager.KVManager(cfg, name, joint_comm_group, transfer_engine_info, device, dtype=torch.bfloat16)[source]#
Bases:
AttentionResource- Parameters:
cfg (KVConfig)
name (str)
joint_comm_group (JointGroups | None)
transfer_engine_info (TransferEngineInfo)
device (device)
- 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 (KVStep)
ctx (StepContext)
- Return type:
- admit_retrieve(rid, node_name, graph_walk, published)[source]#
Takes the output of publish, possibly from another device, and kicks of a retrieval if needed (e.g., PD disaggregation KV transfer). Returns whether the retrieve has completed.
- Parameters:
rid (str)
node_name (str)
graph_walk (str)
published (PublishedKVInfo | None)
- Return type:
- classmethod build(spec, info)[source]#
- Parameters:
spec (KVSpec)
info (EngineResourceInfo)
- build_cuda_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)
- commit(step, ctx)[source]#
record step consumption
- Parameters:
step (KVStep)
ctx (StepContext)
- get_offload_priority(rid)[source]#
Device pages the request is holding — the most reclaimable first.
- ingest_request(rid, overrides=None)[source]#
- Parameters:
overrides (KVReqConfig | None)
- is_offloaded(rid)[source]#
True from the moment an offload claims the request, not just once its pages are on the host.
check_readygates admission on this, so the window where the copy is still in flight must not look schedulable — and the worker’s victim filter must not pick a request that is already on its way out.
- layer_view(layer_idx=None)[source]#
layer pages as needed by attention kernel
handed to AttentionManager::run. in kv_manager so storage mechanics are opaque to layers
- offload(rid)[source]#
Move every stream of
ridto host memory. Returns pages freed.A stream whose pages don’t fit on the host keeps them, so a partial offload still frees whatever did fit.
Device pages go back to the arena only once every stream has been copied: a step admitted before the claim can still run its fork copy, and that copy reads one of these streams.
- plan(step, ctx)[source]#
Returns list of sequence views per plan label
- Parameters:
step (KVStep)
ctx (StepContext)
- Return type:
- post_warmup_validate()[source]#
Assert
num_free_pagesis identical across every TP rankCatches YAML drift (e.g.
cpu_offload_pagesset on one rank but not another), allocator-init bugs, and any future code path that adds requests asymmetrically beforewarmupreturns. Theall_gatheritself is synchronizing, so no extra barrier is needed on the success path.
- read_kv(layer_idx=None, plan_label=None)[source]#
The slots this step’s plan writes, e.g. for NHD: [num_tokens, 2, num_kv_heads, head_dim] (K at index 0, V at 1).
- reclaimable(rid)[source]#
Device pages the request is holding; 0 once offloaded, and for one admitted but not yet run.
- reload(rid)[source]#
Bring every offloaded stream of
ridback on device.False when the device can’t fit them right now; nothing moves in that case, so the caller can evict further and try again.
- property supports_eviction#
- property supports_preplan#
- class mstar.engine.resources.kv.manager.KVPlanState(token_to_page: torch.Tensor, token_to_cache: torch.Tensor, total_tokens: int | None = None)[source]#
Bases:
object- copy_(other, capture_len)[source]#
Stage a step’s addressing into this captured state.
Neutralize only
[n:capture_len]— the slots the graph scatters beyond the real tokens (SINK_PAGE, else they hit another request’s KV). Decode fills its bucket exactly (n == capture_len), so no-op there; only packed prefill pays it, over the real gap not the whole buffer.- Parameters:
other (KVPlanState)
capture_len (int)
- class mstar.engine.resources.kv.manager.KVSequenceInfo(seq_len: int, latest_kv_transfer_info: Any, page_indices: list[int] = <factory>)[source]#
Bases:
object
- class mstar.engine.resources.kv.manager.PageArena(kv_cache, allocator)[source]#
Bases:
objectphysical storage and free list management
- Parameters:
kv_cache (KVCache)
allocator (PageAllocator)
- allocator: PageAllocator#
- property num_free#
- class mstar.engine.resources.kv.manager.PublishedKVInfo(info: dict[int, dict[str, mstar.engine.resources.kv.manager.KVSequenceInfo]]=<factory>, world_size: int = 1)[source]#
Bases:
PublishedInfo- classmethod build_for_rank(rank, world_size, seq_info)[source]#
- Parameters:
rank (int)
world_size (int)
seq_info (dict[str, KVSequenceInfo])
- update(other)[source]#
- Parameters:
other (PublishedKVInfo)