|
| 1 | +<!-- markdownlint-disable MD041 --> |
| 2 | +--8<-- [start:installation] |
| 3 | + |
| 4 | +vLLM has experimental support for GPU-accelerated inference on Apple Silicon using the MPS (Metal Performance Shaders) backend. This enables running LLM inference on the unified GPU in M1/M2/M3/M4 Macs. |
| 5 | + |
| 6 | +!!! warning "Experimental" |
| 7 | + MPS support is under active development. Some features available on CUDA (PagedAttention, tensor parallelism, continuous batching for high-throughput serving) are not yet implemented. MPS is best suited for single-user local inference. |
| 8 | + |
| 9 | +--8<-- [end:installation] |
| 10 | +--8<-- [start:requirements] |
| 11 | + |
| 12 | +- Hardware: Apple Silicon Mac (M1, M2, M3, or M4 series) |
| 13 | +- OS: macOS 15 (Sequoia) or later |
| 14 | +- Memory: 16 GB unified memory minimum, 24+ GB recommended |
| 15 | +- Python: 3.10 -- 3.13 |
| 16 | +- PyTorch: 2.9+ with MPS support |
| 17 | + |
| 18 | +--8<-- [end:requirements] |
| 19 | +--8<-- [start:set-up-using-python] |
| 20 | + |
| 21 | +There is no extra information on creating a new Python environment for this device. |
| 22 | + |
| 23 | +--8<-- [end:set-up-using-python] |
| 24 | +--8<-- [start:pre-built-wheels] |
| 25 | + |
| 26 | +Currently, there are no pre-built MPS wheels. You must build from source. |
| 27 | + |
| 28 | +--8<-- [end:pre-built-wheels] |
| 29 | +--8<-- [start:build-wheel-from-source] |
| 30 | + |
| 31 | +Clone the MPS support branch and install: |
| 32 | + |
| 33 | +```bash |
| 34 | +git clone https://github.com/robtaylor/vllm.git |
| 35 | +cd vllm |
| 36 | +git checkout mps-platform-support |
| 37 | +pip install -e ".[dev]" |
| 38 | +``` |
| 39 | + |
| 40 | +Verify MPS platform detection: |
| 41 | + |
| 42 | +```bash |
| 43 | +python -c " |
| 44 | +import torch |
| 45 | +print('MPS available:', torch.backends.mps.is_available()) |
| 46 | +from vllm.platforms import current_platform |
| 47 | +print('Platform:', current_platform.device_type) |
| 48 | +" |
| 49 | +``` |
| 50 | + |
| 51 | +### Installing Metal quantization kernels (optional) |
| 52 | + |
| 53 | +For accelerated INT4 (AWQ/GPTQ) and GGUF inference, build and install the Metal dequantization kernels. These require [Nix](https://determinate.systems/nix-installer/) to build. |
| 54 | + |
| 55 | +```bash |
| 56 | +# INT4 dequantization (AWQ + GPTQ) |
| 57 | +cd kernels-community/dequant-int4 |
| 58 | +nix build |
| 59 | +cp -r result/torch210-metal-aarch64-darwin/ \ |
| 60 | + $(python -c "import site; print(site.getsitepackages()[0])")/dequant_int4/ |
| 61 | + |
| 62 | +# GGUF dequantization (Q4_0, Q8_0, Q4_K, and more) |
| 63 | +cd ../dequant-gguf |
| 64 | +nix build |
| 65 | +cp -r result/torch210-metal-aarch64-darwin/ \ |
| 66 | + $(python -c "import site; print(site.getsitepackages()[0])")/dequant_gguf/ |
| 67 | +``` |
| 68 | + |
| 69 | +Without these kernels, quantized models will still work but use a slower PyTorch fallback path. |
| 70 | + |
| 71 | +--8<-- [end:build-wheel-from-source] |
| 72 | +--8<-- [start:pre-built-images] |
| 73 | + |
| 74 | +Docker is not applicable for MPS. macOS does not support GPU passthrough to containers. |
| 75 | + |
| 76 | +--8<-- [end:pre-built-images] |
| 77 | +--8<-- [start:build-image-from-source] |
| 78 | + |
| 79 | +Docker is not applicable for MPS. macOS does not support GPU passthrough to containers. |
| 80 | + |
| 81 | +--8<-- [end:build-image-from-source] |
| 82 | +--8<-- [start:supported-features] |
| 83 | + |
| 84 | +### Running inference |
| 85 | + |
| 86 | +MPS requires spawn multiprocessing. Set the environment variable before running: |
| 87 | + |
| 88 | +```bash |
| 89 | +export VLLM_WORKER_MULTIPROC_METHOD=spawn |
| 90 | +``` |
| 91 | + |
| 92 | +Example with a small model: |
| 93 | + |
| 94 | +```bash |
| 95 | +python -c " |
| 96 | +from vllm import LLM, SamplingParams |
| 97 | +llm = LLM(model='distilgpt2', dtype='float16', max_model_len=128) |
| 98 | +output = llm.generate(['Hello, world!'], SamplingParams(max_tokens=32)) |
| 99 | +print(output[0].outputs[0].text) |
| 100 | +" |
| 101 | +``` |
| 102 | + |
| 103 | +Example with a quantized model (requires Metal kernels above): |
| 104 | + |
| 105 | +```bash |
| 106 | +python -c " |
| 107 | +from vllm import LLM, SamplingParams |
| 108 | +llm = LLM(model='Qwen/Qwen2.5-1.5B-Instruct-AWQ', dtype='float16', |
| 109 | + max_model_len=512, quantization='awq') |
| 110 | +print(llm.generate(['Explain quantum computing.'], |
| 111 | + SamplingParams(max_tokens=64))[0].outputs[0].text) |
| 112 | +" |
| 113 | +``` |
| 114 | + |
| 115 | +### Performance |
| 116 | + |
| 117 | +Typical throughput on Apple Silicon (varies by chip and memory): |
| 118 | + |
| 119 | +| Model | Quantization | Throughput | |
| 120 | +|-------|-------------|------------| |
| 121 | +| GGUF small model | Q8_0 | ~62 tok/s | |
| 122 | +| GGUF small model | Q4_0 | ~45 tok/s | |
| 123 | +| Qwen2.5-1.5B | INT4 AWQ | ~17 tok/s | |
| 124 | +| Qwen2.5-1.5B | INT4 GPTQ | ~16 tok/s | |
| 125 | + |
| 126 | +### Memory guidelines |
| 127 | + |
| 128 | +MPS uses unified memory shared between CPU and GPU. When the KV cache exceeds approximately 40% of system RAM, Metal's memory manager can thrash, causing 50-100x slowdowns. |
| 129 | + |
| 130 | +The default KV cache allocation is set conservatively to 25% of system RAM. On a 24 GB system this allows roughly 9 GB for KV cache. Adjust with `gpu_memory_utilization` if needed. |
| 131 | + |
| 132 | +### Known limitations |
| 133 | + |
| 134 | +- No PagedAttention on Metal (uses PyTorch SDPA) |
| 135 | +- No tensor parallelism (single GPU only) |
| 136 | +- No continuous batching optimizations |
| 137 | +- GGUF Q4_K_M models may be slow if the model uses Q6_K layers (numpy fallback) |
| 138 | +- `fork()` crashes on MPS -- `VLLM_WORKER_MULTIPROC_METHOD=spawn` is required |
| 139 | + |
| 140 | +### Troubleshooting |
| 141 | + |
| 142 | +**Slow inference (50-100x slower than expected)**: |
| 143 | +KV cache memory thrashing. Try a smaller model or set `gpu_memory_utilization=0.2`. |
| 144 | + |
| 145 | +**SIGSEGV during startup**: |
| 146 | +Set `VLLM_WORKER_MULTIPROC_METHOD=spawn`. |
| 147 | + |
| 148 | +**"No module named 'vllm.platforms.mps'"**: |
| 149 | +Ensure you are on the `mps-platform-support` branch. |
| 150 | + |
| 151 | +--8<-- [end:supported-features] |
0 commit comments