IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/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. /max/get-started.md).

Python function

spec_decode_cache_slack

spec_decode_cache_slack()

max.nn.kv_cache.spec_decode_cache_slack(params)

source

Computes the extra KV positions a request may occupy past max_seq_len.

A speculative-decode step can over-speculate past the per-request max_seq_len cap into this slack (the KV pool reserves it beyond max_seq_len), so any per-request sizing derived from max_seq_len – the pool’s page budget, the sparse-indexer score scratch, etc. – must add it. Centralized here so _compute_seq_len, pool sizing, and OverlapTextGenerationPipeline._effective_max_cache_length stay in sync.

Parameters:

params (KVCacheParamInterface) – The KV cache parameters. The speculative-decoding fields (num_draft_tokens and num_draft_tokens_per_step) determine the slack.

Returns:

The number of extra KV positions to reserve past max_seq_len, or 0 when speculative decoding is off.

Return type:

int