Skip to main content

vLLM — Extension & Plugin System

9.1 Python Entry Point Plugin System

Location: vllm/plugins/__init__.py

Plugin Groups

vLLM uses Python importlib.metadata.entry_points() for plugin discovery. Four plugin groups are defined:

Group NameLoaded InPurpose
vllm.general_pluginsAll processesGeneral-purpose plugins (loaded in API server, engine core, and workers)
vllm.io_processor_pluginsProcess 0 onlyI/O processor extensions
vllm.platform_pluginsAll processesPlatform-specific plugins (loaded when current_platform is first accessed)
vllm.stat_logger_pluginsProcess 0 onlyCustom stats logger implementations

Plugin Discovery

def load_plugins_by_group(group: str) -> dict[str, Callable[[], Any]]:
from importlib.metadata import entry_points
discovered_plugins = entry_points(group=group)
# Filter by VLLM_PLUGINS env var if set
# Load matching plugins and return dict[name, callable]

Access control:

  • VLLM_PLUGINS environment variable restricts which plugins are loaded
  • If VLLM_PLUGINS is not set, all discovered plugins are loaded
  • If set, only listed plugin names are loaded

Creating a Plugin

To create a vLLM plugin:

  1. Create a Python package with an entry point in pyproject.toml:
[project.entry-points."vllm.general_plugins"]
my_plugin = "my_package.vllm_plugin:register"
  1. Implement the registration function:
def register():
# Register custom components, hooks, etc.
pass
  1. Install the package: pip install my_plugin_package

9.2 Attention Backend Registry

Location: vllm/v1/attention/backends/registry.py

Mechanism

Attention backends are registered by name and selected at startup based on hardware, model architecture, and user configuration.

Available backends:

BackendFileHardwareNotes
flash_attnflash_attn.pyNVIDIA GPUFlashAttention-2, default for CUDA
flashinferflashinfer.pyNVIDIA GPUFlashInfer library
rocm_attnrocm_attn.pyAMD GPUROCm attention
rocm_aiter_farocm_aiter_fa.pyAMD GPUAITER FlashAttention for ROCm
cpu_attncpu_attn.pyCPUx86 CPU attention
triton_attntriton_attn.pyNVIDIA GPUTriton-based attention
tree_attntree_attn.pyNVIDIA GPUTree attention for speculative decoding
flex_attentionflex_attention.pyNVIDIA GPUPyTorch flex attention (SDPA)
linear_attnlinear_attn.pyAnyLinear attention models
mamba1_attnmamba1_attn.pyAnyMamba 1 SSM
mamba2_attnmamba2_attn.pyAnyMamba 2 SSM
mamba_attnmamba_attn.pyAnyMamba (generic)
mla/*mla/NVIDIA GPUMulti-head Latent Attention (DeepSeek)
short_conv_attnshort_conv_attn.pyAnyShort convolution attention

Selection Logic

The platform-specific registry selects the best available backend based on:

  1. User override via VLLM_ATTENTION_BACKEND env var
  2. Hardware platform (CUDA → flash_attn, ROCm → rocm_attn, CPU → cpu_attn)
  3. Model architecture requirements (Mamba → mamba_attn, MLA → mla)

9.3 Structured Output Backends

Location: vllm/v1/structured_output/

Mechanism

StructuredOutputManager selects a backend at initialization based on StructuredOutputsConfig:

BackendFileDescription
xgrammarbackend_xgrammar.pyXGrammar engine (C++ based, fast)
outlinesbackend_outlines.pyOutlines library
guidancebackend_guidance.pyGuidance library
lm-format-enforcerbackend_lm_format_enforcer.pyLM Format Enforcer

Interface: StructuredOutputBackend — abstract class with:

  • compile_grammar() — compile a structured output spec into a grammar object
  • allocate_token bitmask() — get a bitmask for the next token to enforce grammar constraints

Async compilation: Grammar compilation can happen asynchronously in a thread pool (disabled for external_launcher mode due to determinism requirements across TP ranks).


9.4 Model Architecture Registry

Location: vllm/model_executor/models/ (100+ model implementations)

Mechanism

Each model file registers itself via _MODELS dict or auto-discovery. New models are added by:

  1. Creating a new file in vllm/model_executor/models/
  2. Implementing the model class following the vLLM conventions:
    • Inherit from nn.Module
    • Use vLLM's custom linear layers (ColumnParallelLinear, RowParallelLinear, etc.)
    • Implement forward() with attn_metadata parameter
  3. Register in __init__.py

9.5 Tool Parser Extension

Location: vllm/entrypoints/tool_parsers/

Mechanism

Tool parsers convert model output into structured tool calls for the chat completions and responses APIs.

Registration: ToolParserManager.import_tool_parser() — dynamically imports a custom tool parser.

Built-in parsers: Various model-specific parsers (e.g., for function calling formats).

Custom parser: Can be loaded via --tool-parser-plugin CLI flag.


9.6 Reasoning Parser Extension

Location: vllm/reasoning/

Mechanism

Reasoning parsers handle "thinking" output from reasoning models (e.g., DeepSeek-R1).

Registration: ReasoningParserManager.import_reasoning_parser() — dynamically imports a custom parser.

Custom parser: Can be loaded via --reasoning-parser-plugin CLI flag.


9.7 Speculative Decoding Extensions

Location: vllm/v1/spec_decode/

Multiple speculative decoding strategies are implemented as pluggable components:

StrategyFileDescription
n-gramngram_proposer.py, ngram_proposer_gpu.pyn-gram lookup for draft tokens
Eagleeagle.pyEagle speculative decoding head
Medusamedusa.pyMedusa multi-head speculative decoding
Draft modeldraft_model.pySmall draft model for speculative decoding
Suffix decodingsuffix_decoding.pySuffix-based draft token generation
dFlashdflash.pyFlash-based speculative decoding

9.8 Quantization Method Registry

Location: vllm/model_executor/layers/quantization/

20+ quantization methods are supported as pluggable backends:

MethodFileDescription
FP8fp8.pyFP8 weight/KV cache quantization
AWQawq.py, awq_marlin.pyActivation-aware weight quantization
GPTQgptq.py, gptq_marlin.pyGPTQ weight quantization
BitsAndBytesbitsandbytes.pyNF4/int8 BnB quantization
GGUFgguf.pyGGUF quantized formats
FBGEMM FP8fbgemm_fp8.pyFBGEMM FP8 kernels
ModelOptmodelopt.pyNVIDIA ModelOpt quantization
Compressed Tensorscompressed_tensors/Neural Magic compressed format
INT8 Expertsexperts_int8.pyINT8 MoE expert quantization
KV Cache Quantkv_cache.pyKV cache quantization (FP8, INT8, NVFP4)

Each quantization method implements a QuantizationConfig subclass that defines how weights are loaded and which custom kernels are used.