approximateprefix

package
v0.9.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

README

Approximate Prefix Cache Producer Plugin

Type: approx-prefix-cache-producer

Prepares per-endpoint prefix cache match data consumed by the prefix-cache-affinity-filter and prefix-cache-scorer. Runs in the request handling's DataProducer phase before scheduling.

For each request, the plugin consumes request.Body.TokenizedPrompt (token IDs), hashes the token IDs into fixed-size blocks, and looks up which endpoints have recently served requests with a matching prefix. It writes a PrefixCacheMatchInfo attribute onto each candidate endpoint, then records the selected endpoint(s) in the index after scheduling completes (via PreRequest).

TokenizedPrompt is produced by a token-producer. When none is configured, the framework auto-creates one with the tokenizer-free estimate backend, so prefix caching works without extra setup; configure a token-producer explicitly to select the vLLM /render backend.

Parameters:

  • autoTune (bool, optional, default: true): Infer blockSizeTokens and lruCapacityPerServer from endpoint metrics when available.
  • blockSizeTokens (int, optional, default: 16): Prefix block size in tokens. Used when autoTune is false or endpoint metrics are unavailable; ignored when auto-tuned from metrics. Values below the minimum of 64 are clamped up at request time (see #1158), so the 16 default is effectively 64 absent a larger metric/configured value.
  • maxPrefixBlocksToMatch (int, optional, default: 2048): Maximum number of prefix blocks hashed and matched per request. Not auto-tuned. 0 disables matching (zero blocks hashed).
  • maxPrefixTokensToMatch (int, optional, default: 131072): Cap expressed in tokens instead of blocks (maxBlocks = maxPrefixTokensToMatch / blockSizeTokens). Not auto-tuned. Takes precedence over maxPrefixBlocksToMatch when set (> 0); set to 0 to fall back to the block-based cap. The 131072 default (128K, the context window of large production models such as gpt-oss 120b) is a reasonable upper bound that covers the long-prompt use cases seen in production.
  • lruCapacityPerServer (int, optional, default: 31250): Per-pod LRU index capacity. Used when autoTune is false or endpoint metrics are unavailable; ignored when auto-tuned from metrics.
  • blockSize (int, optional): Deprecated — character-based block size. Use blockSizeTokens instead.

Configuration Examples:

Standard single instance:

plugins:
  - type: approx-prefix-cache-producer
    parameters:
      autoTune: true
      lruCapacityPerServer: 1000

Configuring multiple named instances (e.g., for tiered caching with different parameters):

plugins:
  - name: gpuPrefixProducer
    type: approx-prefix-cache-producer
    parameters:
      blockSizeTokens: 16
  - name: cpuPrefixProducer
    type: approx-prefix-cache-producer
    parameters:
      blockSizeTokens: 64
  - name: gpuPrefixScorer
    type: prefix-cache-scorer
    parameters:
      prefixMatchInfoProducerName: gpuPrefixProducer
  - name: cpuPrefixScorer
    type: prefix-cache-scorer
    parameters:
      prefixMatchInfoProducerName: cpuPrefixProducer

Documentation

Index

Constants

View Source
const (
	ApproxPrefixCachePluginType = approxprefixconstants.ApproxPrefixCachePluginType
)

Variables

This section is empty.

Functions

func ApproxPrefixCacheFactory

func ApproxPrefixCacheFactory(name string, rawParameters *json.Decoder, handle plugin.Handle) (plugin.Plugin, error)

ApproxPrefixCacheFactory is the factory function for the prefix cache data producer plugin.

Types

type HashBlock

type HashBlock struct {
	// Tokens are the token IDs covered by this block.
	Tokens []uint32
}

HashBlock wraps a block of token IDs used for calculating prefix hashes.

func (HashBlock) Hash

func (b HashBlock) Hash() uint64

Hash computes a stable unique identifier for the HashBlock content.

type SchedulingContextState

type SchedulingContextState struct {
	// PerPromptHashes holds the prefix hashes for each prompt in the request,
	// one inner slice per prompt. Single-prompt requests use a length-1 outer slice.
	PerPromptHashes [][]blockHash
	// A map of server to its longest prefix cache match length in blocks.
	PrefixCacheServers map[ServerID]int
}

SchedulingContextState is the state of this plugin to be used during a scheduling cycle.

func (*SchedulingContextState) Clone

Clone creates a deep copy of the SchedulingContextState.

type ServerID

type ServerID k8stypes.NamespacedName

ServerID is a unique identifier for a server, based on its NamespacedName.

func (ServerID) String

func (s ServerID) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL