mstar.engine.resources.kv.bounded.config#
What a model declares about a bounded KV cache.
A request’s cache is a logical stream: an optional read-only source prefix
(a voice prompt’s keys, say, shared by every request that uses it) followed by
the tokens the request writes. Retention keeps the stream’s first sink
entries and its last window (StreamingLLM’s attention sinks plus a sliding
window), so a request’s footprint is fixed and known when it starts: each slot
holds only the written part of the sink and a ring for the window, and source
entries are read where they live.
Classes
|
|
|
|
|
Each segment's |
|
Keep the stream's first |
|
Where a request's stream stands when a step starts. |
- class mstar.engine.resources.kv.bounded.config.BoundedKVConfig(num_layers: int, num_heads: int, head_dim: int, rows_per_request: int, max_source_len: int, retention: collections.abc.Callable[[int], mstar.engine.resources.kv.bounded.config.SinkWindow] | mstar.engine.resources.kv.bounded.config.SinkWindow, max_slots: int = 32, min_source_len: int = 0, dtype: torch.dtype | None = torch.float32, reverse_step_order: bool = False, query_window: int | None = None)[source]#
Bases:
object- Parameters:
- retention: Callable[[int], SinkWindow] | SinkWindow#
- class mstar.engine.resources.kv.bounded.config.BoundedKVSpec(resource_key: str, nodes: set[str], config: mstar.engine.resources.kv.bounded.config.BoundedKVConfig)[source]#
Bases:
NodeResourceSpec- Parameters:
resource_key (str)
config (BoundedKVConfig)
- apply_yaml_overrides(max_slots=None)[source]#
Patch declared parameters from this resource’s YAML block.
The model declares shapes that suit the model; a deployment tunes what suits the box it runs on. The block is scoped to this spec’s
resource_key(seeapply_yaml_overridesbelow), so an unrecognized key here is a typo, not another resource’s setting — subclasses name exactly what they accept and let the rest raise.TODO: generalize. Matching YAML keys against the spec’s (and its config’s) dataclass fields would remove these per-resource implementations, at the cost of silently accepting anything named alike.
- Parameters:
max_slots (int | None)
- config: BoundedKVConfig#
- class mstar.engine.resources.kv.bounded.config.BoundedKVStep(segments=None, positions=<factory>)[source]#
Bases:
ResourceStepEach segment’s
spanis what its request writes this step (0 reads only).The positions come from the model, not the resource, so a plan never waits on the previous step’s commit and planning the same step twice (a piecewise region inside a forward that declared it too) is harmless.
- Parameters:
positions (Mapping[str, StreamPosition])
- positions: Mapping[str, StreamPosition]#
- class mstar.engine.resources.kv.bounded.config.SinkWindow(sink, window, window_includes_step=False)[source]#
Bases:
NamedTupleKeep the stream’s first
sinkand lastwindowentries. Withwindow_includes_stepthe window counts the step’s own tokens, so a step that writesspanattends only the lastwindow - spanretained ones.
- class mstar.engine.resources.kv.bounded.config.StreamPosition(source_len, written, source=0)[source]#
Bases:
NamedTupleWhere a request’s stream stands when a step starts.