mlx-bun library API
    Preparing search index...

    Quantized KV cache — port of mlx-lm QuantizedKVCache: keys/values stored as (packed u32, scales, biases) triples, quantized along head_dim. Only full-attention layers convert (mlx-lm's rotating-cache quantization is NYI upstream; sliding layers are window-capped anyway).

    Built empty, it quantizes from token zero: the first append is read quantized, so the first chunk's numbers differ from today's served path and mlx-lm's, which read it bf16 (Bf16FirstQuantizedKVCache).

    Reads: each named read appends through updateAndFetchQuantized and attends the fetched prefix with the kernel kernels fixed for it at construction: decode with no mask, a window under the bottom-right causal matrix. The composition names the set (composedAffineKernels: tiled-causal for --kv-quant config and --fused-sdpa on, unfused otherwise). The committed read is quantizedAppendAttention. This cache has no sliding window (graphs compose RotatingQuantizedKVCache for sliding layers).

    Implements

    Index
    bits: number
    groupSize: number
    kernels: AffineKernels

    The kernel of each read. Row layouts made from this cache keep them.

    keys: QuantizedTensor | null = null
    masks: AttentionMasks = ...

    The per-forward masks of the model this cache belongs to. Row layouts made from this cache (state/layout) share them.

    minimumReusableOffset?: number

    Earliest prefix whose retained representation can resume generation. Irreversible transitions may preserve bytes while invalidating older precision boundaries. Reuse policy must not trim below this offset.

    offset: number = 0
    ropeOffsetArr?: MlxArray

    Set only by compiled-decode trace adapters (see Cache).

    values: QuantizedTensor | null = null
    STEP: 256
    • Window: L new positions per row, causal within the window, for prefill chunks, prefill tails and speculative verify windows. Query i of a row sees the row's earlier valid positions and window positions 0..i, limited to the cache's sliding window. Left padding and prepared prefill padding are never visible. Outputs at padded query positions are unspecified and the caller ignores them. To append context without attending, make this call and dispose the read unused.

      Parameters

      Returns AttentionRead

    • Stable storage identity for compatibility guards and persistence. REQUIRED: every capability predicate (isPlainKvCache, isRotating*, packages/inference/src/state/persistence.ts codecs) is a string compare on this value, so a missing override used to fail OPEN into wrong routing (PRs #42/#43: BatchedRotatingCache shipped without one and batched joins dropped running rows). Wrappers report their own kind plus the inner kind.

      Returns string

    • Drop the last n tokens (future writes overwrite them). bypass (default false → unchanged behavior) skips the isTrimmable guard for the speculative-decode rollback case (trim the last n ≤ γ tips right after a

      1 concat write); rotating caches then physically shrink the buffer tail.

      Parameters

      • n: number

      Returns void