vllm_mlx.worker¶
MLX Worker for vLLM.
View the complete module source at #L1-L278.
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.worker
¶
MLX Worker for vLLM.
This module implements a vLLM worker that uses Apple's MLX framework for model execution on Apple Silicon.
vllm_mlx.worker.MLXWorker
¶
MLXWorker(vllm_config: VllmConfig, local_rank: int, rank: int, distributed_init_method: str, is_driver_worker: bool = False)
Worker implementation for MLX-based inference on Apple Silicon.
This worker uses mlx-lm for model loading and inference, providing native Apple Silicon GPU acceleration through Metal.
Unlike CUDA workers that use PyTorch with CUDA, this worker: - Uses MLX arrays instead of PyTorch tensors for model weights - Leverages unified memory (no CPU<->GPU transfers needed) - Uses Metal-optimized kernels for attention and other operations
Initialize MLX worker.
Parameters:
-
vllm_config(VllmConfig) –Complete vLLM configuration
-
local_rank(int) –Local device index (usually 0 for single GPU)
-
rank(int) –Global rank in distributed setup
-
distributed_init_method(str) –Distributed initialization method
-
is_driver_worker(bool, default:False) –Whether this worker handles driver responsibilities
Source code in vllm_mlx/worker.py
vllm_mlx.worker.MLXWorker.parallel_config
instance-attribute
¶
vllm_mlx.worker.MLXWorker.scheduler_config
instance-attribute
¶
vllm_mlx.worker.MLXWorker.device_config
instance-attribute
¶
vllm_mlx.worker.MLXWorker.distributed_init_method
instance-attribute
¶
vllm_mlx.worker.MLXWorker.init_device
¶
Initialize MLX device and verify it's working.
Source code in vllm_mlx/worker.py
vllm_mlx.worker.MLXWorker.load_model
¶
Load model using mlx-lm.
Source code in vllm_mlx/worker.py
vllm_mlx.worker.MLXWorker.determine_available_memory
¶
Determine available memory for KV cache.
On Apple Silicon with unified memory, we use a portion of system RAM.
Source code in vllm_mlx/worker.py
vllm_mlx.worker.MLXWorker.initialize_cache
¶
Initialize KV cache with the given size.
Source code in vllm_mlx/worker.py
vllm_mlx.worker.MLXWorker.get_kv_cache_spec
¶
vllm_mlx.worker.MLXWorker.compile_or_warm_up_model
¶
vllm_mlx.worker.MLXWorker.execute_model
¶
Execute model inference for the given scheduler output.
Parameters:
-
scheduler_output(SchedulerOutput) –Contains requests to process
Returns:
-
ModelRunnerOutput | None–ModelRunnerOutput with generation results
Source code in vllm_mlx/worker.py
vllm_mlx.worker.MLXWorker.get_model
¶
vllm_mlx.worker.MLXWorker.check_health
¶
Check worker health.
Source code in vllm_mlx/worker.py
vllm_mlx.worker.MLXWorker.shutdown
¶
Clean up resources.
Source code in vllm_mlx/worker.py
vllm_mlx.worker.MLXWorker.add_lora
¶
vllm_mlx.worker.MLXWorker.remove_lora
¶
vllm_mlx.worker.MLXWorker.pin_lora
¶
vllm_mlx.worker.MLXWorker.list_loras
¶
vllm_mlx.worker.MLXWorker.sleep
¶
Leave the worker active because MLX unified memory has no sleep mode.
vllm_mlx.worker.MLXWorker.wake_up
¶
Perform no work because the MLX worker never enters sleep mode.
vllm_mlx.worker.MLXWorker.get_cache_block_size_bytes
¶
Get size of a cache block in bytes.
Source code in vllm_mlx/worker.py
vllm_mlx.worker.MLXWorker.profile
¶
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.worker.MLXWorker · class
vllm_mlx.worker.MLXWorker(vllm_config: 'VllmConfig', local_rank: int, rank: int, distributed_init_method: str, is_driver_worker: bool = False)
Worker implementation for MLX-based inference on Apple Silicon.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
vllm_config |
'VllmConfig' |
yes |
none |
Complete vLLM configuration |
local_rank |
int |
yes |
none |
Local device index (usually 0 for single GPU) |
rank |
int |
yes |
none |
Global rank in distributed setup |
distributed_init_method |
str |
yes |
none |
Distributed initialization method |
is_driver_worker |
bool |
no |
False |
Whether this worker handles driver responsibilities |
Returns
- Constructs:
vllm_mlx.worker.MLXWorker
Exceptions and behavior
Class MLXWorker declares 21 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.worker.MLXWorker.__init__ · method
vllm_mlx.worker.MLXWorker.__init__(vllm_config: 'VllmConfig', local_rank: int, rank: int, distributed_init_method: str, is_driver_worker: bool = False) -> None
Initialize MLX worker.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
vllm_config |
'VllmConfig' |
yes |
none |
Complete vLLM configuration |
local_rank |
int |
yes |
none |
Local device index (usually 0 for single GPU) |
rank |
int |
yes |
none |
Global rank in distributed setup |
distributed_init_method |
str |
yes |
none |
Distributed initialization method |
is_driver_worker |
bool |
no |
False |
Whether this worker handles driver responsibilities |
Returns
- Type:
None
Exceptions and behavior
Method MLXWorker.__init__ updates self.vllm_config, self.model_config, self.cache_config, self.parallel_config; calls torch.device, logger.info.
No direct raise statement appears in this definition.
vllm_mlx.worker.MLXWorker.init_device · method
Initialize MLX device and verify it's working.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method MLXWorker.init_device updates self.model_runner; calls mx.default_device, logger.info, get_mlx_device_info, MLXModelRunner; can raise ImportError.
Directly raised exceptions: ImportError.
vllm_mlx.worker.MLXWorker.load_model · method
Load model using mlx-lm.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method MLXWorker.load_model calls RuntimeError, self.model_runner.load_model, logger.info; can raise RuntimeError.
Directly raised exceptions: RuntimeError.
vllm_mlx.worker.MLXWorker.determine_available_memory · method
Determine available memory for KV cache.
Parameters
This callable has no explicit inputs.
Returns
- Type:
int - Direct return expressions:
available;4 * 1024 * 1024 * 1024
Exceptions and behavior
Method MLXWorker.determine_available_memory calls subprocess.run, int, result.stdout.strip, logger.info; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.worker.MLXWorker.initialize_cache · method
Initialize KV cache with the given size.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
num_gpu_blocks |
int |
yes |
none |
Required positional or keyword input. |
num_cpu_blocks |
int |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Method MLXWorker.initialize_cache updates self.cache_config.num_gpu_blocks, self.cache_config.num_cpu_blocks; calls self.model_runner.initialize_cache, logger.info.
No direct raise statement appears in this definition.
vllm_mlx.worker.MLXWorker.get_kv_cache_spec · method
Get KV cache specification.
Parameters
This callable has no explicit inputs.
Returns
- Type:
dict - Direct return expressions:
self.model_runner.get_kv_cache_spec();{}
Exceptions and behavior
Method MLXWorker.get_kv_cache_spec calls self.model_runner.get_kv_cache_spec; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.worker.MLXWorker.compile_or_warm_up_model · method
Warm up model for inference.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method MLXWorker.compile_or_warm_up_model calls self.model_runner.warm_up, logger.info.
No direct raise statement appears in this definition.
vllm_mlx.worker.MLXWorker.execute_model · method
vllm_mlx.worker.MLXWorker.execute_model(scheduler_output: 'SchedulerOutput') -> 'ModelRunnerOutput | None'
Execute model inference for the given scheduler output.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
scheduler_output |
'SchedulerOutput' |
yes |
none |
Contains requests to process |
Returns
- Type:
'ModelRunnerOutput | None' - Direct return expressions:
self.model_runner.execute_model(scheduler_output)
Exceptions and behavior
Method MLXWorker.execute_model calls RuntimeError, self.model_runner.execute_model; can raise RuntimeError; returns self.model_runner.execute_model(scheduler_output).
Directly raised exceptions: RuntimeError.
vllm_mlx.worker.MLXWorker.get_model · method
Get the underlying model.
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated - Direct return expressions:
self.model_runner.model;None
Exceptions and behavior
Method MLXWorker.get_model has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.worker.MLXWorker.check_health · method
Check worker health.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method MLXWorker.check_health calls mx.array, mx.sum(test).item, mx.sum, RuntimeError; can raise RuntimeError.
Directly raised exceptions: RuntimeError.
vllm_mlx.worker.MLXWorker.shutdown · method
Clean up resources.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method MLXWorker.shutdown updates self.model, self.tokenizer, self.model_runner; calls logger.info, mx.clear_cache, gc.collect.
No direct raise statement appears in this definition.
vllm_mlx.worker.MLXWorker.add_lora · method
Report that dynamically adding a LoRA adapter is unsupported.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
lora_request |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
False
Exceptions and behavior
Method MLXWorker.add_lora calls logger.warning; returns False.
No direct raise statement appears in this definition.
vllm_mlx.worker.MLXWorker.remove_lora · method
Report that dynamically removing a LoRA adapter is unsupported.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
lora_id |
int |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
False
Exceptions and behavior
Method MLXWorker.remove_lora returns False.
No direct raise statement appears in this definition.
vllm_mlx.worker.MLXWorker.pin_lora · method
Report that pinning a LoRA adapter is unsupported.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
lora_id |
int |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
False
Exceptions and behavior
Method MLXWorker.pin_lora returns False.
No direct raise statement appears in this definition.
vllm_mlx.worker.MLXWorker.list_loras · method
Return the empty set because runtime LoRA adapters are unsupported.
Parameters
This callable has no explicit inputs.
Returns
- Type:
set[int] - Direct return expressions:
set()
Exceptions and behavior
Method MLXWorker.list_loras calls set; returns set().
No direct raise statement appears in this definition.
vllm_mlx.worker.MLXWorker.sleep · method
Leave the worker active because MLX unified memory has no sleep mode.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
level |
int |
no |
1 |
Optional positional or keyword input; defaults to 1. |
Returns
- Type:
None
Exceptions and behavior
Method MLXWorker.sleep calls logger.debug.
No direct raise statement appears in this definition.
vllm_mlx.worker.MLXWorker.wake_up · method
Perform no work because the MLX worker never enters sleep mode.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tags |
list[str] \| None |
no |
None |
Optional positional or keyword input; defaults to None. |
Returns
- Type:
None
Exceptions and behavior
Method MLXWorker.wake_up calls logger.debug.
No direct raise statement appears in this definition.
vllm_mlx.worker.MLXWorker.vocab_size · method
Get vocabulary size.
Parameters
This callable has no explicit inputs.
Returns
- Type:
int - Direct return expressions:
self.model_config.get_vocab_size()
Exceptions and behavior
Method MLXWorker.vocab_size calls self.model_config.get_vocab_size; returns self.model_config.get_vocab_size().
No direct raise statement appears in this definition.
vllm_mlx.worker.MLXWorker.get_cache_block_size_bytes · method
Get size of a cache block in bytes.
Parameters
This callable has no explicit inputs.
Returns
- Type:
int - Direct return expressions:
self.model_runner.get_cache_block_size_bytes();2 * block_size * num_layers * num_heads * head_size * 2
Exceptions and behavior
Method MLXWorker.get_cache_block_size_bytes calls self.model_runner.get_cache_block_size_bytes, self.model_config.get_head_size, self.model_config.get_num_kv_heads, self.model_config.get_num_layers; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.worker.MLXWorker.profile · method
Profiling (not yet implemented for MLX).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
is_start |
bool |
no |
True |
Optional positional or keyword input; defaults to True. |
Returns
- Type:
None
Exceptions and behavior
Method MLXWorker.profile calls logger.debug.
No direct raise statement appears in this definition.
vllm_mlx.worker.MLXWorker.__repr__ · method
Method MLXWorker.__repr__ returns f'<MLXWorker rank={self.rank} local_rank={self.local_rank}>'.
Parameters
This callable has no explicit inputs.
Returns
- Type:
str - Direct return expressions:
f'<MLXWorker rank={self.rank} local_rank={self.local_rank}>'
Exceptions and behavior
Method MLXWorker.__repr__ returns f'<MLXWorker rank={self.rank} local_rank={self.local_rank}>'.
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 |
|---|---|---|---|---|
MLXWorker |
class | MLXWorker(vllm_config: 'VllmConfig', local_rank: int, rank: int, distributed_init_method: str, is_driver_worker: bool = False) |
Worker implementation for MLX-based inference on Apple Silicon. | #L23-L278 |
MLXWorker.__init__ |
method | MLXWorker.__init__(vllm_config: 'VllmConfig', local_rank: int, rank: int, distributed_init_method: str, is_driver_worker: bool = False) -> None |
Initialize MLX worker. | #L36-L75 |
MLXWorker.init_device |
method | MLXWorker.init_device() -> None |
Initialize MLX device and verify it's working. | #L77-L103 |
MLXWorker.load_model |
method | MLXWorker.load_model() -> None |
Load model using mlx-lm. | #L105-L111 |
MLXWorker.determine_available_memory |
method | MLXWorker.determine_available_memory() -> int |
Determine available memory for KV cache. | #L113-L143 |
MLXWorker.initialize_cache |
method | MLXWorker.initialize_cache(num_gpu_blocks: int, num_cpu_blocks: int) -> None |
Initialize KV cache with the given size. | #L145-L153 |
MLXWorker.get_kv_cache_spec |
method | MLXWorker.get_kv_cache_spec() -> dict |
Get KV cache specification. | #L155-L159 |
MLXWorker.compile_or_warm_up_model |
method | MLXWorker.compile_or_warm_up_model() -> None |
Warm up model for inference. | #L161-L165 |
MLXWorker.execute_model |
method | MLXWorker.execute_model(scheduler_output: 'SchedulerOutput') -> 'ModelRunnerOutput \| None' |
Execute model inference for the given scheduler output. | #L167-L183 |
MLXWorker.get_model |
method | MLXWorker.get_model() -> not annotated |
Get the underlying model. | #L185-L189 |
MLXWorker.check_health |
method | MLXWorker.check_health() -> None |
Check worker health. | #L191-L200 |
MLXWorker.shutdown |
method | MLXWorker.shutdown() -> None |
Clean up resources. | #L202-L219 |
MLXWorker.add_lora |
method | MLXWorker.add_lora(lora_request) -> bool |
Report that dynamically adding a LoRA adapter is unsupported. | #L222-L226 |
MLXWorker.remove_lora |
method | MLXWorker.remove_lora(lora_id: int) -> bool |
Report that dynamically removing a LoRA adapter is unsupported. | #L228-L231 |
MLXWorker.pin_lora |
method | MLXWorker.pin_lora(lora_id: int) -> bool |
Report that pinning a LoRA adapter is unsupported. | #L233-L236 |
MLXWorker.list_loras |
method | MLXWorker.list_loras() -> set[int] |
Return the empty set because runtime LoRA adapters are unsupported. | #L238-L241 |
MLXWorker.sleep |
method | MLXWorker.sleep(level: int = 1) -> None |
Leave the worker active because MLX unified memory has no sleep mode. | #L244-L247 |
MLXWorker.wake_up |
method | MLXWorker.wake_up(tags: list[str] \| None = None) -> None |
Perform no work because the MLX worker never enters sleep mode. | #L249-L252 |
MLXWorker.vocab_size |
method | MLXWorker.vocab_size() -> int |
Get vocabulary size. | #L255-L257 |
MLXWorker.get_cache_block_size_bytes |
method | MLXWorker.get_cache_block_size_bytes() -> int |
Get size of a cache block in bytes. | #L259-L271 |
MLXWorker.profile |
method | MLXWorker.profile(is_start: bool = True) -> None |
Profiling (not yet implemented for MLX). | #L273-L275 |
MLXWorker.__repr__ |
method | MLXWorker.__repr__() -> str |
Method MLXWorker.__repr__ returns f'<MLXWorker rank={self.rank} local_rank={self.local_rank}>'. |
#L277-L278 |