Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7f75d88
Add engine resources package with KV pool segment lifecycle
merceod Aug 9, 2026
d81690e
Route attention planning through KV pool views and admits
merceod Aug 9, 2026
854359a
Delegate rope planning to a position embedder and commit advances thr…
merceod Aug 9, 2026
2f004f6
Move attention plan machinery into resource managers
merceod Aug 9, 2026
82c76ee
Drive the engine step lifecycle through the pool and a step runner
merceod Aug 9, 2026
c8dcdf7
Address decode replay slots at real request ids instead of aliasing s…
merceod Aug 9, 2026
ef10a88
Address packed prefill replay slots the same way and drop the state swap
merceod Aug 9, 2026
a010de9
Address piecewise replay at real request ids and release padding pages
merceod Aug 9, 2026
47404f4
Build per-node resource dicts from model-declared specs
merceod Aug 9, 2026
708501f
Move offload and LRU surfaces onto the KV cache pool
merceod Aug 9, 2026
bb24a49
Read admit outcomes in check_ready via the pool
merceod Aug 9, 2026
e6abef2
Serve the code predictor scratch cache from the engine
merceod Aug 9, 2026
6e7f082
Add step declarations the runner drives for adopting models
merceod Aug 9, 2026
9890514
Adopt step declarations in cosmos3
merceod Aug 10, 2026
aba6041
Adopt step declarations in qwen3_omni and drop the pos-advance side c…
merceod Aug 10, 2026
93e3439
Adopt step declarations in bagel with declared cfg forks
merceod Aug 10, 2026
9d5a491
Add windowed retention and a block positional scheme; mark the facade…
merceod Aug 10, 2026
6e7b1e2
Build the batched-cfg plan through build_paged_indptrs
merceod Aug 10, 2026
2725156
Route request lifecycle through the pool fronts
merceod Aug 10, 2026
9ddc9cb
Note the node-resource end state on spec and model surfaces
merceod Aug 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 16 additions & 53 deletions mstar/engine/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from mstar.communication.tensors import NameToTensorList
from mstar.conductor.request_info import CurrentForwardPassInfo
from mstar.distributed.communication import WorkerParallelGroups
from mstar.engine.kv_store import KVCacheConfig, StoreWritePolicy
from mstar.engine.kv_store import KVCacheConfig
from mstar.profile.worker import ExecTimings


Expand All @@ -23,14 +23,12 @@ class EngineCapabilities:
"""Static declaration of optional surfaces an engine implements.

The worker and ``EngineManager`` consult these flags instead of
``isinstance`` / ``hasattr`` probes to decide whether to iterate or
dispatch into engine-specific code paths (e.g. CPU-offload victim
selection, KV-cache LRU tracking, store write-policy push). The
default ``EngineCapabilities()`` declares an engine that needs none
of the optional surfaces — stateless engines leave it untouched.
``isinstance`` / ``hasattr`` probes. The default declares an engine
that needs none of the optional surfaces; stateless engines leave it
untouched. Per-node resource questions (offload tiers, LRU tracking,
write policy) go through ``node_resources`` instead of flags here.
"""
requires_kv_cache: bool = False
supports_cpu_offload: bool = False


@dataclass
Expand Down Expand Up @@ -308,58 +306,23 @@ def reset_pre_plan_for_batch(self, batch: NodeBatch) -> None:
"""
return

# ── Capabilities + optional surfaces ────────────────────────────────
# ── Capabilities + per-node resources ───────────────────────────────
#
# ``capabilities`` is a class-level declaration of which optional
# surfaces this engine class implements. Worker / EngineManager check
# it instead of ``isinstance`` / ``hasattr`` probes. The methods below
# are the corresponding surfaces — all safe no-op defaults so engines
# that don't opt in can still be called uniformly. KVCacheEngine
# overrides both the capability flags and the methods; stateless
# engines leave them at default.
# surfaces this engine class implements; Worker / EngineManager check
# it instead of ``isinstance`` / ``hasattr`` probes. ``node_resources``
# is the per-node counterpart: the worker reaches an engine's KV cache
# pool (offload, LRU eligibility, write policy) through it rather than
# through per-question engine methods.

capabilities = EngineCapabilities()

def lru_tracked_nodes(self) -> list[str]:
"""Nodes for which the worker should LRU-track per-request activity
(used to pick CPU-offload victims). Default: no nodes — stateless
engines have no KV state to age out.
def node_resources(self, node_name: str) -> dict[str, Any]:
"""The named resources this engine built for ``node_name`` (KV
cache pool, embedder, cross pools, scratch caches). Engines that
build none return an empty dict.
"""
return []

def set_alloc_write_policy(self, policy: StoreWritePolicy) -> None:
"""Apply a store write policy. Default: no-op — engines without an
alloc manager have nothing to set.
"""
return

def offload_candidates(self, node_name: str) -> list[tuple[str, int]]:
"""Return ``(request_id, gpu_pages_held)`` for every request with
GPU pages on ``node_name``. The worker partitions the result into
in-batch vs external candidates and picks an eviction victim.
Default: empty list — no offloadable state.
"""
return []

def offload_request(self, node_name: str, request_id: str) -> int:
"""Offload ``request_id``'s KV pages on ``node_name`` to CPU.
Returns the number of GPU pages freed (0 if nothing was freed or
the engine doesn't support offload).
"""
return 0

def reload_request(self, node_name: str, request_id: str) -> bool:
"""Reload an offloaded request back to GPU on ``node_name``.
Returns True on success; False if the request isn't offloaded, GPU
pages are insufficient, or the engine doesn't support offload.
"""
return False

def is_offloaded(self, node_name: str, request_id: str) -> bool:
"""Whether ``request_id`` is currently CPU-offloaded on ``node_name``.
Default: False.
"""
return False
return {}

def execute_with_max_batch_size(self, batch: NodeBatch) -> NodeOutput:
if self.enable_profile:
Expand Down
Loading