How vllm-project/vllm-metal works
1. What this repository is
- vllm_metal is a plugin layer that adapts vLLM for Apple Silicon.
- The architectural split is: Python orchestration and model plumbing on top, with performance-critical attention and cache operations pushed into prebuilt Metal kernels and a small C++ bridge.
2. Top-level control plane
- vllm_metal/__init__.py, config.py, envs.py, platform.py, and compat.py provide package initialization, feature flags, platform detection, and compatibility shims.
- These modules form the “decision layer” that chooses which backend paths are available on macOS/arm64 and how vLLM should behave in this environment.
3. Attention subsystem as the core runtime path
- vllm_metal/attention is the main performance subsystem.
- It contains:
- cache implementations for KV/MLA/GDN/TurboQuant,
- backend implementations such as SDPA, MLA, linear attention, and lazy GDN,
- runtime orchestration that selects between MHA/MLA/hybrid execution,
- patching hooks that redirect vLLM attention flows into Metal-backed paths.
- This is the critical boundary where model execution is lowered from framework-level operations into backend-specific kernels.
4. Metal kernel and native bridge layer
- vllm_metal/metal contains the native execution assets:
- prebuilt .metal kernels for paging, cache reshaping, KV gather/scaling, MLA, turboquant, and GDN operations,
- paged_ops.cpp as the C++ bridge,
- build helpers and constants.
- The Python code uses this layer for the compute-heavy parts of inference, while the repository’s runtime assumes the kernels are already compiled and shipped.
5. Model loading and GGUF integration
- vllm_metal/gguf handles loading and adapting GGUF models.
- The package includes source/tensor abstractions, wrapper logic, MLX-native support, and explicit integration glue for vLLM.
- This subsystem is a loader/adaptor boundary: it translates external model artifacts into forms usable by the Metal-backed runtime.
6. Multimodal support
- vllm_metal/multimodal adds embedding and feature-spec handling plus model-specific adapters for qwen3_vl and paddleocr_vl.
- These adapters sit upstream of core inference and normalize multimodal inputs into the text/model pipeline.
- The architecture suggests multimodal support is pluggable and model-specific rather than a single generic vision stack.
7. Speech-to-text and ASR runtime
- vllm_metal/stt is a separate inference domain with its own loaders, protocols, runtime, serving entry points, and model families (whisper, qwen3_asr).
- It includes audio/detection utilities and transcriber implementations, meaning STT is modeled as a first-class pipeline rather than just another model type.
- This subsystem likely reuses some of the same backend and batching concepts, but has its own service/runtime surface.
8. v1 model execution path
- vllm_metal/v1 is the newer model execution stack.
- It contains:
- model_runner, worker, and model_lifecycle for inference orchestration,
- sampling/spec decoding/proposer logic,
- pooling and structured-output support,
- LoRA and multimodal cache management,
- Gemma 4 MTP-specific paths and draft model support.
- This layer is the main “application runtime” that coordinates model state, batching, and generation behavior above the backend kernels.
9. Quantization and adapter paths
- vllm_metal/quant and vllm_metal/v1/lora add weight-adaptation support.
- Quantization is centered on AWQ config/loading, while LoRA support includes model manager, PEFT loading, Punica-style wrapper logic, runtime, and worker coordination.
- These are important architectural extension points because they alter how weights are represented and served without changing the core execution engine.
10. Distributed and pipeline execution
- vllm_metal/distributed/pipeline.py provides the distributed/pipeline boundary.
- This indicates the repo supports splitting execution across stages or workers, with attention/cache and runner state remaining coordinated across those boundaries.
- The tests around pipeline and prefix caching suggest correctness depends on preserving cache semantics across distributed execution.
11. PyTorch and tensor interoperability
- vllm_metal/pytorch_backend/tensor_bridge.py is the interop layer between PyTorch tensors and the plugin’s backend representations.
- This is a key boundary because vLLM still expects framework-level tensor semantics, while the plugin needs to move data into MLX/Metal-friendly formats.
12. Operational tooling and validation
- tests/ is broad and architecture-revealing: it covers attention dispatch, paging, prefix caching, GGUF, multimodal, STT, quantization, LoRA, and v1 worker/model-runner flows.
- tools/ contains benchmarking, golden-data generation, smoke tests, and parity checks, which implies the repo is heavily validated for backend correctness and performance regressions.
- docs/ and CI/release scripts indicate a packaged plugin with documented installation, supported models, and backend-specific configuration rather than a standalone application.
13. Primary data flow to diagram
- External model or request enters through vLLM-facing entry points.
- Configuration/platform detection selects Apple-Silicon-specific backend paths.
- Model weights or artifacts are loaded via GGUF, quantization, LoRA, or multimodal/STT adapters.
- The v1 runner/worker or STT runtime batches work and routes it into attention/runtime abstractions.
- Attention and cache operations lower into Metal kernels through the native bridge, with results returned through tensor-bridge compatibility layers back to vLLM.
14. Key architectural boundary
- The most important split is between:
- Python orchestration/adaptation: model loading, routing, batching, feature support, and compatibility;
- native performance execution: Metal kernels plus the small C++ bridge.
- A second important split is between generic LLM inference and specialized domains like multimodal and STT, each with their own adapters and runtimes.
Main entry points: model_runner.py Model runner · runtime Attention runtime · worker.py Worker · paged_ops.cpp C++ bridge
Components 23
Control plane
Package initialization, platform detection, and environment-driven feature selection.
- Package init · Top-level package initialization and public surface.
vllm_metal/__init__.py - Config · Repository configuration and defaults.
vllm_metal/config.py - Env flags · Environment-based toggles and backend selection.
vllm_metal/envs.py - Platform · Apple Silicon and macOS capability detection.
vllm_metal/platform.py - Compat shims · Compatibility helpers for vLLM integration.
vllm_metal/compat.py
Core runtime
Main vLLM execution paths for attention, model serving, and distributed coordination.
- Attention runtime · Selects MHA, MLA, and hybrid attention execution paths.
vllm_metal/attention/runtime - KV caches · KV, MLA, GDN, and turboquant cache implementations.
vllm_metal/attention/caches - Attention backends · SDPA, MLA, linear attention, and lazy GDN implementations.
vllm_metal/attention/impls - Patching hooks · Redirects vLLM attention flows into Metal-backed paths.
vllm_metal/attention/patching.py - Model runner · Inference orchestration, batching, and generation control.
vllm_metal/v1/model_runner.py - Worker · Worker-side model execution and coordination.
vllm_metal/v1/worker.py - Lifecycle · Model setup, teardown, and state management.
vllm_metal/v1/model_lifecycle.py - Spec decode · Sampling, proposer, and speculative decoding logic.
vllm_metal/v1/spec_decode.py - Pipeline · Distributed and pipeline execution boundary.
vllm_metal/distributed/pipeline.py
Native backend
Metal kernels and the C++ bridge used for performance-critical operations.
- Metal kernels · Prebuilt Metal compute kernels for paging, cache updates, MLA, GDN, and turboquant.
vllm_metal/metal/kernels_v2 - C++ bridge · C++ entry point between Python and Metal kernel execution.
vllm_metal/metal/paged_ops.cpp
Loaders and adapters
Model artifact ingestion and representation adapters.
- GGUF loader · Loads and adapts GGUF model artifacts.
vllm_metal/gguf/loader.py - GGUF adapters · Wrappers, source/tensor abstractions, and vLLM integration.
vllm_metal/gguf
Specialized domains
Multimodal and speech-to-text inference paths.
- Multimodal · Embedding, feature-spec, and model-specific multimodal adapters.
vllm_metal/multimodal - STT runtime · Speech-to-text loaders, protocol, runtime, and serving entry points.
vllm_metal/stt
Interop and extension
Framework boundaries, quantization, LoRA, and tensor bridging.
- Tensor bridge · PyTorch tensor interop with backend representations.
vllm_metal/pytorch_backend/tensor_bridge.py - AWQ quant · AWQ configuration and loading paths.
vllm_metal/quant - LoRA runtime · LoRA model management, PEFT loading, and worker coordination.
vllm_metal/v1/lora
Connections 24
- Package init → Config: reads defaults · Package setup uses repository configuration.
- Package init → Platform: detects platform · Selects Apple-Silicon-specific behavior.
- Env flags → Platform: gates features · Environment flags depend on platform capability.
- Compat shims → Patching hooks: supports integration · Compatibility shims smooth vLLM hook points.
- Patching hooks → Attention runtime: routes to · Patching directs requests into the local attention runtime.
- Attention runtime → Attention backends: selects backend · Runtime chooses between attention implementations.
- Attention runtime → KV caches: uses cache · Execution relies on KV and related caches.
- Attention backends → C++ bridge: invokes bridge · Backend implementations lower compute to native calls.
- KV caches → C++ bridge: updates cache · Cache movement and reshaping are handled through the native bridge.
- C++ bridge → Metal kernels: executes · C++ bridge dispatches into prebuilt Metal kernels.
- Tensor bridge → Attention runtime: feeds tensors · Tensor interop provides framework-compatible inputs to runtime execution.
- GGUF loader → GGUF adapters: adapts models · Loader uses GGUF wrappers and integration glue.
- GGUF adapters → Tensor bridge: materializes tensors · GGUF representations are converted for backend consumption.
- AWQ quant → GGUF loader: reshapes weights · Quantized model loading participates in artifact ingestion.
- LoRA runtime → Model runner: extends serving · LoRA paths plug into the main model runner.
- LoRA runtime → Worker: coordinates workers · Worker-side LoRA state is managed separately.
- Multimodal → Model runner: augments input · Multimodal adapters feed the generation runtime.
- STT runtime → Model runner: shares orchestration · STT reuses runtime patterns while keeping its own pipeline surface.
- STT runtime → Tensor bridge: tensor interop · Speech models also cross the tensor boundary.
- Model runner → Lifecycle: manages · Runner coordinates model state and lifecycle.
- Model runner → Spec decode: samples via · Runner delegates generation strategy and speculative decoding.
- Model runner → Worker: dispatches to · Work is executed by worker processes or threads.
- Worker → Attention runtime: executes attention · Worker drives the main attention path.
- Model runner → Pipeline: can split · Pipeline execution can divide work across stages.