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 class
KVCacheParamInterface
KVCacheParamInterface
class max.nn.kv_cache.KVCacheParamInterface(*args, **kwargs)
Bases: Protocol
Interface for KV cache parameters.
allocate_buffers()
allocate_buffers(total_num_pages)
Allocates the buffers for the KV cache.
build_runtime_inputs()
build_runtime_inputs(assignments, buffers, _prefix='')
Builds the runtime KV-cache inputs spanning all replicas.
assignments and buffers are indexed by data-parallel replica.
Returns a single KVCacheInputs leaf (or a
MultiKVCacheInputs tree) whose leaves each hold every
(replica, TP shard) device’s inputs.
bytes_per_block
property bytes_per_block: int
Number of bytes per cache block.
data_parallel_degree
data_parallel_degree: int
Degree of data parallelism.
devices
Devices to use for the cache.
enable_dp_cross_replica_prefix_copy
property enable_dp_cross_replica_prefix_copy: bool
Whether a prefix-cache hit resident on another data-parallel replica’s device may be served by a device-to-device copy.
enable_prefix_caching
property enable_prefix_caching: bool
Whether prefix caching is enabled.
flattened_kv_inputs()
flattened_kv_inputs()
Flattens the symbolic inputs for the KV cache.
-
Return type:
get_symbolic_inputs()
get_symbolic_inputs(namespace='')
Returns the symbolic inputs for the KV cache.
-
Parameters:
-
namespace (str) – Prefix that disambiguates this cache’s page-pool symbolic dim from sibling caches in a multi-group tree. Empty for a single-group cache, leaving its names unchanged.
-
Return type:
-
KVCacheInputsInterface[TensorType, BufferType]
graph_capture_probe_cache_lengths()
graph_capture_probe_cache_lengths(max_cache_length, q_max_seq_len=1)
Returns the cache lengths to probe during decode graph capture.
kv_connector_config
kv_connector_config: KVConnectorConfigInterface
The KV connector’s type and settings.
kv_hash_algo
property kv_hash_algo: Literal['ahash64', 'sha256', 'sha256_64']
Hash algorithm used for KV-cache block identity.
kv_hash_seed
Resolved 32-byte cluster seed for sha256/sha256_64.
None for ahash64.
leaves()
leaves(_prefix='')
Returns the leaves of the KV cache.
n_devices
property n_devices: int
Returns the total number of devices.
num_draft_tokens
num_draft_tokens: int = 0
num_draft_tokens_per_step
property num_draft_tokens_per_step: int
Number of draft tokens written per draft forward.
Zero when speculative decoding is disabled; one for autoregressive
drafts (eagle, mtp); equal to num_draft_tokens for block
drafts (dflash, dflash2).
page_size
page_size: int
Number of tokens per page (block).
replicates_kv_across_tp
property replicates_kv_across_tp: bool
Whether every device holds identical KV state.
resolve_attn_key()
resolve_attn_key(batch_size, max_prompt_length, max_cache_valid_length)
Resolves the decode dispatch shape for the given shape.
Returns an AttnKeyInterface for a single cache, or a
MultiAttnKey tree mirroring the cache tree.
-
Parameters:
-
Return type:
slab_to_buffer_views()
slab_to_buffer_views(buffers)
Converts a slab of memory into a buffer view.
speculative_method
speculative_method: Literal['eagle', 'mtp', 'dflash', 'dflash2'] | None = None
tensor_parallel_degree
property tensor_parallel_degree: int
Returns the tensor parallel degree.
unflatten_basic_kv_tree()
unflatten_basic_kv_tree(it)
Unflattens a basic KV tree from a graph-input iterator.
Requires that the model is a basic height-1 tree. This method does not work on nested trees.
-
Parameters:
-
Return type:
-
tuple[list[KVCacheInputsPerDevice[TensorValue, BufferValue]], …]
unflatten_kv_inputs()
unflatten_kv_inputs(it)
Unflattens the symbolic inputs for the KV cache.
-
Parameters:
-
Return type:
-
KVCacheInputsInterface[TensorValue, BufferValue]