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 class

PagedKVCacheManagerInterface

PagedKVCacheManagerInterface​

class max.pipelines.kv_cache.PagedKVCacheManagerInterface

source

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)

source

Allocates blocks for a request.

Parameters:

ctx (TextContext)

Return type:

KVTransfer

alloc_dummy()​

abstract alloc_dummy(ctx, replica_idx=0)

source

Claims a dummy request and maps it to the replica’s null block.

Parameters:

Return type:

None

block_count()​

abstract block_count(replica_idx=0)

source

Returns the device KV cache block occupancy for the given replica.

Parameters:

replica_idx (int)

Return type:

BlockCount

chunk_alignment_tokens​

property chunk_alignment_tokens: int

source

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)

source

Pins a request to one replica, which owns it until it is released.

Parameters:

Return type:

None

contains()​

abstract contains(ctx)

source

Returns whether the request is claimed on any replica.

Parameters:

ctx (TextContext)

Return type:

bool

disk_byte_count()​

abstract disk_byte_count()

source

Returns the disk KV tier occupancy in bytes, shared by every replica.

Return type:

ByteCount

effective_max_seq_length​

abstract property effective_max_seq_length: int | None

source

Returns the effective maximum sequence length that can be served by the block manager.

get_device_buffer()​

abstract get_device_buffer(replica_idx)

source

Returns the replica’s KV buffer (single leaf or tree).

Parameters:

replica_idx (int)

Return type:

KVCacheBufferInterface

get_metrics_aggregated()​

abstract get_metrics_aggregated()

source

Returns aggregated metrics across all replicas.

Return type:

KVCacheMetrics

get_prefix_cache_hit_counts()​

abstract get_prefix_cache_hit_counts(ctx)

source

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)

source

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:

dict[str, list[int]]

host_byte_count()​

abstract host_byte_count()

source

Returns the host KV tier occupancy in bytes, shared by every replica.

Return type:

ByteCount

num_req_blocks()​

abstract num_req_blocks(ctx)

source

Returns how many pages long the request is on its claimed replica.

Parameters:

ctx (TextContext)

Return type:

int

params​

params: KVCacheParamInterface

source

pending_transfers_exist()​

abstract pending_transfers_exist(replica_idx=0)

source

Returns whether any async KV transfer is in flight on the replica.

Parameters:

replica_idx (int)

Return type:

bool

poll_transfers()​

abstract poll_transfers()

source

Drains completed async KV transfers (onloads and offloads).

Return type:

None

pressure_pct()​

pressure_pct(replica_idx=0)

source

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.

Parameters:

replica_idx (int)

Return type:

float

release()​

abstract release(ctx)

source

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()

source

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)

source

Gets the graph inputs for per-replica batches of requests.

Parameters:

Return type:

KVCacheInputs[Buffer, Buffer]

runtime_inputs_for_leaf()​

abstract runtime_inputs_for_leaf(batches, *, max_cache_length=None, batch_characteristics=None)

source

Returns runtime_inputs() narrowed to a single leaf cache.

Parameters:

Return type:

tuple[KVCacheInputsPerDevice[Buffer, Buffer], …]

shutdown()​

abstract shutdown()

source

Releases the KV connector’s external resources.

Return type:

None

step()​

abstract step(ctx)

source

Commits the request’s newly written tokens into the prefix cache.

Parameters:

ctx (TextContext)

Return type:

None

take_metrics_aggregated()​

abstract take_metrics_aggregated()

source

Reads and clears aggregated metrics across all replicas.

Return type:

KVCacheMetrics