diff --git a/Libraries/MLXLLM/Models/AfMoE.swift b/Libraries/MLXLLM/Models/AfMoE.swift index 2c44470d35..02bc07f832 100644 --- a/Libraries/MLXLLM/Models/AfMoE.swift +++ b/Libraries/MLXLLM/Models/AfMoE.swift @@ -560,12 +560,12 @@ public class AfMoEModel: Module, LLMModel, KVCacheDimensionProvider { // Create cache based on layer type (sliding-window or unbounded). When // `compressionAlgorithm == .affine(...)`, every attention layer is // constructed directly as an AffineQuantizedKVCache (no runtime swap). - let affineStep = defaultPrefillStepSize + let prefillStep = defaultPrefillStepSize return layerUsesSliding.map { usesSliding in makeAttentionCache( parameters: parameters, - maxSize: usesSliding ? slidingWindow : nil, - affineStep: affineStep) + slidingWindow: usesSliding ? slidingWindow : nil, + prefillStep: prefillStep) } } } diff --git a/Libraries/MLXLLM/Models/BaichuanM1.swift b/Libraries/MLXLLM/Models/BaichuanM1.swift index b72834039f..4840a21ee0 100644 --- a/Libraries/MLXLLM/Models/BaichuanM1.swift +++ b/Libraries/MLXLLM/Models/BaichuanM1.swift @@ -262,15 +262,14 @@ public class BaichuanM1Model: Module, LLMModel, KVCacheDimensionProvider { } public func newCache(parameters: GenerateParameters?) -> [KVCache] { - let affineStep = defaultPrefillStepSize + let prefillStep = defaultPrefillStepSize return model.layers.enumerated().map { (i, _) in let isSWA = configuration.slidingWindowLayers.contains(i) let convCache = SSMStateCache() let kvCache = makeAttentionCache( parameters: parameters, - maxSize: isSWA ? configuration.slidingWindow : nil, - affineStep: affineStep, - architecturalSlidingWindow: isSWA) + slidingWindow: isSWA ? configuration.slidingWindow : nil, + prefillStep: prefillStep) return CacheList(convCache, kvCache) } } diff --git a/Libraries/MLXLLM/Models/Exaone4.swift b/Libraries/MLXLLM/Models/Exaone4.swift index 2e72097c8d..3658c0dc34 100644 --- a/Libraries/MLXLLM/Models/Exaone4.swift +++ b/Libraries/MLXLLM/Models/Exaone4.swift @@ -216,13 +216,14 @@ public class Exaone4Model: Module, LLMModel, KVCacheDimensionProvider { } public func newCache(parameters: GenerateParameters? = nil) -> [KVCache] { - let affineStep = defaultPrefillStepSize + let prefillStep = defaultPrefillStepSize return model.layers.map { layer in - let isSliding = layer.attention.isLocal - let maxSize: Int? = isSliding ? configuration.slidingWindow : nil + let slidingWindow: Int? = + layer.attention.isLocal ? configuration.slidingWindow : nil return makeAttentionCache( - parameters: parameters, maxSize: maxSize, affineStep: affineStep, - architecturalSlidingWindow: isSliding) + parameters: parameters, + slidingWindow: slidingWindow, + prefillStep: prefillStep) } } } diff --git a/Libraries/MLXLLM/Models/FalconH1.swift b/Libraries/MLXLLM/Models/FalconH1.swift index f8504194db..2cb98dd709 100644 --- a/Libraries/MLXLLM/Models/FalconH1.swift +++ b/Libraries/MLXLLM/Models/FalconH1.swift @@ -763,11 +763,11 @@ public class FalconH1Model: Module, LLMModel, KVCacheDimensionProvider { } public func newCache(parameters: GenerateParameters?) -> [any KVCache] { - let affineStep = defaultPrefillStepSize + let prefillStep = defaultPrefillStepSize return model.layers.map { _ in CacheList( SSMStateCache(), - makeAttentionCache(parameters: parameters, affineStep: affineStep)) + makeAttentionCache(parameters: parameters, prefillStep: prefillStep)) } } } diff --git a/Libraries/MLXLLM/Models/GPTOSS.swift b/Libraries/MLXLLM/Models/GPTOSS.swift index 5bd18de179..7b194c0d05 100644 --- a/Libraries/MLXLLM/Models/GPTOSS.swift +++ b/Libraries/MLXLLM/Models/GPTOSS.swift @@ -379,13 +379,9 @@ public class GPTOSSModel: Module, LLMModel, KVCacheDimensionProvider { private let configuration: GPTOSSConfiguration @ModuleInfo(key: "lm_head") var lmHead: Linear - /// GPT-OSS uses attention sinks. The α-path runs sinks-bearing attention - /// without crashing (dequant V → standard SDPA fallback) but at - /// `valueBits=2` the output is silently incoherent — Harmony channel - /// markers (`<|channel|>`/`<|message|>`) never appear, so downstream - /// parsers see empty content. See issue #171. Coherent compressed-domain - /// support tracked in #130 (the path-B sinks β-path stack). - public var supportsTurboQuantization: Bool { false } + /// Coherent on `--kv turbo*` via the bias-correction + hybrid + /// sliding-FP16 policy in `newCache(...)` below. Closes #171 / #130. + public var supportsTurboQuantization: Bool { true } public init(_ config: GPTOSSConfiguration) { self.configuration = config @@ -527,22 +523,44 @@ public class GPTOSSModel: Module, LLMModel, KVCacheDimensionProvider { public func newCache(parameters: GenerateParameters?) -> [any KVCache] { var caches: [KVCache] = [] - let affineStep = defaultPrefillStepSize + let prefillStep = defaultPrefillStepSize + // GPT-OSS turbo* policy (spec 041 phase 1.1 follow-up): + // - Full-attention layers: TurboQuant with DC-bias correction + // (`useBias: true`) — model's K/V projections have `bias=True`, + // so the rotated vectors carry a structured DC offset the + // zero-mean Lloyd-Max codebook can't represent. + // - Sliding-window layers (128-token cap): raw FP16 — the codec's + // per-token error compounds in the sinks softmax; the FP16 + // fallback adds ~1.5 MB across all sliding layers vs the + // full-attention layers' 8K-token compressed caches. + // + // `--kv affine*` and `--kv none` keep both layer types on their + // default cache (no silent algorithm substitution). + let isTurboScheme: Bool + if case .turbo = parameters?.compressionAlgorithm { + isTurboScheme = true + } else { + isTurboScheme = false + } for lt in model.layerTypes { if lt == "full_attention" { // keep: 4 preserves attention-sink tokens for full-attention layers. + // No `slidingWindow` — function reads the user's + // `parameters?.maxKVSize` internally as the budget cap. caches.append(makeAttentionCache( parameters: parameters, - maxSize: parameters?.maxKVSize, keep: 4, - affineStep: affineStep)) + prefillStep: prefillStep, + useBias: isTurboScheme)) + } else if isTurboScheme { + caches.append(StandardKVCache( + maxSize: configuration.slidingWindow, keep: 0)) } else { caches.append(makeAttentionCache( parameters: parameters, - maxSize: configuration.slidingWindow, + slidingWindow: configuration.slidingWindow, keep: 0, - affineStep: affineStep, - architecturalSlidingWindow: true)) + prefillStep: prefillStep)) } } return caches diff --git a/Libraries/MLXLLM/Models/Gemma3.swift b/Libraries/MLXLLM/Models/Gemma3.swift index 5893d5f499..da211d830c 100644 --- a/Libraries/MLXLLM/Models/Gemma3.swift +++ b/Libraries/MLXLLM/Models/Gemma3.swift @@ -86,18 +86,17 @@ public class Gemma3TextModel: Module, LLMModel { var caches = [KVCache]() let slidingWindow = config.slidingWindow let slidingWindowPattern = config.slidingWindowPattern - let affineStep = defaultPrefillStepSize + let prefillStep = defaultPrefillStepSize for i in 0 ..< config.hiddenLayers { let isGlobalLayer = (i % slidingWindowPattern == slidingWindowPattern - 1) let cache = makeAttentionCache( parameters: parameters, - maxSize: isGlobalLayer ? nil : slidingWindow, - affineStep: affineStep, - architecturalSlidingWindow: !isGlobalLayer) + slidingWindow: isGlobalLayer ? nil : slidingWindow, + prefillStep: prefillStep) // For global layers (unbounded StandardKVCache), bump the step // size for long-sequence efficiency. Affine-quantized caches - // pick up `affineStep` via the constructor above. + // pick up `prefillStep` via the constructor above. if isGlobalLayer, let standard = cache as? StandardKVCache { standard.step = 1024 } diff --git a/Libraries/MLXLLM/Models/Gemma3nText.swift b/Libraries/MLXLLM/Models/Gemma3nText.swift index 80c8c041b3..9d03a123eb 100644 --- a/Libraries/MLXLLM/Models/Gemma3nText.swift +++ b/Libraries/MLXLLM/Models/Gemma3nText.swift @@ -734,15 +734,14 @@ public class Gemma3nLanguageModel: Module { // conformer), so `defaultPrefillStepSize` isn't in scope. The // outer `Gemma3nTextModel` uses the protocol default (1024) — // hardcode the matching affine step here. - let affineStep = 1024 + let prefillStep = 1024 // KV-sharing in Gemma 3n. Spec 041 phase 5 follow-up: shared // reader layers in `Gemma3nAttention.callAsFunction` now route // through `quantizedScaledDotProductAttention` when the donor is // an `AffineQuantizedKVCache` — no dequant, no compression loss. // `forceRawKV: false` keeps the affine compression on donor - // layers. (Sliding-window donors still fall back via - // `architecturalSlidingWindow: true` since affine has no rotating - // buffer; closing that gap needs spec 041 Phase 1.2 / 1.3 work.) + // layers. Sliding-window donors use the spec 041 phase 1.2 + // rotating-window affine cache (selected by `slidingWindow != nil`). _ = config.numKvSharedLayers > 0 // intentional: previously gated forceRawKV for i in 0 ..< firstKvSharedLayerIdx { let layerType = layerTypes[i] @@ -750,15 +749,15 @@ public class Gemma3nLanguageModel: Module { case "full_attention": caches.append( makeAttentionCache( - parameters: parameters, affineStep: affineStep, + parameters: parameters, prefillStep: prefillStep, forceRawKV: false)) case "sliding_attention": caches.append( makeAttentionCache( - parameters: parameters, maxSize: slidingWindow, - affineStep: affineStep, - forceRawKV: false, - architecturalSlidingWindow: true)) + parameters: parameters, + slidingWindow: slidingWindow, + prefillStep: prefillStep, + forceRawKV: false)) default: fatalError("Unknown layer type: \(layerType) for layer \(i)") } diff --git a/Libraries/MLXLLM/Models/Gemma4.swift b/Libraries/MLXLLM/Models/Gemma4.swift index 47f24e4133..d043b7d402 100644 --- a/Libraries/MLXLLM/Models/Gemma4.swift +++ b/Libraries/MLXLLM/Models/Gemma4.swift @@ -1271,7 +1271,7 @@ public class Gemma4TextModel: Module, LLMModel, KVCacheDimensionProvider { public func newCache(parameters: GenerateParameters? = nil) -> [KVCache] { var caches = [KVCache]() - let affineStep = defaultPrefillStepSize + let prefillStep = defaultPrefillStepSize // Compute the donor set first. Gemma 4 LLM (this file) routes shared // reader layers through `Gemma4TextAttention`'s quantised donor path @@ -1294,21 +1294,14 @@ public class Gemma4TextModel: Module, LLMModel, KVCacheDimensionProvider { } for (idx, layerType) in config.layerTypes.enumerated() { - let maxSize: Int? - let isSliding: Bool - if layerType == "full_attention" { - maxSize = parameters?.maxKVSize - isSliding = false - } else { - maxSize = config.slidingWindow - isSliding = true - } + let slidingWindow: Int? = + (layerType == "full_attention") ? nil : config.slidingWindow caches.append( makeAttentionCache( - parameters: parameters, maxSize: maxSize, - affineStep: affineStep, - forceRawKV: false, // spec 041 phase 5: reader path handles quantised donors. - architecturalSlidingWindow: isSliding)) + parameters: parameters, + slidingWindow: slidingWindow, + prefillStep: prefillStep, + forceRawKV: false)) // spec 041 phase 5: reader path handles quantised donors. _ = idx } diff --git a/Libraries/MLXLLM/Models/GraniteMoeHybrid.swift b/Libraries/MLXLLM/Models/GraniteMoeHybrid.swift index 70119aaec1..1ca8f1f0d5 100644 --- a/Libraries/MLXLLM/Models/GraniteMoeHybrid.swift +++ b/Libraries/MLXLLM/Models/GraniteMoeHybrid.swift @@ -538,12 +538,12 @@ public class GraniteMoeHybridModel: Module, LLMModel, KVCacheDimensionProvider { } public func newCache(parameters: GenerateParameters?) -> [KVCache] { - let affineStep = defaultPrefillStepSize + let prefillStep = defaultPrefillStepSize return configuration.layerTypes.map { layerType in if layerType == "mamba" { return SSMStateCache() } else { - return makeAttentionCache(parameters: parameters, affineStep: affineStep) + return makeAttentionCache(parameters: parameters, prefillStep: prefillStep) } } } diff --git a/Libraries/MLXLLM/Models/Jamba.swift b/Libraries/MLXLLM/Models/Jamba.swift index de5d33edca..5da53e640f 100644 --- a/Libraries/MLXLLM/Models/Jamba.swift +++ b/Libraries/MLXLLM/Models/Jamba.swift @@ -476,10 +476,10 @@ public class JambaModel: Module, LLMModel, KVCacheDimensionProvider { @ModuleInfo(key: "lm_head") var lmHead: Linear? public func newCache(parameters: GenerateParameters?) -> [KVCache] { - let affineStep = defaultPrefillStepSize + let prefillStep = defaultPrefillStepSize return model.layers.map { layer in if layer.isAttn { - return makeAttentionCache(parameters: parameters, affineStep: affineStep) + return makeAttentionCache(parameters: parameters, prefillStep: prefillStep) } else { // Jamba's Mamba mixer uses a per-step parallel scan whose // Spec 040 shipped Mamba state-replay via diff --git a/Libraries/MLXLLM/Models/LFM2.swift b/Libraries/MLXLLM/Models/LFM2.swift index 5b309b73b3..ea8683bce3 100644 --- a/Libraries/MLXLLM/Models/LFM2.swift +++ b/Libraries/MLXLLM/Models/LFM2.swift @@ -60,10 +60,10 @@ public class LFM2Model: Module, LLMModel, KVCacheDimensionProvider { } public func newCache(parameters: GenerateParameters?) -> [KVCache] { - let affineStep = defaultPrefillStepSize + let prefillStep = defaultPrefillStepSize return (0 ..< configuration.hiddenLayers).map { layerIdx in if configuration.fullAttnIdxs.contains(layerIdx) { - makeAttentionCache(parameters: parameters, affineStep: affineStep) + makeAttentionCache(parameters: parameters, prefillStep: prefillStep) } else { SSMStateCache() } diff --git a/Libraries/MLXLLM/Models/LFM2MoE.swift b/Libraries/MLXLLM/Models/LFM2MoE.swift index f7f30ecf84..51bcc77a1b 100644 --- a/Libraries/MLXLLM/Models/LFM2MoE.swift +++ b/Libraries/MLXLLM/Models/LFM2MoE.swift @@ -481,10 +481,10 @@ public class LFM2MoEModel: Module, LLMModel, KVCacheDimensionProvider { } public func newCache(parameters: GenerateParameters?) -> [KVCache] { - let affineStep = defaultPrefillStepSize + let prefillStep = defaultPrefillStepSize return (0 ..< configuration.hiddenLayers).map { layerIdx in if configuration.fullAttnIdxs.contains(layerIdx) { - makeAttentionCache(parameters: parameters, affineStep: affineStep) + makeAttentionCache(parameters: parameters, prefillStep: prefillStep) } else { SSMStateCache() } diff --git a/Libraries/MLXLLM/Models/MiMoV2Flash.swift b/Libraries/MLXLLM/Models/MiMoV2Flash.swift index eeb1c39d55..dfce01f607 100644 --- a/Libraries/MLXLLM/Models/MiMoV2Flash.swift +++ b/Libraries/MLXLLM/Models/MiMoV2Flash.swift @@ -462,14 +462,14 @@ public class MiMoV2FlashModel: Module, LLMModel, KVCacheDimensionProvider { } public func newCache(parameters: GenerateParameters?) -> [KVCache] { - let affineStep = defaultPrefillStepSize + let prefillStep = defaultPrefillStepSize return model.layers.map { layer in - let isSliding = layer.isSlidingWindow + let slidingWindow: Int? = + layer.isSlidingWindow ? configuration.slidingWindowSize : nil return makeAttentionCache( parameters: parameters, - maxSize: isSliding ? configuration.slidingWindowSize : nil, - affineStep: affineStep, - architecturalSlidingWindow: isSliding) + slidingWindow: slidingWindow, + prefillStep: prefillStep) } } } diff --git a/Libraries/MLXLLM/Models/Mistral3.swift b/Libraries/MLXLLM/Models/Mistral3.swift index fd44852d61..e301a34af9 100644 --- a/Libraries/MLXLLM/Models/Mistral3.swift +++ b/Libraries/MLXLLM/Models/Mistral3.swift @@ -226,13 +226,13 @@ public class Mistral3TextModel: Module, LLMModel, KVCacheDimensionProvider { /// Per-layer cache: sliding-attention layers get a windowed /// `StandardKVCache`; full-attention layers get unbounded. public func newCache(parameters: GenerateParameters?) -> [KVCache] { - let affineStep = defaultPrefillStepSize + let prefillStep = defaultPrefillStepSize return model.layers.map { layer in - let isSliding = layer.useSliding - let maxSize: Int? = isSliding ? args.slidingWindow : nil + let slidingWindow: Int? = layer.useSliding ? args.slidingWindow : nil return makeAttentionCache( - parameters: parameters, maxSize: maxSize, affineStep: affineStep, - architecturalSlidingWindow: isSliding) + parameters: parameters, + slidingWindow: slidingWindow, + prefillStep: prefillStep) } } } diff --git a/Libraries/MLXLLM/Models/NemotronH.swift b/Libraries/MLXLLM/Models/NemotronH.swift index f7ac88e8a7..8a0a158a95 100644 --- a/Libraries/MLXLLM/Models/NemotronH.swift +++ b/Libraries/MLXLLM/Models/NemotronH.swift @@ -853,8 +853,7 @@ public class NemotronHModel: Module, LLMModel, KVCacheDimensionProvider, LoRAMod // the boundary-skip set — hand to the standard factory. caches.append(makeAttentionCache( parameters: parameters, - maxSize: parameters?.maxKVSize, - affineStep: defaultPrefillStepSize)) + prefillStep: defaultPrefillStepSize)) } case .mlp, .moe: continue // No cache needed for MLP/MoE layers diff --git a/Libraries/MLXLLM/Models/Olmo3.swift b/Libraries/MLXLLM/Models/Olmo3.swift index 738cd7fb96..60811af6fd 100644 --- a/Libraries/MLXLLM/Models/Olmo3.swift +++ b/Libraries/MLXLLM/Models/Olmo3.swift @@ -224,14 +224,15 @@ public class Olmo3Model: Module, LLMModel, KVCacheDimensionProvider { public func newCache(parameters: GenerateParameters) -> [KVCache] { var caches: [KVCache] = [] - let affineStep = defaultPrefillStepSize + let prefillStep = defaultPrefillStepSize for layerType in args.layerTypes { - let isSliding = (layerType != "full_attention") - let maxSize: Int? = isSliding ? args.slidingWindow : nil + let slidingWindow: Int? = + (layerType != "full_attention") ? args.slidingWindow : nil caches.append( makeAttentionCache( - parameters: parameters, maxSize: maxSize, affineStep: affineStep, - architecturalSlidingWindow: isSliding)) + parameters: parameters, + slidingWindow: slidingWindow, + prefillStep: prefillStep)) } return caches } diff --git a/Libraries/MLXLLM/Models/Qwen35.swift b/Libraries/MLXLLM/Models/Qwen35.swift index b8bf1f7871..4586312aa1 100644 --- a/Libraries/MLXLLM/Models/Qwen35.swift +++ b/Libraries/MLXLLM/Models/Qwen35.swift @@ -950,10 +950,12 @@ public class Qwen35TextModel: Module, LLMModel, KVCacheDimensionProvider { // that the user opted to keep uncompressed. Either way, hand // off to the standard factory (raw `StandardKVCache` for .none, // `AffineQuantizedKVCache` for .affine). + // No `slidingWindow` — Qwen 3.5 attention layers are + // full-attention; the user's `parameters?.maxKVSize` is read + // internally by `makeAttentionCache` as the budget cap. return makeAttentionCache( parameters: parameters, - maxSize: parameters?.maxKVSize, - affineStep: defaultPrefillStepSize) + prefillStep: defaultPrefillStepSize) } } diff --git a/Libraries/MLXLLM/Models/Qwen3Next.swift b/Libraries/MLXLLM/Models/Qwen3Next.swift index 757e427e57..6c03b011be 100644 --- a/Libraries/MLXLLM/Models/Qwen3Next.swift +++ b/Libraries/MLXLLM/Models/Qwen3Next.swift @@ -718,12 +718,12 @@ public class Qwen3NextModel: Module, LLMModel, KVCacheDimensionProvider { } public func newCache(parameters: GenerateParameters?) -> [KVCache] { - let affineStep = defaultPrefillStepSize + let prefillStep = defaultPrefillStepSize return model.layers.map { layer in if layer.isLinear { return SSMStateCache() } - return makeAttentionCache(parameters: parameters, affineStep: affineStep) + return makeAttentionCache(parameters: parameters, prefillStep: prefillStep) } } diff --git a/Libraries/MLXLMCommon/AttentionUtils.swift b/Libraries/MLXLMCommon/AttentionUtils.swift index fb4f963422..f92944fccc 100644 --- a/Libraries/MLXLMCommon/AttentionUtils.swift +++ b/Libraries/MLXLMCommon/AttentionUtils.swift @@ -6,36 +6,20 @@ import MLX /// This provides a single function that automatically routes to quantized or regular /// attention based on cache type, matching Python's `scaled_dot_product_attention` -/// Automatic attention with cache update. +/// Automatic attention with cache update. Routes by `cache.storageKind`: /// -/// Routes to the right backend based on the cache type: -/// - `TurboQuantizedKVCache` (default A path): raw-FP16 cache + standard -/// `MLXFast.scaledDotProductAttention(... sinks:)`. The TurboQuant rotation -/// is bypassed at decode (SDPA is invariant to a fixed orthogonal Π applied -/// to both Q and K), so `prepareQueries`/`inverseRotateOutput` are no-ops -/// and `updateAndDequant` keeps appending to the raw prefill buffer. -/// - `TurboQuantizedKVCache` with `useCompressedAttention = true` (B opt-in): runs -/// `compressedAttention` directly on the packed buffer (sinks-using models -/// auto-fallback to A — compressed-domain pass2 doesn't yet incorporate the -/// sink logits; tracked in PR #99) -/// - `AffineQuantizedKVCache`: affine quantized SDPA (sinks folded in-Swift via -/// numerically-stable manual softmax — see `quantizedScaledDotProductAttention`) -/// - any other cache: standard `MLXFast.scaledDotProductAttention(... sinks:)` +/// - `.turboCompressed` — always `compressedAttention`. The cache itself +/// chooses its decode-time attention path: TurboFlash (default, true +/// compressed-domain) or dequant-then-SDPA (opt-in via +/// `TURBO_DEQUANT_SDPA=1`, materialises a per-layer FP16 K/V buffer). +/// The prefill (`L>1`) case still uses raw update + standard SDPA — +/// the cache compresses on first decode call. +/// - `.affineQuantized` — `quantizedScaledDotProductAttention` (sinks +/// folded in-Swift). +/// - `.raw` / `.ssm` / `.composite` — `MLXFast.scaledDotProductAttention(... +/// sinks:)`. /// /// `sinks` defaults to `nil`; non-sinks-using models can omit it. -/// -/// - Parameters: -/// - queries: Query tensor [B, nHeads, L, D] -/// - keys: Raw key tensor to be cached [B, nKVHeads, L, D] -/// - values: Raw value tensor to be cached [B, nKVHeads, L, D] -/// - cache: Cache instance (any type) -/// - scale: Attention scale factor -/// - mask: Attention mask -/// - sinks: Optional per-head attention-sink logits ([nHeads]) — flows through -/// SDPA and (after this PR) through the affine and turbo-α quantized paths. -/// The β compressed-TurboQuant path silently routes sinks-using models to -/// α; see `AttentionUtils` arm for `.turboCompressed`. -/// - Returns: Attention output [B, nHeads, L, D] public func attentionWithCacheUpdate( queries: MLXArray, keys: MLXArray, @@ -59,11 +43,9 @@ public func attentionWithCacheUpdate( ) } } - // Dispatch on `storageKind` rather than `as?` downcasts (spec 006). The - // typed enum is extensible (new storage kinds don't touch this switch's - // consumers) and self-documenting. The downcast inside each arm is a - // class-identity assertion: storageKind is defined to mirror the concrete - // class, so a mismatch indicates a programming error, not a runtime case. + // Dispatch on the typed `storageKind` enum (spec 006) rather than `as?` + // downcasts. The downcast inside each arm is a class-identity assertion + // — a mismatch indicates a programming error, not a runtime case. switch cache.storageKind { case .turboCompressed: guard let turboCache = cache as? TurboQuantizedKVCache else { @@ -73,7 +55,8 @@ public func attentionWithCacheUpdate( } let L = queries.dim(2) if L > 1 { - // Prefill (L>1): raw update + standard SDPA. Zero overhead. + // Prefill (L>1): raw update + standard SDPA. Cache compresses + // lazily on the first L=1 decode call via `compressRawCache`. let updH = BenchmarkSignpost.begin(BenchmarkSignpost.PhaseLabel.kvUpdate) let (cachedKeys, cachedValues) = turboCache.update(keys: keys, values: values) BenchmarkSignpost.end(updH) @@ -84,36 +67,16 @@ public func attentionWithCacheUpdate( ) } } - // B (default): compressed-domain dequant + matrix-engine SDPA. - // `compressedAttention` emits its own tq_encode/tq_score/tq_value/tq_rotate - // sub-phase signposts internally — don't double-wrap here. - // Sinks-using models (GPT-OSS family) auto-fallback to A — the - // compressed-attention pass2 kernel doesn't yet incorporate the - // sink-token logits in its online softmax (tracked in PR #99). - if turboCache.useCompressedAttention && sinks == nil { - return turboCache.compressedAttention( - queries: queries, keys: keys, values: values, - scale: scale, mask: mask - ) - } - // A path: raw-FP16 cache + standard SDPA(... sinks:). Used when the - // user opts out via `TURBO_COMPRESSED_ATTENTION=0` / - // `useCompressedAttention=false`, or when the model uses attention - // sinks. - // updateAndDequant returns raw K/V; prepareQueries/inverseRotateOutput - // are no-ops in A — SDPA is invariant to the codec's orthogonal rotation - // applied to both Q and K, so we skip the rotation entirely. - let updH = BenchmarkSignpost.begin(BenchmarkSignpost.PhaseLabel.kvUpdate) - let (rotKeys, rotValues) = turboCache.updateAndDequant(keys: keys, values: values) - BenchmarkSignpost.end(updH) - let rotQueries = turboCache.prepareQueries(queries) - let rotOutput = BenchmarkSignpost.interval(BenchmarkSignpost.PhaseLabel.sdpa) { - MLXFast.scaledDotProductAttention( - queries: rotQueries, keys: rotKeys, values: rotValues, - scale: scale, mask: mask, sinks: sinks - ) - } - return turboCache.inverseRotateOutput(rotOutput) + // Decode (L=1): compressed-domain attention. `compressedAttention` + // emits its own tq_* sub-phase signposts and chooses TurboFlash + // (default) or dequant-SDPA (opt-in) internally. + let ws = Int(mask.windowSize) + return turboCache.compressedAttention( + queries: queries, keys: keys, values: values, + scale: scale, mask: mask, + sinks: sinks, + windowSize: ws + ) case .affineQuantized: guard let quantizedKVCache = cache as? AffineQuantizedKVCache else { @@ -121,11 +84,8 @@ public func attentionWithCacheUpdate( "storageKind .affineQuantized but cache is not AffineQuantizedKVCache: \(type(of: cache))" ) } - // Sinks support (GPT-OSS family): folded into the in-Swift softmax of - // `quantizedScaledDotProductAttention`. Sinks add one implicit logit - // per Q head to the softmax denominator; the V is implicit zero, so - // they only affect normalization. See `quantizedScaledDotProductAttention` - // for the math. + // Sinks fold lives in `quantizedScaledDotProductAttention`'s + // numerically-stable manual softmax. let updH = BenchmarkSignpost.begin(BenchmarkSignpost.PhaseLabel.kvUpdate) let (quantizedKeys, quantizedValues) = quantizedKVCache.updateQuantized( keys: keys, values: values) @@ -146,11 +106,9 @@ public func attentionWithCacheUpdate( } case .raw, .ssm, .composite: - // Standard path — raw FP16/BF16 K/V (StandardKVCache), SSM caches - // (SSMStateCache — not actually K/V but routed through the same - // default-update path; layer code typically doesn't call - // attentionWithCacheUpdate for SSM layers anyway), and composite - // (CacheList — same reasoning). + // Standard path. SSM caches (`SSMStateCache`) and composite + // (`CacheList`) reach this arm via fallback — layer code typically + // doesn't call `attentionWithCacheUpdate` for SSM layers. let updH = BenchmarkSignpost.begin(BenchmarkSignpost.PhaseLabel.kvUpdate) let (cachedKeys, cachedValues) = cache.update(keys: keys, values: values) BenchmarkSignpost.end(updH) diff --git a/Libraries/MLXLMCommon/KVCache.swift b/Libraries/MLXLMCommon/KVCache.swift index 4e06b83249..18d8a65027 100644 --- a/Libraries/MLXLMCommon/KVCache.swift +++ b/Libraries/MLXLMCommon/KVCache.swift @@ -951,6 +951,15 @@ public class AffineQuantizedKVCache: BaseKVCache { public let groupSize: Int public let bits: Int public let mode: QuantizationMode + /// Spec 041 phase 1.2: optional sliding-window cap. When set, the cache + /// retains at most `maxSize` tokens — older entries are dropped from + /// the front via slice + concat on each `updateQuantized` call. Used by + /// Gemma 4 / GPT-OSS sliding-attention layers under `--kv affine*` to + /// retain affine compression on layers that previously fell back to + /// `StandardKVCache` via `architecturalSlidingWindow: true`. + private let _maxSize: Int? + + public override var maxSize: Int? { _maxSize } /// SDPA strategy for this cache (spec 041 phases 1+2+4). /// @@ -988,18 +997,25 @@ public class AffineQuantizedKVCache: BaseKVCache { /// - sdpaStrategy: SDPA path selector (default `.auto`). See the /// `sdpaStrategy` property docs for the trade-offs. Env var /// `MLX_AFFINE_SDPA` overrides this when set. + /// - maxSize: Optional sliding-window cap. `nil` (default) → unbounded + /// growth (standard affine cache). When set, the cache retains at + /// most `maxSize` tokens; SDPA on this cache attends over only those + /// recent tokens (mirrors `StandardKVCache(maxSize:)`'s semantics + /// plus affine compression). public init( groupSize: Int = 64, bits: Int = 8, mode: QuantizationMode = .affine, step: Int = 256, - sdpaStrategy: AffineSDPAStrategy = .auto + sdpaStrategy: AffineSDPAStrategy = .auto, + maxSize: Int? = nil ) { self.groupSize = groupSize self.bits = bits self.step = step self.mode = mode self.sdpaStrategy = sdpaStrategy + self._maxSize = maxSize super.init() } @@ -1014,6 +1030,40 @@ public class AffineQuantizedKVCache: BaseKVCache { return arrays } + /// Spec 041 phase 1.2: rotating-window mask override. Mirrors + /// `StandardKVCache.makeMask`'s window mode — the mask offset is + /// capped at `maxSize - 1` so the (queries × T_kv) shape matches the + /// concat return value of `updateQuantized` (which retains at most + /// `maxSize - 1` existing tokens + numSteps new). Without this + /// override, `BaseKVCache.makeMask` uses the absolute `offset` and + /// generates a mask of shape `(n, offset + n)` that doesn't broadcast + /// against the trimmed concat. + public override func makeMask( + n: Int, windowSize: Int?, returnArray: Bool + ) -> MLXFast.ScaledDotProductAttentionMaskMode { + guard let maxCacheSize = _maxSize else { + return super.makeMask(n: n, windowSize: windowSize, returnArray: returnArray) + } + if n > 1 { + let actualWindowSize = windowSize ?? maxCacheSize + let cappedOffset = min(maxCacheSize - 1, offset) + if cappedOffset + n > actualWindowSize || returnArray { + return .array( + createCausalMask(n: n, offset: cappedOffset, windowSize: actualWindowSize)) + } + return .causal + } + // Single-token decode path — sliding-window mask not needed within + // a single step. + if let _ = windowSize, offset >= (windowSize ?? maxCacheSize) { + // Cache has wrapped; subsequent decode tokens attend over the + // rolling window. No mask is required because the cache only + // exposes `min(maxSize, offset)` tokens. + return .none + } + return .none + } + /// Tree map equivalent for applying function to tuple elements private func treeMap(_ transform: (MLXArray) -> T, _ tuple: (MLXArray, MLXArray, MLXArray?)) -> (T, T, T?) @@ -1062,8 +1112,14 @@ public class AffineQuantizedKVCache: BaseKVCache { )? { guard let keys = keys, let values = values else { return nil } - let trimmedKeys = treeMap({ $0[.ellipsis, .. 0, + let existingKeys = self.keys, let existingValues = self.values + { + let keptKeys = treeMap( + { $0[.ellipsis, trimExisting ..< liveLen, 0...] }, existingKeys) + let keptValues = treeMap( + { $0[.ellipsis, trimExisting ..< liveLen, 0...] }, existingValues) + combinedKeys = ( + concatenated([keptKeys.0, newKTuple.0], axis: -2), + concatenated([keptKeys.1, newKTuple.1], axis: -2), + (keptKeys.2 != nil && newKTuple.2 != nil) + ? concatenated([keptKeys.2!, newKTuple.2!], axis: -2) + : nil) + combinedValues = ( + concatenated([keptValues.0, newVTuple.0], axis: -2), + concatenated([keptValues.1, newVTuple.1], axis: -2), + (keptValues.2 != nil && newVTuple.2 != nil) + ? concatenated([keptValues.2!, newVTuple.2!], axis: -2) + : nil) + } else { + combinedKeys = newKTuple + combinedValues = newVTuple + } + + // Internal storage: trim to last `maxSize` tokens for bounded + // memory. The combined return tuple may be longer (up to + // `maxSize - 1 + numSteps`) — that's what SDPA's mask + // shape expects. + let combinedLen = combinedKeys.0.dim(-2) + let storedLen = min(combinedLen, maxSize) + let storageTrim = combinedLen - storedLen + let storedKeys: (MLXArray, MLXArray, MLXArray?) + let storedValues: (MLXArray, MLXArray, MLXArray?) + if storageTrim > 0 { + storedKeys = treeMap( + { $0[.ellipsis, storageTrim..., 0...] }, combinedKeys) + storedValues = treeMap( + { $0[.ellipsis, storageTrim..., 0...] }, combinedValues) + } else { + storedKeys = combinedKeys + storedValues = combinedValues + } + + self.keys = storedKeys + self.values = storedValues + offset += numSteps + + // Materialise after the concat/trim chain — the affine path's + // peak-GPU fix (PR #209) eval barrier applies here too. + var pendingEval: [MLXArray] = [ + storedKeys.0, storedKeys.1, storedValues.0, storedValues.1, + ] + if let kBiases = storedKeys.2 { pendingEval.append(kBiases) } + if let vBiases = storedValues.2 { pendingEval.append(vBiases) } + eval(pendingEval) + + // Return the FULL concat (not the storage-trimmed view) so + // downstream SDPA's mask shape matches. + return (combinedKeys, combinedValues) + } + // Check if we need to expand the cache if self.keys == nil || (prev + numSteps) > self.keys!.0.dim(-2) { let newSteps = ((step + numSteps - 1) / step) * step @@ -2232,15 +2379,37 @@ public enum AffineSDPAStrategy: Sendable { /// `.discrete` based on `L`. public enum Path { case kernel, flash, discrete } - /// Pick path given the call's query length, with the caller's per-cache - /// strategy as the fallback when no env override is set. - static func choose(L: Int, strategy: AffineSDPAStrategy = .auto) -> Path { + /// Pick path given the call's query length, mask mode, and the caller's + /// per-cache strategy. Resolution precedence: env var when set ▶ per-cache + /// `strategy` ▶ `.auto` default. + /// + /// Auto-strategy (`.auto` default) heuristics: + /// - **Sliding-window mask** (`.slidingWindow(_)`): always `.flash`. The + /// cache is bounded so the dequant transient is small; MLXFast SDPA's + /// native sliding-window kernel is faster than the discrete-path + /// augmented-softmax-with-sinks fold (which has correctness issues on + /// the sliding+sinks combination on GPT-OSS-20B — produces 6 garbage + /// tokens then EOS). Tracked as follow-up. + /// - **L > 1 prefill (non-sliding)**: `.flash`. No score-matrix + /// materialisation; dequant transient amortises across the chunk. + /// - **L = 1 decode (non-sliding)**: `.discrete`. Score matrix is small + /// (L=1 row); per-step dequant cost would otherwise dominate at long + /// context. + static func choose( + L: Int, + mask: MLXFast.ScaledDotProductAttentionMaskMode, + strategy: AffineSDPAStrategy = .auto + ) -> Path { let effective = envOverride ?? strategy switch effective { case .kernel: return .kernel case .flash: return .flash case .discrete: return .discrete - case .auto: return L > 1 ? .flash : .discrete + case .auto: + if case .slidingWindow = mask { + return .flash + } + return L > 1 ? .flash : .discrete } } } @@ -2258,7 +2427,7 @@ public func quantizedScaledDotProductAttention( strategy: AffineSDPAStrategy = .auto ) -> MLXArray { let queryL = queries.dim(2) - switch AffineSDPAStrategy.choose(L: queryL, strategy: strategy) { + switch AffineSDPAStrategy.choose(L: queryL, mask: mask, strategy: strategy) { case .kernel: return fusedFlashQuantizedSDPA( queries: queries, @@ -2486,32 +2655,34 @@ private func fusedFlashQuantizedSDPA( groupSize: groupSize, bits: bits, mode: mode) } - // Map mask mode → (causal flag, array mask). + // Map mask mode → (causal flag, array mask, window size). let causal: Bool let maskArr: MLXArray? + let windowSize: Int switch mask { case .causal: causal = true maskArr = nil + windowSize = -1 case .array(let m): causal = false maskArr = m + windowSize = -1 case .arrays(let arrs): causal = false maskArr = arrs.first - case .slidingWindow: - // Sliding-window: kernel doesn't have a native windowed path yet; - // route through the dequant-then-SDPA stop-gap which calls - // `MLXFast.scaledDotProductAttention(... mask: .slidingWindow(...))`. - return flashQuantizedScaledDotProductAttention( - queries: queries, - quantizedKeys: quantizedKeys, - quantizedValues: quantizedValues, - scale: scale, mask: mask, sinks: sinks, - groupSize: groupSize, bits: bits, mode: mode) + windowSize = -1 + case .slidingWindow(let size): + // Phase 1.2: kernel now has a native windowed-causal path. + // The `do_sliding_fq` function constant + `window_size` buffer + // arg drop keys at `i <= q_pos - windowSize`. + causal = true + maskArr = nil + windowSize = size case .none: causal = false maskArr = nil + windowSize = -1 } // The kernel's bias arg is non-optional; affine quantize always emits @@ -2538,6 +2709,7 @@ private func fusedFlashQuantizedSDPA( bits: bits, groupSize: groupSize, causal: causal, + windowSize: windowSize, mask: maskArr, sinks: sinks) } diff --git a/Libraries/MLXLMCommon/KVCacheTypes.swift b/Libraries/MLXLMCommon/KVCacheTypes.swift index 368a8c7d05..584d6c6143 100644 --- a/Libraries/MLXLMCommon/KVCacheTypes.swift +++ b/Libraries/MLXLMCommon/KVCacheTypes.swift @@ -245,7 +245,7 @@ public func turboBoundarySkipSet( public func makeKVCache( scheme: KVCache.CompressionAlgorithm = .none, eviction: KVEviction = .unbounded, - affineStep: Int? = nil + prefillStep: Int? = nil ) -> any KVCache { switch scheme { case .none: @@ -256,13 +256,13 @@ public func makeKVCache( // sliding-window cache is swapped for a non-rotating quantized // cache (per the comment on `StandardKVCache.toQuantized`). // - // `affineStep` lets callers size the cache's growth increment to + // `prefillStep` lets callers size the cache's growth increment to // their model's prefill chunk (defaults to 256 when omitted). Sized // to match `LanguageModel.defaultPrefillStepSize` collapses growth // events 1:1 with prefill chunks instead of `chunkSize/256`. return AffineQuantizedKVCache( groupSize: schemeGroupSize(scheme), bits: bits, - step: affineStep ?? 256) + step: prefillStep ?? 256) case let .turbo(keyBits, valueBits, _, _): // TurboQuantizedKVCache supports windowed eviction natively via its // `rotatingMaxSize` + `rotatingIdx` write-position machinery — the @@ -306,83 +306,112 @@ public func makeKVCache( /// Diagnostic env knob: `MLX_TURBO_WINDOWED=0` forces the legacy /// fallback (`StandardKVCache`) for the windowed-turbo case. Useful /// for A/B testing or regressions; not needed in normal operation. +/// Build the per-layer KV cache that matches `parameters.compressionAlgorithm` +/// + the layer's architectural shape. +/// +/// **Two distinct caps drive rotating eviction:** +/// +/// 1. `slidingWindow: Int?` — **architectural** cap. Set per-layer by the +/// model factory when the layer's attention path **must** attend over +/// only the last N tokens (Gemma 4 local layers, GPT-OSS sliding layers, +/// Mistral 3 sliding layers, etc.). When non-nil, the returned cache +/// rotates at this cap regardless of compression algorithm. This is +/// non-negotiable — the model architecture demands it. +/// +/// 2. `parameters?.maxKVSize` — **user budget** cap. Read internally from +/// the parameters tuple. When the layer is **not** architecturally +/// sliding-window, this serves as the user's "bound the cache here for +/// memory budgeting" hint. Honored uniformly across all three schemes: +/// - `.none`: returns `StandardKVCache(maxSize:)` — rotating eviction. +/// - `.turbo`: returns `TurboQuantizedKVCache(maxSize:)` — rotating +/// eviction + compression. +/// - `.affine`: returns `AffineQuantizedKVCache(maxSize:)` — rotating +/// eviction + compression (via spec 041 phase 1.2 rotating-window +/// affine cache, same dispatch as the architectural-sliding case). +/// +/// Precedence when both are present: `slidingWindow` wins. The architectural +/// cap is non-negotiable; the user cannot make a sliding-window layer +/// attend over more tokens than the architecture allows. +/// +/// `forceRawKV: true` is a separate caller's-contract flag for KV-sharing +/// donor layers whose reader path can only consume raw FP16 K/V (Gemma 3n, +/// Gemma 4 VLM today). Under affine, such donors fall back to +/// `StandardKVCache` instead of the quantized donor tuple. public func makeAttentionCache( parameters: GenerateParameters?, - maxSize: Int? = nil, + slidingWindow: Int? = nil, keep: Int = 0, - affineStep: Int? = nil, + prefillStep: Int? = nil, forceRawKV: Bool = false, - architecturalSlidingWindow: Bool = false + useBias: Bool = false ) -> KVCache { + // The architectural cap takes precedence over the user budget cap. From + // this point, all three schemes (`.none` / `.turbo` / `.affine`) treat + // `effectiveMaxSize` uniformly — rotating eviction at that cap when set. + let effectiveMaxSize: Int? = slidingWindow ?? parameters?.maxKVSize + + // Per-cache growth-chunk size for incremental buffer expansion. Threaded + // uniformly into all three cache classes' `step:` constructor params so + // each class's `concatenated(...)` growth ops happen at the model's + // prefill-chunk granularity, not the per-class hardcoded default. + // Precedence: user override (`parameters.prefillStepSize`) ▶ model + // default (`prefillStep` arg, typically the caller's + // `defaultPrefillStepSize`) ▶ 256. + let resolvedStep = parameters?.prefillStepSize ?? prefillStep ?? 256 + if case let .affine(bits, groupSize) = parameters?.compressionAlgorithm { - // Two cases force a `StandardKVCache` fallback under affine: - // - // 1. **Architectural sliding window (`architecturalSlidingWindow == - // true`).** Gemma 4 / Mistral3 / etc. define sliding-window layers - // in the model architecture itself — SDPA *must* attend over only - // the last `slidingWindow` tokens. `AffineQuantizedKVCache` has no - // rotating-buffer logic (grows unbounded), so without this - // fallback the model attends over the full prefill once context - // exceeds the window and produces gibberish. + // Affine path. Three branches: // - // 2. **KV-sharing donors when the caller can't consume quantized - // donor state (`forceRawKV == true`).** Spec 041 Phase 5 added a - // reader path in `Gemma4TextAttention.callAsFunction(useSharedKV:...)` - // that consumes the donor's `getQuantizedState()` tuple directly - // via `quantizedScaledDotProductAttention`. That callsite passes - // `forceRawKV: false` so its donors stay compressed under affine. - // Other KV-sharing callers (Gemma 3n, Gemma 4 VLM — both still - // routing donors through FP16 SDPA in the reader) keep - // `forceRawKV: true`, falling back to `StandardKVCache` here. The - // flag is the caller's contract: "my reader can / cannot route - // quantized donor state." + // 1. `forceRawKV`: KV-shared donor whose reader path consumes raw + // FP16 K/V (not the quantised tuple). Fall back to `StandardKVCache` + // so the reader gets raw K/V via `lastReturnedKeys`. (Gemma 4 LLM + // Phase 5 reader handles the quantised tuple; Gemma 3n / Gemma 4 + // VLM readers still need raw — they pass `forceRawKV: true`.) // - // `maxSize` alone is NOT a fallback trigger — the bench harness - // and library callers set `maxSize == contextSize` on full-attention - // layers as an operational budgeting hint, not as a "wrap and evict - // on overflow" instruction. For Qwen 3.5 (no sliding-window - // architecture) those layers should keep their affine compression - // even with a `maxSize` set. + // 2. Any cap is set (architectural sliding-window OR user budget): + // spec 041 phase 1.2 rotating-window `AffineQuantizedKVCache`. + // Affine compression retained alongside rotating eviction at the + // cap. Same dispatch for both cap sources — the cache class's + // rotation logic doesn't care whether the cap came from the + // model architecture or `parameters.maxKVSize`. // - // Trade-off where the sliding-window fallback still engages: those - // specific layers stay FP16 instead of quantising. On Gemma 4 - // sliding-window layers the cache is bounded at - // `slidingWindow ≈ 1024` tokens so the absolute memory cost is - // small. Closing this gap fully needs a rotating-buffer-aware - // affine cache — tracked in - // https://github.com/ekryski/mlx-swift-lm/issues/202 and on spec - // 041 Phase 1 (the kernel-level fix carries window semantics in - // its mask). - if forceRawKV || architecturalSlidingWindow { - if let maxSize { - return StandardKVCache(maxSize: maxSize, keep: keep) + // 3. No cap: unbounded `AffineQuantizedKVCache`. + if forceRawKV { + if let cap = effectiveMaxSize { + return StandardKVCache(maxSize: cap, keep: keep, step: resolvedStep) } - return StandardKVCache() + return StandardKVCache(eviction: .unbounded, step: resolvedStep) + } + if let cap = effectiveMaxSize { + return AffineQuantizedKVCache( + groupSize: groupSize, bits: bits, + step: resolvedStep, maxSize: cap) } - // Prefer the user-overridden prefill step over the per-model default - // — when the caller resized prefill chunks, the cache should match. - // `affineStep` carries the model's `defaultPrefillStepSize` from the - // `newCache(parameters:)` call site; combined with the parameters - // override here, we land on `parameters.prefillStepSize ?? - // model.defaultPrefillStepSize ?? 256`. - let resolvedStep = parameters?.prefillStepSize ?? affineStep ?? 256 return AffineQuantizedKVCache( groupSize: groupSize, bits: bits, step: resolvedStep) } + + // Turbo path. Windowed turbo cache when ANY cap is set (architectural + // sliding-window OR user budget). The codec has its own rotating-window + // logic so both shapes route identically. let env = ProcessInfo.processInfo.environment let windowedTurboDisabled = env["MLX_TURBO_WINDOWED"] == "0" if case let .turbo(keyBits, valueBits, _, _) = parameters?.compressionAlgorithm, - let maxSize, !windowedTurboDisabled + let cap = effectiveMaxSize, !windowedTurboDisabled { return TurboQuantizedKVCache( bits: max(keyBits, valueBits), keyBits: keyBits, valueBits: valueBits, - maxSize: maxSize) + step: resolvedStep, + maxSize: cap, + useBias: useBias) } - if let maxSize { - return StandardKVCache(maxSize: maxSize, keep: keep) + + // `.none` path. Any cap (architectural or user) → rotating StandardKVCache. + if let cap = effectiveMaxSize { + return StandardKVCache(maxSize: cap, keep: keep, step: resolvedStep) } - return StandardKVCache() + return StandardKVCache(eviction: .unbounded, step: resolvedStep) } /// Internal helper to extract groupSize from an affine compression scheme. diff --git a/Libraries/MLXLMCommon/LanguageModel.swift b/Libraries/MLXLMCommon/LanguageModel.swift index f1b7a4ae08..5d08ae1f4d 100644 --- a/Libraries/MLXLMCommon/LanguageModel.swift +++ b/Libraries/MLXLMCommon/LanguageModel.swift @@ -227,11 +227,9 @@ public protocol LanguageModel: BaseLanguageModel { /// Whether this model's attention path supports TurboQuant-compressed KV. /// - /// The default (`useCompressedAttention = false`) routes through standard - /// `MLXFast.scaledDotProductAttention(... sinks:)`, so attention-sink models - /// (GPT-OSS) work without opting out. Override to `false` only if a model's - /// attention path is genuinely incompatible with `TurboQuantizedKVCache`'s - /// `update`/`updateAndDequant` semantics. Defaults to `true`. + /// Override to `false` only if a model's attention path is genuinely + /// incompatible with `TurboQuantizedKVCache`'s `update` / `compressedAttention` + /// semantics. Defaults to `true`. var supportsTurboQuantization: Bool { get } } @@ -262,14 +260,14 @@ public protocol KVCacheDimensionProvider { extension LanguageModel where Self: KVCacheDimensionProvider { public func newCache(parameters: GenerateParameters?) -> [KVCache] { - // Create one cache per layer (kvHeads.count = number of layers) - // The number of heads per layer (kvHeads[i]) is not used for cache creation + // Create one cache per layer (kvHeads.count = number of layers). + // The number of heads per layer (kvHeads[i]) is not used for cache + // creation. Default protocol path is full-attention layers — no + // `slidingWindow` arg; `makeAttentionCache` reads the user's + // `parameters?.maxKVSize` internally as the budget cap. let numLayers = kvHeads.count return (0 ..< numLayers).map { _ in - makeAttentionCache( - parameters: parameters, - maxSize: parameters?.maxKVSize, - keep: 4) + makeAttentionCache(parameters: parameters, keep: 4) } } } diff --git a/Libraries/MLXLMCommon/TurboQuantKVCache.swift b/Libraries/MLXLMCommon/TurboQuantKVCache.swift index 2b498574bd..d5f1d007e2 100644 --- a/Libraries/MLXLMCommon/TurboQuantKVCache.swift +++ b/Libraries/MLXLMCommon/TurboQuantKVCache.swift @@ -596,11 +596,18 @@ public enum TurboQuantPacking { /// State for MSE-quantized vectors. public struct MSECodecState { - public var norms: MLXArray // [B, H, T] — original vector L2 norms + public var norms: MLXArray // [B, H, T] — L2 norm of (centered) vector public var packedIndices: MLXArray // [B, H, T, PackedWidth] — packed codebook indices public var tokenCount: Int public let dim: Int public let bits: Int + /// Optional per-vector DC offset. Present when the codec ran with + /// `useBias: true`. `decode` adds `bias` back after the inverse + /// rotation; `decodeRotated` adds `bias * rotatedOnes` in rotated + /// space (since rotation is linear). Captures the mean the zero-mean + /// Lloyd-Max codebook can't represent. See `testDualScaleMSEReduction` + /// for the empirical case (9-22% MSE on structured K/V). + public var bias: MLXArray? // [B, H, T] — per-vector DC offset (optional) } /// MSE-optimal codec per TurboQuant Algorithm 1. @@ -626,6 +633,11 @@ public class MSECodec { /// Π^T — for forward rotation public let rotationT: MLXArray + /// `1_vec @ rotationT`, precomputed once. A per-vector DC bias `b` in + /// original space maps to `b * rotatedOnes[d]` in rotated space (since + /// rotation is linear). Used by the rotated-space bias-aware dequant. + public let rotatedOnes: MLXArray // [1, dim] + public init(dim: Int, bits: Int, seed: UInt64 = 42) { self.dim = dim self.bits = bits @@ -656,6 +668,13 @@ public class MSECodec { self.rotation = rot.asType(.bfloat16) self.rotationT = self.rotation.transposed() } + // Precompute `1_vec @ rotationT`. For WHT-rotated codecs this is a + // function of the codec's WHT signs (not just `dim`), so it stays + // cached on the codec instance — codecs are shared per + // `(dim, bits, seed)` via `getOrCreateCodec`, so this is computed + // once per unique codec for the lifetime of the process. + self.rotatedOnes = + matmul(MLXArray.ones([1, dim], dtype: .bfloat16), self.rotationT) } /// Encode vectors (Algorithm 1 QUANT) with optional norm correction. @@ -670,28 +689,32 @@ public class MSECodec { /// Dense rotation path: stores `original_norm / reconstruction_norm` (norm correction). /// This compensates for quantization error in the non-orthogonal rotation case. /// - // TODO: Dual half-block scales (TQ4_1S format optimization) - // - // Our llama.cpp TQ4_1S format uses dual half-block scales (d0 for elements 0-15, - // d1 for elements 16-31) instead of a single per-block L2 norm. After WHT rotation, - // the two halves of a 32-element block can have very different energy distributions, - // so a single norm under-scales one half and over-scales the other. - // - // Dual scales reduce MSE by ~15-25% in our testing (see TurboQuant+ paper, Section 4.2). - // - // Implementing this requires changes to: - // 1. MSECodecState packing format — store two norms per block instead of one - // 2. This encode path — compute half-block norms separately: - // d0 = ||rotated[..., :16]||₂, d1 = ||rotated[..., 16:]||₂ - // 3. Metal dequant kernels — use d0/d1 during reconstruction - // 4. TurboFlash attention kernels — weighted dequant with two scales per block - // - // Too invasive for this PR, but high-value follow-up for accuracy-sensitive models. - public func encode(_ vectors: MLXArray) -> MSECodecState { + // Dual-block scales (TQ4_1S-style) were considered but empirically only + // give 1-8% MSE reduction on this codec (the WHT rotation flattens the + // per-half-block energy asymmetry the scheme is designed to exploit). + // The 9-22% gain from per-vector DC-bias correction below is the larger + // structural win on real K/V; see `testDualScaleMSEReduction` in + // `TurboQuantKernelTests`. + public func encode(_ vectors: MLXArray, useBias: Bool = false) -> MSECodecState { + // With `useBias`, subtract per-vector mean (head-dim axis) before + // unit-norm + rotation. Centers the input so the zero-mean + // Lloyd-Max codebook fits structured K/V (e.g. GPT-OSS's + // `RMSNorm → Linear(bias=True)` projections). + let centered: MLXArray + let storedBias: MLXArray? + if useBias { + let bias = vectors.mean(axis: -1, keepDims: true) // [B, H, T, 1] + storedBias = bias.squeezed(axis: -1) // [B, H, T] + centered = vectors - bias + } else { + storedBias = nil + centered = vectors + } + // Extract norms and normalize (paper assumes unit sphere; we store norms separately) - let norms = sqrt((vectors * vectors).sum(axis: -1)) + let norms = sqrt((centered * centered).sum(axis: -1)) let safeNorms = maximum(norms, Float(1e-8)) - let unit = vectors / expandedDimensions(safeNorms, axis: -1) + let unit = centered / expandedDimensions(safeNorms, axis: -1) // Rotate: y ← Π · x (Algorithm 1 line 5) let rotated = matmul(unit, rotationT) @@ -719,7 +742,8 @@ public class MSECodec { packedIndices: packed, tokenCount: vectors.dim(2), dim: dim, - bits: bits + bits: bits, + bias: storedBias ) } @@ -735,8 +759,12 @@ public class MSECodec { // Inverse rotate: x̃ ← Π^T · ỹ (Algorithm 1 line 10) let unrotated = matmul(approx, rotation) - // Rescale by stored norms - return expandedDimensions(state.norms, axis: -1) * unrotated + // Rescale by stored norms; add DC bias back in original space. + var recovered = expandedDimensions(state.norms, axis: -1) * unrotated + if let bias = state.bias { + recovered = recovered + expandedDimensions(bias, axis: -1) + } + return recovered } /// Decode in rotated space (skip inverse rotation). @@ -745,7 +773,13 @@ public class MSECodec { public func decodeRotated(_ state: MSECodecState) -> MLXArray { let indices = TurboQuantPacking.unpackLowBit(state.packedIndices, bits: bits, count: dim) let approx = codebook[indices] - return expandedDimensions(state.norms, axis: -1) * approx + var recovered = expandedDimensions(state.norms, axis: -1) * approx + // Bias-aware dequant in rotated space: `(c + b·1) @ R^T = + // c @ R^T + b·rotatedOnes`. No extra matmul per token. + if let bias = state.bias { + recovered = recovered + expandedDimensions(bias, axis: -1) * rotatedOnes.asType(recovered.dtype) + } + return recovered } /// Pre-rotate queries for compressed-domain scoring. @@ -799,39 +833,26 @@ public class MSECodec { // MARK: - TurboQuantizedKVCache -/// KV cache using TurboQuant (MSE-optimal) compression. Two attention paths: +/// KV cache backed by TurboQuant (MSE-optimal) compression. /// -/// **A — default (`useCompressedAttention = false`):** raw-FP16 cache + standard -/// `MLXFast.scaledDotProductAttention(... sinks:)`. The TurboQuant rotation Π -/// is bypassed at decode — SDPA is invariant to a fixed orthogonal rotation -/// applied to both Q and K (and the equivalent rotation around V), so rotating -/// the cache buys nothing for the fused-SDPA path while costing a transition -/// matmul + transient peak (raw + rotated copies + rotated dequant buffer all -/// live during transition) and a per-token rotation matmul. After this fix the -/// prefill→decode boundary keeps `rawKeys`/`rawValues` alive and decode appends -/// to them in place — semantically identical to `StandardKVCache` while -/// preserving rotating-window and sliding-window semantics. Memory and decode -/// speed match `--kv none`. Sinks flow through SDPA natively, all `(kb,vb)` -/// combos work, no graph-fuser barriers. +/// Decode-time attention has two paths inside `compressedAttention`: /// -/// Note: under A the compressed packed buffer is not built — `state` snapshots -/// round-trip only what was already in `rawKeys`/`rawValues`. For mid-decode -/// state preservation backed by compressed storage, opt into B. +/// - **A path (default)** — TurboFlash. The `turboFlashAttention` Metal +/// kernel (or `turboFlashSDPAv` for sinks-using models) scores +/// directly against packed K/V and writes the weighted V in one +/// dispatch. No FP16 K/V materialisation. /// -/// **B — opt-in (`useCompressedAttention = true`):** compressed-domain Metal -/// kernels (`mseScore` + `mseWeightedSum`, or fused `turboFlashAttention`) read -/// the packed buffer directly — no FP16 workspace, memory ≈ `memoryBytes`. -/// Slower than A on alpha today on every model in the cross-bench (50-75% -/// regression vs A on Qwen, Nemotron) — left in place behind the gate for -/// future kernel work and as a compressed-state-snapshot escape hatch. Does -/// not support attention sinks. +/// - **B path (opt-in via `TURBO_DEQUANT_SDPA=1` env var or the +/// `useDequantSDPA: true` constructor arg)** — `bulkDequantRotated` +/// produces a transient FP16 K/V tensor each decode step, then +/// `MLXFast.scaledDotProductAttention` runs on it. The cache stays +/// compressed but working memory expands by `B*nKV*T*D*2` bytes per +/// layer per step. Also the path that consumes the stored bias term — +/// `useBias` forces the B path until TurboFlash kernels learn to +/// apply the per-vector DC bias themselves. /// -/// Both K and V use Algorithm 1 (MSE at b bits, no QJL). See file header for -/// algorithmic details. -/// -/// Renamed from `TurboQuantizedKVCache` in spec 006 (2026-05-04) for symmetry with -/// `AffineQuantizedKVCache`. The typealias `TurboQuantizedKVCache = TurboQuantizedKVCache` -/// is kept for one release. +/// K and V follow Algorithm 1 from the TurboQuant paper (MSE at b bits, +/// no QJL). See the file header for the codec details. public class TurboQuantizedKVCache: BaseKVCache { public let bits: Int // Legacy: used when keyBits == valueBits @@ -872,6 +893,10 @@ public class TurboQuantizedKVCache: BaseKVCache { private var keyNorms: MLXArray? private var valPackedMSE: MLXArray? private var valNorms: MLXArray? + // Per-vector DC offset, allocated when `useBias == true`. Shape + // mirrors norms ([B, H, allocSteps]) — one fp32 per token-head. + private var keyBias: MLXArray? + private var valBias: MLXArray? private var compressedAllocSteps = 0 /// Whether we've transitioned from raw → compressed @@ -907,25 +932,45 @@ public class TurboQuantizedKVCache: BaseKVCache { public override var maxSize: Int? { rotatingMaxSize } - /// When true (default), decode attention uses the compressed-domain - /// fused-dequant + matrix-engine SDPA path — the B path. When false, - /// decode uses the raw-FP16 cache + standard - /// `MLXFast.scaledDotProductAttention` — the A path. B is the default - /// because the dequant+SDPA pipeline (shipped in `c5ca7a3`) closes most - /// of the historic A/B gap while preserving the compressed cache's - /// memory savings. A path remains available via: - /// - `useCompressedAttention: false` on the constructor, or - /// - `TURBO_COMPRESSED_ATTENTION=0` env var (overrides the constructor). - /// Sinks-using models (GPT-OSS family) auto-fallback to A in - /// `AttentionUtils.attentionWithCacheUpdate` regardless of this flag, - /// since the compressed-attention pass2 kernel doesn't yet incorporate - /// sink-token logits in its online softmax. - public var useCompressedAttention: Bool = true + /// Decode attention path selector for the L=1 case: + /// + /// - **A path (default, `useDequantSDPA == false`)** — TurboFlash. The + /// compressed-domain `turboFlashAttention` Metal kernel scores + /// directly against packed K/V; no per-layer FP16 K/V working + /// buffer. True compressed attention end-to-end. + /// - **B path (opt-in, `useDequantSDPA == true`)** — + /// `bulkDequantRotated` materialises a transient FP16 K/V buffer + /// per decode step, then `MLXFast.scaledDotProductAttention` runs + /// on the matmul engine. The cache stays compressed but working + /// memory expands by `B*nKV*T*D*2` bytes per layer per step. + /// Faster on small / medium `headDim` shapes; required today by + /// the bias-correction path (TurboFlash kernels don't yet + /// consume the stored bias term — tracked as a follow-up). + /// + /// Env override: `TURBO_DEQUANT_SDPA=1` forces B globally; `=0` + /// forces A; unset honours the constructor. + public let useDequantSDPA: Bool + + /// When true, encode subtracts per-vector DC bias before + /// quantisation; decode adds it back. Captures the mean offset that + /// the zero-mean Lloyd-Max codebook can't represent — the dominant + /// codec error source on K/V from `RMSNorm → Linear(bias=True)`. + /// Default-off for general use, default-on for GPT-OSS-20B under + /// turbo* schemes (see `GPTOSSModel.newCache(...)`). Env override: + /// `TURBO_BIAS=1`/`=0`. See `testDualScaleMSEReduction` for the + /// empirical comparison against the dual-scale alternative. + /// + /// Bias correction currently requires the B (dequant-SDPA) path — + /// the TurboFlash kernels don't yet apply the stored bias term + /// during attention. When `useBias == true`, the cache routes + /// decode through dequant SDPA regardless of `useDequantSDPA`. + public let useBias: Bool public init( bits: Int = 4, keyBits: Int? = nil, valueBits: Int? = nil, step: Int = 1024, seed: UInt64 = 42, maxSize: Int? = nil, - useCompressedAttention: Bool = true, + useDequantSDPA: Bool = false, + useBias: Bool = false, headDim: Int? = nil ) { self.bits = bits @@ -935,16 +980,19 @@ public class TurboQuantizedKVCache: BaseKVCache { self.seed = seed self.step = step self.rotatingMaxSize = maxSize - // `TURBO_COMPRESSED_ATTENTION` env var explicitly opts in or out of - // the compressed-attention (B) path, overriding the constructor - // default. `=0` forces A; `=1` forces B; unset uses the constructor - // value (B by default). Useful when comparing decode tok/s before - // and after a codec change without recompiling. - let envOverride = ProcessInfo.processInfo.environment["TURBO_COMPRESSED_ATTENTION"] - switch envOverride { - case "0": self.useCompressedAttention = false - case "1": self.useCompressedAttention = true - default: self.useCompressedAttention = useCompressedAttention + // Env overrides for A/B testing without recompiling. Each accepts + // `0`/`1` to force the flag; unset uses the constructor default. + let dequantEnv = ProcessInfo.processInfo.environment["TURBO_DEQUANT_SDPA"] + switch dequantEnv { + case "0": self.useDequantSDPA = false + case "1": self.useDequantSDPA = true + default: self.useDequantSDPA = useDequantSDPA + } + let biasEnv = ProcessInfo.processInfo.environment["TURBO_BIAS"] + switch biasEnv { + case "0": self.useBias = false + case "1": self.useBias = true + default: self.useBias = useBias } super.init() // Eager codec init when headDim is known. This pre-warms the MLX @@ -1094,7 +1142,8 @@ public class TurboQuantizedKVCache: BaseKVCache { ) -> (packed: MLXArray, norms: MLXArray) { if !Self.loggedEncodeKernel { Self.loggedEncodeKernel = true - print("[TURBO] Encode kernel: \(codec.useWHT ? "WHT butterfly" : "dense matmul"), dim=\(headDim), bits=\(codec.bits)") + let biasTag = useBias ? " +bias" : "" + print("[TURBO] Encode kernel: \(codec.useWHT ? "WHT butterfly" : "dense matmul"), dim=\(headDim), bits=\(codec.bits)\(biasTag)") } if codec.useWHT, let signs = codec.whtSigns { return TurboQuantKernelOps.fusedEncodeWHT( @@ -1111,6 +1160,29 @@ public class TurboQuantizedKVCache: BaseKVCache { } } + /// Wrap `fusedEncodeDispatch` with DC-bias correction. When `useBias` + /// is enabled, subtracts the per-vector mean in Swift before handing + /// the *centered* tensor to the Metal encode kernel and returns the + /// stored bias alongside the existing (packed, norms) pair. When + /// `useBias` is off, bias is `nil` and the centered tensor is the + /// input itself — zero overhead vs the old path. + private func fusedEncodeDispatchWithBias( + input: MLXArray, codec: MSECodec, headDim: Int + ) -> (packed: MLXArray, norms: MLXArray, bias: MLXArray?) { + if !useBias { + let (p, n) = fusedEncodeDispatch(input: input, codec: codec, headDim: headDim) + return (p, n, nil) + } + // `input` is [N, D] flat. `keepDims: true` gives [N, 1] for the + // squeeze step. We return bias as a [N] vector to match the + // norms shape downstream consumers expect. + let biasKeep = input.mean(axis: -1, keepDims: true) // [N, 1] + let centered = input - biasKeep + let (packed, norms) = fusedEncodeDispatch( + input: centered, codec: codec, headDim: headDim) + return (packed, norms, biasKeep.squeezed(axis: -1)) // bias: [N] + } + // MARK: - Phase 1: Raw Prefill /// Prefill update: store raw K/V, return raw. Zero encoding overhead. @@ -1355,7 +1427,7 @@ public class TurboQuantizedKVCache: BaseKVCache { let vpw = TurboQuantPacking.packedWidth(count: headDim, bits: valueBits) let flatVals = allValues.reshaped([B * H * tokenCount, headDim]) - let (valPackedFlat, valNormsFlat) = fusedEncodeDispatch( + let (valPackedFlat, valNormsFlat, valBiasFlat) = fusedEncodeDispatchWithBias( input: flatVals, codec: valueMSECodec, headDim: headDim) // Pre-allocate to at least one step beyond current tokenCount to accommodate @@ -1365,25 +1437,36 @@ public class TurboQuantizedKVCache: BaseKVCache { let allocSteps = ((max(minAlloc, tokenCount + step) + step - 1) / step) * step valPackedMSE = MLXArray.zeros([B, H, allocSteps, vpw], dtype: .uint32) valNorms = MLXArray.zeros([B, H, allocSteps]) + if useBias { + valBias = MLXArray.zeros([B, H, allocSteps]) + } if !rawKeyMode { // Compress keys too (standard TurboQuant path) guard let keyMSECodec else { return } let kpw = TurboQuantPacking.packedWidth(count: headDim, bits: keyBits) let flatKeys = allKeys.reshaped([B * H * tokenCount, headDim]) - let (keyPackedFlat, keyNormsFlat) = fusedEncodeDispatch( + let (keyPackedFlat, keyNormsFlat, keyBiasFlat) = fusedEncodeDispatchWithBias( input: flatKeys, codec: keyMSECodec, headDim: headDim) keyPackedMSE = MLXArray.zeros([B, H, allocSteps, kpw], dtype: .uint32) keyNorms = MLXArray.zeros([B, H, allocSteps]) + if useBias { + keyBias = MLXArray.zeros([B, H, allocSteps]) + } keyPackedMSE![.ellipsis, .. 0 { let copyLen = min(writeIdx, compressedAllocSteps) newVP[.ellipsis, .. compressedAllocSteps { let newAlloc = rotatingMaxSize ?? (((writeIdx + numSteps + step - 1) / step) * step) @@ -1497,15 +1590,26 @@ public class TurboQuantizedKVCache: BaseKVCache { let newKN = MLXArray.zeros([B, H, newAlloc]) let newVP = MLXArray.zeros([B, H, newAlloc, vpw], dtype: .uint32) let newVN = MLXArray.zeros([B, H, newAlloc]) + let newKB: MLXArray? = useBias ? MLXArray.zeros([B, H, newAlloc]) : nil + let newVB: MLXArray? = useBias ? MLXArray.zeros([B, H, newAlloc]) : nil if writeIdx > 0 { let copyLen = min(writeIdx, compressedAllocSteps) newKP[.ellipsis, .. (MLXArray, MLXArray) { - let headDim = newKeys.dim(-1) - let prevOffset = offset - let S = newKeys.dim(2) - - if !isCompressed { - isCompressed = true - compressedWriteOffset = min(offset, rotatingMaxSize ?? offset) - if let maxSz = rotatingMaxSize { - let bufferTokens = min(offset, maxSz) - rotatingIdx = bufferTokens % maxSz - } - } - - offset = prevOffset + S - // `compressedWriteOffset` advances symbolically so `memoryBytes` reports - // what compressed storage would cost for the current token count. - compressedWriteOffset += S - - // Rotating-window: time-ordered retain-and-append. - // - // Previous design used modular-slot writes (`rawKeys[writePos:writePos+S] - // = newKeys`) and returned `rawKeys[.. 0 { hasWrappedRotatingBuffer = true } - } else { - combinedK = newKeys - combinedV = newValues - } - rawKeys = combinedK - rawValues = combinedV - if combinedK.dim(2) > maxSz { hasWrappedRotatingBuffer = true } - // Issue #185: KV-shared models read `lastReturnedKeys` / - // `lastReturnedValues` after the donor layer's update. - self.lastReturnedKeys = rawKeys - self.lastReturnedValues = rawValues - return (rawKeys!, rawValues!) - } - - // Linear (non-rotating): StandardKVCache-style step-aligned growth. - let reset = - if let rk = self.rawKeys, prevOffset + S > rk.dim(2) { - true - } else { - self.rawKeys == nil - } - if reset { - let B = newKeys.dim(0) - let H = newKeys.dim(1) - let nSteps = (step + S - 1) / step - let kShape = [B, H, nSteps * step, headDim] - let newRK = MLXArray.zeros(kShape, dtype: newKeys.dtype) - let newRV = MLXArray.zeros(kShape, dtype: newValues.dtype) - - if var currentKeys = self.rawKeys, var currentValues = self.rawValues { - if prevOffset % step != 0 { - currentKeys = currentKeys[.ellipsis, .. MLXArray { - return queries - } - - /// Inverse-rotate SDPA output back to original V basis. - /// A path is a no-op — V is returned in its original basis, so SDPA output - /// is already in the right space. - public func inverseRotateOutput(_ rotatedOutput: MLXArray) -> MLXArray { - return rotatedOutput - } - - /// Compressed-domain attention via Metal kernels. + /// Compressed-domain attention. /// - /// On first call: compresses raw prefill cache in one batch. - /// Then: encode 1 new token → fused attention kernel → inverse rotation. + /// First call: bulk-compresses the raw prefill cache. Subsequent + /// calls: encode the new token → run a fused attention path → undo + /// the V rotation. /// - /// For L=1 (decode): uses TurboFlashAttention — a single Metal dispatch that fuses - /// Q×K scoring + online softmax + Attn×V aggregation. No intermediate score or weight - /// arrays are materialized. This reduces 3 dispatches (score + softmax + value) to 1. + /// Decode (`L=1`) routing: + /// - **A path (default)** — TurboFlash. `turboFlashAttention` (or + /// `turboFlashSDPAv` for sinks-using models, or + /// `turboFlashAttentionCausal` for L>1 prefill) scores directly + /// against packed K/V. No FP16 K/V materialisation. + /// - **B path (opt-in)** — `bulkDequantRotated` materialises a + /// per-layer FP16 K/V buffer, then `MLXFast.scaledDotProductAttention` + /// runs on the matmul engine. Selected when `useDequantSDPA == true` + /// or `useBias == true` (bias correction currently requires the + /// B path — TurboFlash kernels don't yet consume the stored + /// bias term). /// - /// For L>1 (prefill chunks): falls back to separate score → softmax → value kernels - /// since causal masking across multiple query positions requires the full score matrix. + /// Prefill (`L>1`) with `.causal` mask uses + /// `turboFlashAttentionCausal`; otherwise falls back to the + /// separated `mseScore → softmax → mseWeightedSum` kernels. /// - /// In rawKeyMode: uses standard matmul for Q*K scoring (raw FP16 keys, no rotation), - /// then compressed-domain Metal kernel for Attn*V (TurboQuant compressed values). - /// TurboFlash is NOT used — it assumes both K and V are packed. + /// `rawKeyMode` (raw FP16 keys + compressed values) bypasses the K + /// codec: standard matmul for scoring, compressed-domain Metal kernel + /// for `Attn · V`. public func compressedAttention( queries: MLXArray, keys newKeys: MLXArray, values newValues: MLXArray, scale: Float, - mask: MLXFast.ScaledDotProductAttentionMaskMode = .none + mask: MLXFast.ScaledDotProductAttentionMaskMode = .none, + sinks: MLXArray? = nil, + windowSize: Int = -1 ) -> MLXArray { let headDim = newKeys.dim(-1) let B = queries.dim(0) @@ -1922,101 +1895,119 @@ public class TurboQuantizedKVCache: BaseKVCache { } }() - // Dequant-first SDPA path (default for decode L=1 when bits ∈ - // {2, 4, 8}). Bulk-dequant K/V to FP16 in rotated codec space - // via a fused Metal kernel (8 dims/thread bit-unpack + codebook - // gather + norm scale fused), then call MLXFast SDPA — same - // matrix-engine kernel A path uses. Costs temporary FP16 K/V - // (B*H*T*D*2 bytes per layer, freed after SDPA) but skips - // TurboFlash's per-token bit-unpack inside the score loop. - // - // M1 Max sweep (turbo4v2 summarization vs TurboFlash): - // Qwen 0.8B 1k/4k/8k/16k/32k: +27 / +44 / +52 / +34 / +14 % - // Qwen 9B 1k/4k/8k/16k/32k: + 4 / +14 / +14 / +9 / +18 % - // Nemotron 30B 1k/.../32k: + 1 / + 7 / + 7 / +7 / +15 % - // - // Override via `TURBO_DEQUANT_SDPA=0` to force TurboFlash for - // A/B comparison or fallback if a regression is hit on an - // untested config. - // - // KV-sharing donors (Gemma 4 E2B / E4B `isDonor == true`) skip - // the dequant-first path even when the env var is unset: those - // caches already pay one full-prefix dequant for the - // `lastReturnedKeys` / `lastReturnedValues` refresh that shared - // reader layers consume, so layering another `bulkDequantRotated` - // pair on top for the donor's own SDPA *doubles* the per-step - // dequant traffic. TurboFlash scores directly against the packed - // indices (no separate K / V FP16 materialisation), keeping - // the donor's compute proportional to the cache size while the - // refresh still produces the FP16 K / V the reader path needs. - // Measured impact: Gemma 4 E2B turbo4v2 8K decode 26 → ~? tok/s - // (the dequant-first regression versus pass-1 working configs - // — which were already ~3× slower than `--kv none` on E2B — - // was load-bearing on this redundant work). - let dequantEnv = ProcessInfo.processInfo.environment["TURBO_DEQUANT_SDPA"] - // Gate dequant-first SDPA off in two cases: - // - // 1. **KV-sharing donors (`isDonor == true`).** The donor's own - // SDPA already pays the per-step FP16 mirror update for the - // shared reader path; layering `bulkDequantRotated` on top - // doubles memory traffic for no compute payoff. TurboFlash - // scores directly against packed indices. + // Single-pass TurboFlash kernel with sinks + sliding window + // (`turbo_flash_sdpa_v`). Same (kb,vb) coverage as + // `turboFlashAttention` plus (2,2) / (8,3). + let hasTurboFlashSDPAv: Bool = { + switch (keyBits, valueBits) { + case (4,4), (4,2), (4,3), (3,2), (3,3), + (8,2), (8,3), (8,4), (8,8), (2,2): + return true + default: return false + } + }() + + // ─── B path (opt-in via `TURBO_DEQUANT_SDPA=1`) ─── + // Bulk-dequant K/V to FP16 + MLXFast SDPA. Trades a per-layer + // FP16 working buffer (B*nKV*T*D*2 bytes per decode step) for + // matrix-engine SDPA performance. Also the path that consumes + // the stored `useBias` term — TurboFlash kernels don't yet + // apply it during attention, so `useBias` forces this branch. // - // 2. **Large-headDim models (`headDim >= 256`).** Gemma 4 - // turbo4v2 on the 31B dense variant at ctx ≥ 32k produces - // degenerate `"...la la la..."` looping output via - // dequant-first SDPA — reproducible with fresh GPU + freed - // memory, ruling out a contention-driven cause. TurboFlash - // on the same shape generates mostly-coherent output at - // the cost of ~30% decode tok/s. Root cause is a numerical - // quality issue in `bulkDequantRotated`'s WHT-rotated FP16 - // output combined with MLXFast SDPA over very long - // quantised K (32k tokens × headDim=256); fix is spec 041 - // Phase 1 (flash quantised SDPA). The empirical sweep that - // justified dequant-first as the default (Qwen 0.8B/9B + - // Nemotron 30B) all use headDim ≤ 128, so gating on - // `headDim < 256` preserves that win and routes Gemma 4 - // (and future headDim-256+ families) to the numerically- - // robust TurboFlash path. - let useDequantSDPA = (dequantEnv != "0") && !isDonor && headDim < 256 - if L == 1 - && useDequantSDPA + // Skipped when: + // - cache is a KV-sharing donor (already pays per-step FP16 + // mirror updates for shared readers; layering another + // dequant doubles traffic for no gain). + // - bit widths fall outside `{2, 4, 8}` (no dequant kernel + // instantiation). + let dequantEligible = L == 1 && !isDonor && (keyBits == 4 || keyBits == 8 || keyBits == 2) - && (valueBits == 4 || valueBits == 8 || valueBits == 2) { + && (valueBits == 4 || valueBits == 8 || valueBits == 2) + let runDequantSDPA = dequantEligible && (useDequantSDPA || useBias) + if runDequantSDPA { let vH = BenchmarkSignpost.begin(BenchmarkSignpost.PhaseLabel.tqValue) // The precompiled `turbo_dequant_rotated` kernel only - // instantiates `bfloat` and `half` outputs (mlx fork's - // turbo_quant.metal). Some models (e.g. Gemma 4 26B-A4B) - // run attention in fp32; clamp to bf16 for the dequant + - // SDPA + rotation chain, then cast the final output back - // to the model's dtype so downstream layers see the - // expected precision. + // instantiates `bfloat` and `half` outputs. Some models + // (e.g. Gemma 4 26B-A4B) run attention in fp32; clamp to + // bf16 for the dequant + SDPA + rotation chain and cast + // the final output back to the model's dtype. let originalDtype = queries.dtype let dt: DType = (originalDtype == .bfloat16 || originalDtype == .float16) ? originalDtype : .bfloat16 let qForSDPA = (qRot.dtype == dt) ? qRot : qRot.asType(dt) - let kFP = TurboQuantKernelOps.bulkDequantRotated( + var kFP = TurboQuantKernelOps.bulkDequantRotated( packed: keyPackedMSE![0..., 0..., .. 0 ? .slidingWindow(size: windowSize) : .none let rotOut = MLXFast.scaledDotProductAttention( queries: qForSDPA.reshaped([B, nQHeads, L, headDim]), keys: kFP, values: vFP, - scale: 1.0, mask: .none) + scale: 1.0, mask: maskMode, + sinks: sinks) output = matmul(rotOut, valueMSECodec.rotation) if output.dtype != originalDtype { output = output.asType(originalDtype) } BenchmarkSignpost.end(vH) + } else if let sinksArr = sinks, L == 1, hasTurboFlashSDPAv { + // ─── A path (sinks variant) ─── + // Single-pass TurboFlash kernel that folds sinks + sliding + // window into its online softmax. Scores directly against + // packed K/V; no FP16 working buffer. + let vH = BenchmarkSignpost.begin(BenchmarkSignpost.PhaseLabel.tqValue) + let causal = (windowSize > 0) + let rotOut = TurboQuantKernelOps.turboFlashSDPAv( + rotatedQueries: flatQ, + keyPacked: flatKeyPacked, keyNorms: flatKeyNorms, + keyCodebook: keyMSECodec.codebook, + valPacked: flatValPacked, valNorms: flatValNorms, + valCodebook: valueMSECodec.codebook, + tokenCount: tokenCount, repeatCount: nRepeats, + keyBits: self.keyBits, valueBits: self.valueBits, dim: headDim, + sinks: sinksArr, + causal: causal, + windowSize: causal ? windowSize : -1, + valRotation: valRotation + ) + BenchmarkSignpost.end(vH) + output = rotOut.reshaped([B, nQHeads, L, headDim]) + if output.dtype != queries.dtype { + output = output.asType(queries.dtype) + } + return output } else if L == 1 && hasTurboFlashKernel { - // TurboFlashAttention path (decode, L=1) — fuses score + softmax + value. + // ─── A path (no-sinks decode) ─── + // `turboFlashAttention` fuses score + online softmax + + // value-weighted sum into one pass over packed K/V. let vH = BenchmarkSignpost.begin(BenchmarkSignpost.PhaseLabel.tqValue) output = TurboQuantKernelOps.turboFlashAttention( rotatedQueries: flatQ, @@ -2031,7 +2022,7 @@ public class TurboQuantizedKVCache: BaseKVCache { BenchmarkSignpost.end(vH) } else if case .causal = mask, hasTurboFlashKernel { - // Causal TurboFlashAttention path (prefill, L>1) + // ─── A path (causal prefill, L>1) ─── let vH = BenchmarkSignpost.begin(BenchmarkSignpost.PhaseLabel.tqValue) let queryOffset = tokenCount - L output = TurboQuantKernelOps.turboFlashAttentionCausal( @@ -2109,13 +2100,10 @@ public class TurboQuantizedKVCache: BaseKVCache { if let rv = rawValues { total += arrayBytes(rv) } return total } - // Resolve [B, H, T, D] from whichever storage is live. `rawKeys` is - // kept in rawKeyMode and during the first decode call; the packed - // buffers exist post-compression in both modes. - // Prefer the packed buffers since they're the authoritative - // post-compression storage; fall back to `rawKeys` (rawKeyMode) and - // finally to legacy `dequantKeys` for older state shapes. - let shapeSrc: MLXArray? = keyPackedMSE ?? valPackedMSE ?? rawKeys ?? dequantKeys + // Resolve [B, H, T, D] from whichever storage is live. Packed buffers + // are authoritative post-compression; `rawKeys` is kept during + // `rawKeyMode` and across the first decode call. + let shapeSrc: MLXArray? = keyPackedMSE ?? valPackedMSE ?? rawKeys guard let rk = shapeSrc else { return 0 } let tokenCount = compressedWriteOffset guard tokenCount > 0 else { return 0 } @@ -2155,22 +2143,33 @@ public class TurboQuantizedKVCache: BaseKVCache { if isCompressed { if rawKeyMode { // Raw-K mode compressed: [rawKeys, valPacked, valNorms] + // (+ [valBias] when `useBias=true`) guard let rk = rawKeys, let vpm = valPackedMSE, let vn = valNorms, offset > 0 else { return [] } - return [ + var out: [MLXArray] = [ rk[0..., 0..., .. 0 else { return [] } - return [ + var out: [MLXArray] = [ kpm[0..., 0..., .. 0 else { return [] } @@ -2178,18 +2177,24 @@ public class TurboQuantizedKVCache: BaseKVCache { } } set { - if rawKeyMode && newValue.count == 3 { + if rawKeyMode && (newValue.count == 3 || newValue.count == 4) { // Raw-K mode compressed state: [rawKeys, valPacked, valNorms] + // (+ [valBias] when `useBias=true`) rawKeys = newValue[0] rawAllocSteps = newValue[0].dim(2) valPackedMSE = newValue[1]; valNorms = newValue[2] + if newValue.count == 4 { valBias = newValue[3] } offset = newValue[0].dim(2) compressedAllocSteps = newValue[1].dim(2) isCompressed = true - } else if newValue.count == 4 { + } else if newValue.count == 4 || newValue.count == 6 { // Standard compressed state: [keyPacked, keyNorms, valPacked, valNorms] + // (+ [keyBias, valBias] when `useBias=true`) keyPackedMSE = newValue[0]; keyNorms = newValue[1] valPackedMSE = newValue[2]; valNorms = newValue[3] + if newValue.count == 6 { + keyBias = newValue[4]; valBias = newValue[5] + } offset = newValue[0].dim(2) compressedAllocSteps = offset isCompressed = true @@ -2213,7 +2218,7 @@ public class TurboQuantizedKVCache: BaseKVCache { rawKeys = nil; rawValues = nil; rawAllocSteps = 0 keyPackedMSE = nil; keyNorms = nil valPackedMSE = nil; valNorms = nil - dequantKeys = nil; dequantValues = nil + keyBias = nil; valBias = nil compressedAllocSteps = 0; isCompressed = false } return trimCount diff --git a/Libraries/MLXLMCommon/TurboQuantKernels.swift b/Libraries/MLXLMCommon/TurboQuantKernels.swift index adc8d4183b..b11d733611 100644 --- a/Libraries/MLXLMCommon/TurboQuantKernels.swift +++ b/Libraries/MLXLMCommon/TurboQuantKernels.swift @@ -1760,6 +1760,87 @@ public enum TurboQuantKernelOps { ) } + /// TurboQuant fused single-pass SDPA with sinks (spec 041 phase 1.1 + /// follow-up). Wraps `MLXFast.turboFlashSDPAv` — a single Metal + /// kernel dispatch that does score + online softmax + sinks fold + + /// value aggregation over compressed K/V, no pass1/pass2 split. The + /// single-pass design replaces the earlier + /// `ek/turbo-flash-sinks` chain whose cross-block sinks fold + /// produced incoherent output on GPT-OSS-20B. + /// + /// Output is in rotated V space — caller multiplies by `valRotation` + /// (`Π_v^T`) when supplied. + /// + /// Decode-only today (L=1); causal masking with `windowSize` covers the + /// sliding-window models (GPT-OSS, Gemma 4 family). The kernel template + /// is instantiated for `dim ∈ {64, 96, 128, 256, 512}` and + /// `(keyBits, valueBits) ∈ {(4,4),(4,2),(4,3),(3,2),(3,3),(8,4), + /// (8,2),(8,3),(8,8),(2,2)}` (mlx + /// `kernels/turbo_flash_sdpa.metal`). + /// + /// - Parameters: + /// - rotatedQueries: Pre-rotated and pre-scaled queries [totalQ, D] + /// (scale folded into the codec rotation matrix by + /// `prepareQueriesScaled`) + /// - keyPacked: Packed key indices [totalKVHeads, T, KeyPackedWidth] uint32 + /// - keyNorms: Key norms [totalKVHeads, T] float32 + /// - keyCodebook: Key centroids [2^keyBits] float32 + /// - valPacked: Packed value indices [totalKVHeads, T, ValPackedWidth] uint32 + /// - valNorms: Value norms [totalKVHeads, T] float32 + /// - valCodebook: Value centroids [2^valueBits] float32 + /// - tokenCount: Number of cached tokens (T) + /// - repeatCount: GQA repeat factor (nQHeads / nKVHeads) + /// - keyBits: Key codec bit-width + /// - valueBits: Value codec bit-width + /// - dim: Per-head dimension (D) + /// - sinks: Optional `[nQHeads]` per-Q-head sink logits (GPT-OSS family) + /// - causal: When true, applies causal mask (sliding window when + /// `windowSize > 0`). At L=1, "causal" means "all positions visible" + /// unless `windowSize` restricts the prefix. + /// - windowSize: Sliding-window size (<=0 ⇒ no window) + /// - valRotation: Optional inverse value rotation matrix Π_v^T — + /// applied as a single matmul on the output. Pass `nil` to leave the + /// output in rotated V space and apply the rotation in the caller. + /// - Returns: Output [totalQ, D] (`bfloat16` from the kernel; caller + /// typically casts to the model dtype) + public static func turboFlashSDPAv( + rotatedQueries: MLXArray, + keyPacked: MLXArray, + keyNorms: MLXArray, + keyCodebook: MLXArray, + valPacked: MLXArray, + valNorms: MLXArray, + valCodebook: MLXArray, + tokenCount: Int, + repeatCount: Int, + keyBits: Int, + valueBits: Int, + dim: Int, + sinks: MLXArray? = nil, + causal: Bool = false, + windowSize: Int = -1, + valRotation: MLXArray? = nil + ) -> MLXArray { + let raw = MLXFast.turboFlashSDPAv( + queries: rotatedQueries, + kPacked: keyPacked, kNorms: keyNorms, kCodebook: keyCodebook, + vPacked: valPacked, vNorms: valNorms, vCodebook: valCodebook, + keyBits: keyBits, valueBits: valueBits, dim: dim, + repeatCount: repeatCount, + sinks: sinks, + causal: causal, + windowSize: windowSize + ) + if let valRotation { + // raw: [totalQ, D] in rotated V space → matmul with Π_v^T + // (`valueMSECodec.rotation`) puts the result back into the + // model's native V space, matching the contract of the existing + // turboFlash*Attention wrappers above. + return matmul(raw, valRotation) + } + return raw + } + /// Compute Q×K attention scores from packed codebook indices. /// /// - Parameters: diff --git a/Libraries/MLXVLM/Models/Gemma3.swift b/Libraries/MLXVLM/Models/Gemma3.swift index e63315ad90..8ed24b2e76 100644 --- a/Libraries/MLXVLM/Models/Gemma3.swift +++ b/Libraries/MLXVLM/Models/Gemma3.swift @@ -113,14 +113,13 @@ private class LanguageModel: Module, KVCacheDimensionProvider { let slidingWindowPattern = config.slidingWindowPattern // LLM Gemma 3 leaves `defaultPrefillStepSize` at the protocol default // (1024); align the affine cache step here. - let affineStep = 1024 + let prefillStep = 1024 for i in 0 ..< config.hiddenLayers { let isGlobalLayer = (i % slidingWindowPattern == slidingWindowPattern - 1) caches.append(makeAttentionCache( parameters: parameters, - maxSize: isGlobalLayer ? nil : slidingWindow, - affineStep: affineStep, - architecturalSlidingWindow: !isGlobalLayer)) + slidingWindow: isGlobalLayer ? nil : slidingWindow, + prefillStep: prefillStep)) } return caches } diff --git a/Libraries/MLXVLM/Models/Gemma4.swift b/Libraries/MLXVLM/Models/Gemma4.swift index 977a2110aa..57a742c174 100644 --- a/Libraries/MLXVLM/Models/Gemma4.swift +++ b/Libraries/MLXVLM/Models/Gemma4.swift @@ -1078,28 +1078,26 @@ private final class Gemma4TextLanguageModel: Module, KVCacheDimensionProvider { // `--kv affine4` is selected. The LLM constant // (`Gemma4Defaults.prefillStepSize`) is `private`, so the value // is duplicated here intentionally. - let affineStep = 4096 + let prefillStep = 4096 // Spec 041 phase 5 follow-up: the VLM variant's // `Gemma4TextAttention` already builds a `.quantized(...)` // Gemma4SharedKVState when the donor cache is // `AffineQuantizedKVCache`, and its shared-layer path runs // `quantizedScaledDotProductAttention` directly. So we can drop // `forceRawKV: true` — donors stay compressed under affine, - // mirroring the Gemma 4 LLM fix. Sliding-window layers still hit - // the `architecturalSlidingWindow: true` fallback because affine - // has no rotating-buffer path; closing that gap is the Phase 1.2 - // sliding-window kernel work. + // mirroring the Gemma 4 LLM fix. Sliding-window layers use the + // spec 041 phase 1.2 rotating-window affine cache. _ = config.numKVSharedLayers > 0 // previously gated forceRawKV return config.layerTypes .prefix(config.hiddenLayers - config.numKVSharedLayers) .map { layerType in - let isSliding = (layerType != "full_attention") - let maxSize: Int? = - (layerType == "full_attention") ? parameters?.maxKVSize : slidingWindow + let layerSlidingWindow: Int? = + (layerType == "full_attention") ? nil : slidingWindow return makeAttentionCache( - parameters: parameters, maxSize: maxSize, - affineStep: affineStep, forceRawKV: false, - architecturalSlidingWindow: isSliding) + parameters: parameters, + slidingWindow: layerSlidingWindow, + prefillStep: prefillStep, + forceRawKV: false) } } diff --git a/Libraries/MLXVLM/Models/LFM2VL.swift b/Libraries/MLXVLM/Models/LFM2VL.swift index 0ff2d7c43d..f8b3488b80 100644 --- a/Libraries/MLXVLM/Models/LFM2VL.swift +++ b/Libraries/MLXVLM/Models/LFM2VL.swift @@ -866,10 +866,10 @@ public class LFM2VL: Module, VLMModel, KVCacheDimensionProvider { let textConfig = config.textConfiguration // LFM2 LLM leaves `defaultPrefillStepSize` at the protocol default // (1024); align the affine cache step here. - let affineStep = 1024 + let prefillStep = 1024 return (0 ..< textConfig.hiddenLayers).map { layerIdx in if textConfig.fullAttnIdxs.contains(layerIdx) { - makeAttentionCache(parameters: parameters, affineStep: affineStep) + makeAttentionCache(parameters: parameters, prefillStep: prefillStep) } else { SSMStateCache() } diff --git a/Libraries/MLXVLM/Models/Mistral3.swift b/Libraries/MLXVLM/Models/Mistral3.swift index 6a43010e83..ece70b2458 100644 --- a/Libraries/MLXVLM/Models/Mistral3.swift +++ b/Libraries/MLXVLM/Models/Mistral3.swift @@ -366,20 +366,21 @@ private enum Language { ?? Array(repeating: "full_attention", count: config.numHiddenLayers) // LLM Mistral3 leaves `defaultPrefillStepSize` at the protocol // default (1024); align the affine cache step here. - let affineStep = 1024 + let prefillStep = 1024 return layerTypes.map { layerType in if layerType == "sliding_attention", let slidingWindow = config.slidingWindow { return makeAttentionCache( - parameters: parameters, maxSize: slidingWindow, - affineStep: affineStep, - architecturalSlidingWindow: true) + parameters: parameters, + slidingWindow: slidingWindow, + prefillStep: prefillStep) } else { + // Full-attention layer: function reads + // `parameters?.maxKVSize` internally as the budget cap. return makeAttentionCache( parameters: parameters, - maxSize: parameters?.maxKVSize, keep: 4, - affineStep: affineStep) + prefillStep: prefillStep) } } } diff --git a/Libraries/MLXVLM/Models/Pixtral.swift b/Libraries/MLXVLM/Models/Pixtral.swift index ebe8dd749e..4a578aeeeb 100644 --- a/Libraries/MLXVLM/Models/Pixtral.swift +++ b/Libraries/MLXVLM/Models/Pixtral.swift @@ -715,13 +715,12 @@ private enum PixtralLanguage { func newCache(parameters: GenerateParameters?) -> [KVCache] { // Pixtral's text model uses the protocol-default prefill step // (1024); align the affine cache step here. - let affineStep = 1024 + let prefillStep = 1024 return (0 ..< config.numHiddenLayers).map { _ in makeAttentionCache( parameters: parameters, - maxSize: parameters?.maxKVSize, keep: 4, - affineStep: affineStep) + prefillStep: prefillStep) } } } diff --git a/Libraries/MLXVLM/Models/Qwen35.swift b/Libraries/MLXVLM/Models/Qwen35.swift index 93afae45a5..a1bb2fdf48 100644 --- a/Libraries/MLXVLM/Models/Qwen35.swift +++ b/Libraries/MLXVLM/Models/Qwen35.swift @@ -1003,16 +1003,15 @@ enum Qwen35Language { // and `4096` for MoE — the VLM text-model defaults aren't exposed // through this inner class, so use the dense default (1024) // which is the conservative floor across the family. - let affineStep = 1024 + let prefillStep = 1024 return model.layers.map { layer in if layer.isLinear { return SSMStateCache() } return makeAttentionCache( parameters: parameters, - maxSize: parameters?.maxKVSize, keep: 4, - affineStep: affineStep) + prefillStep: prefillStep) } } } diff --git a/Tests/MLXLMTests/KVCacheTests.swift b/Tests/MLXLMTests/KVCacheTests.swift index d229aafa81..f9dfec6c46 100644 --- a/Tests/MLXLMTests/KVCacheTests.swift +++ b/Tests/MLXLMTests/KVCacheTests.swift @@ -819,7 +819,7 @@ func testMakeAttentionCacheTurboWindowed() async throws { let turboParams = GenerateParameters( compressionAlgorithm: .turbo(keyBits: 4, valueBits: 2)) let turboWindow = makeAttentionCache( - parameters: turboParams, maxSize: 1024) + parameters: turboParams, slidingWindow: 1024) #expect(type(of: turboWindow) == TurboQuantizedKVCache.self) #expect(turboWindow.maxSize == 1024) if case .turboCompressed(let kb, let vb) = turboWindow.storageKind { @@ -829,27 +829,59 @@ func testMakeAttentionCacheTurboWindowed() async throws { Issue.record("Expected .turboCompressed storageKind on windowed turbo") } - // Turbo without maxSize → still falls through to unbounded - // StandardKVCache. Models that want unbounded TurboQuant construct - // it directly with `headDim:` to pre-warm the JIT (see - // Qwen35.swift::newCache and NemotronH.swift::newCache). - let turboNoWindow = makeAttentionCache( - parameters: turboParams, maxSize: nil) + // Turbo without any cap (no architectural slidingWindow, no user + // maxKVSize) → falls through to unbounded `StandardKVCache`. Models + // that want unbounded TurboQuant construct it directly with `headDim:` + // to pre-warm the JIT (see Qwen35.swift::newCache and + // NemotronH.swift::newCache). + let turboNoWindow = makeAttentionCache(parameters: turboParams) #expect(type(of: turboNoWindow) == StandardKVCache.self) - // No compression + maxSize → StandardKVCache windowed (unchanged). + // No compression + architectural slidingWindow → StandardKVCache windowed. let noneWindow = makeAttentionCache( - parameters: GenerateParameters(), maxSize: 4096, keep: 4) + parameters: GenerateParameters(), slidingWindow: 4096, keep: 4) #expect(type(of: noneWindow) == StandardKVCache.self) #expect(noneWindow.maxSize == 4096) - // Affine + maxSize → AffineQuantizedKVCache (window ignored, matching the - // pre-spec-006 legacy `maybeQuantizeKVCache` swap behaviour). - let affineParams = GenerateParameters( + // No compression + user budget cap (parameters.maxKVSize) → also + // StandardKVCache windowed. Validates the user-budget path: when + // there's no architectural sliding-window but the user wants a + // bounded cache, the function reads maxKVSize internally. + let noneUserBudget = makeAttentionCache( + parameters: GenerateParameters(maxKVSize: 2048), keep: 4) + #expect(type(of: noneUserBudget) == StandardKVCache.self) + #expect(noneUserBudget.maxSize == 2048) + + // Affine + user budget cap (parameters.maxKVSize) but no architectural + // sliding-window → rotating-window `AffineQuantizedKVCache(maxSize:)`. + // Same rotating dispatch as the architectural-sliding affine path — + // the cache class's rotation logic doesn't care where the cap came + // from. Closes the previous UX wart where `--max-kv-size` was + // silently ignored under `.affine`. + let affineUserBudgetParams = GenerateParameters( + maxKVSize: 4096, compressionAlgorithm: .affine(bits: 4, groupSize: 64)) - let affineWindow = makeAttentionCache( - parameters: affineParams, maxSize: 4096) - #expect(type(of: affineWindow) == AffineQuantizedKVCache.self) + let affineUserBudget = makeAttentionCache(parameters: affineUserBudgetParams) + #expect(type(of: affineUserBudget) == AffineQuantizedKVCache.self) + #expect(affineUserBudget.maxSize == 4096) + + // Affine + architectural slidingWindow → rotating-window + // `AffineQuantizedKVCache` (spec 041 phase 1.2). Affine compression + // retained on sliding-window layers. + let affineSliding = makeAttentionCache( + parameters: GenerateParameters( + compressionAlgorithm: .affine(bits: 4, groupSize: 64)), + slidingWindow: 4096) + #expect(type(of: affineSliding) == AffineQuantizedKVCache.self) + #expect(affineSliding.maxSize == 4096) + + // Affine + no cap at all (no architectural sliding, no user budget) + // → unbounded `AffineQuantizedKVCache`. + let affineUnbounded = makeAttentionCache( + parameters: GenerateParameters( + compressionAlgorithm: .affine(bits: 4, groupSize: 64))) + #expect(type(of: affineUnbounded) == AffineQuantizedKVCache.self) + #expect(affineUnbounded.maxSize == nil) } @Test("KVCache.CompressionAlgorithm parser round-trips every supported string format") @@ -1448,6 +1480,72 @@ func testToQuantizedDispatchesOnEviction() async throws { #expect(!outHasNaN) } +// MARK: - TurboQuant + sinks path (GPT-OSS family) + +/// End-to-end regression for `TurboQuantizedKVCache.compressedAttention(... +/// sinks:)`. Compares one L=1 decode step against raw-FP16 +/// `MLXFast.scaledDotProductAttention(... sinks:)`. Tolerance is the +/// 4-bit MSE codec quantisation ceiling (~22% relative). +/// +/// Originally caught the kv-head-1+ silent-zero bug — the kernel +/// assumed contiguous layout but `keyPackedMSE[..., .. MLXArray(lower) // [T] bool + let keep4 = keep + .expandedDimensions(axis: 0) + .expandedDimensions(axis: 0) // [1, 1, T] + scores = MLX.where(keep4, scores, MLXArray(-Float.infinity)) + + // Softmax with sinks fold: numerically stable manual softmax. + let maxScore = scores.max(axis: -1, keepDims: true) // [nQ, 1, 1] + let sinksReshaped = sinks.reshaped([nQ, 1, 1]) + let folded = MLX.maximum(maxScore, sinksReshaped) + let expScores = MLX.exp(scores - folded) // [nQ, 1, T] + let expSinks = MLX.exp(sinksReshaped - folded) // [nQ, 1, 1] + let denom = expScores.sum(axis: -1, keepDims: true) + expSinks + let weights = expScores / denom // [nQ, 1, T] + + let refOut = matmul(weights, vExp).reshaped([nQ, D]) // [nQ, D] + eval(refOut) + + // Kernel emits bfloat16; cast to float32 for the diff. + let kernelF32 = kernelOut.asType(.float32) + let diff = MLX.abs(kernelF32 - refOut) + let maxDiff = diff.max().item(Float.self) + let refMax = MLX.abs(refOut).max().item(Float.self) + let relErr = refMax > 0 ? maxDiff / refMax : maxDiff + let hasNaN = MLX.isNaN(kernelF32).any().item(Bool.self) + let hasInf = MLX.isInf(kernelF32).any().item(Bool.self) + + print("turboFlashSDPAv kb=\(kb) vb=\(vb): maxDiff=\(maxDiff) relErr=\(String(format: "%.4f", relErr))") + XCTAssertFalse(hasNaN, "kernel output NaN at kb=\(kb) vb=\(vb)") + XCTAssertFalse(hasInf, "kernel output Inf at kb=\(kb) vb=\(vb)") + // bf16 + online softmax tolerance — same bar the affine flash + // SDPA tests use (~6e-2 worst-case for 4-bit codec on this shape). + XCTAssertLessThan(relErr, 0.1, + "turboFlashSDPAv relErr too high at kb=\(kb) vb=\(vb)") + } + } + + /// With `sinks` set to large-negative values (≈ no contribution), + /// the new single-pass kernel must match the existing two-pass + /// `turboFlashAttention` on the same packed K/V — catches + /// score/softmax/value regressions independent of the sinks fold. + func testTurboFlashSDPAvNoSinksMatchesTurboFlashAttention() { + let kb = 4, vb = 4 + let B = 1, nQ = 8, nKV = 2, T = 64, D = 64 + let repeatCount = nQ / nKV + let kpw = TurboQuantPacking.packedWidth(count: D, bits: kb) + let vpw = TurboQuantPacking.packedWidth(count: D, bits: vb) + + let qRot = MLXRandom.normal([B * nQ, D], + key: MLXRandom.key(701)).asType(.float32) + + let kCodec = MSECodec(dim: D, bits: kb, seed: 71) + let vCodec = MSECodec(dim: D, bits: vb, seed: 73) + let rawK = MLXRandom.normal([nKV * T, D], + key: MLXRandom.key(81)).asType(.float32) + let rawV = MLXRandom.normal([nKV * T, D], + key: MLXRandom.key(83)).asType(.float32) + + let (kPackedFlat, kNormsFlat) = TurboQuantKernelOps.fusedEncodeWHT( + input: rawK, whtSigns: kCodec.whtSigns!, + boundaries: kCodec.boundaries, codebook: kCodec.codebook, + bits: kb, dim: D) + let (vPackedFlat, vNormsFlat) = TurboQuantKernelOps.fusedEncodeWHT( + input: rawV, whtSigns: vCodec.whtSigns!, + boundaries: vCodec.boundaries, codebook: vCodec.codebook, + bits: vb, dim: D) + let kPacked = kPackedFlat.reshaped([nKV, T, kpw]) + let kNorms = kNormsFlat.reshaped([nKV, T]) + let vPacked = vPackedFlat.reshaped([nKV, T, vpw]) + let vNorms = vNormsFlat.reshaped([nKV, T]) + + // Reference: existing two-pass kernel, no sinks. Already validated. + let outRef = TurboQuantKernelOps.turboFlashAttention( + rotatedQueries: qRot, + keyPacked: kPacked, keyNorms: kNorms, keyCodebook: kCodec.codebook, + valPacked: vPacked, valNorms: vNorms, valCodebook: vCodec.codebook, + tokenCount: T, repeatCount: repeatCount, + keyBits: kb, valueBits: vb, dim: D, + valRotation: nil + ) + + // New single-pass kernel with sinks ≈ -INF (suppressed). The fold's + // `exp(sink - new_max)` term goes to ~0, leaving the result equal to + // the no-sinks path within fp32 precision. + let suppressedSinks = MLXArray([Float](repeating: -1e30, count: nQ)) + let outBeta = MLXFast.turboFlashSDPAv( + queries: qRot, + kPacked: kPacked, kNorms: kNorms, kCodebook: kCodec.codebook, + vPacked: vPacked, vNorms: vNorms, vCodebook: vCodec.codebook, + keyBits: kb, valueBits: vb, dim: D, repeatCount: repeatCount, + sinks: suppressedSinks, + causal: false, + windowSize: -1 + ) + eval(outRef, outBeta) + + let outRefF = outRef.asType(.float32) + let outBetaF = outBeta.asType(.float32) + let diff = MLX.abs(outRefF - outBetaF) + let maxDiff = diff.max().item(Float.self) + let refMag = MLX.abs(outRefF).max().item(Float.self) + let relErr = refMag > 0 ? maxDiff / refMag : maxDiff + let hasNaN = MLX.isNaN(outBetaF).any().item(Bool.self) + + print("turbo_flash_sdpa_v vs turboFlashAttention (sinks≈-INF): maxDiff=\(maxDiff) relErr=\(String(format: "%.4f", relErr))") + XCTAssertFalse(hasNaN, "single-pass kernel output must not be NaN") + // bf16 round-trip + fp32 reduction differences across two + // independently-implemented kernels — same threshold as the + // sinks test (0.05). + XCTAssertLessThan(relErr, 0.05, + "single-pass kernel (sinks≈-INF) must match turboFlashAttention; relErr=\(relErr)") + + // Sinks=0 probe: the sink contributes exp(0)=1 to the denominator, + // which shifts the output magnitude slightly but not by ~30%. If + // the output differs by more than ~30% relative to the no-sinks + // path, the sinks handling has a systematic bug. + let zeroSinks = MLXArray([Float](repeating: 0.0, count: nQ)) + let outBetaZero = MLXFast.turboFlashSDPAv( + queries: qRot, + kPacked: kPacked, kNorms: kNorms, kCodebook: kCodec.codebook, + vPacked: vPacked, vNorms: vNorms, vCodebook: vCodec.codebook, + keyBits: kb, valueBits: vb, dim: D, repeatCount: repeatCount, + sinks: zeroSinks, + causal: false, + windowSize: -1 + ) + eval(outBetaZero) + let outBetaZeroF = outBetaZero.asType(.float32) + let diffZero = MLX.abs(outBetaZeroF - outRefF) + let maxDiffZero = diffZero.max().item(Float.self) + let relErrZero = refMag > 0 ? maxDiffZero / refMag : maxDiffZero + print("turbo_flash_sdpa_v +sinks=0 vs turboFlashAttention: maxDiff=\(maxDiffZero) relErr=\(String(format: "%.4f", relErrZero))") + XCTAssertLessThan(relErrZero, 0.3, + "single-pass kernel (sinks=0) drifted too far from no-sinks: relErr=\(relErrZero)") + + // End-to-end equivalence WITH rotation. The existing path fuses + // the inverse rotation into the pass2 kernel; the new single-pass wrapper + // applies it as a separate `matmul(raw, valRotation)`. If both + // are matmul(rotated_out, valRotation), the outputs must match + // within bf16 precision. + let valRotation = vCodec.rotation + let outRefRotated = TurboQuantKernelOps.turboFlashAttention( + rotatedQueries: qRot, + keyPacked: kPacked, keyNorms: kNorms, keyCodebook: kCodec.codebook, + valPacked: vPacked, valNorms: vNorms, valCodebook: vCodec.codebook, + tokenCount: T, repeatCount: repeatCount, + keyBits: kb, valueBits: vb, dim: D, + valRotation: valRotation + ) + let outBetaRotated = TurboQuantKernelOps.turboFlashSDPAv( + rotatedQueries: qRot, + keyPacked: kPacked, keyNorms: kNorms, keyCodebook: kCodec.codebook, + valPacked: vPacked, valNorms: vNorms, valCodebook: vCodec.codebook, + tokenCount: T, repeatCount: repeatCount, + keyBits: kb, valueBits: vb, dim: D, + sinks: zeroSinks, + causal: false, + windowSize: -1, + valRotation: valRotation + ) + eval(outRefRotated, outBetaRotated) + let diffRot = MLX.abs(outRefRotated.asType(.float32) - outBetaRotated.asType(.float32)) + let maxDiffRot = diffRot.max().item(Float.self) + let refRotMag = MLX.abs(outRefRotated.asType(.float32)).max().item(Float.self) + let relErrRot = refRotMag > 0 ? maxDiffRot / refRotMag : maxDiffRot + print("turbo_flash_sdpa_v (sinks=0, +rot) vs turboFlashAttention (+rot): maxDiff=\(maxDiffRot) relErr=\(String(format: "%.4f", relErrRot))") + XCTAssertLessThan(relErrRot, 0.05, + "turbo_flash_sdpa_v (sinks=0) +rotation differs from turboFlashAttention +rotation: relErr=\(relErrRot)") + + // bf16 Q vs fp32 Q: the existing path and the new single-pass path both cast + // queries to float32 inside the kernel, so the bf16 input should + // produce ~identical output to the fp32 input. If not, something + // in the cast chain is broken. + let qRotBF16 = qRot.asType(.bfloat16) + let outRefBF16 = TurboQuantKernelOps.turboFlashAttention( + rotatedQueries: qRotBF16, + keyPacked: kPacked, keyNorms: kNorms, keyCodebook: kCodec.codebook, + valPacked: vPacked, valNorms: vNorms, valCodebook: vCodec.codebook, + tokenCount: T, repeatCount: repeatCount, + keyBits: kb, valueBits: vb, dim: D, + valRotation: valRotation + ) + let outBetaBF16 = TurboQuantKernelOps.turboFlashSDPAv( + rotatedQueries: qRotBF16, + keyPacked: kPacked, keyNorms: kNorms, keyCodebook: kCodec.codebook, + valPacked: vPacked, valNorms: vNorms, valCodebook: vCodec.codebook, + tokenCount: T, repeatCount: repeatCount, + keyBits: kb, valueBits: vb, dim: D, + sinks: zeroSinks, + causal: false, + windowSize: -1, + valRotation: valRotation + ) + eval(outRefBF16, outBetaBF16) + let diffBF16 = MLX.abs(outRefBF16.asType(.float32) - outBetaBF16.asType(.float32)) + let maxDiffBF16 = diffBF16.max().item(Float.self) + let refMagBF16 = MLX.abs(outRefBF16.asType(.float32)).max().item(Float.self) + print("turbo_flash_sdpa_v (BF16 Q, sinks=0, +rot) vs turboFlashAttention (BF16 Q, +rot): maxDiff=\(maxDiffBF16) refMag=\(refMagBF16)") + XCTAssertLessThan(maxDiffBF16, 0.1, + "turbo_flash_sdpa_v (BF16 Q, sinks=0) +rotation differs from turboFlashAttention BF16: maxDiff=\(maxDiffBF16)") + } + + /// Empirical MSE comparison probe — single-scale vs dual-half-scale + /// (TQ4_1S-style) vs DC-bias-correction on the MSE codec. Drove the + /// session's decision to ship bias correction (9-22% MSE reduction on + /// structured K/V) rather than dual-scale (1-8% — the WHT rotation + /// flattens the per-half asymmetry dual-scale wants to exploit). Also + /// asserts that `MSECodec.encode(useBias:)` matches the inline + /// reference math. + func testDualScaleMSEReduction() { + let dim = 64 + let halfDim = dim / 2 + let N = 1024 + + // Quantize helper that mirrors codec.boundaryQuantize but only for 2D input. + func quantize2D(_ x: MLXArray, boundaries: MLXArray) -> MLXArray { + let nBoundaries = boundaries.shape[0] + let xExp = expandedDimensions(x, axis: -1) // [N, D, 1] + let bExp = boundaries.reshaped([1, 1, nBoundaries]) // [1, 1, B] + let gt = (xExp .> bExp).asType(.int32) + return gt.sum(axis: -1) // [N, D] + } + + // Three input distributions to probe dual-scale's behavior: + // (a) random unit — symmetric per-half on average, expect no gain + // (b) per-dim asymmetric mean — mimics K/V mean components + let inputs: [(String, MLXArray)] = [ + ("normal_unit", { + let v = MLXRandom.normal([N, dim], key: MLXRandom.key(11)).asType(.float32) + return v + }()), + ("asymmetric_mean", { + let firstMean = MLXArray.ones([1, halfDim], dtype: .float32) * MLXArray(Float(1.5)) + let secondMean = MLXArray.ones([1, halfDim], dtype: .float32) * MLXArray(Float(-0.4)) + let mean = concatenated([firstMean, secondMean], axis: -1) + let noise = MLXRandom.normal([N, dim], key: MLXRandom.key(12)).asType(.float32) + return mean + noise * MLXArray(Float(0.3)) + }()) + ] + + for bits in [2, 3, 4, 8] { + let codec = MSECodec(dim: dim, bits: bits, seed: 42) + let rotationT = codec.rotationT.asType(.float32) + let rotation = codec.rotation.asType(.float32) + let codebook = codec.codebook.asType(.float32) + let boundaries = codec.boundaries + + for (label, v) in inputs { + let totalNorm = sqrt((v * v).sum(axis: -1, keepDims: true)) + let safeNorm = maximum(totalNorm, MLXArray(Float(1e-8))) + let unit = v / safeNorm + let rotated = matmul(unit, rotationT) // [N, dim], L2≈1 + + // ─── Single-scale ─── + let idxSingle = quantize2D(rotated, boundaries: boundaries) + let approxSingle = codebook[idxSingle] // [N, dim] + let recoveredVSingle = matmul(approxSingle, rotation) * totalNorm + let mseSingle = ((v - recoveredVSingle) * (v - recoveredVSingle)).mean().item(Float.self) + + // ─── Dual-scale ─── + let firstHalf = rotated[0..., 0 ..< halfDim] + let secondHalf = rotated[0..., halfDim ..< dim] + let lowPartial = sqrt((firstHalf * firstHalf).sum(axis: -1, keepDims: true)) + let highPartial = sqrt((secondHalf * secondHalf).sum(axis: -1, keepDims: true)) + let sqrt2 = MLXArray(Float(sqrt(2.0))) + let scaleLow = maximum(lowPartial * sqrt2, MLXArray(Float(1e-8))) + let scaleHigh = maximum(highPartial * sqrt2, MLXArray(Float(1e-8))) + let renormFirst = firstHalf / scaleLow + let renormSecond = secondHalf / scaleHigh + let renormed = concatenated([renormFirst, renormSecond], axis: -1) + let idxDual = quantize2D(renormed, boundaries: boundaries) + let approxDual = codebook[idxDual] + let approxFirst = approxDual[0..., 0 ..< halfDim] * scaleLow + let approxSecond = approxDual[0..., halfDim ..< dim] * scaleHigh + let recoveredRotDual = concatenated([approxFirst, approxSecond], axis: -1) + let recoveredVDual = matmul(recoveredRotDual, rotation) * totalNorm + let mseDual = ((v - recoveredVDual) * (v - recoveredVDual)).mean().item(Float.self) + + let ratio = mseSingle > 0 ? mseDual / mseSingle : Float(1.0) + let reduction = (1.0 - ratio) * 100.0 + print("[MSE] bits=\(bits) dist=\(label) single=\(String(format: "%.6f", mseSingle)) dual=\(String(format: "%.6f", mseDual)) ratio=\(String(format: "%.3f", ratio)) reduction=\(String(format: "%.1f%%", reduction))") + + // ─── Single-scale + per-vector bias correction ─── + // Subtract per-vector mean, encode the centered vector, + // add mean back at decode time. Bias captures DC offset + // that the Lloyd-Max codebook (zero-mean calibrated) + // can't otherwise represent. + let meanScalar = v.mean(axis: -1, keepDims: true) // [N, 1] + let vCentered = v - meanScalar + let totalNormB = sqrt((vCentered * vCentered).sum(axis: -1, keepDims: true)) + let safeNormB = maximum(totalNormB, MLXArray(Float(1e-8))) + let unitB = vCentered / safeNormB + let rotatedB = matmul(unitB, rotationT) + let idxBias = quantize2D(rotatedB, boundaries: boundaries) + let approxBias = codebook[idxBias] + let recoveredRotBias = approxBias + let recoveredCenteredBias = matmul(recoveredRotBias, rotation) * totalNormB + let recoveredVBias = recoveredCenteredBias + meanScalar + let mseBias = ((v - recoveredVBias) * (v - recoveredVBias)).mean().item(Float.self) + let ratioBias = mseSingle > 0 ? mseBias / mseSingle : Float(1.0) + let reductionBias = (1.0 - ratioBias) * 100.0 + print("[MSE] bias=\(String(format: "%.6f", mseBias)) ratio=\(String(format: "%.3f", ratioBias)) reduction=\(String(format: "%.1f%%", reductionBias))") + + // Verify the integrated MSECodec.encode/decode bias path + // matches the inline implementation above. + let v4 = v.reshaped([1, 1, N, dim]) + let stateBias = codec.encode(v4, useBias: true) + let recoveredBias4 = codec.decode(stateBias).reshaped([N, dim]) + let diffCodecBias = ((recoveredBias4 - recoveredVBias) * (recoveredBias4 - recoveredVBias)).mean().item(Float.self) + XCTAssertLessThan(diffCodecBias, 1e-6, + "MSECodec.encode(useBias:) should match inline bias path; dist=\(label) bits=\(bits) diff=\(diffCodecBias)") + + // And bias=false matches the original (non-bias) encode. + let stateNoBias = codec.encode(v4, useBias: false) + XCTAssertNil(stateNoBias.bias) + } + } + } } diff --git a/benchmarks/m1-max-64gb-2026-05-13.A-path.md b/benchmarks/m1-max-64gb-2026-05-13.A-path.md new file mode 100644 index 0000000000..3243eb6bb9 --- /dev/null +++ b/benchmarks/m1-max-64gb-2026-05-13.A-path.md @@ -0,0 +1,3716 @@ +# Benchmark: Apple M1 Max (applegpu_g13s) — 2026-05-13 / 2026-05-14 (A-path sweep, regenerated) + +**Hardware:** Apple M1 Max (applegpu_g13s), 64GB unified memory (GPU limit 52GB) +**OS:** macOS 26.4.1 +**Branch:** `ek/spec-041-phase1-2-perf-sliding` +**Commit:** `85afa9b feat(turbo-kv): TurboFlash is now the unconditional A path; dequant SDPA opt-in via TURBO_DEQUANT_SDPA=1` +**NAX:** ENABLED ✓ +**Created:** 2026-05-14T17:06:31Z +**Source:** Regenerated from `/tmp/bench-a-path.log` — pure A-path sweep (TURBO_DEQUANT_SDPA unset, TurboFlash unconditional default for L=1 decode on TurboQuant caches). + +## Models + +### Qwen3.5 0.8B +**Model:** `mlx-community/Qwen3.5-0.8B-4bit` +#### Results +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1011 | 3068.1 | 154.9 | 154.9 | 154.9 | 330ms | — | — | — | — | 404MB | 1.71GB | 22MB | Based on the excerpt provided from *The Great Gatsby*, here is a summary of the text: | +| 4bit / no-quant / summarization | 1 | 8192 | 8182 | 2748.9 | 129.2 | 129.2 | 129.2 | 2977ms | — | — | — | — | 404MB | 1.75GB | 106MB | Here is a summary of *The Great Gatsby* by F. Scott Fitzgerald: | +| 4bit / affine-8 / summarization | 1 | 1024 | 1011 | 2589.1 | 143.5 | 143.5 | 143.5 | 392ms | — | — | — | — | 404MB | 1.64GB | 22MB | Here is a summary of *The Great Gatsby* based on the excerpt provided: | +| 4bit / affine-8 / summarization | 1 | 8192 | 8182 | 2705.5 | 118.4 | 118.4 | 118.4 | 3025ms | — | — | — | — | 404MB | 1.65GB | 67MB | Here is a summary of the text *The Great Gatsby* by F. Scott Fitzgerald: | +| 4bit / affine-4 / summarization | 1 | 1024 | 1011 | 2704.3 | 147.7 | 147.7 | 147.7 | 375ms | — | — | — | — | 404MB | 1.71GB | 16MB | Based on the provided excerpts from *The Great Gatsby*, here is a summary of the character's experiences and perspective: | +| 4bit / affine-4 / summarization | 1 | 8192 | 8182 | 2695.5 | 127.9 | 127.9 | 127.9 | 3036ms | — | — | — | — | 404MB | 1.65GB | 40MB | Based on the provided text, here is a summary of **"The Great Gatsby" by F. Scott Fitzgerald**: | +| 4bit / turbo4 / summarization | 1 | 1024 | 1011 | 2556.0 | 119.4 | 119.4 | 119.4 | 397ms | — | — | — | — | 405MB | 1.71GB | 14MB | Based on the provided text from F. Scott Fitzgerald's *The Great Gatsby*, here is a summary of the content: | +| 4bit / turbo4 / summarization | 1 | 8192 | 8182 | 2828.4 | 81.1 | 81.1 | 81.1 | 2894ms | — | — | — | — | 405MB | 1.77GB | 36MB | Based on the provided text *The Great Gatsby*, here is a summary of the story: | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1011 | 2578.4 | 118.2 | 118.2 | 118.2 | 394ms | — | — | — | — | 405MB | 1.71GB | 13MB | Based on the text you provided, here is a summary of "The Great Gatsby" and the themes developed within it: | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8182 | 2668.6 | 84.9 | 84.9 | 84.9 | 3067ms | — | — | — | — | 405MB | 1.77GB | 29MB | Based on the provided text, *The Great Gatsby* (or its summary by Fitzgerald as "Once more to Zelda"), offers a nuanced exploration of the narrator's | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1011 | 2548.4 | 131.4 | 131.4 | 131.4 | 398ms | — | — | — | — | 405MB | 1.71GB | 16MB | This text is an early excerpt from F. Scott Fitzgerald's *The Great Gatsby*. It serves as a transitional passage, functioning as a retrospective refle | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8182 | 2698.5 | 64.1 | 64.1 | 64.1 | 3033ms | — | — | — | — | 405MB | 1.77GB | 48MB | Based on the text **F***'s Great and G*ays by F Scott Fitzgerald**, the book presents a complex narrative that oscillates between two distinct tones o | + +#### Parameters + +**4bit / no-quant / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / no-quant / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + + +### Qwen3.5 2B +**Model:** `mlx-community/Qwen3.5-2B-4bit` +#### Results +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1011 | 1205.1 | 114.5 | 114.5 | 114.5 | 840ms | — | — | — | — | 1010MB | 2.19GB | 22MB | This excerpt from *The Great Gatsby* by F. Scott Fitzgerald covers the opening chapters, introducing two major themes: **Fitzgerald's life philosophy* | +| 4bit / no-quant / summarization | 1 | 8192 | 8182 | 1313.5 | 99.4 | 99.4 | 99.4 | 6230ms | — | — | — | — | 1010MB | 2.31GB | 106MB | This text presents the opening chapters and early prose of **"The Great Gatsby" by F. Scott Fitzgerald**. It centers on the narrator, **Nick Carraway* | +| 4bit / affine-8 / summarization | 1 | 1024 | 1011 | 1276.1 | 134.5 | 134.5 | 134.5 | 794ms | — | — | — | — | 1010MB | 2.21GB | 22MB | Here is a summary of the excerpt from *The Great Gatsby*, beginning with F. Scott Fitzgerald's advice to himself and concluding with the summary: | +| 4bit / affine-8 / summarization | 1 | 8192 | 8182 | 1311.5 | 98.9 | 98.9 | 98.9 | 6239ms | — | — | — | — | 1010MB | 2.19GB | 67MB | ### **Summary of "The Great Gatsby"** by F. Scott Fitzgerald | +| 4bit / affine-4 / summarization | 1 | 1024 | 1011 | 1266.8 | 113.0 | 113.0 | 113.0 | 800ms | — | — | — | — | 1010MB | 2.20GB | 16MB | This text is a passage from **Chapter 1** of *The Great Gatsby* by F. Scott Fitzgerald. It blends short, lyrical prose with a narrative stream of thou | +| 4bit / affine-4 / summarization | 1 | 8192 | 8182 | 1313.4 | 100.8 | 100.8 | 100.8 | 6230ms | — | — | — | — | 1010MB | 2.27GB | 40MB | **Introduction** | +| 4bit / turbo4 / summarization | 1 | 1024 | 1011 | 1235.0 | 92.9 | 92.9 | 92.9 | 820ms | — | — | — | — | 1011MB | 2.19GB | 14MB | Here is a summary of F. Scott Fitzgerald's novel, *The Great Gatsby*: | +| 4bit / turbo4 / summarization | 1 | 8192 | 8182 | 1283.7 | 68.1 | 68.1 | 68.1 | 6375ms | — | — | — | — | 1011MB | 2.31GB | 36MB | **The Great Gatsby and Beyond: A Summary of Chapter I** | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1011 | 1221.4 | 92.4 | 92.4 | 92.4 | 829ms | — | — | — | — | 1011MB | 2.19GB | 13MB | This text consists of **table of contents** pages and excerpts from the story **"The Great Gatsby"** by F. Scott Fitzgerald, arranged chronologically | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8182 | 1278.1 | 71.2 | 71.2 | 71.2 | 6403ms | — | — | — | — | 1011MB | 2.31GB | 29MB | # Summary: "The Great Gatsby" (F. Scott Fitzgerald) | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1011 | 1234.3 | 86.7 | 86.7 | 86.7 | 821ms | — | — | — | — | 1011MB | 2.19GB | 16MB | This excerpt from *The Great Gatsby* by **F. Scott Fitzgerald** serves as a personal address to **Zelda** (a nickname likely referencing Zelda Addams) | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8182 | 1258.1 | 55.1 | 55.1 | 55.1 | 6505ms | — | — | — | — | 1011MB | 2.31GB | 48MB | This text is a sample from F. Scott Fitzgerald's novel *The Great Gatsby*. It covers the protagonist Nick Carraway, and focuses on his first impressio | + +#### Parameters + +**4bit / no-quant / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / no-quant / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + + +### Qwen3.5 4B +**Model:** `mlx-community/Qwen3.5-4B-4bit` +#### Results +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1009 | 520.0 | 76.8 | 76.8 | 76.8 | 1941ms | — | — | — | — | 2.20GB | 3.53GB | 57MB | Thinking Process: | +| 4bit / no-quant / summarization | 1 | 8192 | 8180 | 501.3 | 57.4 | 57.4 | 57.4 | 16318ms | — | — | — | — | 2.20GB | 3.76GB | 281MB | Here's a thinking process that leads to the suggested summary: | +| 4bit / affine-8 / summarization | 1 | 1024 | 1009 | 510.9 | 73.7 | 73.7 | 73.7 | 1977ms | — | — | — | — | 2.20GB | 3.44GB | 59MB | Thinking Process: | +| 4bit / affine-8 / summarization | 1 | 8192 | 8180 | 497.2 | 53.3 | 53.3 | 53.3 | 16454ms | — | — | — | — | 2.20GB | 3.51GB | 178MB | Here's a thinking process that leads to the suggested summary: | +| 4bit / affine-4 / summarization | 1 | 1024 | 1009 | 510.4 | 74.0 | 74.0 | 74.0 | 1978ms | — | — | — | — | 2.20GB | 3.43GB | 43MB | Thinking Process: | +| 4bit / affine-4 / summarization | 1 | 8192 | 8180 | 495.8 | 55.1 | 55.1 | 55.1 | 16499ms | — | — | — | — | 2.20GB | 3.49GB | 106MB | Here's a thinking process that leads to the summary: | +| 4bit / turbo4 / summarization | 1 | 1024 | 1009 | 505.1 | 57.3 | 57.3 | 57.3 | 1999ms | — | — | — | — | 2.21GB | 3.53GB | 36MB | Thinking Process: | +| 4bit / turbo4 / summarization | 1 | 8192 | 8180 | 497.3 | 44.8 | 44.8 | 44.8 | 16452ms | — | — | — | — | 2.21GB | 3.76GB | 94MB | Here's a thinking process that leads to the suggested summary: | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1009 | 509.8 | 65.4 | 65.4 | 65.4 | 1981ms | — | — | — | — | 2.21GB | 3.53GB | 34MB | Thinking Process: | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8180 | 496.3 | 46.0 | 46.0 | 46.0 | 16485ms | — | — | — | — | 2.21GB | 3.76GB | 77MB | Here's a thinking process that leads to the suggested summary: | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1009 | 509.3 | 60.6 | 60.6 | 60.6 | 1983ms | — | — | — | — | 2.21GB | 3.53GB | 42MB | Here's a thinking process that leads to the suggested summary: | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8180 | 496.4 | 34.7 | 34.7 | 34.7 | 16479ms | — | — | — | — | 2.21GB | 3.76GB | 128MB | Here's a thinking process that leads to the suggested summary: | + +#### Parameters + +**4bit / no-quant / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / no-quant / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + + +### Qwen3.5 9B +**Model:** `mlx-community/Qwen3.5-9B-4bit` +#### Results +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1009 | 285.5 | 47.1 | 47.1 | 47.1 | 3535ms | — | — | — | — | 4.69GB | 6.00GB | 57MB | Thinking Process: | +| 4bit / no-quant / summarization | 1 | 8192 | 8180 | 291.1 | 43.7 | 43.7 | 43.7 | 28100ms | — | — | — | — | 4.69GB | 6.18GB | 281MB | Thinking Process: | +| 4bit / affine-8 / summarization | 1 | 1024 | 1009 | 290.2 | 45.5 | 45.5 | 45.5 | 3479ms | — | — | — | — | 4.69GB | 5.92GB | 59MB | Thinking Process: | +| 4bit / affine-8 / summarization | 1 | 8192 | 8180 | 285.9 | 40.0 | 40.0 | 40.0 | 28609ms | — | — | — | — | 4.69GB | 6.02GB | 178MB | Here's a thinking process that leads to the suggested summary: | +| 4bit / affine-4 / summarization | 1 | 1024 | 1009 | 288.6 | 46.7 | 46.7 | 46.7 | 3497ms | — | — | — | — | 4.69GB | 5.91GB | 43MB | Thinking Process: | +| 4bit / affine-4 / summarization | 1 | 8192 | 8180 | 287.6 | 45.1 | 45.1 | 45.1 | 28445ms | — | — | — | — | 4.69GB | 5.95GB | 106MB | Here's a thinking process that leads to the suggested summary: | +| 4bit / turbo4 / summarization | 1 | 1024 | 1009 | 287.7 | 43.0 | 43.0 | 43.0 | 3509ms | — | — | — | — | 4.69GB | 6.00GB | 36MB | Thinking Process: | +| 4bit / turbo4 / summarization | 1 | 8192 | 8180 | 287.9 | 35.5 | 35.5 | 35.5 | 28411ms | — | — | — | — | 4.69GB | 6.18GB | 94MB | Here's a thinking process that leads to the suggested summary: | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1009 | 288.0 | 43.3 | 43.3 | 43.3 | 3506ms | — | — | — | — | 4.69GB | 6.08GB | 34MB | Thinking Process: | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8180 | 288.0 | 36.4 | 36.4 | 36.4 | 28404ms | — | — | — | — | 4.69GB | 6.18GB | 77MB | Thinking Process: | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1009 | 287.9 | 40.8 | 40.8 | 40.8 | 3507ms | — | — | — | — | 4.69GB | 6.00GB | 42MB | Thinking Process: | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8180 | 286.6 | 28.4 | 28.4 | 28.4 | 28547ms | — | — | — | — | 4.69GB | 6.18GB | 128MB | Thinking Process: | + +#### Parameters + +**4bit / no-quant / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / no-quant / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + + +### Gemma 4 E2B +**Model:** `mlx-community/gemma-4-e2b-it-4bit` +#### Results +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1008 | 3211.4 | 101.7 | 101.7 | 101.7 | 316ms | — | — | — | — | 2.45GB | 3.46GB | 12MB | This excerpt from *The Great Gatsby* introduces a narrator (likely Nick Carraway, given the context of the novel) and establishes their **cautious, re | +| 4bit / no-quant / summarization | 1 | 8192 | 8192 | 2902.9 | 95.1 | 95.1 | 95.1 | 2824ms | — | — | — | — | 2.45GB | 5.48GB | 54MB | This is a fascinating and dense excerpt from **Nick Carraway's perspective** in *The Great Gatsby*. It showcases Nick's characteristic way of observin | +| 4bit / affine-8 / summarization | 1 | 1024 | 1008 | 2481.9 | 52.7 | 52.7 | 52.7 | 408ms | — | — | — | — | 2.45GB | 2.82GB | 16MB | This excerpt from *The Great Gatsby* by F. Scott Fitzgerald introduces a narrator's complex relationship with judgment, vulnerability, and the human h | +| 4bit / affine-8 / summarization | 1 | 8192 | 8192 | 2762.9 | 47.5 | 47.5 | 47.5 | 2966ms | — | — | — | — | 2.45GB | 5.45GB | 41MB | This is an excerpt from **The Great Gatsby** by **F. Scott Fitzgerald**. | +| 4bit / affine-4 / summarization | 1 | 1024 | 1008 | 2385.9 | 53.7 | 53.7 | 53.7 | 424ms | — | — | — | — | 2.45GB | 2.81GB | 8MB | This excerpt is from *The Great Gatsby* by F. Scott Fitzgerald and appears to be a collection of literary or personal reflections. Here is a summary o | +| 4bit / affine-4 / summarization | 1 | 8192 | 8192 | 2770.2 | 50.5 | 50.5 | 50.5 | 2958ms | — | — | — | — | 2.45GB | 5.42GB | 22MB | This is a fascinating and dense excerpt from a work of literature, likely **Nick Carraway's narration** from **The Great Gatsby**. It's rich in charac | +| 4bit / turbo4 / summarization | 1 | 1024 | 1008 | 2513.1 | 64.4 | 64.4 | 64.4 | 406ms | — | — | — | — | 2.45GB | 3.46GB | 5MB | This excerpt comes from **The Great Gatsby** by F. Scott Fitzgerald. It features a collection of fragmented prose and dialogue, focusing on themes of | +| 4bit / turbo4 / summarization | 1 | 8192 | 8192 | 2734.4 | 49.2 | 49.2 | 49.2 | 3000ms | — | — | — | — | 2.46GB | 5.48GB | 16MB | This is an excerpt from **Nick Carraway's narration** in **The Great Gatsby**. | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1008 | 2292.7 | 64.0 | 64.0 | 64.0 | 445ms | — | — | — | — | 2.45GB | 3.46GB | 4MB | This excerpt from *The Great Gatsby* provides a detailed introduction to the narrator's **personal philosophy regarding judging others**, their **fami | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8192 | 2741.6 | 49.9 | 49.9 | 49.9 | 2992ms | — | — | — | — | 2.46GB | 5.48GB | 12MB | This is an excerpt from **The Great Gatsby** by F. Scott Fitzgerald. | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1008 | 2578.0 | 60.2 | 60.2 | 60.2 | 396ms | — | — | — | — | 2.45GB | 3.46GB | 7MB | This excerpt from *The Great Gatsby* introduces a narrator who is highly reserved and judgmental, stemming from advice given by their father. | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8192 | 2844.5 | 41.0 | 41.0 | 41.0 | 2884ms | — | — | — | — | 2.46GB | 5.48GB | 23MB | This text appears to be an excerpt from **Nick Carraway's narration** within **The Great Gatsby** by F. Scott Fitzgerald. | + +#### Parameters + +**4bit / no-quant / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / no-quant / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + + +### Gemma 4 E4B +**Model:** `mlx-community/gemma-4-e4b-it-4bit` +#### Results +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1008 | 904.2 | 63.8 | 63.8 | 63.8 | 1118ms | — | — | — | — | 3.98GB | 5.12GB | 36MB | Here is a summary of the provided text: | +| 4bit / no-quant / summarization | 1 | 8192 | 8192 | 863.2 | 61.4 | 61.4 | 61.4 | 9492ms | — | — | — | — | 3.98GB | 6.87GB | 148MB | Here is a breakdown of the provided text, which is the beginning chapters of F. Scott Fitzgerald's novel, *The Great Gatsby*. | +| 4bit / affine-8 / summarization | 1 | 1024 | 1008 | 821.6 | 36.5 | 36.5 | 36.5 | 1229ms | — | — | — | — | 3.98GB | 4.51GB | 45MB | Here's a summary of the provided text: | +| 4bit / affine-8 / summarization | 1 | 8192 | 8192 | 856.5 | 34.7 | 34.7 | 34.7 | 9566ms | — | — | — | — | 3.98GB | 6.79GB | 113MB | Here is a breakdown of the text you provided, which appears to be the beginning of F. Scott Fitzgerald's *The Great Gatsby*. | +| 4bit / affine-4 / summarization | 1 | 1024 | 1008 | 828.8 | 36.6 | 36.6 | 36.6 | 1218ms | — | — | — | — | 3.98GB | 4.48GB | 24MB | The provided text is an excerpt from the novel *The Great Gatsby*. It consists of two main parts: a poetic dedication and the beginning of the main na | +| 4bit / affine-4 / summarization | 1 | 8192 | 8192 | 860.8 | 34.8 | 34.8 | 34.8 | 9518ms | — | — | — | — | 3.98GB | 6.71GB | 60MB | Here is a summary and analysis of the provided text, which is the beginning of "The Great Gatsby." | +| 4bit / turbo4 / summarization | 1 | 1024 | 1008 | 843.4 | 42.7 | 42.7 | 42.7 | 1201ms | — | — | — | — | 3.98GB | 5.12GB | 15MB | This selection presents the beginning of F. Scott Fitzgerald's *The Great Gatsby*, offering a mix of epigraphs and the novel's opening chapters. | +| 4bit / turbo4 / summarization | 1 | 8192 | 8192 | 862.6 | 33.2 | 33.2 | 33.2 | 9502ms | — | — | — | — | 3.98GB | 6.87GB | 43MB | Here is a breakdown of the provided text, offering different levels of summary depending on what you need: | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1008 | 845.8 | 43.0 | 43.0 | 43.0 | 1198ms | — | — | — | — | 3.98GB | 5.12GB | 11MB | This text provides the beginning of a novel, *The Great Gatsby*, by F. Scott Fitzgerald. It introduces two distinct, yet thematically linked elements: | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8192 | 862.5 | 34.2 | 34.2 | 34.2 | 9502ms | — | — | — | — | 3.98GB | 6.87GB | 33MB | Here is a summary and analysis of the provided text, which is the beginning of F. Scott Fitzgerald's *The Great Gatsby*. | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1008 | 848.0 | 39.1 | 39.1 | 39.1 | 1195ms | — | — | — | — | 3.98GB | 5.12GB | 22MB | This text appears to be the beginning of *The Great Gatsby* by F. Scott Fitzgerald, and it contains fragments from several different sources, which co | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8192 | 861.9 | 26.7 | 26.7 | 26.7 | 9510ms | — | — | — | — | 3.98GB | 6.87GB | 65MB | This is the beginning of a novel, *The Great Gatsby* by F. Scott Fitzgerald, with some preceding pages that provide context or serve as extracts. | + +#### Parameters + +**4bit / no-quant / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / no-quant / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + + +### Nemotron 30B A3B +**Model:** `mlx-community/Nemotron-Cascade-2-30B-A3B-4bit` +#### Results +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1025 | 463.6 | 75.2 | 75.2 | 75.2 | 2212ms | — | — | — | — | 16.56GB | 18.07GB | 30MB | We need to respond to the user. The user posted a text that looks like a modified version of The Great Gatsby, but with a different style, and then en | +| 4bit / no-quant / summarization | 1 | 8192 | 8174 | 457.5 | 71.5 | 71.5 | 71.5 | 17867ms | — | — | — | — | 16.56GB | 18.18GB | 72MB | We need to summarize the provided text, which appears to be a variant or parody of The Great Gatsby with many details. The user asks: "Summarize the c | +| 4bit / affine-8 / summarization | 1 | 1024 | 1025 | 449.3 | 74.1 | 74.1 | 74.1 | 2283ms | — | — | — | — | 16.56GB | 18.07GB | 30MB | We need to respond. The user posted a text that seems like a mixture of The Great Gatsby introduction and some other content, maybe a parody or rewrit | +| 4bit / affine-8 / summarization | 1 | 8192 | 8174 | 458.2 | 69.7 | 69.7 | 69.7 | 17842ms | — | — | — | — | 16.56GB | 18.16GB | 52MB | We need to summarize the content above, which appears to be a rendition of The Great Gatsby, but with many differences: Some kind of weird text that i | +| 4bit / affine-4 / summarization | 1 | 1024 | 1025 | 448.4 | 74.3 | 74.3 | 74.3 | 2287ms | — | — | — | — | 16.56GB | 18.07GB | 27MB | We need to respond to user. The user posted the start of The Great Gatsby text? Actually it's a modified version, with some weird text. Probably they | +| 4bit / affine-4 / summarization | 1 | 8192 | 8174 | 457.9 | 69.9 | 69.9 | 69.9 | 17851ms | — | — | — | — | 16.56GB | 18.16GB | 39MB | We need to provide a summary of the given text. The user gave a large excerpt that is not exactly the novel "The Great Gatsby" but some weird retellin | +| 4bit / turbo4 / summarization | 1 | 1024 | 1025 | 442.0 | 70.9 | 70.9 | 70.9 | 2320ms | — | — | — | — | 16.56GB | 18.07GB | 26MB | We need to respond to the user. The user posted a text that appears to be a modified version of The Great Gatsby, with some weird formatting and then | +| 4bit / turbo4 / summarization | 1 | 8192 | 8174 | 454.6 | 62.1 | 62.1 | 62.1 | 17983ms | — | — | — | — | 16.56GB | 18.18GB | 37MB | We need to provide a summary of the content above. The content is an excerpt from The Great Gatsby, but it is a weird version. It includes a table of | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1025 | 449.7 | 70.9 | 70.9 | 70.9 | 2281ms | — | — | — | — | 16.56GB | 18.07GB | 26MB | We need to respond to the user's prompt. The user posted a text that looks like a modified version of The Great Gatsby, but the text is cut off. They | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8174 | 454.7 | 63.1 | 63.1 | 63.1 | 17979ms | — | — | — | — | 16.56GB | 18.18GB | 34MB | We need to summarize given passage. It's a long excerpt from a novel, presumably a parody or adaptation of The Great Gatsby titled "The Great Gatsby" | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1025 | 444.8 | 66.0 | 66.0 | 66.0 | 2306ms | — | — | — | — | 16.56GB | 18.07GB | 27MB | The user posted a portion of text: The Great Gatsby with some formatting, then a long passage that looks like a rewritten version of the opening of Th | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8174 | 456.0 | 46.9 | 46.9 | 46.9 | 17928ms | — | — | — | — | 16.56GB | 18.18GB | 43MB | We need to summarize the content. The user gave a long excerpt, seems like a stylized version of The Great Gatsby (maybe a parody) with a narrator (Ni | + +#### Parameters + +**4bit / no-quant / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / no-quant / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + + +### GPT-OSS 20B +**Model:** `loan-star/gpt-oss-20b-mlx-4Bit` +#### Results +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1024 | 503.7 | 75.4 | 75.4 | 75.4 | 2034ms | — | — | — | — | 10.41GB | 11.37GB | 27MB | <\|channel\|>analysis<\|message\|>We have a user who posted a long text. It's some piece of writing presumably by "F. Scott Fitzgerald" but obviously it's | +| 4bit / no-quant / summarization | 1 | 8192 | 8042 | 514.3 | 64.4 | 64.4 | 64.4 | 15639ms | — | — | — | — | 10.41GB | 11.94GB | 195MB | <\|channel\|>analysis<\|message\|>We have a long text. The user asks: "Summarize the content above." So we need to summarize the content. The content is a | +| 4bit / affine-8 / summarization | 1 | 1024 | 1024 | 479.0 | 49.4 | 49.4 | 49.4 | 2139ms | — | — | — | — | 10.41GB | 11.23GB | 27MB | <\|channel\|>analysis<\|message\|>We need to respond as ChatGPT. The user posted a text that appears to be a weirdly typed text with many typos and gramma | +| 4bit / affine-8 / summarization | 1 | 8192 | 8042 | 510.3 | 44.8 | 44.8 | 44.8 | 15759ms | — | — | — | — | 10.41GB | 11.86GB | 129MB | <\|channel\|>analysis<\|message\|>We have a user-provided text: It's a long text that appears to be a novel or story titled "The Great Gatsby" by "F. Scot | +| 4bit / affine-4 / summarization | 1 | 1024 | 1024 | 475.1 | 48.8 | 48.8 | 48.8 | 2157ms | — | — | — | — | 10.41GB | 11.21GB | 14MB | <\|channel\|>analysis<\|message\|>The user has pasted a huge text that is basically a version of the novel “The Great Gatsby” but in a more or more "The G | +| 4bit / affine-4 / summarization | 1 | 8192 | 8042 | 511.5 | 44.3 | 44.3 | 44.3 | 15723ms | — | — | — | — | 10.41GB | 11.81GB | 68MB | <\|channel\|>analysis<\|message\|>We have a text that is extremely garish, with a mixing of many words, but is basically a “text” (or maybe &). We first, | +| 4bit / turbo4 / summarization | 1 | 1024 | 1024 | 480.5 | 68.8 | 68.8 | 68.8 | 2134ms | — | — | — | — | 10.41GB | 11.37GB | 12MB | <\|channel\|>analysis<\|message\|>We need to analyze the prompt. The user has given a novel/long‑essay‑? They want? They want? They want?…? The prompt is | +| 4bit / turbo4 / summarization | 1 | 8192 | 8042 | 513.7 | 51.5 | 51.5 | 51.5 | 15657ms | — | — | — | — | 10.41GB | 11.94GB | 59MB | <\|channel\|>analysis} The user wants summary, summary? The content, write article,…??……?? ...?? ... ……… **?** ...…………?????…… ... **.. …… **… **………… **… | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1024 | 485.9 | 68.5 | 68.5 | 68.5 | 2110ms | — | — | — | — | 10.41GB | 11.37GB | 10MB | <\|channel\|>analysis<\|message\|>We need to craft a new …? The user says: “We have……..”?? The…………??..….……..………..??……? **…**..??…… | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8042 | 513.9 | 51.5 | 51.5 | 51.5 | 15651ms | — | — | — | — | 10.41GB | 11.94GB | 46MB | <\|channel\|>analysis<\|message\|>We have a question: We need summarizing? The user says: "Summarize? (perhaps we need to summarizing). The user is presum | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1024 | 486.6 | 68.3 | 68.3 | 68.3 | 2107ms | — | — | — | — | 10.41GB | 11.37GB | 17MB | <\|channel\|>analysis<\|message\|>… | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8042 | 512.9 | 50.6 | 50.6 | 50.6 | 15680ms | — | — | — | — | 10.41GB | 11.94GB | 83MB | <\|channel\|>analysis<\|message\|>The user’s prompt: "Summarize ...?? 2? …???..???????????..??…..??..?????..….…....??....?? ??????……???????……??…????…..?? | + +#### Parameters + +**4bit / no-quant / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / no-quant / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + + +### Qwen3.5 35B A3B +**Model:** `mlx-community/Qwen3.5-35B-A3B-4bit` +#### Results +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1009 | 502.8 | 66.2 | 66.2 | 66.2 | 2008ms | — | — | — | — | 18.16GB | 19.28GB | 51MB | Thinking Process: | +| 4bit / no-quant / summarization | 1 | 8192 | 8180 | 546.2 | 55.6 | 55.6 | 55.6 | 14977ms | — | — | — | — | 18.16GB | 19.83GB | 191MB | Here's a thinking process that leads to the summary: | +| 4bit / affine-8 / summarization | 1 | 1024 | 1009 | 493.9 | 57.8 | 57.8 | 57.8 | 2045ms | — | — | — | — | 18.16GB | 19.30GB | 74MB | Thinking Process: | +| 4bit / affine-8 / summarization | 1 | 8192 | 8180 | 547.5 | 48.7 | 48.7 | 48.7 | 14942ms | — | — | — | — | 18.16GB | 19.76GB | 159MB | Thinking Process: | +| 4bit / affine-4 / summarization | 1 | 1024 | 1009 | 501.1 | 58.1 | 58.1 | 58.1 | 2015ms | — | — | — | — | 18.16GB | 19.28GB | 54MB | Thinking Process: | +| 4bit / affine-4 / summarization | 1 | 8192 | 8180 | 550.2 | 49.3 | 49.3 | 49.3 | 14868ms | — | — | — | — | 18.16GB | 19.72GB | 99MB | Thinking Process: | +| 4bit / turbo4 / summarization | 1 | 1024 | 1009 | 491.0 | 49.9 | 49.9 | 49.9 | 2057ms | — | — | — | — | 18.16GB | 19.28GB | 39MB | Thinking Process: | +| 4bit / turbo4 / summarization | 1 | 8192 | 8180 | 547.3 | 38.7 | 38.7 | 38.7 | 14947ms | — | — | — | — | 18.16GB | 19.83GB | 75MB | Thinking Process: | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1009 | 497.1 | 50.1 | 50.1 | 50.1 | 2032ms | — | — | — | — | 18.16GB | 19.28GB | 37MB | Thinking Process: | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8180 | 548.2 | 40.0 | 40.0 | 40.0 | 14923ms | — | — | — | — | 18.16GB | 19.83GB | 64MB | Thinking Process: | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1009 | 506.0 | 46.8 | 46.8 | 46.8 | 1996ms | — | — | — | — | 18.16GB | 19.28GB | 42MB | Thinking Process: | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8180 | 537.7 | 30.0 | 30.0 | 30.0 | 15214ms | — | — | — | — | 18.16GB | 19.83GB | 96MB | Thinking Process: | + +#### Parameters + +**4bit / no-quant / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / no-quant / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + + +### Gemma 4 26B A4B +**Model:** `mlx-community/gemma-4-26b-a4b-it-4bit` +#### Results +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1012 | 644.2 | 28.1 | 28.1 | 28.1 | 1572ms | — | — | — | — | 13.48GB | 15.78GB | 432MB | The provided text serves as the opening of F. Scott Fitzgerald’s *The Great Gatsby*, consisting of the table of contents, an epigraph, and the introdu | +| 4bit / no-quant / summarization | 1 | 8192 | 8192 | 499.6 | 25.9 | 25.9 | 25.9 | 16399ms | — | — | — | — | 13.48GB | 23.67GB | 712MB | This is the complete text of **Chapter I** of F. Scott Fitzgerald's *The Great Gatsby*. | +| 4bit / affine-8 / summarization | 1 | 1024 | 1012 | 557.0 | 8.2 | 8.2 | 8.2 | 1818ms | — | — | — | — | 13.48GB | 15.50GB | 157MB | The provided text contains the opening of F. Scott Fitzgerald’s *The Great Gatsby*, including the epigraph and the first part of Chapter I. It can be | +| 4bit / affine-8 / summarization | 1 | 8192 | 8192 | 575.7 | 8.0 | 8.0 | 8.0 | 14231ms | — | — | — | — | 13.48GB | 22.25GB | 247MB | This text is the complete first chapter of F. Scott Fitzgerald's classic novel, ***The Great Gatsby***. | +| 4bit / affine-4 / summarization | 1 | 1024 | 1012 | 552.4 | 8.1 | 8.1 | 8.1 | 1833ms | — | — | — | — | 13.48GB | 15.44GB | 87MB | The provided text is the opening of F. Scott Fitzgerald’s *The Great Gatsby*, consisting of the title, table of contents, epigraph, and the beginning | +| 4bit / affine-4 / summarization | 1 | 8192 | 8192 | 581.5 | 8.0 | 8.0 | 8.0 | 14089ms | — | — | — | — | 13.48GB | 21.97GB | 137MB | This text constitutes the complete **Chapter I** of F. Scott Fitzgerald's masterpiece, *The Great Gatsby*. | +| 4bit / turbo4 / summarization | 1 | 1024 | 1012 | 626.8 | 31.0 | 31.0 | 31.0 | 1619ms | — | — | — | — | 13.48GB | 15.82GB | 74MB | This text constitutes the opening of F. Scott Fitzgerald's *The Great Gatsby. It includes the book's front matter, a dedicatory poem, and the first se | +| 4bit / turbo4 / summarization | 1 | 8192 | 8192 | 592.9 | 25.3 | 25.3 | 25.3 | 13820ms | — | — | — | — | 13.48GB | 23.67GB | 109MB | This is the complete text of the first chapter of *The Great Gatsby*. | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1012 | 561.2 | 31.1 | 31.1 | 31.1 | 1807ms | — | — | — | — | 13.48GB | 15.82GB | 52MB | The provided text contains the opening of F. Scott Fitzgerald's *The Great Gatsby*, including the dedication, the first chapter, and the beginning of | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8192 | 600.8 | 26.1 | 26.1 | 26.1 | 13639ms | — | — | — | — | 13.48GB | 24.10GB | 82MB | This provided text is the first chapter of F. Scott Fitzgerald's *The Great Gatsby*. It introduces the narrator, Nick Carraway, and his first encounte | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1012 | 578.5 | 26.7 | 26.7 | 26.7 | 1753ms | — | — | — | — | 13.48GB | 15.82GB | 113MB | This text contains the opening of F. Scott Fitzgerald's *The Great Gatsby, including the table of contents, an epigraph, and the first few paragraphs | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8192 | 596.8 | 20.4 | 20.4 | 20.4 | 13729ms | — | — | — | — | 13.48GB | 23.67GB | 170MB | This is the complete text of the first chapter of **F. Scott Fitzgerald's *The Great Gatsby***. | + +#### Parameters + +**4bit / no-quant / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / no-quant / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + + +### Qwen3.5 27B +**Model:** `mlx-community/Qwen3.5-27B-4bit` +#### Results +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1009 | 86.5 | 18.7 | 18.7 | 18.7 | 11660ms | — | — | — | — | 14.09GB | 15.45GB | 139MB | Here's a thinking process that leads to the suggested summary: | +| 4bit / no-quant / summarization | 1 | 8192 | 8180 | 84.8 | 16.7 | 16.7 | 16.7 | 96499ms | — | — | — | — | 14.09GB | 15.86GB | 587MB | Here's a thinking process that leads to the summary: | +| 4bit / affine-8 / summarization | 1 | 1024 | 1009 | 85.4 | 17.2 | 17.2 | 17.2 | 11819ms | — | — | — | — | 14.09GB | 15.44GB | 143MB | Thinking Process: | +| 4bit / affine-8 / summarization | 1 | 8192 | 8180 | 84.8 | 15.4 | 15.4 | 15.4 | 96497ms | — | — | — | — | 14.09GB | 15.63GB | 381MB | Thinking Process: | +| 4bit / affine-4 / summarization | 1 | 1024 | 1009 | 85.5 | 17.2 | 17.2 | 17.2 | 11808ms | — | — | — | — | 14.09GB | 15.42GB | 111MB | Here's a thinking process that leads to the suggested summary: | +| 4bit / affine-4 / summarization | 1 | 8192 | 8180 | 84.8 | 15.5 | 15.5 | 15.5 | 96465ms | — | — | — | — | 14.09GB | 15.50GB | 237MB | Thinking Process: | +| 4bit / turbo4 / summarization | 1 | 1024 | 1009 | 85.7 | 17.3 | 17.3 | 17.3 | 11775ms | — | — | — | — | 14.09GB | 15.45GB | 98MB | Thinking Process: | +| 4bit / turbo4 / summarization | 1 | 8192 | 8180 | 85.0 | 14.1 | 14.1 | 14.1 | 96292ms | — | — | — | — | 14.09GB | 15.86GB | 213MB | Here's a thinking process that leads to the suggested summary: | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1009 | 85.6 | 16.4 | 16.4 | 16.4 | 11789ms | — | — | — | — | 14.09GB | 15.45GB | 92MB | Thinking Process: | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8180 | 85.0 | 14.3 | 14.3 | 14.3 | 96263ms | — | — | — | — | 14.09GB | 15.86GB | 180MB | Here's a thinking process that leads to the suggested summary: | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1009 | 81.7 | 15.8 | 15.8 | 15.8 | 12351ms | — | — | — | — | 14.09GB | 15.45GB | 109MB | Thinking Process: | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8180 | 86.4 | 11.4 | 11.4 | 11.4 | 94697ms | — | — | — | — | 14.09GB | 15.86GB | 280MB | Here's a thinking process that leads to the suggested summary: | + +#### Parameters + +**4bit / no-quant / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / no-quant / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + + +### Qwen3.6 27B +**Model:** `mlx-community/Qwen3.6-27B-4bit` +#### Results +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1009 | 87.3 | 18.0 | 18.0 | 18.0 | 11558ms | — | — | — | — | 14.09GB | 15.45GB | 139MB | Here's a thinking process: | +| 4bit / no-quant / summarization | 1 | 8192 | 8180 | 86.1 | 17.0 | 17.0 | 17.0 | 94958ms | — | — | — | — | 14.09GB | 15.87GB | 587MB | Here's a thinking process: | +| 4bit / affine-8 / summarization | 1 | 1024 | 1009 | 86.9 | 17.5 | 17.5 | 17.5 | 11607ms | — | — | — | — | 14.09GB | 15.44GB | 143MB | Here's a thinking process: | +| 4bit / affine-8 / summarization | 1 | 8192 | 8180 | 86.0 | 15.7 | 15.7 | 15.7 | 95091ms | — | — | — | — | 14.09GB | 15.63GB | 381MB | Here's a thinking process: | +| 4bit / affine-4 / summarization | 1 | 1024 | 1009 | 86.7 | 17.6 | 17.6 | 17.6 | 11640ms | — | — | — | — | 14.09GB | 15.42GB | 111MB | Here's a thinking process: | +| 4bit / affine-4 / summarization | 1 | 8192 | 8180 | 85.9 | 15.8 | 15.8 | 15.8 | 95195ms | — | — | — | — | 14.09GB | 15.50GB | 237MB | Here's a thinking process: | +| 4bit / turbo4 / summarization | 1 | 1024 | 1009 | 86.7 | 16.7 | 16.7 | 16.7 | 11637ms | — | — | — | — | 14.09GB | 15.45GB | 98MB | Here's a thinking process: | +| 4bit / turbo4 / summarization | 1 | 8192 | 8180 | 86.4 | 14.4 | 14.4 | 14.4 | 94710ms | — | — | — | — | 14.09GB | 15.86GB | 213MB | Here's a thinking process: | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1009 | 86.7 | 16.7 | 16.7 | 16.7 | 11635ms | — | — | — | — | 14.09GB | 15.45GB | 92MB | Here's a thinking process: | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8180 | 86.4 | 14.6 | 14.6 | 14.6 | 94715ms | — | — | — | — | 14.09GB | 15.86GB | 180MB | Here's a thinking process: | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1009 | 86.7 | 15.8 | 15.8 | 15.8 | 11634ms | — | — | — | — | 14.09GB | 15.45GB | 109MB | Here's a thinking process: | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8180 | 86.1 | 12.0 | 12.0 | 12.0 | 94980ms | — | — | — | — | 14.09GB | 15.87GB | 280MB | Here's a thinking process: | + +#### Parameters + +**4bit / no-quant / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / no-quant / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + + +### Gemma 4 31B +**Model:** `mlx-community/gemma-4-31b-it-4bit` +#### Results +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1012 | 74.0 | 14.5 | 14.5 | 14.5 | 13675ms | — | — | — | — | 16.08GB | 17.91GB | 880MB | The provided text is the opening of F. Scott Fitzgerald's *The Great Gatsby*. It introduces the narrator, Nick Carraway, who establishes his personali | +| 4bit / no-quant / summarization | 1 | 8192 | 8192 | 68.7 | 13.7 | 13.7 | 13.7 | 119228ms | — | — | — | — | 16.08GB | 28.10GB | 1.41GB | This opening chapter of *The Great Gatsby* establishes the novel's primary themes: the corruption of the American Dream, the rigidity of social class, | +| 4bit / affine-8 / summarization | 1 | 1024 | 1012 | 72.0 | 10.1 | 10.1 | 10.1 | 14057ms | — | — | — | — | 16.08GB | 17.59GB | 595MB | The provided text is the opening of F. Scott Fitzgerald's *The Great Gatsby*. It introduces the narrator, Nick Carraway, who establishes his character | +| 4bit / affine-8 / summarization | 1 | 8192 | 8192 | 67.8 | 9.4 | 9.4 | 9.4 | 120854ms | — | — | — | — | 16.08GB | 25.89GB | 935MB | This opening chapter of *The Great Gatsby* establishes the novel's narrator, Nick Carraway, and introduces the central themes of social class, illusio | +| 4bit / affine-4 / summarization | 1 | 1024 | 1012 | 72.0 | 10.3 | 10.3 | 10.3 | 14049ms | — | — | — | — | 16.08GB | 17.33GB | 315MB | This text comprises the opening pages of F. Scott Fitzgerald's *The Great Gatsby*. It introduces the narrator, Nick Carraway, who establishes his pers | +| 4bit / affine-4 / summarization | 1 | 8192 | 8192 | 67.8 | 9.6 | 9.6 | 9.6 | 120858ms | — | — | — | — | 16.08GB | 24.76GB | 495MB | Based on the text provided, here is a summary and analysis of the key elements introduced in Chapter I of *The Great Gatsby*. | +| 4bit / turbo4 / summarization | 1 | 1024 | 1012 | 72.4 | 10.8 | 10.8 | 10.8 | 13990ms | — | — | — | — | 16.08GB | 17.91GB | 266MB | The provided text is the opening of F. Scott Fitzgerald's novel, *The Great Gatsby*. It introduces the narrator, Nick Carraway, who begins by reflecti | +| 4bit / turbo4 / summarization | 1 | 8192 | 8192 | 68.7 | 8.3 | 8.3 | 8.3 | 119258ms | — | — | — | — | 16.09GB | 28.10GB | 457MB | This opening chapter of *The Great Gatsby* serves as a masterclass in character establishment and thematic foreshadowing. Through the narrator, Nick C | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1012 | 73.4 | 11.1 | 11.1 | 11.1 | 13788ms | — | — | — | — | 16.08GB | 17.91GB | 208MB | The provided text is the opening of F. Scott Fitzgerald's *The The Great Gatsby*. It introduces the narrator, Nick Carraw выполняCary, who establishes | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8192 | 68.9 | 8.6 | 8.6 | 8.6 | 118988ms | — | — | — | — | 16.09GB | 28.10GB | 346MB | This deconstructs the opening of **The Great Gatsby**, one of the most influential openings in American literature. In these pages, F. Scott Fitzgeral | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1012 | 73.1 | 8.9 | 8.9 | 8.9 | 13854ms | — | — | — | — | 16.08GB | 17.91GB | 386MB | The provided text is the opening of F. Scott Fitzgerald's novel, *The Great Gatsby*. It introduces the narrator, Nick Carraway, who reflects on his up | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8192 | 69.2 | 5.6 | 5.6 | 5.6 | 118320ms | — | — | — | — | 16.09GB | 28.10GB | 681MB | This excerpt comprises the opening of F. Scott Fitzgerald's *The Great Gatsby*. It establishes the narrator, Nick Carraway, and introduces the primary | + +#### Parameters + +**4bit / no-quant / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / no-quant / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-8 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / affine-4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo4v2 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (4-bit K, 2-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=1024)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 1024 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + +**4bit / turbo8v4 / summarization (ctx=8192)** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (8-bit K, 4-bit V) | +| Max KV size | 8192 tokens (StandardKVCache wrapper) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Presence penalty | 1.5 | +| Speculative decoding | none | +| N-gram size | 0 | +| Track perplexity | false | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| TURBO_DEQUANT_SDPA | unset (A path, TurboFlash unconditional) | + diff --git a/benchmarks/m1-max-64gb-2026-05-13.B-path.md b/benchmarks/m1-max-64gb-2026-05-13.B-path.md new file mode 100644 index 0000000000..63a60ff3b5 --- /dev/null +++ b/benchmarks/m1-max-64gb-2026-05-13.B-path.md @@ -0,0 +1,3199 @@ +# Benchmark: Apple M1 Max (applegpu_g13s) — 2026-05-14 + +**Hardware:** Apple M1 Max (applegpu_g13s), 64GB unified memory (GPU limit 52GB) +**OS:** macOS 26.4.1 +**Branch:** `ek/spec-041-phase1-2-perf-sliding` +**Commit:** `85afa9b feat(turbo-kv): TurboFlash is now the unconditional A path; dequant SDPA opt-in via TURBO_DEQUANT_SDPA=1` +**NAX:** ENABLED ✓ +**Created:** 2026-05-14T07:19:38Z + +## Models + +### Qwen3.5 0.8B + +**Model:** `mlx-community/Qwen3.5-0.8B-4bit` + +#### Results + +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1011 | 2960.3 | 144.7 | 144.7 | 147.2 | 342ms | — | — | — | — | 404MB | 1.71GB | 22MB | Based on the provided text of **"Once Again to Zelda" by F. Scott Fitzgerald**, here is a summary of the novel's content: ### **Themes and Characterization** T… | +| 4bit / no-quant / summarization | 1 | 8192 | 8182 | 2813.0 | 124.7 | 124.7 | 124.5 | 2909ms | — | — | — | — | 404MB | 1.77GB | 106MB | Here is a summary of *The Great Gatsby* by F. Scott Fitzgerald: **Summary of Plot:** The book is divided into four main storylines within the book itself, thou… | +| 4bit / affine-8 / summarization | 1 | 1024 | 1011 | 2635.9 | 147.0 | 147.0 | 148.5 | 385ms | — | — | — | — | 404MB | 1.64GB | 22MB | The text is a fragmented interview or diary entry featuring Thomas Parke from the 1920s, reflecting his own personal reflection and analysis of the novel *The G… | +| 4bit / affine-8 / summarization | 1 | 8192 | 8182 | 2721.6 | 126.0 | 126.0 | 126.2 | 3007ms | — | — | — | — | 404MB | 1.65GB | 67MB | Here is a summary of the provided text from F. Scott Fitzgerald's *The Great Gatsby*. ### Key Themes and Plot Points * **Fathers' Advice:** The narrator… | +| 4bit / affine-4 / summarization | 1 | 1024 | 1011 | 2655.4 | 190.3 | 190.3 | 192.0 | 382ms | — | — | — | — | 404MB | 1.63GB | 16MB | This text is a letter written by the son of F. Scott Fitzgerald during his college years in 1928, addressed to Zelda Pritchard (Zelda) on September 4, 1928. It … | +| 4bit / affine-4 / summarization | 1 | 8192 | 8182 | 2725.8 | 130.4 | 130.4 | 130.4 | 3002ms | — | — | — | — | 404MB | 1.65GB | 40MB | This is a detailed table of contents and an extended chapter from *The Great Gatsby*. Based on the text provided, here is a summary: **Context and Setting:** T… | +| 4bit / turbo4 / summarization | 1 | 1024 | 1011 | 2503.1 | 138.2 | 138.2 | 140.3 | 406ms | — | — | — | — | 405MB | 1.71GB | 14MB | Based on the text provided from F. Scott Fitzgerald's *The Great Gatsby*, here is a summary of the content: **Family and Background** * **Social Prestige:** … | +| 4bit / turbo4 / summarization | 1 | 8192 | 8182 | 2814.8 | 123.5 | 123.5 | 123.4 | 2908ms | — | — | — | — | 405MB | 1.77GB | 36MB | Here is a summary of *The Great Gatsby*: **Plot Summary:** Set in West Egg, New Jersey, the novel follows Nick Caro as an observer of his friends' life through… | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1011 | 2711.5 | 145.1 | 145.1 | 146.5 | 374ms | — | — | — | — | 405MB | 1.71GB | 13MB | This is a dense and complex literary non-sequitum (often called "The Great Red Letter Line" in academic discussions of *Finnigan's Witty Poem*). Below is a summ… | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8182 | 2739.7 | 123.5 | 123.5 | 123.7 | 2987ms | — | — | — | — | 405MB | 1.75GB | 29MB | Based on the text *The Great Gatsby*, here is a summary of its contents and themes: ### **1. Structure and Theme** * **Folklore vs. Reality:** The text begin… | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1011 | 2321.2 | 184.1 | 184.1 | 185.3 | 437ms | — | — | — | — | 405MB | 1.71GB | 16MB | This text is an early section of Fitzgerald's novel *Fiction*, likely preceding a later chapter where he writes about the specific characters in his novel, Zeld… | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8182 | 2919.9 | 146.2 | 146.2 | 146.2 | 2803ms | — | — | — | — | 405MB | 1.85GB | 48MB | Based on the provided text from *The Great Gatsby*, here is a summary of the key themes, characters, and plot points: ### **Main Themes** * **Alienation and … | + +#### Parameters + +**4bit / no-quant / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-8 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4v2 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4v2) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo8v4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo8v4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +### Qwen3.5 2B + +**Model:** `mlx-community/Qwen3.5-2B-4bit` + +#### Results + +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1011 | 1396.9 | 118.4 | 118.4 | 119.6 | 724ms | — | — | — | — | 1010MB | 2.19GB | 22MB | Here is a summary of *The Great Gatsby* by F. Scott Fitzgerald, structured to capture the essence of the text you provided: **Introduction and Family Backgroun… | +| 4bit / no-quant / summarization | 1 | 8192 | 8182 | 1355.4 | 103.4 | 103.4 | 103.4 | 6037ms | — | — | — | — | 1010MB | 2.31GB | 106MB | This excerpt from *The Great Gatsby* by F. Scott Fitzgerald is divided into a prologue (once again to Zelda) and Part I (the opening chapters). It outlines Gats… | +| 4bit / affine-8 / summarization | 1 | 1024 | 1011 | 1312.7 | 135.6 | 135.6 | 136.1 | 771ms | — | — | — | — | 1010MB | 2.21GB | 22MB | This passage presents a concise summary of F. Scott Fitzgerald's novel ***The Great Gatsby***, capturing both the author's introduction and the narrative arc. … | +| 4bit / affine-8 / summarization | 1 | 8192 | 8182 | 1324.1 | 99.7 | 99.7 | 100.4 | 6180ms | — | — | — | — | 1010MB | 2.19GB | 67MB | This text contains a mix of modern prose and the play "The Great Gatsby," originally written by F. Scott Fitzgerald. **Modern Prose Introductory Material:** Th… | +| 4bit / affine-4 / summarization | 1 | 1024 | 1011 | 1290.2 | 114.5 | 114.5 | 115.4 | 785ms | — | — | — | — | 1010MB | 2.20GB | 16MB | This excerpt from *The Great Gatsby* by F. Scott Fitzgerald presents a narrative of social observation, internal philosophy, and personal identity formation wit… | +| 4bit / affine-4 / summarization | 1 | 8192 | 8182 | 1324.5 | 104.4 | 104.4 | 105.2 | 6178ms | — | — | — | — | 1010MB | 2.19GB | 40MB | This excerpt from *The Great Gatsby* by F. Scott Fitzgerald is a narrative introduction that explores the protagonist's (Nick Carraway) disillusionment with the… | +| 4bit / turbo4 / summarization | 1 | 1024 | 1011 | 1311.3 | 133.8 | 133.8 | 134.2 | 773ms | — | — | — | — | 1011MB | 2.19GB | 14MB | This excerpt from *The Great Gatsby* by F. Scott Fitzgerald introduces the narrator, **Tom Buchanan**, and outlines his character development during World War I… | +| 4bit / turbo4 / summarization | 1 | 8192 | 8182 | 1348.8 | 98.3 | 98.3 | 99.0 | 6067ms | — | — | — | — | 1011MB | 2.31GB | 36MB | Here is a summary of John Steinbeck's **To Others: The Great Gatsby and the Art of Hope**: ### **Introduction to Hope** The book "Gandhi" is a powerful explora… | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1011 | 1308.2 | 111.0 | 111.0 | 111.9 | 774ms | — | — | — | — | 1011MB | 2.19GB | 13MB | This excerpt is from *The Great Gatsby* by F. Scott Fitzgerald, and it serves as a narrative bridge connecting the author's childhood education to his departure… | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8182 | 1325.8 | 98.2 | 98.2 | 98.9 | 6172ms | — | — | — | — | 1011MB | 2.31GB | 29MB | Here is a summary of *The Great Gatsby* by F. Scott Fitzgerald, focusing on the core themes and plot progression presented in the provided text: **Introduction… | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1011 | 1311.0 | 113.7 | 113.7 | 114.6 | 773ms | — | — | — | — | 1011MB | 2.19GB | 16MB | This text presents the opening sections of **The Great Gatsby** by **F. Scott Fitzgerald**, structured into an epilogue to the original novel followed by a narr… | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8182 | 1350.5 | 96.8 | 96.8 | 96.9 | 6059ms | — | — | — | — | 1011MB | 2.31GB | 48MB | This excerpt from *The Great Gatsby* by F. Scott Fitzgerald introduces the central characters, establishes their contrasting lifestyles, and begins a significan… | + +#### Parameters + +**4bit / no-quant / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-8 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4v2 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4v2) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo8v4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo8v4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +### Qwen3.5 4B + +**Model:** `mlx-community/Qwen3.5-4B-4bit` + +#### Results + +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1009 | 544.2 | 71.8 | 71.8 | 71.9 | 1855ms | — | — | — | — | 2.20GB | 3.53GB | 57MB | Here's a thinking process that leads to the suggested summary: 1. **Analyze the Request:** * **Source Material:** An excerpt from Chapter 1 of F. Scott … | +| 4bit / no-quant / summarization | 1 | 8192 | 8180 | 529.5 | 68.2 | 68.2 | 68.3 | 15450ms | — | — | — | — | 2.20GB | 3.76GB | 281MB | Here's a thinking process that leads to the summary: 1. **Analyze the Request:** * **Source Material:** The provided text is Chapter One of F. Scott Fit… | +| 4bit / affine-8 / summarization | 1 | 1024 | 1009 | 541.6 | 66.6 | 66.6 | 66.9 | 1864ms | — | — | — | — | 2.20GB | 3.44GB | 59MB | Thinking Process: 1. **Analyze the Request:** * Input: A text segment from F. Scott Fitzgerald's "The Great Gatsby". * Task: Summarize the content… | +| 4bit / affine-8 / summarization | 1 | 8192 | 8180 | 517.7 | 56.6 | 56.6 | 56.6 | 15801ms | — | — | — | — | 2.20GB | 3.52GB | 178MB | Here's a thinking process that leads to the suggested summary: 1. **Analyze the Request:** * **Source Text:** The beginning of F. Scott Fitzgerald's nov… | +| 4bit / affine-4 / summarization | 1 | 1024 | 1009 | 533.2 | 68.2 | 68.2 | 68.6 | 1894ms | — | — | — | — | 2.20GB | 3.43GB | 43MB | Thinking Process: 1. **Analyze the Request:** * Input: An excerpt from Chapter I of F. Scott Fitzgerald's *The Great Gatsby*, including the title, dedic… | +| 4bit / affine-4 / summarization | 1 | 8192 | 8180 | 517.2 | 58.3 | 58.3 | 58.3 | 15816ms | — | — | — | — | 2.20GB | 3.49GB | 106MB | Here's a thinking process that leads to the summary: 1. **Analyze the Request:** * **Input Text:** A significant portion of Chapter I of F. Scott Fitzge… | +| 4bit / turbo4 / summarization | 1 | 1024 | 1009 | 532.0 | 77.0 | 77.0 | 77.2 | 1898ms | — | — | — | — | 2.21GB | 3.53GB | 36MB | Thinking Process: 1. **Analyze the Request:** * Input: A segment of the text from F. Scott Fitzgerald's novel "The Great Gatsby", including the prologue… | +| 4bit / turbo4 / summarization | 1 | 8192 | 8180 | 518.2 | 58.6 | 58.6 | 58.7 | 15787ms | — | — | — | — | 2.21GB | 3.76GB | 94MB | Here's a thinking process that leads to the suggested summary: 1. **Analyze the Request:** * **Source Material:** A provided text, which appears to be t… | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1009 | 531.0 | 68.4 | 68.4 | 68.8 | 1902ms | — | — | — | — | 2.21GB | 3.53GB | 34MB | Thinking Process: 1. **Analyze the Request:** * Input: An excerpt from F. Scott Fitzgerald's "The Great Gatsby" (specifically the beginning, including t… | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8180 | 521.1 | 59.2 | 59.2 | 59.2 | 15698ms | — | — | — | — | 2.21GB | 3.76GB | 77MB | Here's a thinking process that leads to the summary: 1. **Analyze the Request:** * **Task:** Summarize the provided text. * **Source Text:** The b… | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1009 | 530.7 | 67.5 | 67.5 | 68.0 | 1903ms | — | — | — | — | 2.21GB | 3.53GB | 42MB | Thinking Process: 1. **Analyze the Request:** * Input: An excerpt from Chapter I of F. Scott Fitzgerald's *The Great Gatsby*, including the title page (… | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8180 | 517.9 | 56.9 | 56.9 | 56.9 | 15796ms | — | — | — | — | 2.21GB | 3.76GB | 128MB | Here's a thinking process that leads to the suggested summary: 1. **Analyze the Request:** * **Task:** Summarize the provided text. * **Text Sourc… | + +#### Parameters + +**4bit / no-quant / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-8 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4v2 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4v2) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo8v4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo8v4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +### Qwen3.5 9B + +**Model:** `mlx-community/Qwen3.5-9B-4bit` + +#### Results + +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1009 | 298.1 | 49.3 | 49.3 | 49.4 | 3385ms | — | — | — | — | 4.69GB | 6.00GB | 57MB | Thinking Process: 1. **Analyze the Request:** * Input: The beginning of F. Scott Fitzgerald's novel *The Great Gatsby*. It includes the title page (with… | +| 4bit / no-quant / summarization | 1 | 8192 | 8180 | 293.8 | 43.8 | 43.8 | 43.9 | 27847ms | — | — | — | — | 4.69GB | 6.27GB | 281MB | Thinking Process: 1. **Analyze the Request:** * Input: A provided text segment from F. Scott Fitzgerald's *The Great Gatsby*. * Task: Summarize th… | +| 4bit / affine-8 / summarization | 1 | 1024 | 1009 | 294.6 | 52.0 | 52.0 | 52.1 | 3427ms | — | — | — | — | 4.69GB | 5.92GB | 59MB | Thinking Process: 1. **Analyze the Request:** * Input: A text excerpt from the novel *The Great Gatsby* by F. Scott Fitzgerald (Chapter I mostly, with s… | +| 4bit / affine-8 / summarization | 1 | 8192 | 8180 | 291.8 | 41.6 | 41.6 | 41.8 | 28034ms | — | — | — | — | 4.69GB | 6.02GB | 178MB | Thinking Process: 1. **Analyze the Request:** * Input: The first two chapters (and a dedication) of the novel *The Great Gatsby* by F. Scott Fitzgerald.… | +| 4bit / affine-4 / summarization | 1 | 1024 | 1009 | 294.0 | 47.8 | 47.8 | 48.1 | 3433ms | — | — | — | — | 4.69GB | 5.91GB | 43MB | Thinking Process: 1. **Analyze the Request:** * Input: A provided text excerpt from "The Great Gatsby" by F. Scott Fitzgerald. It includes the title pag… | +| 4bit / affine-4 / summarization | 1 | 8192 | 8180 | 292.1 | 42.6 | 42.6 | 42.7 | 28005ms | — | — | — | — | 4.69GB | 5.95GB | 106MB | Thinking Process: 1. **Analyze the Request:** * Input: A text excerpt from "The Great Gatsby" by F. Scott Fitzgerald (Table of Contents, Dedication/Epig… | +| 4bit / turbo4 / summarization | 1 | 1024 | 1009 | 293.9 | 47.8 | 47.8 | 48.0 | 3435ms | — | — | — | — | 4.69GB | 6.00GB | 36MB | Thinking Process: 1. **Analyze the Request:** * Input text: The opening chapters of "The Great Gatsby" by F. Scott Fitzgerald, specifically the dedicati… | +| 4bit / turbo4 / summarization | 1 | 8192 | 8180 | 292.4 | 42.5 | 42.5 | 42.7 | 27978ms | — | — | — | — | 4.69GB | 6.18GB | 94MB | Thinking Process: 1. **Analyze the Request:** * Input text: The provided text is Chapter I of *The Great Gatsby* by F. Scott Fitzgerald, including the d… | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1009 | 293.4 | 47.9 | 47.9 | 48.1 | 3441ms | — | — | — | — | 4.69GB | 6.00GB | 34MB | Thinking Process: 1. **Analyze the Request:** * Input text: The beginning of F. Scott Fitzgerald's novel *The Great Gatsby*. Specifically, it includes t… | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8180 | 292.5 | 43.0 | 43.0 | 43.1 | 27971ms | — | — | — | — | 4.69GB | 6.18GB | 77MB | Thinking Process: 1. **Analyze the Request:** * Input: A large excerpt from F. Scott Fitzgerald's *The Great Gatsby*. * Content: It covers the tit… | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1009 | 293.1 | 47.6 | 47.6 | 47.8 | 3445ms | — | — | — | — | 4.69GB | 6.00GB | 42MB | Thinking Process: 1. **Analyze the Request:** * Input text: The beginning of F. Scott Fitzgerald's novel *The Great Gatsby* (chapters I through the end … | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8180 | 292.4 | 41.7 | 41.7 | 41.7 | 27980ms | — | — | — | — | 4.69GB | 6.18GB | 128MB | Thinking Process: 1. **Analyze the Request:** * Input: A text containing the Table of Contents and Chapter I from F. Scott Fitzgerald's *The Great Gatsb… | + +#### Parameters + +**4bit / no-quant / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-8 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4v2 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4v2) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo8v4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo8v4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +### Gemma 4 E2B + +**Model:** `mlx-community/gemma-4-e2b-it-4bit` + +#### Results + +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1008 | 3125.8 | 100.5 | 100.5 | 101.3 | 324ms | — | — | — | — | 2.45GB | 3.46GB | 12MB | The provided text is an excerpt from *The Great Gatsby* by F. Scott Fitzgerald, featuring a speech or reflection attributed to **Thomas Parke d’Invilliers**. H… | +| 4bit / no-quant / summarization | 1 | 8192 | 8192 | 2852.0 | 94.5 | 94.5 | 95.2 | 2874ms | — | — | — | — | 2.45GB | 5.48GB | 54MB | This is an excerpt from **Nick Carraway's narration** in **The Great Gatsby**. Here is a breakdown of what this section reveals about the novel and Nick's pers… | +| 4bit / affine-8 / summarization | 1 | 1024 | 1008 | 2520.2 | 55.8 | 55.8 | 55.8 | 402ms | — | — | — | — | 2.45GB | 2.82GB | 16MB | This excerpt from *The Great Gatsby* appears to be a collection of fragmented prose, including a poetic line and several distinct, narrative passages, likely fr… | +| 4bit / affine-8 / summarization | 1 | 8192 | 8192 | 2798.4 | 51.6 | 51.6 | 51.6 | 2928ms | — | — | — | — | 2.45GB | 5.45GB | 41MB | This is a fascinating and dense excerpt from **The Great Gatsby**, likely a section of Nick Carraway's narration. It is rich with internal reflection, social ob… | +| 4bit / affine-4 / summarization | 1 | 1024 | 1008 | 2518.3 | 55.5 | 55.5 | 55.5 | 402ms | — | — | — | — | 2.45GB | 2.81GB | 8MB | This excerpt is taken from **The Great Gatsby** by F. Scott Fitzgerald. It appears to be a collection of fragmented prose and literary passages, likely from a n… | +| 4bit / affine-4 / summarization | 1 | 8192 | 8192 | 2792.6 | 51.4 | 51.4 | 51.4 | 2934ms | — | — | — | — | 2.45GB | 5.42GB | 22MB | This is a fascinating excerpt from **The Great Gatsby** by F. Scott Fitzgerald. It is clearly a section of Nick Carraway's narrative, likely from the novel's op… | +| 4bit / turbo4 / summarization | 1 | 1024 | 1008 | 2638.3 | 87.5 | 87.5 | 88.4 | 387ms | — | — | — | — | 2.45GB | 3.46GB | 5MB | This excerpt from *The Great Gatsby* establishes a narrator's highly guarded and critical perspective on the world and human behavior, contrasting their upbring… | +| 4bit / turbo4 / summarization | 1 | 8192 | 8192 | 2812.3 | 73.7 | 73.7 | 73.8 | 2917ms | — | — | — | — | 2.46GB | 5.48GB | 16MB | This is a very detailed excerpt from **The Great Gatsby** by F. Scott Fitzgerald, likely presented from the perspective of the narrator, **Nick Carraway**. Her… | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1008 | 2593.3 | 88.1 | 88.1 | 88.2 | 393ms | — | — | — | — | 2.45GB | 3.46GB | 4MB | This excerpt is a collection of fragmented passages from a literary work, likely *The Great Gatsby*, featuring a dialogue or internal reflection, a piece of poe… | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8192 | 2798.2 | 74.3 | 74.3 | 74.3 | 2931ms | — | — | — | — | 2.46GB | 5.48GB | 12MB | This is a fascinating and dense excerpt from **Nick Carraway's narration** in *The Great Gatsby*. Here are some key observations and thematic breakdowns of the… | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1008 | 2321.7 | 85.2 | 85.2 | 86.0 | 439ms | — | — | — | — | 2.45GB | 3.46GB | 7MB | This excerpt from *The Great Gatsby* introduces a narrator with a highly reserved and critical view of others, stemming from advice given by their father. Here… | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8192 | 2791.4 | 66.8 | 66.8 | 66.8 | 2938ms | — | — | — | — | 2.46GB | 5.48GB | 23MB | This is an excerpt from **The Great Gatsby** by F. Scott Fitzgerald. Based on the content, this section appears to be from the **narrative portion of the novel… | + +#### Parameters + +**4bit / no-quant / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | nil | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 64 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-8 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine8 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 64 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine4 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 64 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 64 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4v2 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4v2) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 64 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo8v4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo8v4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 64 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +### Gemma 4 E4B + +**Model:** `mlx-community/gemma-4-e4b-it-4bit` + +#### Results + +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1008 | 905.5 | 65.9 | 65.9 | 66.0 | 1116ms | — | — | — | — | 3.98GB | 5.12GB | 36MB | The provided text contains the beginning sections of a novel, likely **The Great Gatsby**, by F. Scott Fitzgerald. The content consists of three distinct parts:… | +| 4bit / no-quant / summarization | 1 | 8192 | 8192 | 858.1 | 60.8 | 60.8 | 60.9 | 9549ms | — | — | — | — | 3.98GB | 6.87GB | 148MB | This is the beginning of the novel **The Great Gatsby** by F. Scott Fitzgerald. The text you have provided contains three main sections woven together: 1. **A… | +| 4bit / affine-8 / summarization | 1 | 1024 | 1008 | 823.3 | 36.8 | 36.8 | 36.8 | 1226ms | — | — | — | — | 3.98GB | 4.51GB | 45MB | This text contains the beginning of a novel, *The Great Gatsby* by F. Scott Fitzgerald. Here's a summary of the key elements presented: **The Epigraph (Opening… | +| 4bit / affine-8 / summarization | 1 | 8192 | 8192 | 847.3 | 34.7 | 34.7 | 34.9 | 9670ms | — | — | — | — | 3.98GB | 6.79GB | 113MB | This is the beginning of the novel **The Great Gatsby** by F. Scott Fitzgerald. You have provided: 1. **A Dedication Page:** Dedicated to Zelda. 2. **A Fore… | +| 4bit / affine-4 / summarization | 1 | 1024 | 1008 | 805.6 | 36.7 | 36.7 | 36.8 | 1253ms | — | — | — | — | 3.98GB | 4.48GB | 24MB | The text you provided contains the beginning of a novel, "The Great Gatsby," by F. Scott Fitzgerald. Here's a summary of the content: The passage introduces th… | +| 4bit / affine-4 / summarization | 1 | 8192 | 8192 | 846.5 | 34.7 | 34.7 | 34.7 | 9679ms | — | — | — | — | 3.98GB | 6.71GB | 60MB | Here is an analysis of the provided text, which is the opening section of F. Scott Fitzgerald's *The Great Gatsby*. ## Summary and Context The text provides a… | +| 4bit / turbo4 / summarization | 1 | 1024 | 1008 | 819.0 | 57.4 | 57.4 | 57.8 | 1237ms | — | — | — | — | 3.98GB | 5.12GB | 14MB | The provided text contains excerpts from **The Great Gatsby** by F. Scott Fitzgerald. Here is a summary of the content provided: The passage begins with a ded… | +| 4bit / turbo4 / summarization | 1 | 8192 | 8192 | 851.1 | 48.6 | 48.6 | 49.1 | 9630ms | — | — | — | — | 3.98GB | 6.87GB | 41MB | This is the beginning of the novel *The Great Gatsby*, by F. Scott Fitzgerald. The text you have provided includes: 1. **An Epigraph:** A quote from Thomas P… | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1008 | 846.2 | 57.6 | 57.6 | 57.9 | 1197ms | — | — | — | — | 3.98GB | 5.12GB | 11MB | This text presents the beginning of F. Scott Fitzgerald's *The Great Gatsby*, divided into two main parts: an epigraph and the opening chapters. Here is a summ… | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8192 | 852.0 | 49.5 | 49.5 | 49.7 | 9620ms | — | — | — | — | 3.98GB | 6.87GB | 32MB | This is the beginning of F. Scott Fitzgerald's novel, *The Great Gatsby*. The text you have provided includes: 1. **An epigraph from Thomas Parke d’Invilliers… | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1008 | 830.4 | 56.2 | 56.2 | 56.7 | 1220ms | — | — | — | — | 3.98GB | 5.12GB | 21MB | This text appears to be the beginning of a short story or novel, *The Great Gatsby*, by F. Scott Fitzgerald. It includes several introductory pieces that provid… | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8192 | 850.8 | 42.8 | 42.8 | 42.7 | 9634ms | — | — | — | — | 3.98GB | 6.87GB | 65MB | Here is a summary and analysis of the provided text excerpt from F. Scott Fitzgerald's *The Great Gatsby*. ## Summary of the Excerpt The text presents a colle… | + +#### Parameters + +**4bit / no-quant / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | nil | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 64 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-8 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine8 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 64 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine4 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 64 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 64 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4v2 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4v2) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 64 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo8v4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo8v4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 64 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +### Nemotron 30B A3B + +**Model:** `mlx-community/Nemotron-Cascade-2-30B-A3B-4bit` + +#### Results + +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1025 | 458.7 | 74.3 | 74.3 | 74.4 | 2236ms | — | — | — | — | 16.56GB | 18.07GB | 30MB | We need to respond to the user's input. The user posted a text that seems like a reworked version of The Great Gatsby, perhaps a creative rewrite, with some int… | +| 4bit / no-quant / summarization | 1 | 8192 | 8174 | 451.2 | 70.6 | 70.6 | 70.6 | 18116ms | — | — | — | — | 16.56GB | 18.18GB | 72MB | We need to provide a summary of the content above. The user gave a text that appears to be a parody or alternative version of The Great Gatsby, with a new narra… | +| 4bit / affine-8 / summarization | 1 | 1024 | 1025 | 449.7 | 72.4 | 72.4 | 72.5 | 2281ms | — | — | — | — | 16.56GB | 18.07GB | 30MB | We need to respond to user. The user posted a text that seems to be a modified version of The Great Gatsby, with some weird intro and then a passage. They likel… | +| 4bit / affine-8 / summarization | 1 | 8192 | 8174 | 451.4 | 68.7 | 68.7 | 68.8 | 18110ms | — | — | — | — | 16.56GB | 18.16GB | 52MB | We need to summarize the content above, which appears to be an excerpt from The Great Gatsby, but the given text is a mixture of a modernized or parody version,… | +| 4bit / affine-4 / summarization | 1 | 1024 | 1025 | 445.2 | 73.2 | 73.2 | 73.3 | 2304ms | — | — | — | — | 16.56GB | 18.07GB | 27MB | We need to respond to the user's request. The user posted a text that seems to be an excerpt from The Great Gatsby with some weird formatting and then a continu… | +| 4bit / affine-4 / summarization | 1 | 8192 | 8174 | 451.9 | 68.9 | 68.9 | 68.9 | 18087ms | — | — | — | — | 16.56GB | 18.16GB | 39MB | We need to respond: "Summarize the content above." The content includes a fairly extensive excerpt from The Great Gatsby and also a weird extra text that seems … | +| 4bit / turbo4 / summarization | 1 | 1024 | 1025 | 452.8 | 72.8 | 72.8 | 72.9 | 2265ms | — | — | — | — | 16.56GB | 18.07GB | 26MB | The user posted a text that appears to be a modified version of The Great Gatsby, with some weird headings, and then a continuation that ends abruptly. The user… | +| 4bit / turbo4 / summarization | 1 | 8192 | 8174 | 448.9 | 67.9 | 67.9 | 67.9 | 18208ms | — | — | — | — | 16.56GB | 18.18GB | 37MB | We need to provide a summary of the content above. The user gave a large excerpt that appears to be a mash-up of The Great Gatsby and some other text. Let’s rea… | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1025 | 450.7 | 72.8 | 72.8 | 72.9 | 2276ms | — | — | — | — | 16.56GB | 18.07GB | 26MB | We need to respond. The user posted a text that looks like a modified version of The Great Gatsby introduction with some weird formatting. They likely want some… | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8174 | 449.4 | 67.9 | 67.9 | 67.9 | 18190ms | — | — | — | — | 16.56GB | 18.18GB | 34MB | We need to provide a summary of the above text. The user gave a text that appears to be a retelling or a piece of a novel titled "The Great Gatsby" but with a d… | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1025 | 452.2 | 72.8 | 72.8 | 72.8 | 2269ms | — | — | — | — | 16.56GB | 18.07GB | 27MB | Okay, the user has shared a passage from "The Great Gatsby" with a table of contents and some introductory text, but it seems incomplete. The passage they share… | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8174 | 449.4 | 67.6 | 67.6 | 67.6 | 18191ms | — | — | — | — | 16.56GB | 18.18GB | 43MB | The user has posted a large block that looks like the opening of The Great Gatsby, but it's heavily altered, with a preface, a summary, and then a long descript… | + +#### Parameters + +**4bit / no-quant / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 0.6 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-8 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 0.6 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 0.6 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 0.6 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4v2 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4v2) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 0.6 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo8v4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo8v4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 0.6 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +### GPT-OSS 20B + +**Model:** `loan-star/gpt-oss-20b-mlx-4Bit` + +#### Results + +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1024 | 494.0 | 74.7 | 74.7 | 75.0 | 2074ms | — | — | — | — | 10.41GB | 11.37GB | 27MB | <\|channel\|>analysis<\|message\|>We have a user message containing an excerpt of a text. They likely want something done with the text. The user didn't ask a quest… | +| 4bit / no-quant / summarization | 1 | 8192 | 8042 | 507.7 | 63.6 | 63.6 | 63.6 | 15840ms | — | — | — | — | 10.41GB | 11.94GB | 195MB | <\|channel\|>analysis<\|message\|>We have a user message: a large text of a novel or story. The user wants a summary. The instructions: "Summarize the content above… | +| 4bit / affine-8 / summarization | 1 | 1024 | 1024 | 471.0 | 48.4 | 48.4 | 48.6 | 2176ms | — | — | — | — | 10.41GB | 11.23GB | 27MB | <\|channel\|>analysis<\|message\|>We have a user asking: They posted a text: "The Great Gatsby" by F. Scott Fitzgerald? It's an excerpt? The user might be asking so… | +| 4bit / affine-8 / summarization | 1 | 8192 | 8042 | 500.8 | 43.9 | 43.9 | 43.9 | 16059ms | — | — | — | — | 10.41GB | 11.86GB | 129MB | <\|channel\|>analysis<\|message\|>We need to summarize content. The text is long, messy. It's a story about narrator, father advice, talk about Gatsby, etc. Need to… | +| 4bit / affine-4 / summarization | 1 | 1024 | 1024 | 466.9 | 48.4 | 48.4 | 48.5 | 2195ms | — | — | — | — | 10.41GB | 11.21GB | 14MB | <\|channel\|>analysis<\|message\|>We need to produce a short, clear, and in first. The user has given a long text. We need to produce an answer. There's no question… | +| 4bit / affine-4 / summarization | 1 | 8192 | 8042 | 501.3 | 43.9 | 43.9 | 43.9 | 16043ms | — | — | — | — | 10.41GB | 11.81GB | 68MB | <\|channel\|>analysis}I need to deliver summary of? The text is a long, intricate,... Ok, this [ ... ) The text? This? So, we can …… Ok ... ? **?‑???…;?... We n… | +| 4bit / turbo4 / summarization | 1 | 1024 | 1024 | 479.0 | 68.0 | 68.0 | 68.0 | 2140ms | — | — | — | — | 10.41GB | 11.37GB | 12MB | <\|channel\|>commentary.. No…….….……. **…**…… **…**…..??… **? Let's call…….…... Alright, **??………... This **……… ……...??...... The **(??… Wow. ****…** Scrollin… | +| 4bit / turbo4 / summarization | 1 | 8192 | 8042 | 507.3 | 50.9 | 50.9 | 50.9 | 15853ms | — | — | — | — | 10.41GB | 11.94GB | 59MB | <\|channel\|>analysis<\|message\|>We need to summarizing the content...<\|end\|><\|start\|>assistant<\|channel\|>final<\|message\|>**Summary**: The text is a long, fragment… | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1024 | 478.2 | 68.0 | 68.0 | 68.0 | 2144ms | — | — | — | — | 10.41GB | 11.37GB | 10MB | <\|channel\|>commentary‑?????????? ??????..??..?????..???? **D..??…....??…?????…????..??..?????–..??..???… **???????????...???????……..???????????..???**** We n… | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8042 | 506.2 | 50.7 | 50.7 | 50.7 | 15889ms | — | — | — | — | 10.41GB | 11.94GB | 46MB | <\|channel\|>analysis<\|message\|>We have a user query: "Summarize [I] (???)" ??? Actually they want summary. The user wants a summary of the content. So we need to… | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1024 | 480.3 | 67.5 | 67.5 | 67.6 | 2134ms | — | — | — | — | 10.41GB | 11.37GB | 17MB | <\|channel\|>analysis<\|message\|>We need to write something like this? The user asks: "Write a short statement for a particular about “i have ???". The user is giv… | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8042 | 505.5 | 49.9 | 49.9 | 49.9 | 15910ms | — | — | — | — | 10.41GB | 11.94GB | 83MB | <\|channel\|>analysis<\|message\|>Ok, we need to read the text to get something... *… …..... …......??……………... ........?… The…..... well?…?………?……...….. We have…..… | + +#### Parameters + +**4bit / no-quant / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | nil | +| Prefill step size | 2048 | +| Max tokens | 400 | +| Temperature | 0.8 | +| Top P | 0.8 | +| Top K | 0 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | medium | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-8 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine8 | +| Prefill step size | 2048 | +| Max tokens | 400 | +| Temperature | 0.8 | +| Top P | 0.8 | +| Top K | 0 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | medium | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine4 | +| Prefill step size | 2048 | +| Max tokens | 400 | +| Temperature | 0.8 | +| Top P | 0.8 | +| Top K | 0 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | medium | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4 | +| Prefill step size | 2048 | +| Max tokens | 400 | +| Temperature | 0.8 | +| Top P | 0.8 | +| Top K | 0 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | medium | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4v2 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4v2) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 2048 | +| Max tokens | 400 | +| Temperature | 0.8 | +| Top P | 0.8 | +| Top K | 0 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | medium | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo8v4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo8v4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 2048 | +| Max tokens | 400 | +| Temperature | 0.8 | +| Top P | 0.8 | +| Top K | 0 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | medium | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +### Qwen3.5 35B A3B + +**Model:** `mlx-community/Qwen3.5-35B-A3B-4bit` + +#### Results + +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1009 | 508.6 | 59.5 | 59.5 | 59.5 | 1985ms | — | — | — | — | 18.16GB | 19.27GB | 51MB | Thinking Process: 1. **Analyze the Request:** * Input: A portion of the text from F. Scott Fitzgerald's novel *The Great Gatsby* (specifically the Title… | +| 4bit / no-quant / summarization | 1 | 8192 | 8180 | 543.2 | 55.1 | 55.1 | 55.1 | 15060ms | — | — | — | — | 18.16GB | 19.83GB | 191MB | Thinking Process: 1. **Analyze the Request:** * Input: The text provided is Chapter I of F. Scott Fitzgerald's novel *The Great Gatsby*. It includes the… | +| 4bit / affine-8 / summarization | 1 | 1024 | 1009 | 498.6 | 57.1 | 57.1 | 57.4 | 2025ms | — | — | — | — | 18.16GB | 19.30GB | 74MB | Thinking Process: 1. **Analyze the Request:** * Input: A text snippet from "The Great Gatsby" by F. Scott Fitzgerald, specifically the beginning (Title … | +| 4bit / affine-8 / summarization | 1 | 8192 | 8180 | 546.5 | 48.1 | 48.1 | 48.1 | 14968ms | — | — | — | — | 18.16GB | 19.76GB | 159MB | Thinking Process: 1. **Analyze the Request:** * Input: A large portion of text from "The Great Gatsby" by F. Scott Fitzgerald (specifically, Chapters I … | +| 4bit / affine-4 / summarization | 1 | 1024 | 1009 | 482.4 | 57.3 | 57.3 | 57.6 | 2093ms | — | — | — | — | 18.16GB | 19.27GB | 54MB | Thinking Process: 1. **Analyze the Request:** * Input: The beginning of F. Scott Fitzgerald's novel "The Great Gatsby" (Title, Dedication, Poem, Chapter… | +| 4bit / affine-4 / summarization | 1 | 8192 | 8180 | 543.7 | 53.6 | 53.6 | 53.6 | 15045ms | — | — | — | — | 18.16GB | 19.72GB | 99MB | Thinking Process: 1. **Analyze the Request:** * Input: The first chapter (Chapter I) of "The Great Gatsby" by F. Scott Fitzgerald (including title page,… | +| 4bit / turbo4 / summarization | 1 | 1024 | 1009 | 487.4 | 57.2 | 57.2 | 57.4 | 2073ms | — | — | — | — | 18.16GB | 19.27GB | 39MB | Thinking Process: 1. **Analyze the Request:** * Input: A text segment from F. Scott Fitzgerald's novel *The Great Gatsby* (specifically the title page, … | +| 4bit / turbo4 / summarization | 1 | 8192 | 8180 | 544.3 | 50.7 | 50.7 | 50.8 | 15030ms | — | — | — | — | 18.16GB | 19.83GB | 75MB | Thinking Process: 1. **Analyze the Request:** * Input: A large text containing the first chapter (and partial table of contents/introduction) of F. Scot… | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1009 | 490.4 | 62.9 | 62.9 | 63.0 | 2060ms | — | — | — | — | 18.16GB | 19.27GB | 37MB | Thinking Process: 1. **Analyze the Request:** * Input Text: The beginning of the novel "The Great Gatsby" by F. Scott Fitzgerald (specifically Chapter I… | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8180 | 544.9 | 50.8 | 50.8 | 50.8 | 15014ms | — | — | — | — | 18.16GB | 19.83GB | 64MB | Thinking Process: 1. **Analyze the Request:** * Input: A significant portion of F. Scott Fitzgerald's novel *The Great Gatsby* (specifically Chapter 1, … | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1009 | 487.8 | 57.2 | 57.2 | 57.4 | 2071ms | — | — | — | — | 18.16GB | 19.27GB | 42MB | Thinking Process: 1. **Analyze the Request:** * Input: A text excerpt from "The Great Gatsby" by F. Scott Fitzgerald (specifically the Dedication, Chapt… | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8180 | 541.0 | 50.1 | 50.1 | 50.2 | 15120ms | — | — | — | — | 18.16GB | 19.83GB | 96MB | Thinking Process: 1. **Analyze the Request:** * Input: A text containing the beginning of F. Scott Fitzgerald's novel *The Great Gatsby* (Chapter I, mos… | + +#### Parameters + +**4bit / no-quant / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | nil | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-8 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine8 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine4 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4v2 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4v2) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo8v4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo8v4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +### Gemma 4 26B A4B + +**Model:** `mlx-community/gemma-4-26b-a4b-it-4bit` + +#### Results + +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1012 | 593.0 | 28.1 | 28.1 | 28.2 | 1708ms | — | — | — | — | 13.48GB | 15.82GB | 432MB | The provided text serves as the opening of F. Scott Fitzgerald’s *The Great Gatsby*, consisting of the Table of Contents, an epigraph, and the beginning of Chap… | +| 4bit / no-quant / summarization | 1 | 8192 | 8192 | 596.2 | 25.9 | 25.9 | 25.9 | 13741ms | — | — | — | — | 13.48GB | 23.67GB | 712MB | This text is the complete opening of **Chapter I of *The Great Gatsby***. It establishes the narrator, Nick Carraway, his relationship to the central characters… | +| 4bit / affine-8 / summarization | 1 | 1024 | 1012 | 552.9 | 8.1 | 8.1 | 8.1 | 1832ms | — | — | — | — | 13.48GB | 15.50GB | 157MB | The provided text serves as the introductory section of F. Scott Fitzgerald’s *The Great Gatsby*, consisting of the Table of Contents, an epigraph, and the open… | +| 4bit / affine-8 / summarization | 1 | 8192 | 8192 | 594.3 | 8.0 | 8.0 | 8.0 | 13784ms | — | — | — | — | 13.48GB | 22.25GB | 247MB | This text is the complete first chapter of F. Scott Fitzgerald's masterpiece, ***The Great Gatsby***. ### Summary of Chapter I The chapter serves as an introdu… | +| 4bit / affine-4 / summarization | 1 | 1024 | 1012 | 622.8 | 8.2 | 8.2 | 8.2 | 1626ms | — | — | — | — | 13.48GB | 15.44GB | 87MB | The provided text contains the opening of F. Scott Fitzgerald's *The Great Gatsby*, consisting of the table of contents, an epigraph, and the beginning of Chapt… | +| 4bit / affine-4 / summarization | 1 | 8192 | 8192 | 593.5 | 8.1 | 8.1 | 8.1 | 13804ms | — | — | — | — | 13.48GB | 21.97GB | 137MB | This is the complete text of the first chapter of F. Scott Fitzgerald's masterpiece, *The Great Gatsby*. ### **Summary of Chapter I** **The Narrator and His P… | +| 4bit / turbo4 / summarization | 1 | 1024 | 1012 | 630.1 | 27.1 | 27.1 | 27.2 | 1610ms | — | — | — | — | 13.48GB | 15.82GB | 74MB | The provided text comprises the opening of F. Scott Fitzgerald’s *The Great Gatsby*, including the table of contents, dedication, epigraph, and the beginning of… | +| 4bit / turbo4 / summarization | 1 | 8192 | 8192 | 606.3 | 26.1 | 26.1 | 26.1 | 13515ms | — | — | — | — | 13.48GB | 23.67GB | 114MB | This text is the complete first chapter of F. Scott Fitzgerald's *The Great Gatsby*. The chapter establishes the setting, the narrator (Nick Carraway), and th… | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1012 | 612.8 | 27.1 | 27.1 | 27.2 | 1655ms | — | — | — | — | 13.48GB | 15.82GB | 54MB | This text serves as the opening of F. Scott Fitzgerald’s *The Great Gatsby*. It establishes the narrator, Nick Carraway, and his perspective on the world around… | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8192 | 607.3 | 25.9 | 25.9 | 26.0 | 13493ms | — | — | — | — | 13.48GB | 23.67GB | 82MB | This-is the first chapter of F. Scott Fitzgerald's *The Great Gatsby*. It introduces the narrator, Nick Carraway, and establishes the setting of West Egg and Ea… | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1012 | 617.1 | 26.8 | 26.8 | 26.9 | 1644ms | — | — | — | — | 13.48GB | 15.82GB | 110MB | The provided text contains the opening of F. Scott Fitzgerald’s ***The Great Gatsby***, including the dedication and the beginning of Chapter I. ### **Summary … | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8192 | 604.3 | 25.6 | 25.6 | 25.7 | 13560ms | — | — | — | — | 13.48GB | 23.67GB | 163MB | This is the complete text of the first chapter of F. Scott Fitzgerald's *The Great Gatsby*. In this opening chapter, we are introduced to the narrator, **Nick… | + +#### Parameters + +**4bit / no-quant / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | nil | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 64 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-8 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine8 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 64 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine4 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 64 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 64 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4v2 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4v2) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 64 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo8v4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo8v4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 64 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +### Qwen3.5 27B + +**Model:** `mlx-community/Qwen3.5-27B-4bit` + +#### Results + +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1009 | 87.4 | 18.0 | 18.0 | 18.0 | 11550ms | — | — | — | — | 14.09GB | 15.45GB | 139MB | Thinking Process: 1. **Analyze the Request:** * Input: Text from the beginning of F. Scott Fitzgerald's novel *The Great Gatsby* (Title page, dedication… | +| 4bit / no-quant / summarization | 1 | 8192 | 8180 | 86.2 | 17.1 | 17.1 | 17.1 | 94922ms | — | — | — | — | 14.09GB | 15.86GB | 587MB | Here's a thinking process that leads to the suggested summary: 1. **Analyze the Request:** * **Source Material:** The provided text is Chapter I of *The… | +| 4bit / affine-8 / summarization | 1 | 1024 | 1009 | 87.0 | 17.6 | 17.6 | 17.6 | 11606ms | — | — | — | — | 14.09GB | 15.44GB | 143MB | Thinking Process: 1. **Analyze the Request:** * Input: The beginning of F. Scott Fitzgerald's *The Great Gatsby*, including the Table of Contents, dedic… | +| 4bit / affine-8 / summarization | 1 | 8192 | 8180 | 86.1 | 16.6 | 16.6 | 16.6 | 95039ms | — | — | — | — | 14.09GB | 15.64GB | 381MB | Here's a thinking process that leads to the summary: 1. **Analyze the Request:** * **Source Material:** The provided text is Chapter One of F. Scott Fit… | +| 4bit / affine-4 / summarization | 1 | 1024 | 1009 | 86.8 | 17.6 | 17.6 | 17.6 | 11632ms | — | — | — | — | 14.09GB | 15.42GB | 111MB | Thinking Process: 1. **Analyze the Request:** * Input: Text from the beginning of F. Scott Fitzgerald's *The Great Gatsby*, specifically the Table of Co… | +| 4bit / affine-4 / summarization | 1 | 8192 | 8180 | 86.0 | 15.8 | 15.8 | 15.8 | 95084ms | — | — | — | — | 14.09GB | 15.50GB | 237MB | Thinking Process: 1. **Analyze the Request:** * Input: The text of Chapter I of "The Great Gatsby" by F. Scott Fitzgerald (including title page, dedicat… | +| 4bit / turbo4 / summarization | 1 | 1024 | 1009 | 86.7 | 17.6 | 17.6 | 17.7 | 11639ms | — | — | — | — | 14.09GB | 15.45GB | 98MB | Thinking Process: 1. **Analyze the Request:** * Input: Text from the beginning of F. Scott Fitzgerald's novel *The Great Gatsby* (specifically the title… | +| 4bit / turbo4 / summarization | 1 | 8192 | 8180 | 86.1 | 16.2 | 16.2 | 16.2 | 95013ms | — | — | — | — | 14.09GB | 15.86GB | 213MB | Here's a thinking process that leads to the suggested summary: 1. **Analyze the Request:** * **Source Material:** Chapter I of F. Scott Fitzgerald's *Th… | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1009 | 86.7 | 17.6 | 17.6 | 17.6 | 11634ms | — | — | — | — | 14.09GB | 15.45GB | 92MB | Thinking Process: 1. **Analyze the Request:** * Input text: The beginning of F. Scott Fitzgerald's novel *The Great Gatsby*, specifically the dedication… | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8180 | 86.1 | 16.2 | 16.2 | 16.2 | 95016ms | — | — | — | — | 14.09GB | 15.86GB | 180MB | Here's a thinking process that leads to the suggested summary: 1. **Analyze the Request:** * **Source Text:** Chapter One of F. Scott Fitzgerald's *The … | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1009 | 86.7 | 17.6 | 17.6 | 17.6 | 11635ms | — | — | — | — | 14.09GB | 15.45GB | 109MB | Thinking Process: 1. **Analyze the Request:** * Input: Text from the beginning of "The Great Gatsby" by F. Scott Fitzgerald (Title page, dedication, epi… | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8180 | 86.4 | 16.0 | 16.0 | 16.1 | 94731ms | — | — | — | — | 14.09GB | 15.86GB | 280MB | Here's a thinking process that leads to the suggested summary: 1. **Analyze the Request:** * **Source Material:** Chapter I of *The Great Gatsby* by F. … | + +#### Parameters + +**4bit / no-quant / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-8 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4v2 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4v2) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo8v4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo8v4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +### Qwen3.6 27B + +**Model:** `mlx-community/Qwen3.6-27B-4bit` + +#### Results + +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1009 | 87.3 | 18.0 | 18.0 | 18.0 | 11557ms | — | — | — | — | 14.09GB | 15.45GB | 139MB | Here's a thinking process: 1. **Analyze User Input:** - The user provides the beginning of F. Scott Fitzgerald's *The Great Gatsby*, specifically the title… | +| 4bit / no-quant / summarization | 1 | 8192 | 8180 | 86.4 | 17.0 | 17.0 | 17.1 | 94659ms | — | — | — | — | 14.09GB | 15.86GB | 587MB | Here's a thinking process: 1. **Analyze User Input:** - The user provided the full text of Chapter I of F. Scott Fitzgerald's *The Great Gatsby*. - The … | +| 4bit / affine-8 / summarization | 1 | 1024 | 1009 | 86.8 | 18.6 | 18.6 | 18.6 | 11621ms | — | — | — | — | 14.09GB | 15.44GB | 143MB | Here's a thinking process: 1. **Analyze User Input:** - **Input Text:** The beginning of F. Scott Fitzgerald's *The Great Gatsby*, including the title page… | +| 4bit / affine-8 / summarization | 1 | 8192 | 8180 | 85.9 | 15.7 | 15.7 | 15.7 | 95181ms | — | — | — | — | 14.09GB | 15.63GB | 381MB | Here's a thinking process: 1. **Analyze User Input:** - **Input Text:** The first chapter (and dedication/epigraph) of F. Scott Fitzgerald's *The Great Gat… | +| 4bit / affine-4 / summarization | 1 | 1024 | 1009 | 86.7 | 17.6 | 17.6 | 17.6 | 11644ms | — | — | — | — | 14.09GB | 15.42GB | 111MB | Here's a thinking process: 1. **Analyze User Input:** - The user provided the beginning of F. Scott Fitzgerald's *The Great Gatsby*, specifically the title… | +| 4bit / affine-4 / summarization | 1 | 8192 | 8180 | 86.0 | 15.7 | 15.7 | 15.8 | 95092ms | — | — | — | — | 14.09GB | 15.50GB | 237MB | Here's a thinking process: 1. **Analyze User Input:** - **Input Text:** The first chapter of *The Great Gatsby* by F. Scott Fitzgerald, including the title… | +| 4bit / turbo4 / summarization | 1 | 1024 | 1009 | 86.9 | 18.7 | 18.7 | 18.7 | 11619ms | — | — | — | — | 14.09GB | 15.45GB | 98MB | Here's a thinking process: 1. **Analyze User Input:** - **Input Text:** The beginning of F. Scott Fitzgerald's *The Great Gatsby* (Chapter 1, up to a certa… | +| 4bit / turbo4 / summarization | 1 | 8192 | 8180 | 86.1 | 16.2 | 16.2 | 16.2 | 95031ms | — | — | — | — | 14.09GB | 15.86GB | 213MB | Here's a thinking process: 1. **Analyze User Input:** - **Input Text:** Chapter I of F. Scott Fitzgerald's *The Great Gatsby*. - **Task:** Summarize the… | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1009 | 86.7 | 17.6 | 17.6 | 17.7 | 11640ms | — | — | — | — | 14.09GB | 15.45GB | 92MB | Here's a thinking process: 1. **Analyze User Input:** - The user provided the beginning of F. Scott Fitzgerald's *The Great Gatsby* (dedication, epigraph, … | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8180 | 86.4 | 16.2 | 16.2 | 16.2 | 94713ms | — | — | — | — | 14.09GB | 15.86GB | 180MB | Here's a thinking process: 1. **Analyze User Input:** - **Input Text:** The complete first chapter of F. Scott Fitzgerald's *The Great Gatsby* (up to the e… | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1009 | 86.7 | 17.6 | 17.6 | 17.6 | 11639ms | — | — | — | — | 14.09GB | 15.45GB | 109MB | Here's a thinking process: 1. **Analyze User Input:** - The user provided the beginning of F. Scott Fitzgerald's *The Great Gatsby* (specifically, the titl… | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8180 | 86.2 | 16.9 | 16.9 | 16.9 | 94949ms | — | — | — | — | 14.09GB | 15.87GB | 280MB | Here's a thinking process: 1. **Analyze User Input:** - The user provided the text of Chapter I of F. Scott Fitzgerald's *The Great Gatsby*. - The reque… | + +#### Parameters + +**4bit / no-quant / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | nil | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-8 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine8 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4v2 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4v2) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo8v4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo8v4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 1024 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 20 | +| Min P | 0.0 | +| Repetition penalty | 1 | +| Repetition context size | 20 | +| Presence penalty | 1.5 | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +### Gemma 4 31B + +**Model:** `mlx-community/gemma-4-31b-it-4bit` + +#### Results + +| Config | B | Ctx | Prompt | Prefill tok/s | Decode (agg) tok/s | Decode (seq) tok/s | Steady tok/s | TTFT | Think PPL | Gen PPL | Think KLD | Gen KLD | GPU Base | GPU Peak | KV Cache | Sample | +|--------|--:|----:|-------:|--------------:|-------------------:|-------------------:|-------------:|-----:|----------:|--------:|----------:|--------:|---------:|---------:|---------:|--------| +| 4bit / no-quant / summarization | 1 | 1024 | 1012 | 74.1 | 14.8 | 14.8 | 14.9 | 13667ms | — | — | — | — | 16.08GB | 17.91GB | 880MB | The provided text is the opening of F. Scott Fitzgerald's *The Great Gatsby*. It introduces the narrator, Nick Carraway, who begins by reflecting on a piece of … | +| 4bit / no-quant / summarization | 1 | 8192 | 8192 | 69.0 | 13.9 | 13.9 | 13.9 | 118799ms | — | — | — | — | 16.08GB | 28.10GB | 1.41GB | This opening chapter of *The Great Gatsby* serves as a masterful introduction to the novel's themes of social class, disillusionment, and the elusive nature of … | +| 4bit / affine-8 / summarization | 1 | 1024 | 1012 | 73.1 | 10.3 | 10.3 | 10.3 | 13847ms | — | — | — | — | 16.08GB | 17.59GB | 595MB | The provided text is the opening of F. Scott Fitzgerald's *The Great Gatsby*. It introduces the narrator, Nick Carraway, who establishes his personality and bac… | +| 4bit / affine-8 / summarization | 1 | 8192 | 8192 | 68.7 | 9.6 | 9.6 | 9.6 | 119170ms | — | — | — | — | 16.08GB | 25.89GB | 935MB | This is the complete first chapter of F. Scott Fitzgerald's *The Great Gatsby*. In this opening, Fitzgerald establishes the novel's narrator, Nick Carraway, and… | +| 4bit / affine-4 / summarization | 1 | 1024 | 1012 | 73.0 | 10.4 | 10.4 | 10.4 | 13856ms | — | — | — | — | 16.08GB | 17.33GB | 315MB | The provided text is the opening section of F. Scott Fitzgerald's novel, *The Great Gatsby*. It introduces the narrator, Nick Carraway, and establishes the nove… | +| 4bit / affine-4 / summarization | 1 | 8192 | 8192 | 68.8 | 9.7 | 9.7 | 9.7 | 119120ms | — | — | — | — | 16.08GB | 24.76GB | 495MB | Based on the text provided from Chapter I of *The Great Gatsby*, here is a summary of the key characters and the narrative setup: ### **The Narrator: Nick Carr… | +| 4bit / turbo4 / summarization | 1 | 1024 | 1012 | 73.4 | 13.3 | 13.3 | 13.4 | 13793ms | — | — | — | — | 16.08GB | 17.91GB | 258MB | The provided text serves as the opening of F. Scott Fitzgerald's *The Great Gatsby*. It introduces the narrator, Nick Carraway, who establishes his persona as a… | +| 4bit / turbo4 / summarization | 1 | 8192 | 8192 | 68.9 | 12.3 | 12.3 | 12.3 | 118985ms | — | — | — | — | 16.09GB | 28.10GB | 457MB | This opening chapter of *The Great Gatsby* establishes the central themes and characters of the novel while introducing the narrator, Nick Carraway. Here is a b… | +| 4bit / turbo4v2 / summarization | 1 | 1024 | 1012 | 73.3 | 13.4 | 13.4 | 13.4 | 13819ms | — | — | — | — | 16.08GB | 17.91GB | 210MB | The provided text consists of the opening pages of *The Gatsby deal Gatsby*. The content can be summarized as follows: **Introduction of the Narrator** The nar… | +| 4bit / turbo4v2 / summarization | 1 | 8192 | 8192 | 69.3 | 12.3 | 12.3 | 12.3 | 118132ms | — | — | — | — | 16.09GB | 28.10GB | 346MB | This deconstructy of the opening of *The Great de laa de la de la’ de la la*—pardon the phrase, the opening of *The Great Gatsby*—introdues us to Nick CarrawLwa… | +| 4bit / turbo8v4 / summarization | 1 | 1024 | 1012 | 73.1 | 13.2 | 13.2 | 13.2 | 13858ms | — | — | — | — | 16.08GB | 17.91GB | 425MB | This excerpt serves as the opening of F. Scott Fitzgerald's *The Great Gatsby*. It introduces the narrator, **Nick Carraway**, who establishes the narrative voi… | +| 4bit / turbo8v4 / summarization | 1 | 8192 | 8192 | 69.4 | 12.0 | 12.0 | 12.0 | 118030ms | — | — | — | — | 16.09GB | 28.10GB | 681MB | This opening chapter of *The Great Gatsby* serves as a masterclass in character introduction and thematic establishment. Through the eyes of Nick Carraway, Fitz… | + +#### Parameters + +**4bit / no-quant / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | None (FP16) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | nil | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 64 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-8 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (8-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine8 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 64 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / affine-4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | Affine (4-bit, group 64) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | affine4 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 64 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 64 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo4v2 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo4v2) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo4v2 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 64 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +**4bit / turbo8v4 / summarization** + +| Parameter | Value | +|-----------|-------| +| KV cache strategy | TurboQuant (turbo8v4) | +| Max KV size | 1024 tokens (StandardKVCache) | +| Compression algorithm | turbo8v4 | +| Prefill step size | 4096 | +| Max tokens | 400 | +| Temperature | 1.0 | +| Top P | 0.95 | +| Top K | 64 | +| Min P | 0.0 | +| Repetition penalty | nil | +| Repetition context size | 20 | +| Presence penalty | nil | +| Presence context size | 20 | +| Frequency penalty | nil | +| Frequency context size | 20 | +| Reasoning effort | nil | +| Think start token id | nil | +| Think end token id | nil | +| Thinking phase prefilled | false | +| Thinking (effective) | No | +| Speculative decoding | none | +| N-gram size | 0 | +| Max n-gram draft tokens | 0 | +| Collect per-token data | false | +| Track perplexity | false | +| Perplexity tracking (MLX_BENCH_PPL) | No | +| KL divergence (MLX_BENCH_KLD) | No | +| Batch size (MLX_BENCH_BATCH) | 1 | +| Additional processors count | 0 | +| Max ops per buffer (MLX_MAX_OPS_PER_BUFFER) | 500 (from device.cpp, applegpu_g13s) | + +_System prompt:_ No system role message; user-only messages per methodology (no full user prompt in this report). + +## Methodology + +See [benchmarks/README.md](README.md#methodology) for method definitions, perplexity / KLD computation, and memory accounting. diff --git a/documentation/kv-cache.md b/documentation/kv-cache.md index 75834278e8..d9aee400e6 100644 --- a/documentation/kv-cache.md +++ b/documentation/kv-cache.md @@ -11,25 +11,37 @@ parser. This page covers the public API and how to choose between them. |---|---|---|---| | **No compression** (`StandardKVCache`, default) | Baseline. Speed-critical short / mid context. | 1× (raw fp16/bf16) | Supports unbounded growth or sliding-window eviction (`maxKVSize`). | | **Affine quantization** (`AffineQuantizedKVCache`) | Memory-constrained; attention quality matters. | ~3.5× at 4-bit | 4 / 6 / 8-bit affine group-quant. Self-transitions raw → quantized at `startOffset` so prefill stays fast. | -| **TurboQuant compression** (`TurboQuantizedKVCache`) | Best memory ratio at minimal quality loss. Sliding-window support is implemented in the codec but model-factory dispatch is held back until [#185](https://github.com/ekryski/mlx-swift-lm/issues/185) (Gemma 4 specific) is fixed; direct construction via `makeKVCache(scheme:eviction:)` works on Mistral 3 / Ministral 3 / Gemma 3. | ~6–8× at `turbo4v2` | Block-wise MSE codec with **asymmetric K/V bits** (e.g. 4-bit K, 2-bit V). Separate decode paths: compressed-attention "B" (default) and raw-fp16 working-buffer "A". | +| **TurboQuant compression** (`TurboQuantizedKVCache`) | Best memory ratio at minimal quality loss. Sliding-window models (Gemma 4, GPT-OSS, Mistral 3, etc.) supported via the codec's built-in rotating buffer. | ~6–8× at `turbo4v2` | Block-wise MSE codec with **asymmetric K/V bits** (e.g. 4-bit K, 2-bit V). Decode runs through one of two attention paths: **A path (default)** — TurboFlash compressed-domain Metal kernel (scores directly against packed K/V); **B path (opt-in via `TURBO_DEQUANT_SDPA=1`)** — `bulkDequantRotated` to FP16 + Apple's `MLXFast.scaledDotProductAttention`. | | **Hybrid (`SSMStateCache`)** | Mamba / GatedDeltaNet (Qwen 3.5 / Nemotron-H / Jamba) | n/a | Stores conv + recurrent state instead of K/V. Composes with attention layers via `CacheList`. | | **Batched (`BatchedKVCache` / `BatchedHybridCache`)** | Multi-stream decode (speculative, B>1 serving) | linear in B | Slot-based admission for fixed-size batches. | For configuration shapes (Qwen 3.5 / Nemotron-H boundary-layer skip, GPT-OSS sinks gate, etc.) see [models.md](models.md). -## What's shipped recently +## Choosing a configuration -- **Spec 020 — `SSMStateCache: StateReplayCache`** (shipped 2026-05-11). Hybrid models (Qwen 3.5 / 3.6 GDN+attention) now support speculative-decode rollback. `SSMStateCache` conforms to `StateReplayCache`, exposing `beginRecord` / `recordStep` / `commitFull` / `rollback(acceptedPrefix:)` / `cancel`. Native Metal kernels (`gated_delta_step_record` / `state_replay`) replace the legacy snapshot/restore pair on the speculative path. **Mamba opt-out**: per-cache `canStateReplay` defaults `true` for GDN; Mamba-using factories (NemotronH, Jamba) set it `false` and the speculative router falls back to vanilla `TokenIterator`. See [speculative-decoding.md](speculative-decoding.md#hybrid-model-coverage-spec-020). -- **Spec 017 — Cross-request prefix KV cache** (shipped 2026-05-12 as **opt-in for v1**). Snapshot the cache at request end keyed on a stable token prefix; hydrate at the next request's start. Per-class `serialise()` / `hydrate(from:)` for `StandardKVCache` (unbounded + windowed, refuses wrapped windowed buffers), `AffineQuantizedKVCache`, `TurboQuantizedKVCache` (**raw mode only — compressed-mode round-trip tracked in [#197](https://github.com/ekryski/mlx-swift-lm/issues/197)**), `SSMStateCache` (via spec 020 state-replay path). Defence-in-depth `quantisationKindMismatch` guard prevents hydrating across quantisation boundaries. **Opt in** via `GenerateParameters.prefixCacheEnabled = true` or env `MLX_PREFIX_CACHE=1`. When enabled, the default policy is **auto-resolved per model family** via `AssistantOpener.detect(forModelID:)`: Qwen (1.x–3.6, QwQ) → ChatML opener; Gemma (1/2/3/4) → `model\n`; GPT-OSS → harmony; unknown families fall back to `IdentityPolicy`. `prefixCacheModelID` auto-resolves from `ModelContext.configuration.name`. Phase 4 disk persistence at `~/.cache/mlx-swift-lm/prefix/` is strictly opt-in (`prefixCacheDiskEnabled` / `MLX_PREFIX_CACHE_DISK=1`). Measured **2-10× TTFT** on multi-turn chat. Default-on flip is gated on [#197](https://github.com/ekryski/mlx-swift-lm/issues/197) (TurboQuant compressed-mode round-trip) and [#196](https://github.com/ekryski/mlx-swift-lm/issues/196) (Gemma 4 26B/31B lookup miss) — both surfaced under `--kv turbo4v2`. See [generate-parameters.md](generate-parameters.md#cross-request-prefix-kv-cache-spec-017) for full opt-in + limitations. +```swift +let parameters = GenerateParameters( + temperature: 0.6, + maxTokens: 1024, + compressionAlgorithm: .turbo(keyBits: 4, valueBits: 2) // "turbo4v2" +) +``` -## What's coming +The `compressionAlgorithm` field accepts: -Tracked in [`specs/IMPLEMENTATION-PLAN.md`](../specs/IMPLEMENTATION-PLAN.md): +- `.none` — `StandardKVCache` (default). +- `.affine(bits: Int, groupSize: Int = 64)` — `AffineQuantizedKVCache`. +- `.turbo(keyBits: Int, valueBits: Int)` — `TurboQuantizedKVCache`. Allowed + pairs: `(8,8)`, `(6,6)`, `(4,4)`, `(4,3)`, `(4,2)`. The `(keyBits, + valueBits)` shape captures the "turbo" trade-off — keys are typically more + compressible than values. -- **Spec 024 — KV-cache write fusion.** Eliminates ~60 `copy_bfloat16` dispatches per decode token on Gemma 4 E2B by fusing the per-layer K/V append into one Metal kernel. Tier 4 follow-up. -- **Spec 027 — adaptive per-layer mixed-precision KV.** Per-layer bit budget driven by an offline calibration pass (most PPL-sensitive layers at higher precision). -- **Spec 038 — Active KV cache SSD offload.** InfiniGen-style mid-generation page-out of cold pages to SSD. Disjoint from spec 017's *cross-request* disk cache; this is *single-request* memory overflow for long-context workloads on memory-constrained Macs. Tier 4, blocked on paged KV + DuoAttention. -- **Issue [#117](https://github.com/ekryski/mlx-swift-lm/issues/117) — RMSNorm + GEMV fusion.** Folds the q/k norm into the attention GEMV when the storage is quantized. Precondition for a unified `Attention` consolidation across families. +You can also pass a string (`"turbo4v2"`, `"affine4"`, `"none"`) via the +parser: + +```swift +let parameters = GenerateParameters(compressionAlgorithm: .init("turbo4v2")) +``` ## How models use the KV cache @@ -60,16 +72,33 @@ let stream = try generate( Or omit `cache:` and let `generate(...)` build one from the parameters internally — the same `model.newCache(parameters:)` call site. -For multi-turn / prefix-cache reuse, keep the cache around across calls; -`StandardKVCache` and `AffineQuantizedKVCache` are trimmable with -`trimPromptCache(cache, numTokens:)`. `TurboQuantizedKVCache` and -rotating `StandardKVCache` (whose buffer has wrapped past `maxSize`) are -not (they don't preserve a clean tail). - -For hybrid models (Qwen 3.5 / 3.6 GDN+attention), `SSMStateCache` is -not trimmable in the positional sense but supports **state-replay -rollback** for speculative decoding — see `canRollbackPromptCache(_:)` -in `Libraries/MLXLMCommon/StateReplayCache.swift` and +For multi-turn / prefix-cache reuse, keep the cache around across calls. +All three single-stream cache classes are trimmable via +`trimPromptCache(cache, numTokens:)`: + +- `StandardKVCache` — trimmable in `.unbounded` mode; in `.window(maxSize)` + mode, trimmable only while `offset < maxSize` (i.e., before the rotating + buffer has wrapped — after wrap, the physical tail no longer corresponds + to the logical tail). +- `AffineQuantizedKVCache` — trimmable. Both unbounded and rotating + variants (the spec 041 phase 1.2 rotating-window cache shipped in this + PR). +- `TurboQuantizedKVCache` — trimmable. Same wrap-time caveat as + `StandardKVCache` applies to the rotating variant; trim adjusts the + absolute `offset` but does not re-slice the packed K/V buffer. + +For **cross-request** prefix-cache snapshot/hydrate the picture is +narrower — `PrefixKVCache.snapshot()` currently round-trips +`TurboQuantizedKVCache` in raw mode only ([#197](https://github.com/ekryski/mlx-swift-lm/issues/197); +compressed-domain round-trip is spec 039 follow-up). That's separate +from in-cache `trim(_:)`, which works on the compressed buffer directly. + +For hybrid models — Qwen 3.5 / 3.6 (GDN+attention) and Mamba / Mamba 2 +families (NemotronH, GraniteMoeHybrid, FalconH1; Jamba partial) — +`SSMStateCache` is not trimmable in the positional sense but supports +**state-replay rollback** for speculative decoding via specs 020 (GDN) +and 040 (Mamba). See `canRollbackPromptCache(_:)` in +`Libraries/MLXLMCommon/StateReplayCache.swift` and [speculative-decoding.md](speculative-decoding.md#hybrid-model-coverage-spec-020). For **cross-request prefix caching** (different `generate(...)` calls @@ -81,43 +110,59 @@ let the runtime snapshot / hydrate transparently. See ## Concrete classes All implementations conform to the `KVCache` protocol. The factory -`makeAttentionCache(parameters:maxSize:keep:)` is the preferred way to -instantiate one — it parses `GenerateParameters.compressionAlgorithm` and -returns the right concrete type. +`makeAttentionCache(parameters:slidingWindow:keep:prefillStep:forceRawKV:useBias:)` +is the preferred way to instantiate one — it parses +`GenerateParameters.compressionAlgorithm` and returns the right concrete type. | Class | When to use it | |---|---| | `StandardKVCache` | Default. Uncompressed fp16 K / V. Supports unbounded growth or windowed eviction (rotating buffer). | -| `AffineQuantizedKVCache` | Affine 4 / 6 / 8-bit K and V (per-row scale + zero point). Reduces KV memory ~3.5× at 4-bit; modest decode-tok/s tax. **Note:** sliding-window attention layers and KV-sharing donor layers (Gemma 4 family: E2B, E4B, 26B-A4B, 31B; plus Gemma 3, Gemma 3n, Mistral 3, Mistral Small, etc.) automatically fall back to `StandardKVCache` under `.affine(...)`. Affine compression on those specific layers is lost; the rest of the model still compresses. Tracked in [#202](https://github.com/ekryski/mlx-swift-lm/issues/202); proper fix is spec 041 Phase 5 (flash quantised SDPA → shared readers consume the donor's quantised tuple directly). | -| `TurboQuantizedKVCache` | Block-wise quantization with separate key / value bit budgets (e.g. 4-bit K, 2-bit V — `turbo4v2`). Best memory ratio of the shipped algorithms. Two attention paths inside (compressed-attention "B" path is the default; raw fp16 working buffer "A" path opt-in). See the [batched-decoding](batched-decoding.md) deployment-shape table for memory / quality tradeoffs. | +| `AffineQuantizedKVCache` | Affine 4 / 6 / 8-bit K and V (per-row scale + zero point). Reduces KV memory ~3.5× at 4-bit; modest decode-tok/s tax. Supports rotating eviction via the optional `maxSize` constructor parameter — engaged automatically by `makeAttentionCache(...)` when either an architectural `slidingWindow` or the user's `parameters.maxKVSize` is set. Sliding-window layers (Gemma 4 local, GPT-OSS sliding, Mistral 3 sliding, etc.) and KV-shared donor layers (Gemma 4 LLM + VLM, Gemma 3n) now retain affine compression end-to-end (closed [#202](https://github.com/ekryski/mlx-swift-lm/issues/202) via spec 041 phase 1.2 + phase 5). | +| `TurboQuantizedKVCache` | Block-wise MSE codec with separate key / value bit budgets (e.g. 4-bit K, 2-bit V — `turbo4v2`). Best memory ratio of the shipped algorithms. Decode runs the TurboFlash compressed-domain Metal kernel by default (A path) — scores directly against packed K/V with no FP16 working buffer; opt into the dequant-then-SDPA path (B) via `TURBO_DEQUANT_SDPA=1` for matmul-engine performance at the cost of a per-layer FP16 K/V working buffer. See the [batched-decoding](batched-decoding.md) deployment-shape table for memory / quality tradeoffs. | | `BatchedKVCache` | One cache shared across N concurrent decode streams. Used by speculative decoding and multi-request servers. | | `SSMStateCache` | Hybrid models (Qwen 3.5, Nemotron-H, Jamba). Stores conv + recurrent state for the SSM / GatedDeltaNet blocks. Inherits `ArraysCache.innerState()` so the same prefill-sync barrier covers it. | -## Choosing a configuration +## Capping KV Cache Size + +End users pass `maxKVSize` via `GenerateParameters` — they do not call +`makeAttentionCache(...)` directly. The factory is invoked internally by each +model's `newCache(parameters:)`. ```swift -let parameters = GenerateParameters( - temperature: 0.6, - maxTokens: 1024, - compressionAlgorithm: .turbo(keyBits: 4, valueBits: 2) // "turbo4v2" +let params = GenerateParameters( + maxKVSize: 8192, + compressionAlgorithm: .affine(bits: 4, groupSize: 64) +) + +let stream = try generate( + input: lmInput, + parameters: params, + context: context ) ``` -The `compressionAlgorithm` field accepts: +| `compressionAlgorithm` | What `makeAttentionCache` returns | Behaviour | +|---|---|---| +| `.none` (default) | `StandardKVCache(maxSize: 8192, keep: 4)` | Rotating eviction at 8K, fp16 K/V. | +| `.affine(bits: 4, groupSize: 64)` | `AffineQuantizedKVCache(maxSize: 8192)` | Rotating eviction at 8K + ~3.5× affine compression. | +| `.turbo(keyBits: 4, valueBits: 2)` | `TurboQuantizedKVCache(maxSize: 8192)` | Rotating eviction at 8K + ~6-8× TurboQuant compression. | -- `.none` — `StandardKVCache` (default). -- `.affine(bits: Int, groupSize: Int = 64)` — `AffineQuantizedKVCache`. -- `.turbo(keyBits: Int, valueBits: Int)` — `TurboQuantizedKVCache`. Allowed - pairs: `(8,8)`, `(6,6)`, `(4,4)`, `(4,3)`, `(4,2)`. The `(keyBits, - valueBits)` shape captures the "turbo" trade-off — keys are typically more - compressible than values. +> ⚠️ **Note:** When the user omits `maxKVSize` and the model has no architectural sliding- +window layers, all three schemes return their **unbounded** variants. -You can also pass a string (`"turbo4v2"`, `"affine4"`, `"none"`) via the -parser: +## KV Cache Eviction -```swift -let parameters = GenerateParameters(compressionAlgorithm: .init("turbo4v2")) -``` +**Two distinct caps drive rotating eviction**, both honored uniformly across +every compression scheme: + +| Source | Where it comes from | Behaviour | +|---|---|---| +| **Architectural** (`slidingWindow: Int?`) | Per-layer flag from the model factory — set when the layer's attention path **must** attend over only the last N tokens (Gemma 4 local layers, GPT-OSS sliding layers, Mistral 3 sliding layers, etc.). | When non-nil: rotating eviction at this cap. Non-negotiable — the model architecture demands it. | +| **User budget** (`parameters?.maxKVSize`) | Read internally from the parameters tuple — the `GenerateParameters.maxKVSize` field. | When the layer is **not** architecturally sliding and `maxKVSize` is set: rotating eviction at the user's cap. Honored uniformly across `.none`, `.affine`, and `.turbo`. | + +Precedence when both are set: `slidingWindow` wins. The architectural cap is +non-negotiable — the user cannot make a sliding-window layer attend over more +tokens than the architecture allows. ## Compatibility per architecture @@ -128,7 +173,7 @@ for the gate. | Model | Notes | |---|---| -| GPT-OSS-20B + `turbo4v2` | Falls back to no-quant. Sinks-bearing attention loses Harmony channel-marker fidelity at value-bits=2. Tracked in [#171](https://github.com/ekryski/mlx-swift-lm/issues/171). | +| GPT-OSS-20B + `turbo*` | Coherent — `GPTOSSModel.newCache(...)` enables DC-bias correction on full-attention turbo caches and routes sliding-window layers to raw-FP16 `StandardKVCache`. Bias correction currently requires the B (dequant-SDPA) path, so GPT-OSS with `--kv turbo*` runs the B path regardless of `TURBO_DEQUANT_SDPA`. Closes [#171](https://github.com/ekryski/mlx-swift-lm/issues/171) / [#130](https://github.com/ekryski/mlx-swift-lm/issues/130). | | All others | Affine + turbo work. See [models.md](models.md) for per-model gaps. | ## Bench-time vs library-time @@ -157,10 +202,12 @@ Behaviour knobs on the cache classes themselves: | Flag | Default | Notes | |---|---|---| -| `TurboQuantizedKVCache.useCompressedAttention` | `true` | **B path is the default as of [`c5ca7a3`](https://github.com/ekryski/mlx-swift-lm/commit/c5ca7a3).** Decode runs the fused bulk-dequant Metal kernel + `MLXFast.scaledDotProductAttention` on the compressed cache — within ~3 % of `--kv none` on Qwen 9B and faster than `--kv none` at short context. Set the constructor flag to `false` (or use `TURBO_COMPRESSED_ATTENTION=0`) for the historic A path that keeps a raw-fp16 cache. | -| `AffineQuantizedKVCache.sdpaStrategy` | `.auto` | SDPA path selector (spec 041 phases 1+2+4). **`.auto`**: flash for L>1 (prefill) — no `[B, H, L, T]` score-tensor materialisation; discrete for L=1 (decode) — small score matrix, avoids per-step K/V dequant. **`.flash`**: force flash everywhere; wins on small-model long-context shapes where score materialisation dominates. **`.discrete`**: force discrete everywhere; regression-check / legacy materialise-scores path. Set via the `sdpaStrategy:` constructor parameter: `AffineQuantizedKVCache(bits: 4, sdpaStrategy: .flash)`. Env var `MLX_AFFINE_SDPA={auto,flash,discrete}` overrides this globally when set. | +| `TurboQuantizedKVCache.useDequantSDPA` | `false` | Decode-time attention path selector. **Default (A path)**: TurboFlash. The compressed-domain Metal kernel scores directly against packed K/V; no per-layer FP16 K/V materialisation. **Opt-in (B path, `true`)**: `bulkDequantRotated` builds a transient FP16 K/V tensor per decode step → `MLXFast.scaledDotProductAttention`. Trades a per-layer FP16 working buffer (`B*nKV*T*D*2` bytes per step) for matmul-engine throughput. Env override: `TURBO_DEQUANT_SDPA=1` forces on globally, `=0` forces off. | +| `AffineQuantizedKVCache.sdpaStrategy` | `.auto` | SDPA path selector (spec 041 phases 1+2+4). **`.auto`**: flash for L>1 (prefill) — no `[B, H, L, T]` score-tensor materialisation; discrete for L=1 (decode) — small score matrix, avoids per-step K/V dequant; sliding-window mask always picks flash (MLXFast's native sliding kernel is faster than the discrete augmented-softmax fold). **`.kernel`**: the spec 041 phase 1.1 fused Metal kernel (`fusedFlashQuantizedSDPA`) — correct but unoptimised, opt-in for kernel validation; perf parity tracked in spec 042 Phase 1b. **`.flash`**: force flash everywhere; wins on small-model long-context shapes where score materialisation dominates. **`.discrete`**: force discrete everywhere; regression-check / legacy materialise-scores path. Set via the `sdpaStrategy:` constructor parameter: `AffineQuantizedKVCache(bits: 4, sdpaStrategy: .flash)`. Env var `MLX_AFFINE_SDPA={auto,kernel,flash,discrete}` overrides this globally when set. | +| `TurboQuantizedKVCache.useBias` | `false` (per-model override) | **Per-vector DC-bias correction.** Captures the mean offset the zero-mean Lloyd-Max codebook can't represent — the dominant codec-error source on K/V from `RMSNorm → Linear(bias=True)`. Storage: one fp32 per token-head alongside `norms` (negligible vs packed indices). When enabled, the cache forces the B path because TurboFlash kernels don't yet consume the stored bias term. **Default off** for general use; **default on** for GPT-OSS-20B under `--kv turbo*` (see `Libraries/MLXLLM/Models/GPTOSS.swift`'s `newCache(...)`). Env override: `TURBO_BIAS=1`/`=0`. | | `BatchedKVCache.maxBatch` | constructor arg | Max simultaneous decode streams sharing one cache. Must match the request shape. | -| `StandardKVCache.reserve(_:)` | not called | **Opt-in workload-size hint** for windowed eviction. Pre-allocates the rotating buffer to a known size up front (typically `prompt_length + maxTokens`) instead of growing in `step`-sized chunks (default `step=256`). Idempotent: only takes effect before the first write. Clamped to `maxCacheSize`, floored at `step`. No-op when eviction is `.unbounded`.
`let cache = StandardKVCache(maxSize: 4096); cache.reserve(promptLen + maxTokens)`. | +| `StandardKVCache.reserve(_:)` | not called | **Opt-in workload-size hint** for windowed eviction. Pre-allocates the rotating buffer to a known size up front (typically `prompt_length + maxTokens`) instead of growing in `step`-sized chunks. Idempotent: only takes effect before the first write. Clamped to `maxCacheSize`, floored at `step`. No-op when eviction is `.unbounded`.
`let cache = StandardKVCache(maxSize: 4096); cache.reserve(promptLen + maxTokens)`. | +| Cache `step` (growth chunk) | model's `defaultPrefillStepSize` (1024 for most LLMs); falls back to `256` | The buffer grows in `step`-sized chunks per `concatenated(...)`. `makeAttentionCache(...)` threads `parameters.prefillStepSize ?? prefillStep ?? 256` uniformly into the `step:` constructor parameter of **all three** cache classes (`StandardKVCache`, `AffineQuantizedKVCache`, `TurboQuantizedKVCache`), so the per-class grow-chunk matches the model's prefill chunk 1:1 — collapsing growth events instead of paying `chunkSize/256`× the realloc cost. Override globally with `GenerateParameters.prefillStepSize`. | Programmatic single-cache construction: `makeKVCache(scheme: .turbo(keyBits: 4, valueBits: 2), eviction: .unbounded)` — @@ -175,8 +222,8 @@ an inference process; read once at first use and cached. | Variable | Effect | |---|---| -| `TURBO_COMPRESSED_ATTENTION=0` | Force the raw-fp16 working buffer "A" path globally. `=1` forces the compressed "B" path. Unset honours the constructor (B by default). The A path is faster but bloats memory; the B path is more true to the Turbo compression algorithm because the compressed KV cache is accessed by either a custom fused Dequant + SDPA Metal kernel (default) or the TurboFlash kernel. **Trade-off: memory savings vs. speed.** | -| `TURBO_DEQUANT_SDPA=0` | Disable the fused-dequant + matrix-engine SDPA path; fall back to TurboFlash. Useful when sweeping very long contexts where TurboFlash's per-token bit-unpack still wins (≥ 24k on Qwen 9B / Nemotron-class). | +| `TURBO_DEQUANT_SDPA=1` / `=0` | Decode-time attention path selector for `TurboQuantizedKVCache` (`useDequantSDPA` row above). `=1` forces the B path (dequant K/V to FP16 → MLXFast SDPA — adds a per-layer FP16 working buffer per decode step) globally; `=0` forces the A path (TurboFlash compressed-domain — no FP16 materialisation); unset honours the constructor. | +| `TURBO_BIAS=1` / `=0` | Per-vector DC-bias correction in the MSE codec (`useBias` row above). When enabled, the cache forces the B path because TurboFlash kernels don't yet consume the stored bias term. Default-on for GPT-OSS-20B under `--kv turbo*`; default-off elsewhere. | | `TURBO_DEQUANT_JIT=1` | Force the JIT'd `MLXFast.metalKernel` bulk-dequant path instead of the precompiled `MLXFast.turboBulkDequantRotated`. Use for A/B comparison when iterating on the dequant kernel itself. | | `TURBO_FLASH_BLOCK_SIZE=N` | Pin TurboFlash pass1's kernel block size (override the adaptive `tokenCount/32` heuristic). Powers of two only. | | `TURBO_FLASH_NR0=N` | Number of query rows handled per SIMD group in the first pass of TurboFlash decode. Default `2`; `1` falls back to single-row first pass. | @@ -189,6 +236,21 @@ For wired-memory env vars (`MLX_MEMORY_LIMIT`, `MLX_SMART_MEMORY`) see env vars (`GEMMA4_FUSED_NORM_ROPE`, `MLX_COMPILE_SHARED_MLP`, `GDN_EVAL_INTERVAL`) see [generate-parameters.md](generate-parameters.md). +## What's shipped recently + +- **Spec 020 — `SSMStateCache: StateReplayCache`** (shipped 2026-05-11). GatedDeltaNet families (Qwen 3.5 / 3.6 GDN+attention) gained speculative-decode rollback. `SSMStateCache` conforms to `StateReplayCache`, exposing `beginRecord` / `recordStep` / `commitFull` / `rollback(acceptedPrefix:)` / `cancel`. Native Metal kernels (`gated_delta_step_record` / `state_replay`) replace the legacy snapshot/restore pair on the speculative path. See [speculative-decoding.md](speculative-decoding.md#hybrid-model-coverage-spec-020). +- **Spec 040 — Mamba / Mamba 2 state-replay** (shipped 2026-05-14). Extended the spec 020 infrastructure to the Mamba recurrence via new `ssm_step_record` / `ssm_replay` Metal kernels. `NemotronH` (Mamba 2), `GraniteMoeHybrid` (Mamba 2), and `FalconH1` (Mamba 2) are integrated end-to-end — `cache.isRecording` routes through `ssmStepRecord`; partial-accept rollback restores both the recurrent state and the depthwise-conv buffer (per-step `mambaConvPadded` capture). Jamba's cache exposes `canStateReplay = true` but its mamba-mixer forward path does not yet wire the recording branch — a mechanical follow-up tracked in [spec 040 known limitations](../specs/040-mamba-state-replay.md). +- **Spec 017 — Cross-request prefix KV cache** (shipped 2026-05-12 as **opt-in for v1**). Snapshot the cache at request end keyed on a stable token prefix; hydrate at the next request's start. Per-class `serialise()` / `hydrate(from:)` for `StandardKVCache` (unbounded + windowed, refuses wrapped windowed buffers), `AffineQuantizedKVCache`, `TurboQuantizedKVCache` (**raw mode only — compressed-mode round-trip tracked in [#197](https://github.com/ekryski/mlx-swift-lm/issues/197)**), `SSMStateCache` (via spec 020 state-replay path). Defence-in-depth `quantisationKindMismatch` guard prevents hydrating across quantisation boundaries. **Opt in** via `GenerateParameters.prefixCacheEnabled = true` or env `MLX_PREFIX_CACHE=1`. When enabled, the default policy is **auto-resolved per model family** via `AssistantOpener.detect(forModelID:)`: Qwen (1.x–3.6, QwQ) → ChatML opener; Gemma (1/2/3/4) → `model\n`; GPT-OSS → harmony; unknown families fall back to `IdentityPolicy`. `prefixCacheModelID` auto-resolves from `ModelContext.configuration.name`. Phase 4 disk persistence at `~/.cache/mlx-swift-lm/prefix/` is strictly opt-in (`prefixCacheDiskEnabled` / `MLX_PREFIX_CACHE_DISK=1`). Measured **2-10× TTFT** on multi-turn chat. Default-on flip is gated on [#197](https://github.com/ekryski/mlx-swift-lm/issues/197) (TurboQuant compressed-mode round-trip) and [#196](https://github.com/ekryski/mlx-swift-lm/issues/196) (Gemma 4 26B/31B lookup miss) — both surfaced under `--kv turbo4v2`. See [generate-parameters.md](generate-parameters.md#cross-request-prefix-kv-cache-spec-017) for full opt-in + limitations. + +## What's coming + +Tracked in [`specs/IMPLEMENTATION-PLAN.md`](../specs/IMPLEMENTATION-PLAN.md): + +- **Spec 024 — KV-cache write fusion.** Eliminates ~60 `copy_bfloat16` dispatches per decode token on Gemma 4 E2B by fusing the per-layer K/V append into one Metal kernel. Tier 4 follow-up. +- **Spec 027 — adaptive per-layer mixed-precision KV.** Per-layer bit budget driven by an offline calibration pass (most PPL-sensitive layers at higher precision). +- **Spec 038 — Active KV cache SSD offload.** InfiniGen-style mid-generation page-out of cold pages to SSD. Disjoint from spec 017's *cross-request* disk cache; this is *single-request* memory overflow for long-context workloads on memory-constrained Macs. Tier 4, blocked on paged KV + DuoAttention. +- **Issue [#117](https://github.com/ekryski/mlx-swift-lm/issues/117) — RMSNorm + GEMV fusion.** Folds the q/k norm into the attention GEMV when the storage is quantized. Precondition for a unified `Attention` consolidation across families. + ## See also - [`GenerateParameters` reference](generate-parameters.md) — the full diff --git a/documentation/models.md b/documentation/models.md index 1a2c4e8134..1a1ac800d1 100644 --- a/documentation/models.md +++ b/documentation/models.md @@ -95,7 +95,7 @@ These are documented current behavioural gaps. File new ones as GitHub issues. | Model / config | Issue | Status | |---|---|---| | `mlx-community/gemma-3-4b-it-qat-4bit` | [#170](https://github.com/ekryski/mlx-swift-lm/issues/170) — single-token loop on Gemma 3 4B QAT 4-bit | Open. Suspected: weight-sanitization fallback hardcodes `(64, 4, .affine)` when `quantization_config` missing in the JSON. Workaround: use the bf16 / 8bit variants. | -| `gpt-oss-20b` + `--kv turbo4v2` | [#171](https://github.com/ekryski/mlx-swift-lm/issues/171) — non-Harmony output on GPT-OSS-20B with TurboQuant value-bits=2 | Closed by default-guard. `supportsTurboQuantization: false` on `GPTOSS.swift` makes `--kv turbo4v2` silently fall back to no-quant. Path-A diagnosis (why the dequant working-buffer path fails on this model) is the open follow-up. | +| `gpt-oss-20b` + `--kv turbo*` | [#171](https://github.com/ekryski/mlx-swift-lm/issues/171) — non-Harmony / degenerate output on GPT-OSS-20B with TurboQuant | **Mitigated** by spec 041 phase 1.1 follow-up: `GPTOSSModel.newCache(...)` enables `useBias: true` on full-attention `TurboQuantizedKVCache`s and routes sliding-window layers to raw-FP16 `StandardKVCache`. Per-vector DC-bias correction recovers the structured mean lost by the zero-mean Lloyd-Max codebook (K/V projections have `bias=True` → structured DC offset). Override via `TURBO_BIAS=0` env var for A/B testing. Coherence verified at 1k + 8k summarization across `turbo4`, `turbo4v2`, `turbo8v4`. | | `gemma-4-*-VL` + `temp > 0` | [#169](https://github.com/ekryski/mlx-swift-lm/issues/169) — `` flood / `ThisThis` duplicate on Gemma 4 VLM | Closed. Hard `eval(cache + logits)` barrier in `Gemma4.prepare` flushes the prefill K/V writes before the iterator's first decode forward. | | `mlx-community/Qwen3.5-27B-4bit` (vision) | [#181](https://github.com/ekryski/mlx-swift-lm/issues/181) — token-loop on vision input | Closed by [PR #180](https://github.com/ekryski/mlx-swift-lm/pull/180). Same prefill-sync race; the barrier covers both attention K/V and `SSMStateCache` state arrays via `innerState()`. | | DeepSeek V4 | (no issue yet) | Phase-1 approximate math — see file header in `Libraries/MLXLLM/Models/DeepseekV4.swift`. Outputs are coherent; numerics tracked separately. | diff --git a/specs/IMPLEMENTATION-PLAN.md b/specs/IMPLEMENTATION-PLAN.md index a8451103a3..1c0f54d14b 100644 --- a/specs/IMPLEMENTATION-PLAN.md +++ b/specs/IMPLEMENTATION-PLAN.md @@ -1,6 +1,6 @@ # Implementation plan — speculative decoding rollout -**Last updated:** 2026-05-12 +**Last updated:** 2026-05-13 **Owner:** Eric (with research help from Claude) This is the running implementation order across [specs 013–040](.) plus the forked [`ekryski/CoreML-LLM`](https://github.com/ekryski/CoreML-LLM) integration. Items in earlier tiers should ship before items in later tiers because of measurement dependencies, code dependencies, or risk-management ordering — not because later items are less important. @@ -46,7 +46,7 @@ These benefit every decoder family and unlock measurable wins on already-support | 6 | **017 — prefix KV cache** | Snapshot target KV state at request end keyed on stable prefix; hydrate on next request with the same prefix. All five phases consolidated: Phase 1 (`PrefixKVCache` + `PrefixKey` + LRU + stats), Phase 1B (per-class `serialise()` / `hydrate(from:)` + `generate()` wiring with stream wrapper + defence-in-depth `quantisationKindMismatch` guard), Phase 2 (`LastAssistantOpenerPolicy` for Qwen / Gemma 4 / GPT-OSS), Phase 3 (hybrid GDN+attention via spec 020 state-replay — `SSMStateCache` snapshots), Phase 4 (opt-in disk persistence at `~/.cache/mlx-swift-lm/prefix/`, off by default), Phase 5 (Option A: snapshot post-prefill, before decode wraps anything — fixes #185 / #196 / #197 + spec 017 §5 SSM stale + restores warm-turn hits on Gemma 4 26B/31B at `prompt_len == sliding_window`). **Opt-in for v1** (`prefixCacheEnabled = false` default). When the caller opts in, `prefixCachePolicy` auto-resolves via `AssistantOpener.detect(forModelID:)` → `LastAssistantOpenerPolicy` for Qwen / Gemma / GPT-OSS families (Identity fallback), and `prefixCacheModelID` auto-resolves from `ModelContext.configuration.name`. Cross-session sharing via `BlockAllocator.retain()` tracked in [#133](https://github.com/ekryski/mlx-swift-lm/issues/133). Compressed-domain snapshots (~4× smaller) move to spec 039 (row 6a). | **Measured 2026-05-12 (M1 Max 64GB, `--method summarization --kv turbo4v2 --cache-prefix`, Option A post-prefill snapshot):** Qwen3.5-0.8B 32K cold 18.9s → warm 322 ms (**59×** TTFT). Qwen3.5-0.8B 1K cold 459ms → warm 222ms (**2.1×**). Gemma 4 26B-A4B / 31B coherent multi-turn with `hits=1 prefillTokensSaved=34`. GPT-OSS-20B still no benefit on the Path A fallback (window=128 wrap during prefill — `serialiseStandard` correctly refuses; spec 039 doesn't fix this either since it's a wrap issue, not a compression issue). | ✅ Shipped 2026-05-12 ([PR #144](https://github.com/ekryski/mlx-swift-lm/pull/144) + close-out [PR #198](https://github.com/ekryski/mlx-swift-lm/pull/198)). Closes issues [#185](https://github.com/ekryski/mlx-swift-lm/issues/185) / [#196](https://github.com/ekryski/mlx-swift-lm/issues/196) / [#197](https://github.com/ekryski/mlx-swift-lm/issues/197). | | 6a | **039 — compressed-domain prefix KV cache** | Snapshot KV in TurboQuant compressed form (~4× smaller bytes via `valueBits=2` packed indices + norms) and hydrate back into compressed buffers without going through FP16. Reuses spec 017 phase 5's post-prefill hook, `TurboQuantizedKVCache.fusedEncodeDispatch` for the snapshot-time batch encode, and `compressedAttention(L>1)` for the warm suffix prefill (the L>1 path already exists; today's dispatcher in `AttentionUtils.attentionWithCacheUpdate` just routes it to the raw path). Lossless (compressed-bytes round-trip — no compress / dequant cycle on the warm path) and zero new Metal kernels — purely a re-route of existing primitives. Bumps `PrefixKey.formatVersion` 2 → 3 (L2 disk-cache migration). | **~3.4× smaller snapshot bytes** at the same `--kv turbo4v2` precision: Qwen3.5-35B-A3B 32K snapshot drops ~1.65 GB → ~485 MB; Gemma 4 26B-A4B 4K drops ~440 MB → ~130 MB. At the default 8 GB L1 budget this is 3.4× more cached prefixes resident → fewer LRU evictions on extended multi-session workloads. **Warm-turn TTFT:** estimated 50–200 ms faster (no FP16-load + first-decode-compression). **Decode tok/s:** unchanged (compressed-domain decode is the same post-hydrate). | 📋 Spec written 2026-05-12 ([`039-compressed-prefix-kv-cache.md`](039-compressed-prefix-kv-cache.md)). Not started. Phase 1 + 2 are the load-bearing pieces; phase 3 is just a format-version bump. | | 6b | **040 — Mamba / Mamba 2 state-replay rollback** | Native `ssm_step_record` + `ssm_replay` Metal kernel pair, parallel to spec 020's shipped `gated_delta_step_record` / `state_replay` chain (spec 040 picks option 1 of spec 020's three follow-up options — preferred over sequential fallback or `ssmAttn` augmentation). Same 4-repo PR chain shape: mlx kernel + C++ Primitive → mlx-c bridge → mlx-swift Swift wrapper → mlx-swift-lm cache wiring. Flips `canStateReplay` from `false` → `true` on `NemotronH.swift` + `Jamba.swift` SSM cache slots; `canRollbackPromptCache` lights up; n-gram speculative + prefix-cache (spec 017) + spec 039 compressed prefix + future spec 015 DFlash all start working on Mamba families with no extra change. | Unblocks n-gram + prefix-cache + DFlash for **Nemotron Cascade 2 (Mamba)** and **Jamba / Granite-MoE-Hybrid / FalconH1 (Mamba 2)**. Estimated n-gram lift parallel to spec 020 GDN measurements: Nemotron Cascade 2-30B-A3B 4bit at D=12 adapt+strict should land in the **1.4–1.7× baseline** range (similar accept-rate profile to Qwen3.5-35B-A3B at the same model class). Brings the Mamba families to feature parity with GDN. ~1500 LOC across the 4-repo chain (similar scope to spec 020 phases 1–3). | 📋 Spec written 2026-05-12 ([`040-mamba-state-replay.md`](040-mamba-state-replay.md)). Not started. **Promoted to Tier 1 (2026-05-12)** to land alongside row 6a — both close out the "model-family feature parity" gap. | -| 6c | **GPT-OSS-20B attention-sinks on TurboQuant path B** | Four-repo cross-cutting PR chain to make the compressed-domain decode path (`-compact` suffix, `useCompressedAttention=true`) coherent on attention-sinks models. Path B + non-sinks works coherently; path B + sinks is wired but disabled because output is incoherent despite kernel math being right on paper. The cross-repo chain has been OPEN since before spec 020 shipped; main outstanding work is identifying the divergence between path A (coherent) and path B (incoherent) on GPT-OSS-20B with the same sinks tensor (sliding-window + graph-fuser already ruled out). | Brings GPT-OSS-20B to feature parity with Qwen 3.5 / Gemma 4 on the `--kv turbo4v2` path — long-context KV compression on sinks-using models without the path-A-only constraint. Path-B-only optimisation; path A remains the speed default for sinks models. Estimated decode tok/s on path B: 30–60% of path A (compressed-attention sub-phases). Worth it for the user segment that explicitly needs ≥16K context KV compression. **Also fixes one stuck Tier-1 prerequisite for spec 039:** spec 039's L>1 dispatcher branch on hydrated compressed caches currently checks `sinks == nil` and falls through to the raw path on sinks-using models — once this lands, spec 039 covers GPT-OSS-20B too. | 🚧 Four-repo PR chain OPEN: [mlx#16](https://github.com/ekryski/mlx/pull/16) (kernel + C++ primitive — pass2 folds per-head sink logit into cross-block softmax), [mlx-c#8](https://github.com/ekryski/mlx-c/pull/8) (C ABI + 5 missing decls), [mlx-swift#18](https://github.com/ekryski/mlx-swift/pull/18) (Swift wrapper + submodule bumps), [mlx-swift-lm#99](https://github.com/ekryski/mlx-swift-lm/pull/99) (path B CLI surface + sinks routing). Umbrella: [#130](https://github.com/ekryski/mlx-swift-lm/issues/130). **Promoted from Tier 4 (2026-05-12)** to close the "all model families at feature parity" gap alongside rows 6a + 6b. | +| 6c | **GPT-OSS-20B attention-sinks on TurboQuant** | Make `--kv turbo*` coherent on attention-sinks models (GPT-OSS family). The original pass2-sinks-fold approach (mlx#16 / mlx-c#8 / mlx-swift#18 / mlx-swift-lm#99) was abandoned: kernel math was right on paper but the cross-block softmax fusion produced incoherent output. Replaced 2026-05-13 by three orthogonal pieces: (1) a new single-pass **`turbo_flash_sdpa_v`** Metal kernel that does inline dequant + online softmax + sinks fold in one dispatch (sidesteps the pass1/pass2 graph-fusion bug); (2) **DC-bias correction** in the MSE codec (per-vector mean subtraction before WHT — recovers the structured DC offset that K/V from `RMSNorm → Linear(bias=True)` carry, which the zero-mean Lloyd-Max codebook can't represent — 9-22% MSE reduction on this distribution); (3) a **hybrid sliding-FP16 layer policy** for GPT-OSS-20B (sliding-window layers cap at 128 tokens, FP16 is ~1.5 MB across all sliding layers vs the full-attention layers' 8K-token compressed caches — full-attention layers stay on `TurboQuantizedKVCache` with `useBias: true` by default). Plumbing also routes sinks through the dequant-SDPA-with-sinks A path for the L=1 decode case. | GPT-OSS-20B coherent end-to-end on `--kv turbo*` at 1k + 8k summarization (verified with stochastic sampling — both contexts produce proper Harmony channel preamble + content). KV cache: 46 MB at 8K vs ~200 MB FP16 (~4× savings preserved). Decode tok/s: ~50 tok/s at 8K vs ~57 tok/s pre-fix (5-11% bias overhead — fusable into the dequant kernel as a follow-up). | ✅ **Shipped 2026-05-13** via cross-repo chain:
• mlx: [`5c86d7ec`](https://github.com/ekryski/mlx/commit/5c86d7ec) `turbo_flash_sdpa_v` kernel + sinks function constant, [`14728215`](https://github.com/ekryski/mlx/commit/14728215) bit-contiguous unpacking fix, [`78011998`](https://github.com/ekryski/mlx/commit/78011998) `ensure_contiguous` on kernel inputs (kv-head-1+ silent-zero fix), [`283df4cf`](https://github.com/ekryski/mlx/commit/283df4cf) `copy.h` include path
• mlx-swift: [`1886126`](https://github.com/ekryski/mlx-swift/commit/1886126) `MLXFast.turboFlashSDPAv` wrapper + submodule bumps
• mlx-swift-lm (PR [#215](https://github.com/ekryski/mlx-swift-lm/pull/215) chain): [`cf516e3`](https://github.com/ekryski/mlx-swift-lm/commit/cf516e3) routes sinks through `turbo_flash_sdpa_v`, [`db74f37`](https://github.com/ekryski/mlx-swift-lm/commit/db74f37) routes sinks through dequant-SDPA-with-sinks A path, [`afa8cc9`](https://github.com/ekryski/mlx-swift-lm/commit/afa8cc9) DC-bias correction + hybrid sliding-FP16 policy, [`93f191b`](https://github.com/ekryski/mlx-swift-lm/commit/93f191b) defaults `useBias: true` on GPT-OSS turbo caches
• Tests: `testTurboFlashSDPAvSinksSlidingWindow`, `testTurboFlashSDPAvNoSinksMatchesTurboFlashAttention`, `testTurboQuantCompressedAttentionSinksMatchesReference`, `testDualScaleMSEReduction` (MSE-comparison probe that drove the bias-over-dual-scale decision)
• Documentation: [`documentation/kv-cache.md`](../documentation/kv-cache.md) (new `useBias` behaviour-knob row + `TURBO_BIAS` env var), [`documentation/models.md`](../documentation/models.md) (GPT-OSS-20B known-gap row updated)
• **Superseded PRs to close** (replaced by the single-pass kernel + bias approach): mlx#16, mlx-c#8, mlx-swift#18, mlx-swift-lm#99. Umbrella [#130](https://github.com/ekryski/mlx-swift-lm/issues/130).
• Open follow-up: dual-scale codec (empirical 1-8% MSE gain — too small to ship given kernel cost) and model-aware codebook are documented in spec 041 phase 1.1 follow-up notes but not pursued. | ## Tier 2 — compounding optimisations @@ -300,6 +300,7 @@ The plan assumes pass at each measurement gate. Re-evaluate if any of these come - ✅ Spec 030 promoted from Tier 4 to Tier 2 row 10a (MTP / EAGLE-3 draft heads — largest pure-decode win, first in the post-Tier-1 priority order). - ✅ **Tier 1 row #5 — state-replay (spec 020)** shipped 2026-05-11 via [PR #143](https://github.com/ekryski/mlx-swift-lm/pull/143) + cross-repo chain. GDN coverage (Qwen 3.5 / 3.6) live; Mamba opts out for now (kernel variant tracked as future work in spec 020). - ✅ **Tier 1 row #6 — prefix KV cache (spec 017)** all phases consolidated and ready for merge 2026-05-12 via [PR #144](https://github.com/ekryski/mlx-swift-lm/pull/144). Measured ~4.3× TTFT speedup on Qwen3.5-35B-A3B (2186ms → 499ms cold→warm) under realistic 4-turn chat with captured replies; ~2.5× on Qwen3.5-0.8B / Gemma 4 E2B; ~1.5-1.8× on dense Gemma 4 26B-A4B / 31B; GPT-OSS-20B no-benefit (documented limitation). +- ✅ **Tier 1 row #6c — GPT-OSS-20B attention-sinks on TurboQuant** shipped 2026-05-13 via the [PR #215](https://github.com/ekryski/mlx-swift-lm/pull/215) chain. Replaced the abandoned pass2-sinks-fold approach (mlx#16 / mlx-c#8 / mlx-swift#18 / mlx-swift-lm#99 — superseded) with a single-pass `turbo_flash_sdpa_v` Metal kernel + DC-bias correction + hybrid sliding-FP16 policy. GPT-OSS-20B coherent on `--kv turbo*` at 1k + 8k; KV cache ~4× smaller than FP16 at 8K. Closes umbrella [#130](https://github.com/ekryski/mlx-swift-lm/issues/130). - ✅ **Issue [#73](https://github.com/ekryski/mlx-swift-lm/issues/73) closed** — KVCache refactor shipped as spec 006 (PRs #163–#166). - 🔜 Tier 2 phase-1 scaffolds need their phase-2 integration work; runs in parallel with Tier 1. - 🔜 **Post-Tier-1 priority order (the post-hoc spec wave):**