vllm_mlx.lifecycle¶
Model lifecycle / residency management for vllm-mlx.
View the complete module source at #L1-L493.
API details¶
Each callable below includes its exact signature, type annotations, inputs, defaults, return contract, documented exceptions, implementation source, and parsed docstring sections when the source provides them.
vllm_mlx.lifecycle
¶
Model lifecycle / residency management for vllm-mlx.
vllm_mlx.lifecycle.ResidentState
¶
vllm_mlx.lifecycle.ModelSpec
dataclass
¶
ModelSpec(model_key: str, model_name: str, use_batching: bool = False, scheduler_config: Any | None = None, stream_interval: int = 1, max_tokens: int = 32768, force_mllm: bool = False, mtp: bool = False, prefill_step_size: int = 2048, specprefill_enabled: bool = False, specprefill_threshold: int = 8192, specprefill_keep_pct: float = 0.3, specprefill_backbone_pct: float = 0.0, specprefill_draft_model: str | None = None)
Immutable engine construction inputs for a resident model.
vllm_mlx.lifecycle.ModelSpec.use_batching
class-attribute
instance-attribute
¶
vllm_mlx.lifecycle.ModelSpec.scheduler_config
class-attribute
instance-attribute
¶
vllm_mlx.lifecycle.ModelSpec.stream_interval
class-attribute
instance-attribute
¶
vllm_mlx.lifecycle.ModelSpec.max_tokens
class-attribute
instance-attribute
¶
vllm_mlx.lifecycle.ModelSpec.force_mllm
class-attribute
instance-attribute
¶
vllm_mlx.lifecycle.ModelSpec.prefill_step_size
class-attribute
instance-attribute
¶
vllm_mlx.lifecycle.ModelSpec.specprefill_enabled
class-attribute
instance-attribute
¶
vllm_mlx.lifecycle.ModelSpec.specprefill_threshold
class-attribute
instance-attribute
¶
vllm_mlx.lifecycle.ModelSpec.specprefill_keep_pct
class-attribute
instance-attribute
¶
vllm_mlx.lifecycle.ModelSpec.specprefill_backbone_pct
class-attribute
instance-attribute
¶
vllm_mlx.lifecycle.ModelSpec.specprefill_draft_model
class-attribute
instance-attribute
¶
vllm_mlx.lifecycle.ResidentModel
dataclass
¶
ResidentModel(spec: ModelSpec, state: ResidentState = UNLOADED, engine: BaseEngine | None = None, active_requests: int = 0, last_used_at: float | None = None, loaded_at: float | None = None, last_error: str | None = None, estimated_memory_bytes: int | None = None, _load_waiters: int = 0, _load_waiter_task: Task[BaseEngine] | None = None, _prepare_task: Task[None] | None = None, _abandoned_loading_task: Task[BaseEngine] | None = None, _loading_task: Task[BaseEngine] | None = None, _unloading_task: Task[bool] | None = None)
Runtime state for a single resident model.
vllm_mlx.lifecycle.ResidentModel.state
class-attribute
instance-attribute
¶
state: ResidentState = ResidentState.UNLOADED
vllm_mlx.lifecycle.ResidentModel.engine
class-attribute
instance-attribute
¶
engine: BaseEngine | None = None
vllm_mlx.lifecycle.ResidentModel.active_requests
class-attribute
instance-attribute
¶
vllm_mlx.lifecycle.ResidentModel.last_used_at
class-attribute
instance-attribute
¶
vllm_mlx.lifecycle.ResidentModel.loaded_at
class-attribute
instance-attribute
¶
vllm_mlx.lifecycle.ResidentModel.last_error
class-attribute
instance-attribute
¶
vllm_mlx.lifecycle.ResidentModel.estimated_memory_bytes
class-attribute
instance-attribute
¶
vllm_mlx.lifecycle.ResidentModel._load_waiters
class-attribute
instance-attribute
¶
vllm_mlx.lifecycle.ResidentModel._load_waiter_task
class-attribute
instance-attribute
¶
_load_waiter_task: Task[BaseEngine] | None = field(default=None, repr=False)
vllm_mlx.lifecycle.ResidentModel._prepare_task
class-attribute
instance-attribute
¶
vllm_mlx.lifecycle.ResidentModel._abandoned_loading_task
class-attribute
instance-attribute
¶
_abandoned_loading_task: Task[BaseEngine] | None = field(default=None, repr=False)
vllm_mlx.lifecycle.ResidentModel._loading_task
class-attribute
instance-attribute
¶
_loading_task: Task[BaseEngine] | None = field(default=None, repr=False)
vllm_mlx.lifecycle.ResidentModel._unloading_task
class-attribute
instance-attribute
¶
vllm_mlx.lifecycle.ResidencyManager
¶
ResidencyManager(engine_factory: Callable[[ModelSpec], Awaitable[BaseEngine]], *, on_engine_loaded: Callable[[ModelSpec, BaseEngine], Awaitable[None] | None] | None = None, on_engine_unloading: Callable[[ModelSpec, BaseEngine], Awaitable[None] | None] | None = None, time_fn: Callable[[], float] | None = None, auto_unload_idle_seconds: float = 0)
Single-flight lifecycle manager for resident models.
Source code in vllm_mlx/lifecycle.py
vllm_mlx.lifecycle.ResidencyManager._engine_factory
instance-attribute
¶
vllm_mlx.lifecycle.ResidencyManager._on_engine_loaded
instance-attribute
¶
vllm_mlx.lifecycle.ResidencyManager._on_engine_unloading
instance-attribute
¶
vllm_mlx.lifecycle.ResidencyManager._time_fn
instance-attribute
¶
vllm_mlx.lifecycle.ResidencyManager.auto_unload_idle_seconds
instance-attribute
¶
vllm_mlx.lifecycle.ResidencyManager._residents
instance-attribute
¶
_residents: dict[str, ResidentModel] = {}
vllm_mlx.lifecycle.ResidencyManager.register_model
¶
register_model(spec: ModelSpec) -> str
Register a model spec, or replace a dormant resident entry.
Source code in vllm_mlx/lifecycle.py
vllm_mlx.lifecycle.ResidencyManager.get_engine
¶
get_engine(model_key: str) -> BaseEngine | None
vllm_mlx.lifecycle.ResidencyManager.get_status
¶
Return a serializable snapshot of resident state.
Source code in vllm_mlx/lifecycle.py
vllm_mlx.lifecycle.ResidencyManager.ensure_loaded
async
¶
ensure_loaded(model_key: str) -> BaseEngine
Load and start a resident engine if needed.
Source code in vllm_mlx/lifecycle.py
vllm_mlx.lifecycle.ResidencyManager.acquire
async
¶
acquire(model_key: str, *, count_activity: bool = True) -> BaseEngine
Acquire a resident engine for request processing.
Source code in vllm_mlx/lifecycle.py
vllm_mlx.lifecycle.ResidencyManager.release
async
¶
Release a previously acquired resident engine.
Source code in vllm_mlx/lifecycle.py
vllm_mlx.lifecycle.ResidencyManager.unload_if_idle
async
¶
Unload a resident engine if it has been idle past the threshold.
Source code in vllm_mlx/lifecycle.py
vllm_mlx.lifecycle.ResidencyManager.shutdown
async
¶
Stop all loaded residents.
Source code in vllm_mlx/lifecycle.py
vllm_mlx.lifecycle.ResidencyManager._load_engine
async
¶
_load_engine(resident: ResidentModel) -> BaseEngine
Create and start a resident engine.
Source code in vllm_mlx/lifecycle.py
vllm_mlx.lifecycle.ResidencyManager._unload_engine
async
¶
_unload_engine(resident: ResidentModel) -> bool
Stop and drop a resident engine.
Source code in vllm_mlx/lifecycle.py
vllm_mlx.lifecycle.ResidencyManager._resident
¶
_resident(model_key: str) -> ResidentModel
vllm_mlx.lifecycle.ResidencyManager._run_hook
async
¶
_run_hook(hook: Callable[[ModelSpec, BaseEngine], Awaitable[None] | None] | None, spec: ModelSpec, engine: BaseEngine) -> None
Source code in vllm_mlx/lifecycle.py
vllm_mlx.lifecycle.ResidencyManager._prepare_engine_start
async
¶
_prepare_engine_start(resident: ResidentModel, engine: BaseEngine) -> None
Run blocking startup work away from the serving event loop.
Source code in vllm_mlx/lifecycle.py
vllm_mlx.lifecycle.ResidencyManager._cleanup_cancelled_load
async
¶
_cleanup_cancelled_load(resident: ResidentModel, engine: BaseEngine | None) -> None
Stop a partially loaded engine and unwind resident state.
Source code in vllm_mlx/lifecycle.py
vllm_mlx.lifecycle.ResidencyManager._release_load_waiter
async
¶
_release_load_waiter(model_key: str, task: Task[BaseEngine]) -> None
Drop one waiter from a shared load, canceling abandoned solo loads.
Source code in vllm_mlx/lifecycle.py
Complete contract reference¶
Expand any definition for its exact inputs, annotations, defaults, return contract, directly raised exceptions, source-grounded behavior, and immutable line link. This section includes private and nested definitions that ordinary API generators omit.
vllm_mlx.lifecycle.ResidentState · class
Runtime residency state for a configured model.
Parameters
This callable has no explicit inputs.
Returns
- Constructs:
vllm_mlx.lifecycle.ResidentState
Exceptions and behavior
Class ResidentState derives from str, Enum and declares 0 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.lifecycle.ModelSpec · class
vllm_mlx.lifecycle.ModelSpec(model_key: str, model_name: str, use_batching: bool = False, scheduler_config: Any | None = None, stream_interval: int = 1, max_tokens: int = 32768, force_mllm: bool = False, mtp: bool = False, prefill_step_size: int = 2048, specprefill_enabled: bool = False, specprefill_threshold: int = 8192, specprefill_keep_pct: float = 0.3, specprefill_backbone_pct: float = 0.0, specprefill_draft_model: str | None = None)
Immutable engine construction inputs for a resident model.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_key |
str |
yes |
none |
Required constructor field. |
model_name |
str |
yes |
none |
Required constructor field. |
use_batching |
bool |
no |
False |
Optional constructor field; defaults to False. |
scheduler_config |
Any \| None |
no |
None |
Optional constructor field; defaults to None. |
stream_interval |
int |
no |
1 |
Optional constructor field; defaults to 1. |
max_tokens |
int |
no |
32768 |
Optional constructor field; defaults to 32768. |
force_mllm |
bool |
no |
False |
Optional constructor field; defaults to False. |
mtp |
bool |
no |
False |
Optional constructor field; defaults to False. |
prefill_step_size |
int |
no |
2048 |
Optional constructor field; defaults to 2048. |
specprefill_enabled |
bool |
no |
False |
Optional constructor field; defaults to False. |
specprefill_threshold |
int |
no |
8192 |
Optional constructor field; defaults to 8192. |
specprefill_keep_pct |
float |
no |
0.3 |
Optional constructor field; defaults to 0.3. |
specprefill_backbone_pct |
float |
no |
0.0 |
Optional constructor field; defaults to 0.0. |
specprefill_draft_model |
str \| None |
no |
None |
Optional constructor field; defaults to None. |
Returns
- Constructs:
vllm_mlx.lifecycle.ModelSpec
Exceptions and behavior
Class ModelSpec declares 0 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.lifecycle.ResidentModel · class
vllm_mlx.lifecycle.ResidentModel(spec: ModelSpec, state: ResidentState = ResidentState.UNLOADED, engine: BaseEngine | None = None, active_requests: int = 0, last_used_at: float | None = None, loaded_at: float | None = None, last_error: str | None = None, estimated_memory_bytes: int | None = None, _load_waiters: int = field(default=0, repr=False), _load_waiter_task: asyncio.Task[BaseEngine] | None = field(default=None, repr=False), _prepare_task: asyncio.Task[None] | None = field(default=None, repr=False), _abandoned_loading_task: asyncio.Task[BaseEngine] | None = field(default=None, repr=False), _loading_task: asyncio.Task[BaseEngine] | None = field(default=None, repr=False), _unloading_task: asyncio.Task[bool] | None = field(default=None, repr=False))
Runtime state for a single resident model.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
spec |
ModelSpec |
yes |
none |
Required constructor field. |
state |
ResidentState |
no |
ResidentState.UNLOADED |
Optional constructor field; defaults to ResidentState.UNLOADED. |
engine |
BaseEngine \| None |
no |
None |
Optional constructor field; defaults to None. |
active_requests |
int |
no |
0 |
Optional constructor field; defaults to 0. |
last_used_at |
float \| None |
no |
None |
Optional constructor field; defaults to None. |
loaded_at |
float \| None |
no |
None |
Optional constructor field; defaults to None. |
last_error |
str \| None |
no |
None |
Optional constructor field; defaults to None. |
estimated_memory_bytes |
int \| None |
no |
None |
Optional constructor field; defaults to None. |
_load_waiters |
int |
no |
field(default=0, repr=False) |
Optional constructor field; defaults to field(default=0, repr=False). |
_load_waiter_task |
asyncio.Task[BaseEngine] \| None |
no |
field(default=None, repr=False) |
Optional constructor field; defaults to field(default=None, repr=False). |
_prepare_task |
asyncio.Task[None] \| None |
no |
field(default=None, repr=False) |
Optional constructor field; defaults to field(default=None, repr=False). |
_abandoned_loading_task |
asyncio.Task[BaseEngine] \| None |
no |
field(default=None, repr=False) |
Optional constructor field; defaults to field(default=None, repr=False). |
_loading_task |
asyncio.Task[BaseEngine] \| None |
no |
field(default=None, repr=False) |
Optional constructor field; defaults to field(default=None, repr=False). |
_unloading_task |
asyncio.Task[bool] \| None |
no |
field(default=None, repr=False) |
Optional constructor field; defaults to field(default=None, repr=False). |
Returns
- Constructs:
vllm_mlx.lifecycle.ResidentModel
Exceptions and behavior
Class ResidentModel declares 0 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.lifecycle.ResidencyManager · class
vllm_mlx.lifecycle.ResidencyManager(engine_factory: Callable[[ModelSpec], Awaitable[BaseEngine]], *, on_engine_loaded: Callable[[ModelSpec, BaseEngine], Awaitable[None] | None] | None = None, on_engine_unloading: Callable[[ModelSpec, BaseEngine], Awaitable[None] | None] | None = None, time_fn: Callable[[], float] | None = None, auto_unload_idle_seconds: float = 0)
Single-flight lifecycle manager for resident models.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
engine_factory |
Callable[[ModelSpec], Awaitable[BaseEngine]] |
yes |
none |
Required positional or keyword input. |
on_engine_loaded |
Callable[[ModelSpec, BaseEngine], Awaitable[None] \| None] \| None |
no |
None |
Optional keyword-only input; defaults to None. |
on_engine_unloading |
Callable[[ModelSpec, BaseEngine], Awaitable[None] \| None] \| None |
no |
None |
Optional keyword-only input; defaults to None. |
time_fn |
Callable[[], float] \| None |
no |
None |
Optional keyword-only input; defaults to None. |
auto_unload_idle_seconds |
float |
no |
0 |
Optional keyword-only input; defaults to 0. |
Returns
- Constructs:
vllm_mlx.lifecycle.ResidencyManager
Exceptions and behavior
Class ResidencyManager declares 16 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.lifecycle.ResidencyManager.__init__ · method
vllm_mlx.lifecycle.ResidencyManager.__init__(engine_factory: Callable[[ModelSpec], Awaitable[BaseEngine]], *, on_engine_loaded: Callable[[ModelSpec, BaseEngine], Awaitable[None] | None] | None = None, on_engine_unloading: Callable[[ModelSpec, BaseEngine], Awaitable[None] | None] | None = None, time_fn: Callable[[], float] | None = None, auto_unload_idle_seconds: float = 0) -> None
Method ResidencyManager.__init__ updates self._engine_factory, self._on_engine_loaded, self._on_engine_unloading, self._time_fn; calls __import__, asyncio.Lock.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
engine_factory |
Callable[[ModelSpec], Awaitable[BaseEngine]] |
yes |
none |
Required positional or keyword input. |
on_engine_loaded |
Callable[[ModelSpec, BaseEngine], Awaitable[None] \| None] \| None |
no |
None |
Optional keyword-only input; defaults to None. |
on_engine_unloading |
Callable[[ModelSpec, BaseEngine], Awaitable[None] \| None] \| None |
no |
None |
Optional keyword-only input; defaults to None. |
time_fn |
Callable[[], float] \| None |
no |
None |
Optional keyword-only input; defaults to None. |
auto_unload_idle_seconds |
float |
no |
0 |
Optional keyword-only input; defaults to 0. |
Returns
- Type:
None
Exceptions and behavior
Method ResidencyManager.__init__ updates self._engine_factory, self._on_engine_loaded, self._on_engine_unloading, self._time_fn; calls __import__, asyncio.Lock.
No direct raise statement appears in this definition.
vllm_mlx.lifecycle.ResidencyManager.register_model · method
Register a model spec, or replace a dormant resident entry.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
spec |
ModelSpec |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
str - Direct return expressions:
spec.model_key
Exceptions and behavior
Method ResidencyManager.register_model calls self._residents.get, RuntimeError, ResidentModel; can raise RuntimeError; returns spec.model_key.
Directly raised exceptions: RuntimeError.
vllm_mlx.lifecycle.ResidencyManager.get_engine · method
Get the currently loaded engine, if any.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_key |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
BaseEngine | None - Direct return expressions:
self._resident(model_key).engine
Exceptions and behavior
Method ResidencyManager.get_engine calls self._resident; returns self._resident(model_key).engine.
No direct raise statement appears in this definition.
vllm_mlx.lifecycle.ResidencyManager.get_status · method
Return a serializable snapshot of resident state.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_key |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
dict[str, Any] - Direct return expressions:
{'model_key': resident.spec.model_key, 'model_name': resident.spec.model_name, 'state': resident.state.value, 'active_r…
Exceptions and behavior
Method ResidencyManager.get_status calls self._resident; returns {'model_key': resident.spec.model_key, 'model_name': resident.spec.model_name, 'state': resident.state.value, 'active_r….
No direct raise statement appears in this definition.
vllm_mlx.lifecycle.ResidencyManager.ensure_loaded · method
Load and start a resident engine if needed.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_key |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
BaseEngine - Direct return expressions:
resident.engine;await asyncio.shield(task)
Exceptions and behavior
Method ResidencyManager.ensure_loaded calls self._resident, asyncio.create_task, self._load_engine, asyncio.shield; awaits asynchronous work; can raise RuntimeError; has 2 explicit return paths.
Directly raised exceptions: RuntimeError.
vllm_mlx.lifecycle.ResidencyManager.acquire · method
async vllm_mlx.lifecycle.ResidencyManager.acquire(model_key: str, *, count_activity: bool = True) -> BaseEngine
Acquire a resident engine for request processing.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_key |
str |
yes |
none |
Required positional or keyword input. |
count_activity |
bool |
no |
True |
Optional keyword-only input; defaults to True. |
Returns
- Type:
BaseEngine - Direct return expressions:
engine
Exceptions and behavior
Method ResidencyManager.acquire calls self.ensure_loaded, self._resident, self._time_fn; awaits asynchronous work; returns engine.
No direct raise statement appears in this definition.
vllm_mlx.lifecycle.ResidencyManager.release · method
async vllm_mlx.lifecycle.ResidencyManager.release(model_key: str, *, count_activity: bool = True) -> None
Release a previously acquired resident engine.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_key |
str |
yes |
none |
Required positional or keyword input. |
count_activity |
bool |
no |
True |
Optional keyword-only input; defaults to True. |
Returns
- Type:
None
Exceptions and behavior
Method ResidencyManager.release calls self._resident, self._time_fn.
No direct raise statement appears in this definition.
vllm_mlx.lifecycle.ResidencyManager.unload_if_idle · method
Unload a resident engine if it has been idle past the threshold.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_key |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
False;await asyncio.shield(unloading_task)
Exceptions and behavior
Method ResidencyManager.unload_if_idle calls self._resident, self._time_fn, asyncio.create_task, self._unload_engine; awaits asynchronous work; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.lifecycle.ResidencyManager.shutdown · method
Stop all loaded residents.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method ResidencyManager.shutdown calls list, self._residents.keys, self._resident, resident._loading_task.cancel; awaits asynchronous work; can raise RuntimeError.
Directly raised exceptions: RuntimeError.
vllm_mlx.lifecycle.ResidencyManager._load_engine · method
Create and start a resident engine.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
resident |
ResidentModel |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
BaseEngine - Direct return expressions:
engine
Exceptions and behavior
Method ResidencyManager._load_engine calls self._engine_factory, self._prepare_engine_start, engine.start, self._run_hook; awaits asynchronous work; can raise asyncio.CancelledError; returns engine.
Directly raised exceptions: asyncio.CancelledError.
vllm_mlx.lifecycle.ResidencyManager._unload_engine · method
Stop and drop a resident engine.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
resident |
ResidentModel |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
False;True
Exceptions and behavior
Method ResidencyManager._unload_engine calls self._run_hook, engine.stop, str; awaits asynchronous work; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.lifecycle.ResidencyManager._resident · method
Method ResidencyManager._resident calls KeyError; can raise KeyError; returns self._residents[model_key].
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_key |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
ResidentModel - Direct return expressions:
self._residents[model_key]
Exceptions and behavior
Method ResidencyManager._resident calls KeyError; can raise KeyError; returns self._residents[model_key].
Directly raised exceptions: KeyError.
vllm_mlx.lifecycle.ResidencyManager._run_hook · method
async vllm_mlx.lifecycle.ResidencyManager._run_hook(hook: Callable[[ModelSpec, BaseEngine], Awaitable[None] | None] | None, spec: ModelSpec, engine: BaseEngine) -> None
Method ResidencyManager._run_hook calls hook, inspect.isawaitable; awaits asynchronous work; returns None.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
hook |
Callable[[ModelSpec, BaseEngine], Awaitable[None] \| None] \| None |
yes |
none |
Required positional or keyword input. |
spec |
ModelSpec |
yes |
none |
Required positional or keyword input. |
engine |
BaseEngine |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Method ResidencyManager._run_hook calls hook, inspect.isawaitable; awaits asynchronous work; returns None.
No direct raise statement appears in this definition.
vllm_mlx.lifecycle.ResidencyManager._prepare_engine_start · method
async vllm_mlx.lifecycle.ResidencyManager._prepare_engine_start(resident: ResidentModel, engine: BaseEngine) -> None
Run blocking startup work away from the serving event loop.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
resident |
ResidentModel |
yes |
none |
Required positional or keyword input. |
engine |
BaseEngine |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Method ResidencyManager._prepare_engine_start calls getattr, callable, uses_default_prepare, prepare_for_start; awaits asynchronous work; returns None.
No direct raise statement appears in this definition.
vllm_mlx.lifecycle.ResidencyManager._cleanup_cancelled_load · method
async vllm_mlx.lifecycle.ResidencyManager._cleanup_cancelled_load(resident: ResidentModel, engine: BaseEngine | None) -> None
Stop a partially loaded engine and unwind resident state.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
resident |
ResidentModel |
yes |
none |
Required positional or keyword input. |
engine |
BaseEngine \| None |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Method ResidencyManager._cleanup_cancelled_load calls suspend_cancellation, suppress, engine.stop; awaits asynchronous work.
No direct raise statement appears in this definition.
vllm_mlx.lifecycle.ResidencyManager._release_load_waiter · method
async vllm_mlx.lifecycle.ResidencyManager._release_load_waiter(model_key: str, task: asyncio.Task[BaseEngine]) -> None
Drop one waiter from a shared load, canceling abandoned solo loads.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_key |
str |
yes |
none |
Required positional or keyword input. |
task |
asyncio.Task[BaseEngine] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Method ResidencyManager._release_load_waiter calls self._resident, task.done, suspend_cancellation, task_to_cancel.cancel; awaits asynchronous work; returns None.
No direct raise statement appears in this definition.
Complete symbol map¶
This map also includes private definitions and nested helpers. The signature column exposes every explicit input even when an internal helper has no dedicated parameter prose.
| Symbol | Kind | Signature and inputs | What it does | Source |
|---|---|---|---|---|
ResidentState |
class | ResidentState() |
Runtime residency state for a configured model. | #L17-L24 |
ModelSpec |
class | ModelSpec(model_key: str, model_name: str, use_batching: bool = False, scheduler_config: Any \| None = None, stream_interval: int = 1, max_tokens: int = 32768, force_mllm: bool = False, mtp: bool = False, prefill_step_size: int = 2048, specprefill_enabled: bool = False, specprefill_threshold: int = 8192, specprefill_keep_pct: float = 0.3, specprefill_backbone_pct: float = 0.0, specprefill_draft_model: str \| None = None) |
Immutable engine construction inputs for a resident model. | #L28-L44 |
ResidentModel |
class | ResidentModel(spec: ModelSpec, state: ResidentState = ResidentState.UNLOADED, engine: BaseEngine \| None = None, active_requests: int = 0, last_used_at: float \| None = None, loaded_at: float \| None = None, last_error: str \| None = None, estimated_memory_bytes: int \| None = None, _load_waiters: int = field(default=0, repr=False), _load_waiter_task: asyncio.Task[BaseEngine] \| None = field(default=None, repr=False), _prepare_task: asyncio.Task[None] \| None = field(default=None, repr=False), _abandoned_loading_task: asyncio.Task[BaseEngine] \| None = field(default=None, repr=False), _loading_task: asyncio.Task[BaseEngine] \| None = field(default=None, repr=False), _unloading_task: asyncio.Task[bool] \| None = field(default=None, repr=False)) |
Runtime state for a single resident model. | #L48-L66 |
ResidencyManager |
class | ResidencyManager(engine_factory: Callable[[ModelSpec], Awaitable[BaseEngine]], *, on_engine_loaded: Callable[[ModelSpec, BaseEngine], Awaitable[None] \| None] \| None = None, on_engine_unloading: Callable[[ModelSpec, BaseEngine], Awaitable[None] \| None] \| None = None, time_fn: Callable[[], float] \| None = None, auto_unload_idle_seconds: float = 0) |
Single-flight lifecycle manager for resident models. | #L69-L493 |
ResidencyManager.__init__ |
method | ResidencyManager.__init__(engine_factory: Callable[[ModelSpec], Awaitable[BaseEngine]], *, on_engine_loaded: Callable[[ModelSpec, BaseEngine], Awaitable[None] \| None] \| None = None, on_engine_unloading: Callable[[ModelSpec, BaseEngine], Awaitable[None] \| None] \| None = None, time_fn: Callable[[], float] \| None = None, auto_unload_idle_seconds: float = 0) -> None |
Method ResidencyManager.__init__ updates self._engine_factory, self._on_engine_loaded, self._on_engine_unloading, self._time_fn; calls __import__, asyncio.Lock. |
#L72-L91 |
ResidencyManager.register_model |
method | ResidencyManager.register_model(spec: ModelSpec) -> str |
Register a model spec, or replace a dormant resident entry. | #L93-L111 |
ResidencyManager.get_engine |
method | ResidencyManager.get_engine(model_key: str) -> BaseEngine \| None |
Get the currently loaded engine, if any. | #L113-L115 |
ResidencyManager.get_status |
method | ResidencyManager.get_status(model_key: str) -> dict[str, Any] |
Return a serializable snapshot of resident state. | #L117-L130 |
ResidencyManager.ensure_loaded |
method | async ResidencyManager.ensure_loaded(model_key: str) -> BaseEngine |
Load and start a resident engine if needed. | #L132-L184 |
ResidencyManager.acquire |
method | async ResidencyManager.acquire(model_key: str, *, count_activity: bool = True) -> BaseEngine |
Acquire a resident engine for request processing. | #L186-L206 |
ResidencyManager.release |
method | async ResidencyManager.release(model_key: str, *, count_activity: bool = True) -> None |
Release a previously acquired resident engine. | #L208-L215 |
ResidencyManager.unload_if_idle |
method | async ResidencyManager.unload_if_idle(model_key: str) -> bool |
Unload a resident engine if it has been idle past the threshold. | #L217-L253 |
ResidencyManager.shutdown |
method | async ResidencyManager.shutdown() -> None |
Stop all loaded residents. | #L255-L312 |
ResidencyManager._load_engine |
method | async ResidencyManager._load_engine(resident: ResidentModel) -> BaseEngine |
Create and start a resident engine. | #L314-L354 |
ResidencyManager._unload_engine |
method | async ResidencyManager._unload_engine(resident: ResidentModel) -> bool |
Stop and drop a resident engine. | #L356-L388 |
ResidencyManager._resident |
method | ResidencyManager._resident(model_key: str) -> ResidentModel |
Method ResidencyManager._resident calls KeyError; can raise KeyError; returns self._residents[model_key]. |
#L390-L394 |
ResidencyManager._run_hook |
method | async ResidencyManager._run_hook(hook: Callable[[ModelSpec, BaseEngine], Awaitable[None] \| None] \| None, spec: ModelSpec, engine: BaseEngine) -> None |
Method ResidencyManager._run_hook calls hook, inspect.isawaitable; awaits asynchronous work; returns None. |
#L396-L407 |
ResidencyManager._prepare_engine_start |
method | async ResidencyManager._prepare_engine_start(resident: ResidentModel, engine: BaseEngine) -> None |
Run blocking startup work away from the serving event loop. | #L409-L445 |
ResidencyManager._cleanup_cancelled_load |
method | async ResidencyManager._cleanup_cancelled_load(resident: ResidentModel, engine: BaseEngine \| None) -> None |
Stop a partially loaded engine and unwind resident state. | #L447-L465 |
ResidencyManager._release_load_waiter |
method | async ResidencyManager._release_load_waiter(model_key: str, task: asyncio.Task[BaseEngine]) -> None |
Drop one waiter from a shared load, canceling abandoned solo loads. | #L467-L493 |