mlx-bun library API
    Preparing search index...

    Recurrent state for one gated DeltaNet layer. It owns its read the way AttentionCache does: the block hands over its projected inputs and receives the recurrence output. The cache zeroes padded positions, runs the causal convolution over its stored convolution state, keeps each row's convolution tail, runs the gated-delta recurrence with the kernels in kernels/delta, replaces both states and advances its offsets. A training cache runs the differentiable recurrence behind the same calls.

    Both calls have these obligations:

    • qkv [B, S, convDim] is the in_proj_qkv output before convolution, and a, b [B, S, Hv] are the raw in_proj_a and in_proj_b outputs. The call consumes all three: the cache disposes them, or keeps them for an armed speculative round. The caller must not use or dispose them after the call.
    • layer is borrowed and must stay valid until an armed speculative round resolves, because rollback replays through it.
    • The caller owns the output [B, S, Hv, Dv]. The block applies the output gate (z) and the output projection itself.
    • Inside an armed round (specRoundBegin), the call records the pre-call states and its inputs, so specRoundRollback(keep) restores and replays the accepted prefix inside the cache. At most one call per armed round.
    • Rows follow this cache's row layout, as for AttentionCache. The method name is the phase; a cache never infers it from S.
    interface GatedDeltaCache {
        composed?: ComposedStorage;
        minimumReusableOffset?: number;
        offset: number;
        prefillMaintenance?: {
            beginPrefill(): void;
            commitPrefill(rows: readonly number[]): void;
            endPrefill(): void;
        };
        ropeOffsetArr?: MlxArray;
        stateNeedsDispose?: boolean;
        bytesPerToken?(): number;
        captureDonorAttention?(): KvDonorAttention;
        captureDonorRows?(): KvDonorRows;
        dispose(): void;
        isTrimmable(): boolean;
        maxAppendTokens?(): number;
        recurDecode(
            qkv: MlxArray,
            a: MlxArray,
            b: MlxArray,
            layer: GatedDeltaParameters,
        ): MlxArray;
        recurWindow(
            qkv: MlxArray,
            a: MlxArray,
            b: MlxArray,
            layer: GatedDeltaParameters,
        ): MlxArray;
        signature(): string;
        specRoundBegin?(): void;
        specRoundCommit?(): void;
        specRoundRollback?(keep: number): void;
        state(): MlxArray[];
        trim(n: number, bypass?: boolean): void;
    }

    Hierarchy (View Summary)

    Implemented by

    Index
    composed?: ComposedStorage

    Present on a cache that composes the storage it holds (see ComposedStorage).

    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
    prefillMaintenance?: {
        beginPrefill(): void;
        commitPrefill(rows: readonly number[]): void;
        endPrefill(): void;
    }

    A preparation method commits each request's own precision boundary. Splitting a forward for a sibling must not move that boundary.

    ropeOffsetArr?: MlxArray

    Compiled-decode trace adapters expose the RoPE offset as an int32 array input here; real caches leave it unset (static int path).

    stateNeedsDispose?: boolean

    state() returned temporary views that the caller must release.

    • Physical cache storage consumed by one additional token for one row. Recurrent caches return 0 because their state does not grow with the sequence. Optional for stateless/training adapters that are never admitted or persisted.

      Returns number

    • 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

    • Speculative verify-round support for NON-trimmable recurrent caches (SSMCache — gated-DeltaNet conv + recurrent state). A cache exposing these is spec-eligible without isTrimmable(): the serve loop arms a round before the verify forward (the layer snapshots pre-round state — free, MLX arrays are immutable — and records its position-local kernel inputs), then resolves it: commit on full accept, or rollback(keep) which restores the snapshot and bit-exactly REPLAYS the first keep window tokens through the recurrence (identical arithmetic prefix ⇒ identical state). Trimmable caches leave these unset and keep trim().

      Returns void

    • 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
      • Optionalbypass: boolean

      Returns void