mlx-bun library API
    Preparing search index...

    TurboQuant-encoded keys and values for one full-attention layer, bf16 first: the lego --kv-quant turbo composes (sliding-window layers keep a plain RotatingKVCache).

    Numbers: today's served path. Storage is a KVCache until an append leaves it holding at least start positions (the first append when start is 0). That append is read bf16 and then, before it returns, the storage converts (TurboQuantKVCache.fromKVCache over the live window, the reuse floor at a nonzero start, materialized at once). Every later append encodes its positions and is read through the codec. Stored values below the offset equal the convert-after path's bit for bit. The transition has the obligations described on Bf16FirstQuantizedKVCache.

    Reads: before the transition, KVCache's reads; after it, the encoded storage's reads, which attend with turboQuantKernels (no mask for decode, the causal mask for a window): decoded values and the stock fused SDPA for Qwen 3.5's graph, or the deferred-V fetch, the stock fused SDPA and the inverse rotation of the output for Gemma 4's and MiniCPM5's. fusedDecode is resolved by whoever builds the cache; nothing here reads the runtime configuration.

    Implements

    Index
    • Parameters

      • kBits: number
      • vBits: number
      • start: number

        Positions held in bf16 before the conversion; 0 converts after the first append.

      • fusedDecode: boolean

        The codec's decode policy for the converted storage.

      • turboQuantKernels: TurboQuantKernels

        How the converted storage attends, named by the graph the cache serves (denseTurboQuantKernels for Qwen 3.5, deferredTurboQuantKernels for Gemma 4 and MiniCPM5).

      • masks: AttentionMasks = ...

        The per-forward masks of the model this cache belongs to.

      • Optionalstorage: Cache

      Returns Bf16FirstTurboQuantKVCache

    composed: ComposedStorage = ...

    The storage the row layouts, clones and saved files take.

    fusedDecode: boolean

    The codec's decode policy for the converted storage.

    kBits: number
    masks: AttentionMasks = ...

    The per-forward masks of the model this cache belongs to.

    start: number

    Positions held in bf16 before the conversion; 0 converts after the first append.

    turboQuantKernels: TurboQuantKernels

    How the converted storage attends, named by the graph the cache serves (denseTurboQuantKernels for Qwen 3.5, deferredTurboQuantKernels for Gemma 4 and MiniCPM5).

    vBits: number
    • 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