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
PagedKVCacheManagerInterface
PagedKVCacheManagerInterface
class max.pipelines.kv_cache.PagedKVCacheManagerInterface
Bases: ABC
Interface for the KVCache manager.
This is largely a temporarily class to help phase in the JengaKVCacheManager. We want to delete the legacy PagedKVCacheManager and rename JengaKVCacheManager to PagedKVCacheManager soon.
alloc()
abstract alloc(ctx)
Allocates blocks for a request.
-
Parameters:
-
ctx (TextContext)
-
Return type:
-
KVTransfer
alloc_dummy()
abstract alloc_dummy(ctx, replica_idx=0)
Claims a dummy request and maps it to the replica’s null block.
-
Parameters:
-
- ctx (TextContext)
- replica_idx (int)
-
Return type:
-
None
block_count()
abstract block_count(replica_idx=0)
Returns the device KV cache block occupancy for the given replica.
-
Parameters:
-
replica_idx (int)
-
Return type:
chunk_alignment_tokens
property chunk_alignment_tokens: int
Returns the token multiple a context-encoding chunk ends on.
Zero when no group of this cache needs the alignment.
claim()
abstract claim(ctx, replica_idx=0)
Pins a request to one replica, which owns it until it is released.
-
Parameters:
-
- ctx (TextContext)
- replica_idx (int)
-
Return type:
-
None
contains()
abstract contains(ctx)
Returns whether the request is claimed on any replica.
-
Parameters:
-
ctx (TextContext)
-
Return type:
disk_byte_count()
abstract disk_byte_count()
Returns the disk KV tier occupancy in bytes, shared by every replica.
-
Return type:
effective_max_seq_length
Returns the effective maximum sequence length that can be served by the block manager.
get_device_buffer()
abstract get_device_buffer(replica_idx)
Returns the replica’s KV buffer (single leaf or tree).
-
Parameters:
-
replica_idx (int)
-
Return type:
get_metrics_aggregated()
abstract get_metrics_aggregated()
Returns aggregated metrics across all replicas.
-
Return type:
get_prefix_cache_hit_counts()
abstract get_prefix_cache_hit_counts(ctx)
Counts each replica’s contiguous cached prefix for a request.
-
Parameters:
-
ctx (TextContext)
-
Return type:
-
list[PrefixCacheHits]
get_req_blocks_per_leaf()
abstract get_req_blocks_per_leaf(ctx)
Returns the block IDs the request holds, keyed by leaf id.
Covers the replica the request was claimed on, with one entry per leaf
that KVCacheParamInterface.leaves() names. A manager whose leaves
share one block space repeats the same row under every leaf.
-
Parameters:
-
ctx (TextContext)
-
Return type:
host_byte_count()
abstract host_byte_count()
Returns the host KV tier occupancy in bytes, shared by every replica.
-
Return type:
num_req_blocks()
abstract num_req_blocks(ctx)
Returns how many pages long the request is on its claimed replica.
-
Parameters:
-
ctx (TextContext)
-
Return type:
params
params: KVCacheParamInterface
pending_transfers_exist()
abstract pending_transfers_exist(replica_idx=0)
Returns whether any async KV transfer is in flight on the replica.
poll_transfers()
abstract poll_transfers()
Drains completed async KV transfers (onloads and offloads).
-
Return type:
-
None
pressure_pct()
pressure_pct(replica_idx=0)
Returns how close the replica is to refusing work, in [0, 100].
Defaults to block occupancy. A manager whose blocks are coarser than what a request allocates overrides this.
release()
abstract release(ctx)
Releases the blocks the request holds on the replica it was claimed on.
-
Parameters:
-
ctx (TextContext)
-
Return type:
-
None
reset_prefix_cache()
abstract reset_prefix_cache()
Resets the device prefix caches and every connector’s tiers.
-
Return type:
-
None
runtime_inputs()
abstract runtime_inputs(batches, *, max_cache_length=None, batch_characteristics=None)
Gets the graph inputs for per-replica batches of requests.
-
Parameters:
-
- batches (Sequence[Sequence[TextContext]])
- max_cache_length (int | None)
- batch_characteristics (BatchCharacteristics | None)
-
Return type:
runtime_inputs_for_leaf()
abstract runtime_inputs_for_leaf(batches, *, max_cache_length=None, batch_characteristics=None)
Returns runtime_inputs() narrowed to a single leaf cache.
-
Parameters:
-
- batches (Sequence[Sequence[TextContext]])
- max_cache_length (int | None)
- batch_characteristics (BatchCharacteristics | None)
-
Return type:
shutdown()
abstract shutdown()
Releases the KV connector’s external resources.
-
Return type:
-
None
step()
abstract step(ctx)
Commits the request’s newly written tokens into the prefix cache.
-
Parameters:
-
ctx (TextContext)
-
Return type:
-
None
take_metrics_aggregated()
abstract take_metrics_aggregated()
Reads and clears aggregated metrics across all replicas.
-
Return type: