vllm_mlx.optimizations¶
Hardware detection and system information for vllm-mlx.
View the complete module source at #L1-L209.
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.optimizations
¶
Hardware detection and system information for vllm-mlx.
This module provides: - Hardware detection for Apple Silicon (M1, M2, M3, M4 series) - System memory detection - Memory bandwidth benchmarking
Note: mlx-lm already includes optimized implementations internally: - Flash Attention via mx.fast.scaled_dot_product_attention - Efficient memory management - Optimized Metal kernels
No additional optimization is needed - mlx-lm is already fast out of the box.
Usage
from vllm_mlx.optimizations import ( detect_hardware, get_optimization_status, benchmark_memory_bandwidth, )
vllm_mlx.optimizations.HARDWARE_PROFILES
module-attribute
¶
HARDWARE_PROFILES = {'M1': {'bandwidth': 68.25, 'gpu_cores': 8}, 'M1 Pro': {'bandwidth': 200, 'gpu_cores': 16}, 'M1 Max': {'bandwidth': 400, 'gpu_cores': 32}, 'M1 Ultra': {'bandwidth': 800, 'gpu_cores': 64}, 'M2': {'bandwidth': 100, 'gpu_cores': 10}, 'M2 Pro': {'bandwidth': 200, 'gpu_cores': 19}, 'M2 Max': {'bandwidth': 400, 'gpu_cores': 38}, 'M2 Ultra': {'bandwidth': 800, 'gpu_cores': 76}, 'M3': {'bandwidth': 100, 'gpu_cores': 10}, 'M3 Pro': {'bandwidth': 150, 'gpu_cores': 18}, 'M3 Max': {'bandwidth': 400, 'gpu_cores': 40}, 'M3 Ultra': {'bandwidth': 800, 'gpu_cores': 80}, 'M4': {'bandwidth': 120, 'gpu_cores': 10}, 'M4 Pro': {'bandwidth': 273, 'gpu_cores': 20}, 'M4 Max': {'bandwidth': 546, 'gpu_cores': 40}, 'M4 Ultra': {'bandwidth': 800, 'gpu_cores': 80}}
vllm_mlx.optimizations.HardwareInfo
dataclass
¶
Hardware information for Apple Silicon.
vllm_mlx.optimizations.HardwareInfo.memory_bandwidth_gbs
instance-attribute
¶
vllm_mlx.optimizations.get_system_memory_gb
¶
Get actual system memory in GB.
Returns:
-
float–Total system memory in GB (unified memory on Apple Silicon)
Source code in vllm_mlx/optimizations.py
vllm_mlx.optimizations.detect_hardware
¶
detect_hardware() -> HardwareInfo
Detect Apple Silicon hardware and return info.
Memory is detected dynamically from the system. Other specs (bandwidth, GPU cores) come from known chip profiles.
Returns:
-
HardwareInfo–HardwareInfo with detected hardware specifications
Source code in vllm_mlx/optimizations.py
vllm_mlx.optimizations.benchmark_memory_bandwidth
¶
Benchmark actual memory bandwidth achieved.
Returns:
-
dict–dict with bandwidth measurements for different array sizes
Source code in vllm_mlx/optimizations.py
vllm_mlx.optimizations.get_optimization_status
¶
Get current hardware and MLX status.
Returns:
-
dict–dict with hardware info and MLX configuration
Source code in vllm_mlx/optimizations.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.optimizations.HardwareInfo · class
vllm_mlx.optimizations.HardwareInfo(chip_name: str, total_memory_gb: float, memory_bandwidth_gbs: float, gpu_cores: int)
Hardware information for Apple Silicon.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
chip_name |
str |
yes |
none |
Required constructor field. |
total_memory_gb |
float |
yes |
none |
Required constructor field. |
memory_bandwidth_gbs |
float |
yes |
none |
Required constructor field. |
gpu_cores |
int |
yes |
none |
Required constructor field. |
Returns
- Constructs:
vllm_mlx.optimizations.HardwareInfo
Exceptions and behavior
Class HardwareInfo declares 0 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.optimizations.get_system_memory_gb · function
Get actual system memory in GB.
Parameters
This callable has no explicit inputs.
Returns
- Type:
float - Direct return expressions:
mem_bytes / 1024 ** 3;device_info['memory_size'] / 1024 ** 3;16.0
Exceptions and behavior
Function get_system_memory_gb calls subprocess.run, int, result.stdout.strip, mx.device_info; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.optimizations.detect_hardware · function
Detect Apple Silicon hardware and return info.
Parameters
This callable has no explicit inputs.
Returns
- Type:
HardwareInfo - Direct return expressions:
HardwareInfo(chip_name=chip_name, total_memory_gb=actual_memory_gb, memory_bandwidth_gbs=profile['bandwidth'], gpu_core…;HardwareInfo(chip_name='Unknown', total_memory_gb=actual_memory_gb, memory_bandwidth_gbs=200, gpu_cores=16);HardwareInfo(chip_name='Unknown', total_memory_gb=get_system_memory_gb(), memory_bandwidth_gbs=200, gpu_cores=16)
Exceptions and behavior
Function detect_hardware calls mx.device_info, device_info.get, get_system_memory_gb, sorted; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.optimizations.benchmark_memory_bandwidth · function
Benchmark actual memory bandwidth achieved.
Parameters
This callable has no explicit inputs.
Returns
- Type:
dict - Direct return expressions:
results
Exceptions and behavior
Function benchmark_memory_bandwidth calls mx.random.normal, mx.eval, time.perf_counter, range; returns results.
No direct raise statement appears in this definition.
vllm_mlx.optimizations.get_optimization_status · function
Get current hardware and MLX status.
Parameters
This callable has no explicit inputs.
Returns
- Type:
dict - Direct return expressions:
{'hardware': {'chip': hw.chip_name, 'total_memory_gb': hw.total_memory_gb, 'memory_bandwidth_gbs': hw.memory_bandwidth_…
Exceptions and behavior
Function get_optimization_status calls detect_hardware, mx.device_info, hasattr, device_info.get; returns {'hardware': {'chip': hw.chip_name, 'total_memory_gb': hw.total_memory_gb, 'memory_bandwidth_gbs': hw.memory_bandwidth_….
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 |
|---|---|---|---|---|
HardwareInfo |
class | HardwareInfo(chip_name: str, total_memory_gb: float, memory_bandwidth_gbs: float, gpu_cores: int) |
Hardware information for Apple Silicon. | #L34-L40 |
get_system_memory_gb |
function | get_system_memory_gb() -> float |
Get actual system memory in GB. | #L68-L94 |
detect_hardware |
function | detect_hardware() -> HardwareInfo |
Detect Apple Silicon hardware and return info. | #L97-L141 |
benchmark_memory_bandwidth |
function | benchmark_memory_bandwidth() -> dict |
Benchmark actual memory bandwidth achieved. | #L144-L174 |
get_optimization_status |
function | get_optimization_status() -> dict |
Get current hardware and MLX status. | #L177-L209 |