mlx-bun library API
    Preparing search index...

    Quantized rotating (sliding-window) KV cache — port of optiq runtime/kv/rotating.py RotatingQuantizedKVCache with keep=0 (gemma4's configuration): RotatingKVCache's ring mechanics over (packed, scales, biases) triples, storage convention identical to QuantizedKVCache. Returns ACTIVE QUANTIZED SLICES — the oracle's module docstring claims dequantize-on-read, but its code does not (port follows the code). optiq's producer-registry

    • SDPA patches are unnecessary here: our SharedKv carries groupSize/bits through the donor→sharer plumbing explicitly.

    Built empty, it quantizes from token zero, unlike the served path's Bf16FirstRotatingQuantizedKVCache, so its first chunk's numbers differ.

    Reads: the sliding window is maxSize, the window every graph passes for the layers it gives this cache. Decode writes in place at the ring head and attends the whole ring with no mask (eviction enforces the window). A window writes by concatenation, in temporal order, under the bottom-right causal matrix with the window kernel, or createCausalMask with the sliding window and the masked-window kernel once the window binds. The kernels are fixed at construction. Today the graphs' updateAndFetchQuantized picks the in-place write for one position and quantizedSdpa picks the unfused port for one query, so a one-row window concatenates here (the same keys, in another order once the ring wraps) and takes the window kernel.

    Hierarchy (View Summary)

    Implements

    Index
    bits: number
    groupSize: number
    kernels: AffineKernels

    The kernel of each read.

    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.

    maxSize: number
    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
    ringIdx: number = 0

    Ring write index (oracle _idx); public so toQuantized replay and persistence can carry it.

    ropeOffsetArr?: MlxArray

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

    values: QuantizedTensor | null = null
    STEP: 256
    • 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
      • bypass: boolean = false

      Returns void