IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).

Python module

max.nn.kv_cache

Cache configuration

KVCacheBufferA collection of KVCache buffers for one data-parallel replica.
KVCacheParamInterfaceA cache leaf a model reads through an attention op.
KVCacheParamsConfiguration parameters for key-value cache management in transformer models.
MHAKVCacheParams
MLAKVCacheParams
MSAKVCacheParams
KVCacheQuantizationConfigConfiguration for KVCache quantization.
KVConnectorTypeIdentifies which off-device backing store the KV cache uses.
KVCacheMemoryOne logical (child, kind) KV tensor as per-TP-shard uint8 views.
MultiKVCacheParamsAggregates multiple cache parameter sets into a recursive tree.

Cache inputs

KVCacheInputsSymbolic graph input types for a leaf KV cache.
KVCacheInputsPerDeviceSymbolic graph input types for a single device's paged KV cache.
BatchCharacteristicsUpper-bound batch shape used to prepare decode attention metadata.
PagedCacheValuesalias of KVCacheInputsPerDevice[TensorValue, BufferValue]

Attention dispatch

AttnKeyA resolved decode-attention dispatch shape.
MHAAttnKeyDecode dispatch metadata for multi-head attention (MHA).
MLAAttnKeyDecode dispatch metadata for multi-latent attention (MLA).
MSAAttnKeyDecode dispatch metadata for multi-step attention (MSA).

Metrics

KVCacheMetricsMetrics for the KV cache.

Functions

build_max_lengths_tensorsBuilds two [1] uint32 scalar buffers of maximum lengths.
compute_max_seq_len_fitting_in_cacheComputes the maximum sequence length that can fit in the available memory.
compute_num_device_blocksComputes the number of blocks that can be allocated based on the available cache memory.
estimated_memory_sizeComputes the estimated memory size of the KV cache used by all replicas.
spec_decode_cache_slackComputes the extra KV positions a request may occupy past max_seq_len.