mstar.engine.resources.recurrent#
- class mstar.engine.resources.recurrent.DeltaNetGeometry(num_k_heads, num_v_heads, head_k_dim, head_v_dim, conv_kernel_size)[source]#
Bases:
RecurrentGeometryHead geometry of the delta-net family: gated delta rule (Qwen3.5, Qwen3-Next) and Kimi delta attention (Kimi Linear, GLM-5.3).
Both carry a K-last [HV, V, K] state matrix (FlashInfer’s pool layout) and a conv window holding every tap but the current token’s.
to_blocksandfrom_blocksare inverses, so a backend reads its geometry off the pool.- Parameters:
- classmethod from_blocks(blocks)[source]#
Recover head counts from (possibly sharded) block shapes.
Raises if the shapes are not a delta-net’s.
- Parameters:
blocks (dict[str, RecurrentBlockConfig])
- Return type:
- class mstar.engine.resources.recurrent.Mamba2Geometry(num_heads, head_dim, state_size, n_groups, conv_kernel_size)[source]#
Bases:
RecurrentGeometryHead geometry of a Mamba-2 (SSD) layer: Nemotron-H, NVIDIA’s Nemotron Nano/VoiceChat backbones, Mamba-Codestral.
Two blocks, like the delta-net family: an
[H, P, N]SSM state per head (fp32 by default: it is an exponentially decayed running sum over the whole session, and the reference keeps it in fp32) and the conv window over the[x | B | C]projection, every tap but the current token’s.n_groupsis the number ofB/Cgroups shared byHheads. It is a shape fact (conv_dim = H * P + 2 * n_groups * N), so it is recoverable from the blocks andfrom_blocksinvertsto_blocks.- classmethod from_blocks(blocks)[source]#
Recover the geometry from block shapes (sharded ones too, since every axis involved shards). Raises on shapes that are not a Mamba-2’s, which is the check that a pool and the resource planning against it were built for the same model.
- Parameters:
blocks (dict[str, RecurrentBlockConfig])
- Return type:
- class mstar.engine.resources.recurrent.RecurrentAddressing(slot_indices, has_state, num_rows, host_slot_indices=None, host_has_state=None)[source]#
Bases:
objectWhere one label’s rows live this step: the pool’s whole plan output.
Token layout (cu_seqlens, chunk metadata) is the backend’s to build.
- Parameters:
- class mstar.engine.resources.recurrent.RecurrentBlockConfig(shape, dtype, shard_dims=())[source]#
Bases:
objectOne per-slot, per-layer tensor block.
shapeis opaque to the pool.shard_dimsnames the axes divided across ranks.
- class mstar.engine.resources.recurrent.RecurrentGeometry[source]#
Bases:
ABC- abstractmethod classmethod from_blocks(blocks)[source]#
- Parameters:
blocks (dict[str, RecurrentBlockConfig])
- Return type:
- class mstar.engine.resources.recurrent.RecurrentStateConfig(num_layers: int, blocks: dict[str, mstar.engine.resources.recurrent.config.RecurrentBlockConfig]=<factory>, max_slots: int = 256, disable_sink_slot: bool = False)[source]#
Bases:
object- Parameters:
- blocks: dict[str, RecurrentBlockConfig]#
- class mstar.engine.resources.recurrent.RecurrentStatePool(device, config)[source]#
Bases:
Resource- Parameters:
device (torch.device)
config (RecurrentStateConfig)
- addressing(label='main')[source]#
This step’s addressing under
label, for a backend to run against.- Parameters:
label (str)
- Return type:
- admit(step, ctx)[source]#
Reserve a slot per addressed (rid, label), plus fork targets.
Capture rows and a replay’s padding rows reserve nothing and address the sink instead; otherwise the runner’s dummy names would drain a pool sized for the real concurrency.
- Parameters:
step (RecurrentStep)
ctx (StepContext)
- Return type:
- block(name, layer_idx)[source]#
One layer’s contiguous slot-major view of a block:
[max_slots, *shape].
- classmethod build(spec, info)[source]#
- Parameters:
spec (RecurrentStateSpec)
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 (RecurrentStep)
ctx (StepContext)
- Return type:
None
- 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 (RecurrentStep)
ctx (StepContext)
- reset_request(rid, free=False)[source]#
Drop a request’s slots.
freehands them back to the pool.Both paths zero what they release, or a backend could resume on another request’s state.
- rollback_admit(step, ctx)[source]#
Free the slots this step’s admit took fresh; slots a request already held stay with it. Without this, two forking requests can each keep the slot the other’s fork needs, and the pool has no eviction to break that.
- Parameters:
step (RecurrentStep)
ctx (StepContext)
- Return type:
None
- property supports_preplan#
- class mstar.engine.resources.recurrent.RecurrentStateSpec(resource_key: str, nodes: set[str], config: mstar.engine.resources.recurrent.config.RecurrentStateConfig)[source]#
Bases:
NodeResourceSpec- Parameters:
resource_key (str)
config (RecurrentStateConfig)
- apply_yaml_overrides(max_slots=None, state_dtype=None)[source]#
How many slots this deployment gets, and the state’s dtype.
Block shapes are the model’s and not tunable. The dtype trades accumulated precision against bandwidth and decides which kernels the backend can reach.
- config: RecurrentStateConfig#
- class mstar.engine.resources.recurrent.RecurrentStep(segments=None, pre_forks=(), post_forks=())[source]#
Bases:
ResourceStepOne step’s work against the pool.
No
commitflag, unlikeKVStep: a backend writes the pool in place, so a non-committing reader needs two labels, reading one and writing another.Forks mirror
KVStep’s:(from_label, to_label)pairs, reserved at admit and copied at plan (pre) or commit (post).- Parameters:
Modules