mlx-bun library API
    Preparing search index...

    Batched ring over quantized triples — mlx-lm BatchRotatingKVCache mechanics (see batched-rotating.ts) with RotatingQuantizedKVCache storage. Scalar ring state (ringIdx/offset reuse the base fields); per-row offsetArr (absolute positions → RoPE) and leftPad.

    Reads: the sliding window is maxSize. Decode, which runs with no prefill padding pending (finalize first), writes one position in place at the ring head; a window writes by concatenation, which also serves padded prefill chunks. Each attends under mlx-lm's batched rotating mask (buildBatchedRotatingMask) for its write, built once per forward through masks, with the decode and masked-window kernels of kernels: that mask is always an array, which quantizedSdpa never tiles, so the unfused kernel both composed sets hold there is what every configuration computes today. A row it extracts attends alone with the same kernels. The deprecated updateAndFetchQuantized picks the write from the length instead, so a one-row window without pending padding wrote in place there and concatenates here: the same bits until the ring wraps, a different key order after.

    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

    Per-row RoPE positions. STABLE ACROSS A STEP — refreshed only at releaseRopeArr() (the scheduler's post-dispatch hook), never inside the update: a graph that captures it before the update ropes Q after (an in-update dispose would be a use-after-dispose), and one that re-reads it for Q after the update would see K and Q at different positions after an in-update refresh. Widens the base's readonly to mutable.

    values: QuantizedTensor | null = null
    STEP: 256
    • Quantized twin of BatchedRotatingCache.extractRow (mlx-lm BatchRotatingKVCache.extract, models/cache.py:1417, over triples): row i as a fresh SERIAL RotatingQuantizedKVCache — de-rolled to temporal order, left padding stripped, OWNED contiguous copies; offset = the row's absolute position, ringIdx = the new buffer length (the oracle's cache._idx = cache.keys.shape[2]). Token-axis slicing is byte-safe (packing along HEAD_DIM — file header); per-row byte identity vs the serial oracle is the class invariant (packages/inference/tests/state/batched-rotating-quant.test.ts), extraction is a pure slice+copy.

      Parameters

      • i: number
      • limit: number = Infinity

      Returns RotatingQuantizedKVCache

    • Scheduler hook, called on every fwd cache AFTER the step's graph is built — the ONE safe point to swap the rope array for the advanced positions (the step's graph holds its own reference; no JS reads the old handle after this).

      Returns void

    • 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

    • Assemble a batch from per-row temporal quantized slices (the bf16 twin's merge over triples). Each row is a solo/adopted/batched cache's temporalView ([1,H,Li,*], Li ≤ maxSize, temporal order) and offsets[i] its absolute position. Result is in temporal order (rotated=false, ringIdx=offset=width).

      Parameters

      • rows: QuantRow[]
      • offsets: number[]
      • maxSize: number
      • groupSize: number
      • bits: number
      • kernels: AffineKernels
      • masks: AttentionMasks = ...

      Returns BatchedRotatingQuantCache