vllm_mlx.engine_core¶
Engine Core for vllm-mlx continuous batching.
View the complete module source at #L1-L794.
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.engine_core
¶
Engine Core for vllm-mlx continuous batching.
This module provides the EngineCore class that coordinates: - Model loading and management - Request scheduling via Scheduler - Async request processing - Output streaming
The design follows vLLM's engine architecture adapted for MLX.
vllm_mlx.engine_core.EngineConfig
dataclass
¶
EngineConfig(model_name: str = '', scheduler_config: Optional[SchedulerConfig] = None, step_interval: float = 0.001, stream_interval: int = 1, gpu_memory_utilization: float = 0.9)
Configuration for the engine.
vllm_mlx.engine_core.EngineConfig.model_name
class-attribute
instance-attribute
¶
vllm_mlx.engine_core.EngineConfig.scheduler_config
class-attribute
instance-attribute
¶
scheduler_config: Optional[SchedulerConfig] = None
vllm_mlx.engine_core.EngineConfig.step_interval
class-attribute
instance-attribute
¶
vllm_mlx.engine_core.EngineConfig.stream_interval
class-attribute
instance-attribute
¶
vllm_mlx.engine_core.EngineConfig.gpu_memory_utilization
class-attribute
instance-attribute
¶
vllm_mlx.engine_core.EngineCore
¶
EngineCore(model: Any, tokenizer: Any, config: Optional[EngineConfig] = None, engine_id: Optional[str] = None, force_model_ownership: bool = True)
Core engine for vllm-mlx inference with continuous batching.
This engine runs the generation loop and manages request lifecycle. It provides both sync and async interfaces for request handling.
Initialize the engine.
Parameters:
-
model(Any) –The MLX model
-
tokenizer(Any) –The tokenizer
-
config(Optional[EngineConfig], default:None) –Engine configuration
-
engine_id(Optional[str], default:None) –Optional unique ID for this engine (auto-generated if None)
-
force_model_ownership(bool, default:True) –If True (default), forcibly take model ownership from any existing engine. If False, raises ModelOwnershipError if model is in use.
Source code in vllm_mlx/engine_core.py
vllm_mlx.engine_core.EngineCore._engine_id
instance-attribute
¶
vllm_mlx.engine_core.EngineCore.scheduler
instance-attribute
¶
scheduler = Scheduler(model=model, tokenizer=tokenizer, config=scheduler_config)
vllm_mlx.engine_core.EngineCore._output_collectors
instance-attribute
¶
_output_collectors: Dict[str, RequestOutputCollector] = {}
vllm_mlx.engine_core.EngineCore._stream_states
instance-attribute
¶
_stream_states: Dict[str, RequestStreamState] = {}
vllm_mlx.engine_core.EngineCore._finished_events
instance-attribute
¶
vllm_mlx.engine_core.EngineCore._start_time
instance-attribute
¶
vllm_mlx.engine_core.EngineCore.start
async
¶
Start the engine loop.
vllm_mlx.engine_core.EngineCore.stop
async
¶
Stop the engine loop.
Source code in vllm_mlx/engine_core.py
vllm_mlx.engine_core.EngineCore.is_running
¶
vllm_mlx.engine_core.EngineCore._engine_loop
async
¶
Main engine loop.
scheduler.step runs on one dedicated worker thread. MLX streams are thread-local, so we rebind generation streams inside that worker.
Source code in vllm_mlx/engine_core.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
vllm_mlx.engine_core.EngineCore.add_request
async
¶
add_request(prompt: Union[str, List[int]], sampling_params: Optional[SamplingParams] = None, request_id: Optional[str] = None, images: Optional[List[Any]] = None, videos: Optional[List[Any]] = None, prefix_boundary: int = 0) -> str
Add a request for processing.
Parameters:
-
prompt(Union[str, List[int]]) –Input prompt (string or token IDs)
-
sampling_params(Optional[SamplingParams], default:None) –Generation parameters
-
request_id(Optional[str], default:None) –Optional custom request ID
-
images(Optional[List[Any]], default:None) –Optional images for multimodal
-
videos(Optional[List[Any]], default:None) –Optional videos for multimodal
-
prefix_boundary(int, default:0) –Token count for shared prefix (for cache)
Returns:
-
str–The request ID
Source code in vllm_mlx/engine_core.py
vllm_mlx.engine_core.EngineCore.abort_request
async
¶
vllm_mlx.engine_core.EngineCore._cleanup_request
¶
Clean up request tracking.
Source code in vllm_mlx/engine_core.py
vllm_mlx.engine_core.EngineCore.stream_outputs
async
¶
stream_outputs(request_id: str, timeout: Optional[float] = None) -> AsyncIterator[RequestOutput]
Stream outputs for a request with low-latency non-blocking pattern.
Uses the vLLM pattern: get_nowait() or await get() This avoids unnecessary task switches when output is available.
Parameters:
-
request_id(str) –The request ID
-
timeout(Optional[float], default:None) –Optional timeout in seconds
Yields:
-
AsyncIterator[RequestOutput]–RequestOutput objects as tokens are generated
Source code in vllm_mlx/engine_core.py
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | |
vllm_mlx.engine_core.EngineCore.generate
async
¶
generate(prompt: Union[str, List[int]], sampling_params: Optional[SamplingParams] = None, request_id: Optional[str] = None, **kwargs) -> RequestOutput
Generate a complete response (non-streaming).
This method is optimized to avoid streaming overhead when you only need the final result.
Parameters:
-
prompt(Union[str, List[int]]) –Input prompt
-
sampling_params(Optional[SamplingParams], default:None) –Generation parameters
-
request_id(Optional[str], default:None) –Optional request ID
Returns:
-
RequestOutput–Final RequestOutput with complete text
Source code in vllm_mlx/engine_core.py
vllm_mlx.engine_core.EngineCore.generate_batch_sync
¶
generate_batch_sync(prompts: List[Union[str, List[int]]], sampling_params: Optional[SamplingParams] = None) -> List[RequestOutput]
Generate responses synchronously for maximum throughput.
This bypasses the async engine loop entirely, running the scheduler directly for optimal batching performance. Use this when you don't need streaming and want maximum throughput.
Parameters:
-
prompts(List[Union[str, List[int]]]) –List of input prompts
-
sampling_params(Optional[SamplingParams], default:None) –Generation parameters (same for all)
Returns:
-
List[RequestOutput]–List of RequestOutput in same order as prompts
Source code in vllm_mlx/engine_core.py
vllm_mlx.engine_core.EngineCore.get_stats
¶
Get engine statistics.
Source code in vllm_mlx/engine_core.py
vllm_mlx.engine_core.EngineCore.get_cache_stats
¶
vllm_mlx.engine_core.EngineCore.save_cache_to_disk
¶
vllm_mlx.engine_core.EngineCore.load_cache_from_disk
¶
vllm_mlx.engine_core.EngineCore.clear_runtime_caches
¶
vllm_mlx.engine_core.EngineCore.clear_prefix_cache
¶
vllm_mlx.engine_core.EngineCore._release_model
¶
Release model ownership.
Source code in vllm_mlx/engine_core.py
vllm_mlx.engine_core.EngineCore.close
¶
Explicitly close the engine and release resources.
This should be called when done using the engine, especially if you plan to create another engine with the same model.
Source code in vllm_mlx/engine_core.py
vllm_mlx.engine_core.AsyncEngineCore
¶
AsyncEngineCore(model: Any, tokenizer: Any, config: Optional[EngineConfig] = None)
Async context manager wrapper for EngineCore.
Usage
async with AsyncEngineCore(model, tokenizer) as engine: request_id = await engine.add_request("Hello") async for output in engine.stream_outputs(request_id): print(output.new_text)
Source code in vllm_mlx/engine_core.py
vllm_mlx.engine_core.AsyncEngineCore.engine
instance-attribute
¶
engine = EngineCore(model, tokenizer, config)
vllm_mlx.engine_core.AsyncEngineCore.__aenter__
async
¶
__aenter__() -> AsyncEngineCore
vllm_mlx.engine_core.AsyncEngineCore.__aexit__
async
¶
vllm_mlx.engine_core.AsyncEngineCore.start
¶
vllm_mlx.engine_core.AsyncEngineCore.stop
async
¶
vllm_mlx.engine_core.AsyncEngineCore.add_request
async
¶
add_request(prompt: Union[str, List[int]], sampling_params: Optional[SamplingParams] = None, request_id: Optional[str] = None, **kwargs) -> str
Add a request.
Source code in vllm_mlx/engine_core.py
vllm_mlx.engine_core.AsyncEngineCore.abort_request
async
¶
vllm_mlx.engine_core.AsyncEngineCore.stream_outputs
async
¶
stream_outputs(request_id: str, timeout: Optional[float] = None) -> AsyncIterator[RequestOutput]
Stream outputs.
vllm_mlx.engine_core.AsyncEngineCore.generate
async
¶
generate(prompt: Union[str, List[int]], sampling_params: Optional[SamplingParams] = None, **kwargs) -> RequestOutput
Generate complete response.
Source code in vllm_mlx/engine_core.py
vllm_mlx.engine_core.AsyncEngineCore.get_stats
¶
vllm_mlx.engine_core.AsyncEngineCore.get_cache_stats
¶
vllm_mlx.engine_core.AsyncEngineCore.save_cache_to_disk
¶
vllm_mlx.engine_core.AsyncEngineCore.load_cache_from_disk
¶
vllm_mlx.engine_core.AsyncEngineCore.clear_runtime_caches
¶
vllm_mlx.engine_core._is_stream_thread_error
¶
True when MLX reports stream ownership mismatch across threads.
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.engine_core._is_stream_thread_error · function
True when MLX reports stream ownership mismatch across threads.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
error |
Exception |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
'no Stream(' in message or 'no Stream(gpu' in message
Exceptions and behavior
Function _is_stream_thread_error calls str; returns 'no Stream(' in message or 'no Stream(gpu' in message.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineConfig · class
vllm_mlx.engine_core.EngineConfig(model_name: str = '', scheduler_config: Optional[SchedulerConfig] = None, step_interval: float = 0.001, stream_interval: int = 1, gpu_memory_utilization: float = 0.9)
Configuration for the engine.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_name |
str |
no |
'' |
Optional constructor field; defaults to ''. |
scheduler_config |
Optional[SchedulerConfig] |
no |
None |
Optional constructor field; defaults to None. |
step_interval |
float |
no |
0.001 |
Optional constructor field; defaults to 0.001. |
stream_interval |
int |
no |
1 |
Optional constructor field; defaults to 1. |
gpu_memory_utilization |
float |
no |
0.9 |
Optional constructor field; defaults to 0.9. |
Returns
- Constructs:
vllm_mlx.engine_core.EngineConfig
Exceptions and behavior
Class EngineConfig declares 0 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore · class
vllm_mlx.engine_core.EngineCore(model: Any, tokenizer: Any, config: Optional[EngineConfig] = None, engine_id: Optional[str] = None, force_model_ownership: bool = True)
Core engine for vllm-mlx inference with continuous batching.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model |
Any |
yes |
none |
The MLX model |
tokenizer |
Any |
yes |
none |
The tokenizer |
config |
Optional[EngineConfig] |
no |
None |
Engine configuration |
engine_id |
Optional[str] |
no |
None |
Optional unique ID for this engine (auto-generated if None) |
force_model_ownership |
bool |
no |
True |
If True (default), forcibly take model ownership from any existing engine. If False, raises ModelOwnershipError if model is in use. |
Returns
- Constructs:
vllm_mlx.engine_core.EngineCore
Exceptions and behavior
Class EngineCore declares 21 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore.__init__ · method
vllm_mlx.engine_core.EngineCore.__init__(model: Any, tokenizer: Any, config: Optional[EngineConfig] = None, engine_id: Optional[str] = None, force_model_ownership: bool = True) -> not annotated
Initialize the engine.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model |
Any |
yes |
none |
The MLX model |
tokenizer |
Any |
yes |
none |
The tokenizer |
config |
Optional[EngineConfig] |
no |
None |
Engine configuration |
engine_id |
Optional[str] |
no |
None |
Optional unique ID for this engine (auto-generated if None) |
force_model_ownership |
bool |
no |
True |
If True (default), forcibly take model ownership from any existing engine. If False, raises ModelOwnershipError if model is in use. |
Returns
- Type:
not annotated
Exceptions and behavior
Method EngineCore.__init__ updates self.model, self.tokenizer, self.config, self._engine_id; calls EngineConfig, str, uuid.uuid4, get_registry.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore.start · method
Start the engine loop.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Method EngineCore.start updates self._running, self._start_time, self._task; calls time.time, asyncio.create_task, self._engine_loop, logger.info; returns None.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore.stop · method
Stop the engine loop.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method EngineCore.stop updates self._running, self._task; calls self._task.cancel, self.scheduler._close_batch_generator, logger.info; awaits asynchronous work.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore.is_running · method
Check if engine is running.
Parameters
This callable has no explicit inputs.
Returns
- Type:
bool - Direct return expressions:
self._running
Exceptions and behavior
Method EngineCore.is_running returns self._running.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore._engine_loop · method
Main engine loop.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method EngineCore._engine_loop calls asyncio.get_running_loop, ThreadPoolExecutor, mx.device_info().get, mx.device_info; awaits asynchronous work.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore._engine_loop._bind_worker_streams_once · nested function
Nested Function EngineCore._engine_loop._bind_worker_streams_once calls bind_generation_streams.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Nested Function EngineCore._engine_loop._bind_worker_streams_once calls bind_generation_streams.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore._engine_loop._bind_model_streams_once · nested function
Nested Function EngineCore._engine_loop._bind_model_streams_once calls bind_generation_streams.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Nested Function EngineCore._engine_loop._bind_model_streams_once calls bind_generation_streams.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore._engine_loop._step_on_worker · nested function
Nested Function EngineCore._engine_loop._step_on_worker updates self._steps_executed; calls _bind_worker_streams_once, self.scheduler.step, mx.get_active_memory, mx.clear_cache; returns output.
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated - Direct return expressions:
output
Exceptions and behavior
Nested Function EngineCore._engine_loop._step_on_worker updates self._steps_executed; calls _bind_worker_streams_once, self.scheduler.step, mx.get_active_memory, mx.clear_cache; returns output.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore._engine_loop._step_on_model_thread · nested function
Nested Function EngineCore._engine_loop._step_on_model_thread updates self._steps_executed; calls _bind_model_streams_once, self.scheduler.step, mx.get_active_memory, mx.clear_cache; returns output.
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated - Direct return expressions:
output
Exceptions and behavior
Nested Function EngineCore._engine_loop._step_on_model_thread updates self._steps_executed; calls _bind_model_streams_once, self.scheduler.step, mx.get_active_memory, mx.clear_cache; returns output.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore._engine_loop._recover_stream_thread_error_on_worker · nested function
Nested Function EngineCore._engine_loop._recover_stream_thread_error_on_worker calls _bind_worker_streams_once, self.scheduler._recover_from_cache_error, self.scheduler._reschedule_running_requests.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Nested Function EngineCore._engine_loop._recover_stream_thread_error_on_worker calls _bind_worker_streams_once, self.scheduler._recover_from_cache_error, self.scheduler._reschedule_running_requests.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore._engine_loop._clear_cache_on_worker · nested function
Nested Function EngineCore._engine_loop._clear_cache_on_worker calls _bind_worker_streams_once, mx.clear_cache.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Nested Function EngineCore._engine_loop._clear_cache_on_worker calls _bind_worker_streams_once, mx.clear_cache.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore._engine_loop._close_batch_generator_on_worker · nested function
Nested Function EngineCore._engine_loop._close_batch_generator_on_worker calls _bind_worker_streams_once, self.scheduler._close_batch_generator.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Nested Function EngineCore._engine_loop._close_batch_generator_on_worker calls _bind_worker_streams_once, self.scheduler._close_batch_generator.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore.add_request · method
async vllm_mlx.engine_core.EngineCore.add_request(prompt: Union[str, List[int]], sampling_params: Optional[SamplingParams] = None, request_id: Optional[str] = None, images: Optional[List[Any]] = None, videos: Optional[List[Any]] = None, prefix_boundary: int = 0) -> str
Add a request for processing.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
prompt |
Union[str, List[int]] |
yes |
none |
Input prompt (string or token IDs) |
sampling_params |
Optional[SamplingParams] |
no |
None |
Generation parameters |
request_id |
Optional[str] |
no |
None |
Optional custom request ID |
images |
Optional[List[Any]] |
no |
None |
Optional images for multimodal |
videos |
Optional[List[Any]] |
no |
None |
Optional videos for multimodal |
prefix_boundary |
int |
no |
0 |
Token count for shared prefix (for cache) |
Returns
- Type:
str - Direct return expressions:
request_id
Exceptions and behavior
Method EngineCore.add_request calls str, uuid.uuid4, SamplingParams, Request; returns request_id.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore.abort_request · method
Abort a request.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
request_id |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
result
Exceptions and behavior
Method EngineCore.abort_request calls self.scheduler.abort_request, self._cleanup_request; returns result.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore._cleanup_request · method
Clean up request tracking.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
request_id |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Method EngineCore._cleanup_request calls self._output_collectors.pop, collector.clear, self._stream_states.pop, self._finished_events.pop.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore.stream_outputs · method
async vllm_mlx.engine_core.EngineCore.stream_outputs(request_id: str, timeout: Optional[float] = None) -> AsyncIterator[RequestOutput]
Stream outputs for a request with low-latency non-blocking pattern.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
request_id |
str |
yes |
none |
The request ID |
timeout |
Optional[float] |
no |
None |
Optional timeout in seconds |
Returns
- Type:
AsyncIterator[RequestOutput] - Direct return expressions:
None - Yields values incrementally.
Exceptions and behavior
Method EngineCore.stream_outputs calls _time.monotonic, self._output_collectors.get, logger.warning, logger.info; awaits asynchronous work; yields values incrementally; returns None.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore.generate · method
async vllm_mlx.engine_core.EngineCore.generate(prompt: Union[str, List[int]], sampling_params: Optional[SamplingParams] = None, request_id: Optional[str] = None, **kwargs) -> RequestOutput
Generate a complete response (non-streaming).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
prompt |
Union[str, List[int]] |
yes |
none |
Input prompt |
sampling_params |
Optional[SamplingParams] |
no |
None |
Generation parameters |
request_id |
Optional[str] |
no |
None |
Optional request ID |
**kwargs |
not annotated |
no |
none |
Additional variadic keyword inputs accepted by this callable. |
Returns
- Type:
RequestOutput - Direct return expressions:
final_output
Exceptions and behavior
Method EngineCore.generate calls self.add_request, self._finished_events.get, RuntimeError, event.wait; awaits asynchronous work; can raise RuntimeError; returns final_output.
Directly raised exceptions: RuntimeError.
vllm_mlx.engine_core.EngineCore.generate_batch_sync · method
vllm_mlx.engine_core.EngineCore.generate_batch_sync(prompts: List[Union[str, List[int]]], sampling_params: Optional[SamplingParams] = None) -> List[RequestOutput]
Generate responses synchronously for maximum throughput.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
prompts |
List[Union[str, List[int]]] |
yes |
none |
List of input prompts |
sampling_params |
Optional[SamplingParams] |
no |
None |
Generation parameters (same for all) |
Returns
- Type:
List[RequestOutput] - Direct return expressions:
[results[rid] for rid in request_ids]
Exceptions and behavior
Method EngineCore.generate_batch_sync calls SamplingParams, str, uuid_module.uuid4, Request; returns [results[rid] for rid in request_ids].
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore.get_stats · method
Get engine statistics.
Parameters
This callable has no explicit inputs.
Returns
- Type:
Dict[str, Any] - Direct return expressions:
{'running': self._running, 'uptime_seconds': uptime, 'steps_executed': self._steps_executed, 'active_requests': len(sel…
Exceptions and behavior
Method EngineCore.get_stats calls self.scheduler.get_stats, time.time, len, self.scheduler.get_running_requests_info; returns {'running': self._running, 'uptime_seconds': uptime, 'steps_executed': self._steps_executed, 'active_requests': len(sel….
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore.get_cache_stats · method
Get prefix cache statistics.
Parameters
This callable has no explicit inputs.
Returns
- Type:
Optional[Dict[str, Any]] - Direct return expressions:
self.scheduler.get_cache_stats()
Exceptions and behavior
Method EngineCore.get_cache_stats calls self.scheduler.get_cache_stats; returns self.scheduler.get_cache_stats().
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore.save_cache_to_disk · method
Save prefix cache to disk.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
cache_dir |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
self.scheduler.save_cache_to_disk(cache_dir)
Exceptions and behavior
Method EngineCore.save_cache_to_disk calls self.scheduler.save_cache_to_disk; returns self.scheduler.save_cache_to_disk(cache_dir).
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore.load_cache_from_disk · method
Load prefix cache from disk.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
cache_dir |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
int - Direct return expressions:
self.scheduler.load_cache_from_disk(cache_dir)
Exceptions and behavior
Method EngineCore.load_cache_from_disk calls self.scheduler.load_cache_from_disk; returns self.scheduler.load_cache_from_disk(cache_dir).
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore.clear_runtime_caches · method
Clear scheduler-managed runtime caches.
Parameters
This callable has no explicit inputs.
Returns
- Type:
Dict[str, Any] | None - Direct return expressions:
self.scheduler.clear_runtime_caches()
Exceptions and behavior
Method EngineCore.clear_runtime_caches calls self.scheduler.clear_runtime_caches; returns self.scheduler.clear_runtime_caches().
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore.clear_prefix_cache · method
Clear the prefix cache (delegates to scheduler).
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method EngineCore.clear_prefix_cache calls hasattr, self.scheduler.clear_prefix_cache.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore._release_model · method
Release model ownership.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method EngineCore._release_model updates self._owns_model; calls get_registry, registry.release, logger.debug.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore.close · method
Explicitly close the engine and release resources.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Method EngineCore.close updates self._owns_model, self._closed; calls get_registry, registry.release, logger.debug, self.scheduler.deep_reset; returns None.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore.__del__ · method
Cleanup on destruction.
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated
Exceptions and behavior
Method EngineCore.__del__ calls self._release_model.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.EngineCore.engine_id · method
Get the engine ID.
Parameters
This callable has no explicit inputs.
Returns
- Type:
str - Direct return expressions:
self._engine_id
Exceptions and behavior
Method EngineCore.engine_id returns self._engine_id.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.AsyncEngineCore · class
vllm_mlx.engine_core.AsyncEngineCore(model: Any, tokenizer: Any, config: Optional[EngineConfig] = None)
Async context manager wrapper for EngineCore.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model |
Any |
yes |
none |
Required positional or keyword input. |
tokenizer |
Any |
yes |
none |
Required positional or keyword input. |
config |
Optional[EngineConfig] |
no |
None |
Optional positional or keyword input; defaults to None. |
Returns
- Constructs:
vllm_mlx.engine_core.AsyncEngineCore
Exceptions and behavior
Class AsyncEngineCore declares 14 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.engine_core.AsyncEngineCore.__init__ · method
vllm_mlx.engine_core.AsyncEngineCore.__init__(model: Any, tokenizer: Any, config: Optional[EngineConfig] = None) -> not annotated
Method AsyncEngineCore.__init__ updates self.engine; calls EngineCore.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model |
Any |
yes |
none |
Required positional or keyword input. |
tokenizer |
Any |
yes |
none |
Required positional or keyword input. |
config |
Optional[EngineConfig] |
no |
None |
Optional positional or keyword input; defaults to None. |
Returns
- Type:
not annotated
Exceptions and behavior
Method AsyncEngineCore.__init__ updates self.engine; calls EngineCore.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.AsyncEngineCore.__aenter__ · method
Method AsyncEngineCore.__aenter__ calls self.engine.start; awaits asynchronous work; returns self.
Parameters
This callable has no explicit inputs.
Returns
- Type:
'AsyncEngineCore' - Direct return expressions:
self
Exceptions and behavior
Method AsyncEngineCore.__aenter__ calls self.engine.start; awaits asynchronous work; returns self.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.AsyncEngineCore.__aexit__ · method
Method AsyncEngineCore.__aexit__ calls self.engine.stop; awaits asynchronous work.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
*args |
not annotated |
no |
none |
Additional variadic positional inputs accepted by this callable. |
Returns
- Type:
None
Exceptions and behavior
Method AsyncEngineCore.__aexit__ calls self.engine.stop; awaits asynchronous work.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.AsyncEngineCore.start · method
Start engine (creates task in current loop).
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method AsyncEngineCore.start updates self._start_task; calls asyncio.create_task, self.engine.start.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.AsyncEngineCore.stop · method
Stop the engine.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method AsyncEngineCore.stop calls self.engine.stop; awaits asynchronous work.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.AsyncEngineCore.add_request · method
async vllm_mlx.engine_core.AsyncEngineCore.add_request(prompt: Union[str, List[int]], sampling_params: Optional[SamplingParams] = None, request_id: Optional[str] = None, **kwargs) -> str
Add a request.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
prompt |
Union[str, List[int]] |
yes |
none |
Required positional or keyword input. |
sampling_params |
Optional[SamplingParams] |
no |
None |
Optional positional or keyword input; defaults to None. |
request_id |
Optional[str] |
no |
None |
Optional positional or keyword input; defaults to None. |
**kwargs |
not annotated |
no |
none |
Additional variadic keyword inputs accepted by this callable. |
Returns
- Type:
str - Direct return expressions:
await self.engine.add_request(prompt=prompt, sampling_params=sampling_params, request_id=request_id, **kwargs)
Exceptions and behavior
Method AsyncEngineCore.add_request calls self.engine.add_request; awaits asynchronous work; returns await self.engine.add_request(prompt=prompt, sampling_params=sampling_params, request_id=request_id, **kwargs).
No direct raise statement appears in this definition.
vllm_mlx.engine_core.AsyncEngineCore.abort_request · method
Abort a request.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
request_id |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
await self.engine.abort_request(request_id)
Exceptions and behavior
Method AsyncEngineCore.abort_request calls self.engine.abort_request; awaits asynchronous work; returns await self.engine.abort_request(request_id).
No direct raise statement appears in this definition.
vllm_mlx.engine_core.AsyncEngineCore.stream_outputs · method
async vllm_mlx.engine_core.AsyncEngineCore.stream_outputs(request_id: str, timeout: Optional[float] = None) -> AsyncIterator[RequestOutput]
Stream outputs.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
request_id |
str |
yes |
none |
Required positional or keyword input. |
timeout |
Optional[float] |
no |
None |
Optional positional or keyword input; defaults to None. |
Returns
- Type:
AsyncIterator[RequestOutput] - Yields values incrementally.
Exceptions and behavior
Method AsyncEngineCore.stream_outputs calls self.engine.stream_outputs; yields values incrementally.
No direct raise statement appears in this definition.
vllm_mlx.engine_core.AsyncEngineCore.generate · method
async vllm_mlx.engine_core.AsyncEngineCore.generate(prompt: Union[str, List[int]], sampling_params: Optional[SamplingParams] = None, **kwargs) -> RequestOutput
Generate complete response.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
prompt |
Union[str, List[int]] |
yes |
none |
Required positional or keyword input. |
sampling_params |
Optional[SamplingParams] |
no |
None |
Optional positional or keyword input; defaults to None. |
**kwargs |
not annotated |
no |
none |
Additional variadic keyword inputs accepted by this callable. |
Returns
- Type:
RequestOutput - Direct return expressions:
await self.engine.generate(prompt=prompt, sampling_params=sampling_params, **kwargs)
Exceptions and behavior
Method AsyncEngineCore.generate calls self.engine.generate; awaits asynchronous work; returns await self.engine.generate(prompt=prompt, sampling_params=sampling_params, **kwargs).
No direct raise statement appears in this definition.
vllm_mlx.engine_core.AsyncEngineCore.get_stats · method
Get engine stats.
Parameters
This callable has no explicit inputs.
Returns
- Type:
Dict[str, Any] - Direct return expressions:
self.engine.get_stats()
Exceptions and behavior
Method AsyncEngineCore.get_stats calls self.engine.get_stats; returns self.engine.get_stats().
No direct raise statement appears in this definition.
vllm_mlx.engine_core.AsyncEngineCore.get_cache_stats · method
Get prefix cache statistics.
Parameters
This callable has no explicit inputs.
Returns
- Type:
Optional[Dict[str, Any]] - Direct return expressions:
self.engine.get_cache_stats()
Exceptions and behavior
Method AsyncEngineCore.get_cache_stats calls self.engine.get_cache_stats; returns self.engine.get_cache_stats().
No direct raise statement appears in this definition.
vllm_mlx.engine_core.AsyncEngineCore.save_cache_to_disk · method
Save prefix cache to disk.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
cache_dir |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
self.engine.save_cache_to_disk(cache_dir)
Exceptions and behavior
Method AsyncEngineCore.save_cache_to_disk calls self.engine.save_cache_to_disk; returns self.engine.save_cache_to_disk(cache_dir).
No direct raise statement appears in this definition.
vllm_mlx.engine_core.AsyncEngineCore.load_cache_from_disk · method
Load prefix cache from disk.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
cache_dir |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
int - Direct return expressions:
self.engine.load_cache_from_disk(cache_dir)
Exceptions and behavior
Method AsyncEngineCore.load_cache_from_disk calls self.engine.load_cache_from_disk; returns self.engine.load_cache_from_disk(cache_dir).
No direct raise statement appears in this definition.
vllm_mlx.engine_core.AsyncEngineCore.clear_runtime_caches · method
Clear scheduler-managed runtime caches.
Parameters
This callable has no explicit inputs.
Returns
- Type:
Dict[str, Any] | None - Direct return expressions:
self.engine.clear_runtime_caches()
Exceptions and behavior
Method AsyncEngineCore.clear_runtime_caches calls self.engine.clear_runtime_caches; returns self.engine.clear_runtime_caches().
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 |
|---|---|---|---|---|
_is_stream_thread_error |
function | _is_stream_thread_error(error: Exception) -> bool |
True when MLX reports stream ownership mismatch across threads. | #L33-L36 |
EngineConfig |
class | EngineConfig(model_name: str = '', scheduler_config: Optional[SchedulerConfig] = None, step_interval: float = 0.001, stream_interval: int = 1, gpu_memory_utilization: float = 0.9) |
Configuration for the engine. | #L40-L47 |
EngineCore |
class | EngineCore(model: Any, tokenizer: Any, config: Optional[EngineConfig] = None, engine_id: Optional[str] = None, force_model_ownership: bool = True) |
Core engine for vllm-mlx inference with continuous batching. | #L50-L698 |
EngineCore.__init__ |
method | EngineCore.__init__(model: Any, tokenizer: Any, config: Optional[EngineConfig] = None, engine_id: Optional[str] = None, force_model_ownership: bool = True) -> not annotated |
Initialize the engine. | #L58-L114 |
EngineCore.start |
method | async EngineCore.start() -> None |
Start the engine loop. | #L116-L124 |
EngineCore.stop |
method | async EngineCore.stop() -> None |
Stop the engine loop. | #L126-L140 |
EngineCore.is_running |
method | EngineCore.is_running() -> bool |
Check if engine is running. | #L142-L144 |
EngineCore._engine_loop |
method | async EngineCore._engine_loop() -> None |
Main engine loop. | #L146-L334 |
EngineCore._engine_loop._bind_worker_streams_once |
nested function | EngineCore._engine_loop._bind_worker_streams_once() -> None |
Nested Function EngineCore._engine_loop._bind_worker_streams_once calls bind_generation_streams. |
#L160-L164 |
EngineCore._engine_loop._bind_model_streams_once |
nested function | EngineCore._engine_loop._bind_model_streams_once() -> None |
Nested Function EngineCore._engine_loop._bind_model_streams_once calls bind_generation_streams. |
#L166-L170 |
EngineCore._engine_loop._step_on_worker |
nested function | EngineCore._engine_loop._step_on_worker() -> not annotated |
Nested Function EngineCore._engine_loop._step_on_worker updates self._steps_executed; calls _bind_worker_streams_once, self.scheduler.step, mx.get_active_memory, mx.clear_cache; returns output. |
#L172-L190 |
EngineCore._engine_loop._step_on_model_thread |
nested function | EngineCore._engine_loop._step_on_model_thread() -> not annotated |
Nested Function EngineCore._engine_loop._step_on_model_thread updates self._steps_executed; calls _bind_model_streams_once, self.scheduler.step, mx.get_active_memory, mx.clear_cache; returns output. |
#L192-L210 |
EngineCore._engine_loop._recover_stream_thread_error_on_worker |
nested function | EngineCore._engine_loop._recover_stream_thread_error_on_worker() -> None |
Nested Function EngineCore._engine_loop._recover_stream_thread_error_on_worker calls _bind_worker_streams_once, self.scheduler._recover_from_cache_error, self.scheduler._reschedule_running_requests. |
#L212-L215 |
EngineCore._engine_loop._clear_cache_on_worker |
nested function | EngineCore._engine_loop._clear_cache_on_worker() -> None |
Nested Function EngineCore._engine_loop._clear_cache_on_worker calls _bind_worker_streams_once, mx.clear_cache. |
#L217-L219 |
EngineCore._engine_loop._close_batch_generator_on_worker |
nested function | EngineCore._engine_loop._close_batch_generator_on_worker() -> None |
Nested Function EngineCore._engine_loop._close_batch_generator_on_worker calls _bind_worker_streams_once, self.scheduler._close_batch_generator. |
#L221-L223 |
EngineCore.add_request |
method | async EngineCore.add_request(prompt: Union[str, List[int]], sampling_params: Optional[SamplingParams] = None, request_id: Optional[str] = None, images: Optional[List[Any]] = None, videos: Optional[List[Any]] = None, prefix_boundary: int = 0) -> str |
Add a request for processing. | #L336-L384 |
EngineCore.abort_request |
method | async EngineCore.abort_request(request_id: str) -> bool |
Abort a request. | #L386-L390 |
EngineCore._cleanup_request |
method | EngineCore._cleanup_request(request_id: str) -> None |
Clean up request tracking. | #L392-L399 |
EngineCore.stream_outputs |
method | async EngineCore.stream_outputs(request_id: str, timeout: Optional[float] = None) -> AsyncIterator[RequestOutput] |
Stream outputs for a request with low-latency non-blocking pattern. | #L401-L488 |
EngineCore.generate |
method | async EngineCore.generate(prompt: Union[str, List[int]], sampling_params: Optional[SamplingParams] = None, request_id: Optional[str] = None, **kwargs) -> RequestOutput |
Generate a complete response (non-streaming). | #L490-L552 |
EngineCore.generate_batch_sync |
method | EngineCore.generate_batch_sync(prompts: List[Union[str, List[int]]], sampling_params: Optional[SamplingParams] = None) -> List[RequestOutput] |
Generate responses synchronously for maximum throughput. | #L554-L609 |
EngineCore.get_stats |
method | EngineCore.get_stats() -> Dict[str, Any] |
Get engine statistics. | #L611-L624 |
EngineCore.get_cache_stats |
method | EngineCore.get_cache_stats() -> Optional[Dict[str, Any]] |
Get prefix cache statistics. | #L626-L628 |
EngineCore.save_cache_to_disk |
method | EngineCore.save_cache_to_disk(cache_dir: str) -> bool |
Save prefix cache to disk. | #L630-L632 |
EngineCore.load_cache_from_disk |
method | EngineCore.load_cache_from_disk(cache_dir: str) -> int |
Load prefix cache from disk. | #L634-L636 |
EngineCore.clear_runtime_caches |
method | EngineCore.clear_runtime_caches() -> Dict[str, Any] \| None |
Clear scheduler-managed runtime caches. | #L638-L640 |
EngineCore.clear_prefix_cache |
method | EngineCore.clear_prefix_cache() -> None |
Clear the prefix cache (delegates to scheduler). | #L642-L645 |
EngineCore._release_model |
method | EngineCore._release_model() -> None |
Release model ownership. | #L647-L653 |
EngineCore.close |
method | EngineCore.close() -> None |
Explicitly close the engine and release resources. | #L655-L685 |
EngineCore.__del__ |
method | EngineCore.__del__() -> not annotated |
Cleanup on destruction. | #L687-L693 |
EngineCore.engine_id |
method | EngineCore.engine_id() -> str |
Get the engine ID. | #L696-L698 |
AsyncEngineCore |
class | AsyncEngineCore(model: Any, tokenizer: Any, config: Optional[EngineConfig] = None) |
Async context manager wrapper for EngineCore. | #L701-L794 |
AsyncEngineCore.__init__ |
method | AsyncEngineCore.__init__(model: Any, tokenizer: Any, config: Optional[EngineConfig] = None) -> not annotated |
Method AsyncEngineCore.__init__ updates self.engine; calls EngineCore. |
#L712-L718 |
AsyncEngineCore.__aenter__ |
method | async AsyncEngineCore.__aenter__() -> 'AsyncEngineCore' |
Method AsyncEngineCore.__aenter__ calls self.engine.start; awaits asynchronous work; returns self. |
#L720-L722 |
AsyncEngineCore.__aexit__ |
method | async AsyncEngineCore.__aexit__(*args) -> None |
Method AsyncEngineCore.__aexit__ calls self.engine.stop; awaits asynchronous work. |
#L724-L725 |
AsyncEngineCore.start |
method | AsyncEngineCore.start() -> None |
Start engine (creates task in current loop). | #L727-L729 |
AsyncEngineCore.stop |
method | async AsyncEngineCore.stop() -> None |
Stop the engine. | #L731-L733 |
AsyncEngineCore.add_request |
method | async AsyncEngineCore.add_request(prompt: Union[str, List[int]], sampling_params: Optional[SamplingParams] = None, request_id: Optional[str] = None, **kwargs) -> str |
Add a request. | #L735-L748 |
AsyncEngineCore.abort_request |
method | async AsyncEngineCore.abort_request(request_id: str) -> bool |
Abort a request. | #L750-L752 |
AsyncEngineCore.stream_outputs |
method | async AsyncEngineCore.stream_outputs(request_id: str, timeout: Optional[float] = None) -> AsyncIterator[RequestOutput] |
Stream outputs. | #L754-L761 |
AsyncEngineCore.generate |
method | async AsyncEngineCore.generate(prompt: Union[str, List[int]], sampling_params: Optional[SamplingParams] = None, **kwargs) -> RequestOutput |
Generate complete response. | #L763-L774 |
AsyncEngineCore.get_stats |
method | AsyncEngineCore.get_stats() -> Dict[str, Any] |
Get engine stats. | #L776-L778 |
AsyncEngineCore.get_cache_stats |
method | AsyncEngineCore.get_cache_stats() -> Optional[Dict[str, Any]] |
Get prefix cache statistics. | #L780-L782 |
AsyncEngineCore.save_cache_to_disk |
method | AsyncEngineCore.save_cache_to_disk(cache_dir: str) -> bool |
Save prefix cache to disk. | #L784-L786 |
AsyncEngineCore.load_cache_from_disk |
method | AsyncEngineCore.load_cache_from_disk(cache_dir: str) -> int |
Load prefix cache from disk. | #L788-L790 |
AsyncEngineCore.clear_runtime_caches |
method | AsyncEngineCore.clear_runtime_caches() -> Dict[str, Any] \| None |
Clear scheduler-managed runtime caches. | #L792-L794 |