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

KVCacheMemory

KVCacheMemory

class max.nn.kv_cache.KVCacheMemory(replicated, buffers)

source

Bases: object

One logical (child, kind) KV tensor as per-TP-shard uint8 views.

A unit is one logical tensor — a cache’s values or its scales — holding a 2-D [num_pages, bytes_per_page] view per TP shard in canonical device order.

replicated indicates that all buffers hold identical bytes. This is true for certain cases like TP + MLA, TP + MiniMaxM3IndexerAttn, etc.

Parameters:

buffers

buffers: list[Buffer]

source

bytes_per_page

property bytes_per_page: int

source

Returns the per-page byte stride shared by every shard.

host_bytes_per_page

property host_bytes_per_page: int

source

Returns the width of one host block row holding this unit’s page.

A replicated (MLA) unit contributes its stride once – one copy is stored and broadcast back on load, so counting its peers would double the pinned host allocation. Must match across replicas, so a block written by one is readable by another.

replicated

replicated: bool

source

total_num_pages

property total_num_pages: int

source

Returns the total number of pages (including the null block).