mlx-bun library API
    Preparing search index...

    Stateless cache for the training and scoring forward. Training is always a single offset-0 full-sequence pass, so nothing is stored and every append reads exactly the keys and values it is handed; the offset stays 0. The statelessness is REQUIRED: gradient checkpointing re-runs a layer's closure during the backward recompute, and a layer that shares another layer's keys and values reads them through that layer's cache again, so an append must leave the cache as it found it.

    Reads: pass-through views of k and v, attended with attention. Without rowLengths: no mask for decode, the fused causal mask for a window, and the offset-0 sliding-window mask once a window is longer than window. With rowLengths (a right-padded batch whose rows hold that many real positions), both reads take the padded-batch mask (paddedTrainingMask) for the cache's window, so no real query sees a padded key. A layer with a sliding window gets a cache composed with it; the caches of one forward share masks, so its layers build each mask once.

    Implements

    Index
    • Parameters

      • window: number | null = null

        The layer's sliding window; null for full attention.

      • masks: AttentionMasks = ...

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

      • attention: TrainingAttention = "sdpa"

        The kernel this cache's reads attend with.

      • rowLengths: readonly number[] | null = null

        Real positions per row of a right-padded batch; null for unpadded rows.

      Returns TrainingCache

    attention: TrainingAttention = "sdpa"

    The kernel this cache's reads attend with.

    masks: AttentionMasks = ...

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

    offset: number = 0
    rowLengths: readonly number[] | null = null

    Real positions per row of a right-padded batch; null for unpadded rows.

    window: number | null = null

    The layer's sliding window; null for full attention.

    • 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