# vllm-project/vllm-metal architecture

> Architecture diagram of the GitHub repository vllm-project/vllm-metal, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vllm-project/vllm-metal
- Repository: https://github.com/vllm-project/vllm-metal

## Overview

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: [`vllm_metal/v1/model_runner.py`](https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/v1/model_runner.py) (Model runner), [`vllm_metal/attention/runtime`](https://github.com/vllm-project/vllm-metal/tree/main/vllm_metal/attention/runtime) (Attention runtime), [`vllm_metal/v1/worker.py`](https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/v1/worker.py) (Worker), [`vllm_metal/metal/paged_ops.cpp`](https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/metal/paged_ops.cpp) (C++ bridge)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Control plane"]
  node_vllm_metal_init["Package init<br/>python entry<br/>[__init__.py]"]
  node_vllm_metal_config["Config<br/>[config.py]"]
  node_vllm_metal_envs["Env flags<br/>feature flags<br/>[envs.py]"]
  node_vllm_metal_platform["Platform<br/>[platform.py]"]
  node_vllm_metal_compat["Compat shims<br/>compat layer<br/>[compat.py]"]
end

subgraph group_runtime["Core runtime"]
  node_attention_runtime["Attention runtime<br/>execution core"]
  node_attention_caches[("KV caches<br/>cache subsystem")]
  node_attention_impls["Attention backends<br/>backend impls"]
  node_attention_patching["Patching hooks<br/>integration glue<br/>[patching.py]"]
  node_v1_runner["Model runner<br/>serving runtime<br/>[model_runner.py]"]
  node_v1_worker["Worker<br/>[worker.py]"]
  node_v1_lifecycle["Lifecycle<br/>model control<br/>[model_lifecycle.py]"]
  node_v1_spec_decode["Spec decode<br/>decoding<br/>[spec_decode.py]"]
  node_distributed_pipeline["Pipeline<br/>distributed exec<br/>[pipeline.py]"]
end

subgraph group_native["Native backend"]
  node_metal_kernels{{"Metal kernels<br/>gpu kernels"}}
  node_metal_bridge["C++ bridge<br/>native bridge<br/>[paged_ops.cpp]"]
end

subgraph group_loaders["Loaders and adapters"]
  node_gguf_loader["GGUF loader<br/>model loader<br/>[loader.py]"]
  node_gguf_adapters["GGUF adapters<br/>model glue"]
end

subgraph group_specialized["Specialized domains"]
  node_multimodal["Multimodal<br/>adapter stack"]
  node_stt_runtime["STT runtime<br/>speech pipeline"]
end

subgraph group_interop["Interop and extension"]
  node_pytorch_bridge["Tensor bridge<br/>interop bridge<br/>[tensor_bridge.py]"]
  node_quant_awq["AWQ quant<br/>quantization"]
  node_lora_runtime["LoRA runtime<br/>adapter runtime"]
end

node_vllm_metal_init -->|"reads defaults"| node_vllm_metal_config
node_vllm_metal_init -->|"detects platform"| node_vllm_metal_platform
node_vllm_metal_envs -->|"gates features"| node_vllm_metal_platform
node_vllm_metal_compat -->|"supports integration"| node_attention_patching
node_attention_patching -->|"routes to"| node_attention_runtime
node_attention_runtime -->|"selects backend"| node_attention_impls
node_attention_runtime -->|"uses cache"| node_attention_caches
node_attention_impls -->|"invokes bridge"| node_metal_bridge
node_attention_caches -->|"updates cache"| node_metal_bridge
node_metal_bridge -->|"executes"| node_metal_kernels
node_pytorch_bridge -->|"feeds tensors"| node_attention_runtime
node_gguf_loader -->|"adapts models"| node_gguf_adapters
node_gguf_adapters -->|"materializes tensors"| node_pytorch_bridge
node_quant_awq -->|"reshapes weights"| node_gguf_loader
node_lora_runtime -->|"extends serving"| node_v1_runner
node_lora_runtime -->|"coordinates workers"| node_v1_worker
node_multimodal -->|"augments input"| node_v1_runner
node_stt_runtime -->|"shares orchestration"| node_v1_runner
node_stt_runtime -->|"tensor interop"| node_pytorch_bridge
node_v1_runner -->|"manages"| node_v1_lifecycle
node_v1_runner -->|"samples via"| node_v1_spec_decode
node_v1_runner -->|"dispatches to"| node_v1_worker
node_v1_worker -->|"executes attention"| node_attention_runtime
node_v1_runner -->|"can split"| node_distributed_pipeline

click node_vllm_metal_init "https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/__init__.py"
click node_vllm_metal_config "https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/config.py"
click node_vllm_metal_envs "https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/envs.py"
click node_vllm_metal_platform "https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/platform.py"
click node_vllm_metal_compat "https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/compat.py"
click node_attention_runtime "https://github.com/vllm-project/vllm-metal/tree/main/vllm_metal/attention/runtime"
click node_attention_caches "https://github.com/vllm-project/vllm-metal/tree/main/vllm_metal/attention/caches"
click node_attention_impls "https://github.com/vllm-project/vllm-metal/tree/main/vllm_metal/attention/impls"
click node_attention_patching "https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/attention/patching.py"
click node_v1_runner "https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/v1/model_runner.py"
click node_v1_worker "https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/v1/worker.py"
click node_v1_lifecycle "https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/v1/model_lifecycle.py"
click node_v1_spec_decode "https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/v1/spec_decode.py"
click node_metal_kernels "https://github.com/vllm-project/vllm-metal/tree/main/vllm_metal/metal/kernels_v2"
click node_metal_bridge "https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/metal/paged_ops.cpp"
click node_pytorch_bridge "https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/pytorch_backend/tensor_bridge.py"
click node_gguf_loader "https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/gguf/loader.py"
click node_gguf_adapters "https://github.com/vllm-project/vllm-metal/tree/main/vllm_metal/gguf"
click node_quant_awq "https://github.com/vllm-project/vllm-metal/tree/main/vllm_metal/quant"
click node_lora_runtime "https://github.com/vllm-project/vllm-metal/tree/main/vllm_metal/v1/lora"
click node_multimodal "https://github.com/vllm-project/vllm-metal/tree/main/vllm_metal/multimodal"
click node_stt_runtime "https://github.com/vllm-project/vllm-metal/tree/main/vllm_metal/stt"
click node_distributed_pipeline "https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/distributed/pipeline.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_vllm_metal_init,node_vllm_metal_config,node_vllm_metal_envs,node_vllm_metal_platform,node_vllm_metal_compat toneBlue
class node_attention_runtime,node_attention_caches,node_attention_impls,node_attention_patching,node_v1_runner,node_v1_worker,node_v1_lifecycle,node_v1_spec_decode,node_distributed_pipeline toneAmber
class node_metal_kernels,node_metal_bridge toneMint
class node_gguf_loader,node_gguf_adapters toneRose
class node_multimodal,node_stt_runtime toneIndigo
class node_pytorch_bridge,node_quant_awq,node_lora_runtime toneTeal
```

## Components

### Control plane

Package initialization, platform detection, and environment-driven feature selection.

- [Package init](https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/__init__.py): python entry · Top-level package initialization and public surface. · `vllm_metal/__init__.py`
- [Config](https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/config.py): runtime config · Repository configuration and defaults. · `vllm_metal/config.py`
- [Env flags](https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/envs.py): feature flags · Environment-based toggles and backend selection. · `vllm_metal/envs.py`
- [Platform](https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/platform.py): platform detect · Apple Silicon and macOS capability detection. · `vllm_metal/platform.py`
- [Compat shims](https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/compat.py): compat layer · Compatibility helpers for vLLM integration. · `vllm_metal/compat.py`

### Core runtime

Main vLLM execution paths for attention, model serving, and distributed coordination.

- [Attention runtime](https://github.com/vllm-project/vllm-metal/tree/main/vllm_metal/attention/runtime): execution core · Selects MHA, MLA, and hybrid attention execution paths. · `vllm_metal/attention/runtime`
- [KV caches](https://github.com/vllm-project/vllm-metal/tree/main/vllm_metal/attention/caches): cache subsystem · KV, MLA, GDN, and turboquant cache implementations. · `vllm_metal/attention/caches`
- [Attention backends](https://github.com/vllm-project/vllm-metal/tree/main/vllm_metal/attention/impls): backend impls · SDPA, MLA, linear attention, and lazy GDN implementations. · `vllm_metal/attention/impls`
- [Patching hooks](https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/attention/patching.py): integration glue · Redirects vLLM attention flows into Metal-backed paths. · `vllm_metal/attention/patching.py`
- [Model runner](https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/v1/model_runner.py): serving runtime · Inference orchestration, batching, and generation control. · `vllm_metal/v1/model_runner.py`
- [Worker](https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/v1/worker.py): execution worker · Worker-side model execution and coordination. · `vllm_metal/v1/worker.py`
- [Lifecycle](https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/v1/model_lifecycle.py): model control · Model setup, teardown, and state management. · `vllm_metal/v1/model_lifecycle.py`
- [Spec decode](https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/v1/spec_decode.py): decoding · Sampling, proposer, and speculative decoding logic. · `vllm_metal/v1/spec_decode.py`
- [Pipeline](https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/distributed/pipeline.py): distributed exec · 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](https://github.com/vllm-project/vllm-metal/tree/main/vllm_metal/metal/kernels_v2): gpu kernels · Prebuilt Metal compute kernels for paging, cache updates, MLA, GDN, and turboquant. · `vllm_metal/metal/kernels_v2`
- [C++ bridge](https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/metal/paged_ops.cpp): native 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](https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/gguf/loader.py): model loader · Loads and adapts GGUF model artifacts. · `vllm_metal/gguf/loader.py`
- [GGUF adapters](https://github.com/vllm-project/vllm-metal/tree/main/vllm_metal/gguf): model glue · Wrappers, source/tensor abstractions, and vLLM integration. · `vllm_metal/gguf`

### Specialized domains

Multimodal and speech-to-text inference paths.

- [Multimodal](https://github.com/vllm-project/vllm-metal/tree/main/vllm_metal/multimodal): adapter stack · Embedding, feature-spec, and model-specific multimodal adapters. · `vllm_metal/multimodal`
- [STT runtime](https://github.com/vllm-project/vllm-metal/tree/main/vllm_metal/stt): speech pipeline · 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](https://github.com/vllm-project/vllm-metal/blob/main/vllm_metal/pytorch_backend/tensor_bridge.py): interop bridge · PyTorch tensor interop with backend representations. · `vllm_metal/pytorch_backend/tensor_bridge.py`
- [AWQ quant](https://github.com/vllm-project/vllm-metal/tree/main/vllm_metal/quant): quantization · AWQ configuration and loading paths. · `vllm_metal/quant`
- [LoRA runtime](https://github.com/vllm-project/vllm-metal/tree/main/vllm_metal/v1/lora): adapter runtime · LoRA model management, PEFT loading, and worker coordination. · `vllm_metal/v1/lora`

## Connections

- 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.
