Skip to content

vllm.config.cache

Classes:

Functions:

CacheConfig

Configuration for the KV cache.

Methods:

  • compile_factors –

    WARNING: Whenever a new field is added to this config, add it to

Attributes:

_block_size_resolved = field(default=False, init=False) class-attribute instance-attribute

Guard against pydantic re-running _apply_block_size_default.

_extensible_kv_cache_resolved = field(default=False, init=False) class-attribute instance-attribute

Set once enable_extensible_kv_cache has been settled for the model.

block_size = Field(default=None, gt=0) class-attribute instance-attribute

Size of a contiguous cache block in number of tokens. Accepts None (meaning "use default"). After construction, always int.

cache_dtype = 'auto' class-attribute instance-attribute

Data type for kv cache storage. If "auto", will use model data type. An explicit float16 or bfloat16 must match the model data type. Custom dtypes can registered by platform backends via register_kv_cache_dtype are accepted (see vllm.config.cache). CUDA 11.8+ supports fp8 (=fp8_e4m3) and fp8_e5m2. ROCm (AMD GPU) supports fp8 (=fp8_e4m3). Intel Gaudi (HPU) supports fp8 (using fp8_inc). Some models (namely DeepSeekV3.2) default to fp8, set to bfloat16 to use bfloat16 instead, this is an invalid option for models that do not default to fp8. "nvfp4_4over6" uses the NVFP4 layout and selects between max/6 and max/4 scales per 16 values by minimizing squared reconstruction error.

cache_hit_alignment_tokens = field(default=None, init=False) class-attribute instance-attribute

Token granularity at which prefix-cache hits land: hash_block_size with partial hash hits, otherwise the scheduler block size.

device_memory_utilization property writable

Device-neutral alias for gpu_memory_utilization.

effective_attention_block_size = field(default=None, init=False) class-attribute instance-attribute

Full-attention block size in tokens, including DCP, or None if unavailable.

enable_extensible_kv_cache = Field(default=None) class-attribute instance-attribute

Reserve the KV cache address range with device virtual memory and commit physical pages after warmup, so the cache is sized from the memory actually free after CUDA graph capture rather than from a profiling estimate. If unspecified, enabled on CUDA and ROCm unless kv_cache_memory_bytes is set, or NIXL on device memory has no IMEX channel; falls back to estimate-based sizing where the driver lacks VMM support. Explicitly requesting it where unsupported is an error. On unpartitioned discrete ROCm GPUs, the sizing adds back free memory that HIP hides by counting each allocation as at least 2 MiB, so gpu_memory_utilization bounds exact device memory use there. When a KV connector registers the KV cache for RDMA or exports it to another process, each segment is backed by a single physical allocation; connectors declare this by overriding KVConnectorBase_V1.kv_cache_access.

enable_mamba_shared_prefix_checkpoint = False class-attribute instance-attribute

Also register a Mamba checkpoint at the shared-prefix junction -- where a sibling request was observed to resume -- instead of only at the prompt tail. Off by default; only takes effect with prefix caching enabled and a prefix match unit smaller than the Mamba block size.

enable_prefix_caching = True class-attribute instance-attribute

Whether to enable prefix caching.

gpu_memory_utilization = Field(default=None, gt=0, le=1) class-attribute instance-attribute

The fraction of GPU memory to be used for the model executor, which can range from 0 to 1. For example, a value of 0.5 would imply 50% GPU memory utilization. This is a per-instance limit, and only applies to the current vLLM instance. It does not matter if you have another vLLM instance running on the same GPU. For example, if you have two vLLM instances running on the same GPU, you can set the GPU memory utilization to 0.5 for each instance. On non-GPU installs, this value controls the corresponding device memory utilization.

If unspecified, 1.0 with the extensible KV cache (sized from measured memory) and 0.92 otherwise; see resolved_gpu_memory_utilization.

With the extensible KV cache (the default on CUDA and ROCm), leave this unset unless something needs memory that vLLM does not measure: other processes sharing the GPU (including ones that allocate after vLLM has started), unified-memory devices whose memory the CPU also uses, weight transfer buffers for weight updates, or KV connectors that allocate their own device buffers. A lower value takes memory away from the KV cache.

hash_block_size = field(default=None, init=False) class-attribute instance-attribute

Tokens per prefix-cache block hash.

is_attention_free = False class-attribute instance-attribute

Whether the model is attention-free. This is primarily set in ModelConfig and that value should be manually duplicated here.

kv_cache_dtype_skip_layers = field(default_factory=list) class-attribute instance-attribute

Layer patterns to skip KV cache quantization. Accepts layer indices (e.g., '0', '2', '4') or attention type names (e.g., 'sliding_window').

kv_cache_layout = field(default=None, init=False) class-attribute instance-attribute

Resolved physical KV cache layout name (a KVCacheLayout member).

None means the layout has not been resolved yet. The engine core resolves it once (resolve_kv_cache_layout) before memory profiling, and every worker process adopts the resolved name — via the set_kv_cache_layout RPC, or KVCacheConfig.kv_cache_layout for workers spawned after resolution — before the KV cache is allocated. Once set the value is final and read with get_resolved_kv_cache_layout, which raises on None. Tests and standalone tools may pre-set a value, which resolution then honors as-is.

kv_cache_max_concurrency = field(default=None, init=False) class-attribute instance-attribute

Per-DP-engine maximum concurrency at max_model_len tokens.

kv_cache_memory_bytes = None class-attribute instance-attribute

Size of KV Cache per GPU in bytes. By default, this is set to None and vllm can automatically infer the kv cache size based on gpu_memory_utilization. However, users may want to manually specify the kv cache memory size. kv_cache_memory_bytes allows more fine-grain control of how much memory gets used when compared with using gpu_memory_utilization. Note that kv_cache_memory_bytes (when not-None) ignores gpu_memory_utilization

kv_cache_size_tokens = field(default=None, init=False) class-attribute instance-attribute

Per-DP-engine KV cache capacity in tokens (group-aware). Uses group-aware capacity since num_gpu_blocks * block_size can be wrong for hybrid models where requests occupy multiple KV cache groups.

kv_offloading_backend = 'native' class-attribute instance-attribute

The backend to use for KV cache offloading. Supported backends include 'native' (vLLM native CPU offloading), 'lmcache'. KV offloading is only activated when kv_offloading_size is set.

kv_offloading_size = None class-attribute instance-attribute

Size of the KV cache offloading buffer in GiB. When TP > 1, this is the total buffer size summed across all TP ranks. By default, this is set to None, which means no KV offloading is enabled. When set, vLLM will enable KV cache offloading to CPU using the kv_offloading_backend.

kv_sharing_fast_prefill = False class-attribute instance-attribute

In some KV sharing setups, e.g. YOCO (https://arxiv.org/abs/2405.05254), some layers can skip tokens corresponding to prefill. This flag enables attention metadata for eligible layers to be overridden with metadata necessary for implementing this optimization in some models (e.g. Gemma3n). In Model Runner V2, batches containing LoRA requests use regular prefill; batches without LoRA requests can still use fast prefill.

mamba_block_size = Field(default=None, gt=0) class-attribute instance-attribute

Size of a contiguous cache block in number of tokens for mamba cache. Can be set only when prefix caching is enabled.

mamba_cache_dtype = 'auto' class-attribute instance-attribute

The data type to use for the Mamba cache (both the conv as well as the ssm state). If set to 'auto', the data type will be inferred from the model config.

mamba_page_size_padded = None class-attribute instance-attribute

Optional override for mamba page size; used by hybrid mamba/attention models to ensure exact alignment with attention page size.

mamba_ssm_cache_dtype = 'auto' class-attribute instance-attribute

The data type to use for the Mamba cache (ssm state only, conv state will still be controlled by mamba_cache_dtype). If set to 'auto', the data type for the ssm state will be determined by mamba_cache_dtype.

num_cpu_blocks = field(default=None, init=False) class-attribute instance-attribute

The number of blocks to allocate for CPU memory.

num_gpu_blocks = field(default=None, init=False) class-attribute instance-attribute

The number of blocks to allocate for GPU memory.

num_gpu_blocks_override = None class-attribute instance-attribute

Number of GPU blocks to use. This overrides the profiled num_gpu_blocks if specified. Does nothing if None. Used for testing preemption.

prefix_cache_retention_interval = Field(default=0, ge=0) class-attribute instance-attribute

Token interval between retained sliding-window and Mamba prefix-cache checkpoints. 0 retains only semantic checkpoints, including the latest replay boundary and shared-prefix junctions. Positive values additionally retain periodic checkpoints at the specified interval, which must be a multiple of the scheduler block size. None retains checkpoints densely. Applies only to sliding-window and Mamba cache groups.

prefix_caching_hash_algo = 'sha256' class-attribute instance-attribute

Set the hash algorithm for prefix caching:

  • "sha256" uses Pickle for object serialization before hashing. This is the current default, as SHA256 is the most secure choice to avoid potential hash collisions.
  • "sha256_cbor" provides a reproducible, cross-language compatible hash. It serializes objects using canonical CBOR and hashes them with SHA-256.
  • "xxhash" uses Pickle serialization with xxHash (128-bit) for faster, non-cryptographic hashing. Requires the optional xxhash package. IMPORTANT: Use of a hashing algorithm that is not considered cryptographically secure theoretically increases the risk of hash collisions, which can cause undefined behavior or even leak private information in multi-tenant environments. Even if collisions are still very unlikely, it is important to consider your security risk tolerance against the performance benefits before turning this on.
  • "xxhash_cbor" combines canonical CBOR serialization with xxHash for reproducible hashing. Requires the optional xxhash package.

prefix_match_unit = Field(default=None, gt=0) class-attribute instance-attribute

The finest token boundary (in tokens) a prefix-cache hit can land on.

Prefix-cache keys are computed every prefix_match_unit tokens. It can be set finer than the physical KV cache block sizes (e.g. 32 vs a 1024-token hybrid-model block) as long as every KV cache group's block_size is divisible by it, enabling cache hits at boundaries inside a physical block. It controls matching granularity only, not how often states are stored.

An explicit value fails at startup if prefix-cache hits would fall back to the scheduler block size (for example, when a sliding-window group requires block-aligned lookups).

This equals to the hash_block_size used throughout the KV cache code.

replayssm_buffer_len = Field(default=16, gt=0) class-attribute instance-attribute

ReplaySSM logical history length B. Mamba2 Triton standard decode and Gated DeltaNet (Qwen3.5, Qwen4Exp) use B physical rows, at most 32 for Gated DeltaNet; FlashInfer and Triton speculative decoding use B+T, where T is the target verification length. Kimi-K3 speculative decode does not use B. Default 16.

resolved_gpu_memory_utilization property

gpu_memory_utilization, or its default given the sizing mode.

skip_page_size_padded = None class-attribute instance-attribute

Optional override for the page size of layers skipped from KV cache quantization (--kv-cache-dtype-skip-layers); set during block-size alignment so unquantized skip layers pad up to the quantized primary's page.

sliding_window = None class-attribute instance-attribute

Sliding window size for the KV cache. This is primarily set in ModelConfig and that value should be manually duplicated here.

swa_bounded_replay = True class-attribute instance-attribute

Keep the sliding-window KV of models that support it (DeepSeek-V4.1) out of prefix caching and rebuild it after a prefix hit by recomputing the hit's last window. The layers past the last KV-source layer then also run eager prefill steps on each request's trailing window only. Requires model runner V2.

use_kda_recoverssm = field(default=False, init=False) class-attribute instance-attribute

Whether Kimi-K3 KDA uses RecoverSSM speculative decode.

use_replayssm = False class-attribute instance-attribute

Use the ReplaySSM decode kernels for Mamba2 and Gated DeltaNet (Qwen3.5, Qwen4Exp): cache recent SSM inputs and skip the per-step full-state store, writing the checkpoint back only on flush. Triton and FlashInfer support Mamba prefix caching on and off. Mamba2 speculative decoding supports both backends; Gated DeltaNet supports Triton standard decode only. Pipeline parallelism is not supported. Flushes are most efficient when mamba_block_size is a multiple of replayssm_buffer_len, but this is not required.

user_specified_block_size = field(default=False, init=False) class-attribute instance-attribute

Whether block_size was explicitly provided. Derived automatically.

compile_factors()

WARNING: Whenever a new field is added to this config, add it to ignored_factors if it does not affect the computation graph.

Provide a hash that uniquely identifies all the configs that affect the structure of the computation graph from input ids/embeddings to the final hidden states, excluding anything before input ids/embeddings and after the final hidden states.

KVCacheDTypeHandler

Bases: Protocol

Contract for a custom --kv-cache-dtype value.

A platform backend implements this protocol to answer the questions vLLM currently answers with closed tables (STR_DTYPE_TO_TORCH_DTYPE / get_kv_quant_mode / is_quantized_kv_cache). A single handler may be device-aware (e.g., resolving different torch dtypes per device generation).

Methods:

  • quant_mode –

    The KVQuantMode used by generic kernels.

  • torch_dtype –

    Storage dtype for KV cache tensors.

quant_mode()

The KVQuantMode used by generic kernels.

Return an existing mode to reuse generic kernel paths, or KVQuantMode.CUSTOM when the backend fully self-manages kernel dispatch.

torch_dtype()

Storage dtype for KV cache tensors.

Called once at registration time; the result is injected into the shared STR_DTYPE_TO_TORCH_DTYPE dict so existing consumers need no changes. The device must already be resolvable (registration runs at platform activation time).

get_kv_cache_dtype_handler(name)

Return the handler for name.

Returns None for upstream dtypes that have no handler (the dtype table already covers these).

is_known_kv_cache_dtype(name)

Whether name is a valid --kv-cache-dtype value.

register_kv_cache_dtype(name)

Register a custom --kv-cache-dtype value (eager decorator).

Runs at platform activation time (first current_platform access), which is after --help exits and before any KV cache tensor is allocated. During decoration the handler will:

  • append name to the mutable KV_CACHE_DTYPES list (driving Pydantic + CLI validation);
  • resolve torch_dtype() once and inject it into STR_DTYPE_TO_TORCH_DTYPE, so all existing dict[name] / name in dict sites need zero changes;
  • be stored for later quant_mode() queries.

Examples:

>>> @register_kv_cache_dtype("int8")
... class Int8Handler:
...     name = "int8"
...
...     def torch_dtype(self):
...         return torch.int8
...
...     def quant_mode(self):
...         return KVQuantMode.CUSTOM