betaFeedback

WorksComputer Science

One Million Tokens in 20GB: Calibration-Free 2-Bit SRFT KV-Cache Compression for Looped MoE Inference on Apple Silicon

Abstract

Long-context inference on unified-memory edge machines is governed by KV-cache capacity and memory bandwidth. On a 32 GB Apple M6 Mac mini (26.8 GB Metal working set, 150 GB/s DRAM), the 26.4B looped Mixture-of-Experts model Inkling-2-Mini (48 logical visits, 1M native context) exhausts memory by 64K tokens in stock oMLX (and by 512K even after fixing its 40 sliding-window visits to bounded ring buffers). We show that three structural properties of modern hybrid NoPE architectures – bounded sliding windows, a 1,024-token banded relative bias whose tail is identically zero, and unit-RMS value normalization – combine with an orthonormal Subsampled Randomized Fourier Transform (SRFT) to enable calibration-free, scale-free 2.000-bit Value and 2.125-bit Key Lloyd-Max compression (2.0625 effective bits/coordinate, 7.76×7.76\times smaller than bf16) on the 8 global visits' far prefix [0,N−1024)[0, N-1024), merged with the exact bf16 local window and learned sink via online log-sum-exp. A custom GQA-packed Metal decode kernel with a 256-entry half4 LUT and Block-8 lazy exp2 rescaling reaches 73.4 GB/s and runs Inkling-2-Mini at 17.09 tok/s at 256K (3.36×3.36\times faster than bf16), 13.81 tok/s at 512K, and 9.52 tok/s at 1,048,576 tokens in 19.49 GiB peak memory (4.37 GiB KV). Across 4×40964\times 4096 WikiText-2 windows, 3.06-bit SRFT is lossless (ΔΔPPL =−0.007= -0.007), 2.56-bit K3/V2 adds +0.024+0.024, and 2.06-bit adds +0.130+0.130 while achieving 100% (3/3) exact 7-digit passkey retrieval at 8K, 16K, and 32K.

Introduction

Open-weight reasoning models have rapidly converged on sparse Mixture-of-Experts (MoE) backbones with 1M-token context windows designed to fit inside 32 GB consumer unified-memory machines. A representative 2026 release is Thinking Machines Lab’s Inkling-2-Mini [1]: 26.4B physical parameters (15.1 GiB in mixed 4/8-bit oQ4e), 24 physical layers whose middle 12 layers loop three times per token (48 logical visits), 5:1 sliding-window (W=1024W = 1024) to global attention (40 sliding, 8 global visits), no rotary position embeddings (NoPE), a 1,024-token banded relative bias, query-dependent attention sinks, and unit-RMS value normalization.

Despite its modest 15.1 GiB weight footprint, running Inkling-2-Mini at long context on a 32 GB Apple M6 Mac mini fails immediately in existing runtimes:

  1. Unbounded sliding caches: Stock oMLX [2] allocates an unbounded KVCache for all 48 visits rather than rotating ring buffers for the 40 sliding visits, consuming 6.05 GiB of KV at 32K and exceeding M6’s 26.8 GiB Metal working set around 64K (1M would require ∼\sim208 GiB).

  1. Global bf16 KV wall: Even after fixing the 40 sliding visits to bounded RotatingKVCache (contributed upstream as oMLX PR #5512), the 8 global visits still require 32 KB/token in bf16—8.2 GiB at 256K (slowing decode to 5.09 tok/s) and 32.2 GiB at 1M (47.3 GiB total, physically impossible on 32 GB).

  1. Bandwidth-losing low-bit paths: Standard MLX and llama.cpp quantized KV paths either materialize dense masks/copies or dequantize per query head under grouped-query attention (GQA), sacrificing decode speed when compressing KV.

This paper demonstrates that exploiting three architectural properties of Inkling-2-Mini alongside an orthonormal Subsampled Randomized Fourier Transform (SRFT) [3] and a custom GQA-packed Metal kernel unlocks fast 1,048,576-token inference in 19.49 GiB at 9.52 tok/s on a 32 GB Apple M6. Our contributions are:

  • Scale-free 2.000-bit Value compression via SRFT: Because Inkling-2 enforces parameter-free unit-RMS normalization on VV, applying an orthonormal SRFT rotates every value vector into an isotropic N(0,1)\mathcal{N}(0,1)-like distribution that requires zero per-vector or per-block scales under scalar Lloyd–Max quantization—yielding 2.0625 effective bits/coordinate (7.76× compression) with zero offline calibration and no wasted 1-bit QJL residual [4].

  • Split banded-bias attention with exact online LSE merge: Splitting each global visit into a quantized far prefix [0,N−1024)[0, N - 1024) (where banded relative bias is identically zero) and an exact bf16 recent window [N−1024,N)[N - 1024, N) plus learned sink eliminates dense O(N)O(N) mask allocation and KV-copy overhead while preserving exact local attention.

  • GQA-packed 2-bit Metal kernel with a 256-entry half4 LUT: Dequantizing 4 coordinates per lane in a single shared-memory table lookup and serving all $r = 3

query heads in registers with Block-8 lazy exp2 rescaling reaches 73.4 GB/s and outperforms both bf16 (3.36× at 256K) and 4-bit q4_0 (2.60× at 1M).

  • Empirical validation: We verify Foff≤0.41F_{\mathrm{off}} \le0.41 bits (benign, no rotary-offset collapse), +0.130 Δ\DeltaPPL at 2.06 bits (−0.007 at 3.06 bits, +0.024 at 2.56 bits), and 100% exact 7-digit passkey retrieval at 8K, 16K, and 32K.

Architecture Analysis and Offset Safety

Inkling-2-Mini uses nq=24n_q = 24 query heads, nkv=8n_{kv} = 8 KV heads (GQA ratio r=3r = 3), head dimension d=128d = 128, and 48 logical layer visits (6 prelude + 3 × 12 looped core + 6 postlude). Every 6-layer block has 5 sliding-window layers (W=1024W = 1024) and 1 global layer (8 global visits total). Unlike RoPE transformers, position is encoded by depthwise short convolutions (width 4) and an additive relative bias rtWrelr_tW_{\mathrm{rel}} of extent R=1024R = 1024, plus a query-dependent sink logit sts_t.

Offset-Fragility Probe (Foff)

Per-token KV quantization collapses on models whose keys carry large constant offsets in slowly rotating RoPE dimensions (e.g., Qwen2.5 kk-bias or Qwen3-small QK-norm gain amplification [5]). Before quantizing Inkling-2-Mini, we measured the one-pass offset-waste statistic Foff=max⁡l,hlog⁡2(1+0.674 ρl,h/3.5)F_{\mathrm{off}} = \max_{l,h} \log_2(1 + 0.674\,\rho_{l,h}/3.5) with ρ=∥μk∥/rms⁡(k−μk)\rho= \lVert\mu_k\rVert/\operatorname{rms}(k - \mu_k) across all 48 logical visits on 2,048 WikiText-2 tokens. Every visit scored Foff∈[0.18,0.41]F_{\mathrm{off}} \in[0.18, 0.41] bits (well below the 1.3-bit benign threshold), because Inkling-2 has no RoPE, no KK bias, L2-clipped Q/KQ/K, and unit-RMS VV. Consequently, rotated per-token KV quantization requires no offset centering.

Why Stock Runtimes Fail at Long Context

Auditing both mlx-vlm and oMLX revealed two compounding inefficiencies:

  1. Per-token KV copy for learned sinks (mlx-vlm): Appending a zero K/V vector via mx.concatenate on every decode token copies the entire KV cache. Passing MLX’s native sinks= argument to scaled_dot_product_attention is bit-exact (0.00e+00 max diff) and 1.85–2.44× faster from 1K to 128K.

  1. Unbounded sliding caches (oMLX): Allocating KVCache() for all 48 visits stores 48 full-length histories instead of 8. Replacing the 40 sliding visits with RotatingKVCache (with +16-token rollback headroom for DSpark speculative verification) cuts 32K KV memory from 6.05 to 1.36 GiB (4.45×) and fixes speculative wrap-around rollback (merged/submitted as oMLX PR #5512).

Scale-Free 2-Bit SRFT Compression and Metal Kernel

Orthonormal SRFT and Scale-Free Unit-RMS Values

For any head vector x∈Rdx \in\mathbb{R}^d, we apply a real orthonormal Subsampled Randomized Fourier Transform:

x~=SRFT⁡(x)=FR(S⊙x),S∈{−1,+1}d,(1)\tilde{x} = \operatorname{SRFT}(x) = \mathcal{F}_{\mathbb{R}}(S \odot x), \qquad S \in\{-1,+1\}^d, \tag*{(1)}

where FR\mathcal{F}_{\mathbb{R}} packs the normalized real FFT outputs [X0/d,Xd/2/d,2/dRe⁡(X1..d/2−1),2/dIm⁡(X1..d/2−1)][X_0/\sqrt{d}, X_{d/2}/\sqrt{d}, \sqrt{2/d}\operatorname{Re}(X_{1..d/2-1}), \sqrt{2/d}\operatorname{Im}(X_{1..d/2-1})]. Because SRFT is strictly orthogonal (⟨SRFT⁡(q),SRFT⁡(k)⟩=⟨q,k⟩\langle\operatorname{SRFT}(q),\operatorname{SRFT}(k)\rangle= \langle q,k\rangle to 1.14×10−51.14 \times10^{-5}), decode attention operates directly in the rotated domain: we transform qq once per query and inverse-transform the single output vector ofaro_{\mathrm{far}} once per global visit, performing zero inverse FFTs over the cached keys or values.

After SRFT, coordinates are near-Gaussian and identically distributed, making scalar unit-Gaussian Lloyd–Max centroids CbC_b near-optimal (at b=2b = 2: C2={−1.5104,−0.4528,+0.4528,+1.5104}C_2 = \{-1.5104,-0.4528,+0.4528,+1.5104\}, MSE =0.1175σ2= 0.1175\sigma^2). Crucially, Inkling-2 applies parameter-free RMS normalization to VV (use_value_norm_no_gamma=True), guaranteeing rms⁡(v~)=rms⁡(v)=1\operatorname{rms}(\tilde{v}) = \operatorname{rms}(v) = 1 identically. Thus VV requires no stored scale whatsoever (exact bb bits/coord), while KK stores one fp16 RMS norm per 128-element vector (b+0.125b+0.125 bits/coord), giving:

  • SRFT 1m2: 2.125 (KK) + 2.000 (VV) ⇒\Rightarrow 2.0625 eff. bits (7.76× vs bf16).

  • SRFT K3/V2: 3.125 (KK) + 2.000 (VV) ⇒\Rightarrow 2.5625 eff. bits (6.24×).

  • SRFT 1m3: 3.125 (KK) + 3.000 (VV) ⇒\Rightarrow 3.0625 eff. bits (5.23×).

Unlike OSCAR [6], this requires zero offline calibration; unlike TurboQuant [4], it avoids spending 1 bit on a QJL sign residual (which increases softmax logit variance at equal bit budget).

Split Banded-Bias Attention with Exact Online LSE Merge

For each global visit at sequence length N>1024N > 1024, the additive relative bias is nonzero only on the newest R=1024R = 1024 keys. We therefore partition the global cache into:

  1. Far prefix [0,N−1024)[0, N - 1024): Spilled in 256-token chunks through SRFT and packed into 2-bit codes (32 bytes/row for KK, 32 bytes/row for VV, plus 2 bytes/row KK-scale = 66 bytes/head/token). Decoded via our GQA-packed Metal kernel returning (ofar,ℓfar)(o_{\mathrm{far}}, \ell_{\mathrm{far}}) with zero mask memory.

  1. Recent window [N−1024,N)[N - 1024, N) + learned sink: Kept in exact fp16, evaluated with the exact 1,024-wide banded relative bias and query-dependent sink logit to produce (onear,ℓnear)(o_{\mathrm{near}}, \ell_{\mathrm{near}}), and combined with (ofar,ℓfar)(o_{\mathrm{far}}, \ell_{\mathrm{far}}) via exact two-way log-sum-exp merging:

m=max⁡(ℓfar,ℓnear),o=eℓfar−mofar+eℓnear−moneareℓfar−m+eℓnear−m.(2)m = \max(\ell_{\mathrm{far}}, \ell_{\mathrm{near}}), \qquad o = \frac{e^{\ell_{\mathrm{far}}-m}o_{\mathrm{far}} + e^{\ell_{\mathrm{near}}-m}o_{\mathrm{near}}}{e^{\ell_{\mathrm{far}}-m} + e^{\ell_{\mathrm{near}}-m}}. \tag*{(2)}

GQA-Packed 2-Bit Metal Kernel (kv_lm2_metal)

For d=128d = 128 and 2 bits/coordinate, each 32-lane Metal simdgroup maps 4 coordinates to each lane: 1 byte per lane, yielding a perfectly coalesced 32-byte burst per token. Our kernel eliminates three overheads of general-purpose Metal attention:

  1. Zero GQA padding waste: Prior simdgroup_matrix kernels pad r=3r = 3 to 8 rows (62.5% wasted compute).

Our kernel holds all r=3r = 3 query heads (half4 q0, q1, q2) in registers, dequantizes each KK and VV byte once, and updates all 3 heads simultaneously.

  1. 256-entry threadgroup half4 LUT: Every byte encodes 4 two-bit Lloyd–Max indices (256 states total). Precomputing a 2 KiB threadgroup half4 LUT[256] at kernel entry decodes all 4 coordinates in a single table lookup, replacing 28 shift/mask/select instructions and halving register pressure.

  1. Block-8 lazy exp2 rescaling: Computing 8 token scores per head before performing a single hardware exp2 rescale reduces rescaling overhead 8×.

Split-K parallelism across 64–256 partitions per KV head saturates M6’s GPU cores, followed by a single exact LSE reduction dispatch. Against float32 reference attention on dequantized codes (N=4096N = 4096), the kernel matches to 1.39×10−41.39 \times10^{-4} max output error and 1.46×10−41.46 \times10^{-4} max LSE error.

Evaluation on a 32GB Apple M6

All measurements were collected on a 32 GB Apple M6 Mac mini (150 GB/s DRAM, 26.8 GiB Metal working set) using mlx 0.32.4 and mlx-community/Inkling-2-Mini-oQ4e-mtp (15.10 GiB active weights).

End-to-End Speed and Memory from 4K to 1,048,576 Tokens

Table I and Figure 1 report end-to-end decode throughput, KV cache footprint, and peak GPU memory from 4K to 1M tokens. At 256K, m6_lm2_srft delivers 17.09 tok/s (3.36× faster than m6_bf16’s 5.09 tok/s) while cutting KV memory 6.5× (1.27 vs 8.20 GiB). At the full 1,048,576-token native context, m6_lm2_srft decodes at 9.52 tok/s (105.1 ms/tok) in 19.49 GiB total peak memory (4.37 GiB KV)—2.60× faster than 4-bit q4_0 SRFT (3.66 tok/s, 24.36 GiB) and 44× smaller KV than stock oMLX (∼193 GiB).

ContextModetok/sms/tokKV (GiB)Peak (GiB)
4KStock oMLX25.2739.580.8015.91
4Km6_q4_srft (4.5b)25.3139.500.4715.59
32KStock oMLX19.3651.666.0521.16
32Km6_bf16 (PR #5512)19.7150.741.3616.47
32Km6_q4_srft (4.5b)22.2444.960.7215.84
64Km6_bf1616.5560.422.2017.32
64Km6_q4_srft (4.5b)20.8547.960.8115.93
128Km6_bf1611.5986.304.2019.33
128Km6_q4_srft (4.5b)17.5257.091.3816.50
256Km6_bf165.09196.408.2023.34
256Km6_q4_srft (4.5b)12.5080.012.5017.62
256Km6_lm2_srft (2.06b)17.0958.511.2716.39
512Km6_q4_srft (4.5b)8.42118.824.7519.87
512Km6_lm2_srft (2.06b)13.8172.402.3117.43
1Mm6_q4_srft (4.5b)3.66272.949.2024.36
1Mm6_lm2_srft (2.06b)9.52105.084.3719.49

Table I. End-to-End Inkling-2-Mini Decode on a 32 GB Apple M6.

Figure 1. End-to-end Inkling-2-Mini (26.4B looped MoE) decode speed and peak GPU memory from 4K to 1,048,576 tokens on a 32 GB Apple M6. Stock oMLX OOMs around 64K; sliding-fixed m6_bf16 OOMs before 512K. Packed 2.06-bit SRFT (m6_lm2_srft) reaches 17.09 tok/s at 256K (3.36× vs bf16) and runs the full 1M context at 9.52 tok/s in 19.49 GiB.

Kernel Optimization Ladder and SRFT vs. Hadamard

Figure 2 tracks the 1M-token decode speedup across our kernel iterations: moving from 4.5-bit q4_0 SRFT (3.66 tok/s) to naive 2-bit LM2 with per-token exp() (6.67 tok/s, 41.7 GB/s), adding Block-8 lazy exp2 rescaling (8.37 tok/s, 59.4 GB/s), and introducing the 256-entry half4 LUT (9.52 tok/s, 73.4 GB/s; 7.65 ms/layer at 1M). Interestingly, at 64K–256K m6_q4_srft also outran in-kernel FWHT (20.85 vs. 18.88 tok/s at 64K; 17.52 vs. 15.65 tok/s at 128K) because rotating only the single query/output vector with MLX’s Metal FFT allows the attention kernel to run without in-kernel butterfly barriers while maintaining identical quality (63/64 greedy token agreement at 4K for both).

Figure 2. 1,048,576-token end-to-end decode progression on a 32 GB M6 across kernel optimizations (2.60× total speedup over 4-bit SRFT).

Language Modeling Quality and 8K–32K Passkey Retrieval

Table II evaluates multi-window WikiText-2 perplexity (4 × 4096 tokens, scoring the last 2,048 tokens of each window where the earlier prefix resides in the quantized cache) alongside long-range Needle-in-a-Haystack (NIAH) retrieval where a 7-digit passkey is buried at position 1,500 inside 8K, 16K, and 32K WikiText-2 haystacks—6.7K to 30.5K tokens behind the query, 100% invisible to the 40 sliding layers and the 1,024-token bf16 local window.

FormatEff. BitsPPLΔPPL8K16K32K
bf16 (ref)16.00006.7489+0.0000PASSPASSPASS
SRFT 1m44.06256.7428−0.0061———
SRFT 1m33.06256.7418−0.0071PASSPASSPASS
SRFT K3/V22.56256.7725+0.0236PASSPASSPASS
SRFT 1m22.06256.8785+0.1296PASSPASSPASS

Table II. Quality (4×4096 WikiText-2) and Long-Range NIAH Retrieval.

SRFT 1m3 (3.06 bits) is indistinguishable from bf16 (ΔPPL = −0.0071), SRFT K3/V2 (2.56 bits) adds only +0.0236 (+0.35%), and SRFT 1m2 (2.06 bits) adds +0.1296 (+1.9%) while passing 3/3 exact 7-digit passkey retrievals out to 32K.

Note on Speculative Decoding on Sparse MoE

Testing Inkling-2-Mini’s bundled DSpark drafter (B=8B = 8) on M6 revealed an MoE expert-union trade-off: verifying 8 tokens reads the union of ∼35–45 distinct experts from 128, costing 120 ms vs. 40 ms for 1 token. Fixed k=7k = 7 speeds up code (24.80 → 27.52 tok/s, 3.76 tok/step, 128/128 exact) but slows prose (25.78 → 22.90 tok/s, 2.93 tok/step). Quantizing the draft to 4-bit and adapting verify depth k∈{2,3,5,7}k \in\{2, 3, 5, 7\} by acceptance EMA eliminates the prose regression (26.15 tok/s) and lifts code to 28.61 tok/s (128/128 exact).

Related Work and Limitations

Per-channel KV quantization (KIVI [7], KVQuant [8]) and rotation-based methods (QuaRot [9], TurboQuant [4], OSCAR [6]) target full-attention RoPE models and either require offline calibration (OSCAR) or pay a 1-bit QJL overhead. (TurboQuant). Our work shows that modern NoPE hybrid architectures with unit-RMS values admit strictly calibration-free, scale-free 2-bit SRFT compression that simultaneously accelerates decode on unified memory.

Limitations. End-to-end 256K–1M decode timings use direct cache population rather than multi-hour prefill; NIAH was evaluated to 32K (single needle per length); and quality was measured on WikiText-2 and passkey retrieval rather than full RULER or long-chain reasoning benchmarks.

Conclusion

Combining bounded sliding-window caches, split banded-bias online LSE merging, scale-free 2.000-bit SRFT Value compression, and a half4-LUT GQA-packed Metal kernel enables full 1,048,576-token inference of a 26.4B looped MoE model at 9.52 tok/s in 19.49 GiB on a 32 GB Apple M6 Mac mini—3.36× faster than bf16 at 256K and 44× smaller KV than stock oMLX—with 100% passkey retrieval up to 32K and zero offline calibration.

Reproducibility. All Metal kernels, benchmarks, and interactive chat scripts are open-sourced under the MIT license at https://github.com/aminems/inkling-1m-mlx [10], and the sliding-window cache fix is submitted upstream at https://github.com/jundot/omlx/pull/5512.

References

  1. [1]Thinking Machines Lab, “Inkling 2 Mini: Open-weights looped multimodal MoE model,” https://huggingface.co/thinkmachines/Inkling-2-Mini, Nov. 2026.
  2. [2]oMLX Contributors, “oMLX: Optimized MLX inference engine for apple silicon,” https://github.com/jundot/omlx, 2026.
  3. [3]M. A. Berghach, “When quantization is free: An int4 KV cache that outruns fp16 on apple silicon,” 2026.
  4. [4]A. Zandieh, M. Daliri, M. Hadian, and V. Mirrokni, “TurboQuant: Online vector quantization with near-optimal distortion rate,” in International Conference on Learning Representations (ICLR), 2026.arxiv.org/abs/2504.19874
  5. [5]A. Jonasson, “Rotary offset features in large language models,” 2025.arxiv.org/abs/2503.01832
  6. [6]Z. Zhou, D. Zhuang, J. Li, Z. Chen, S. L. Song, B. Athiwaratkun, and X. Wu, “OSCAR: Offline spectral covariance-aware rotation for 2-bit KV cache quantization,” 2026.arxiv.org/abs/2605.17757
  7. [7]Z. Liu, Y. Yuan, H. Jin, S. Zhong, Z. Xu, V. Braverman, B. Chen, and X. Hu, “KIVI: A tuning-free asymmetric 2bit quantization for KV cache,” in International Conference on Machine Learning (ICML), 2024.DOI
  8. [8]C. Hooper, S. Kim, H. Mohammadazdeh, M. W. Mahoney, Y. S. Shao, K. Keutzer, and A. Gholami, “KVQuant: Towards 10 million context length LLM inference with KV cache quantization,” in Advances in Neural Information Processing Systems (NeurIPS), 2024.arxiv.org/abs/2401.18079
  9. [9]S. Ashkboos, A. Mohtashami, M. L. Croci, B. Li, P. Cameron, M. Jaggi, D. Alistarh, T. Hoefler, and J. Hensman, “QuaRot: Outlier-free 4-bit inference in rotated LLMs,” in Advances in Neural Information Processing Systems (NeurIPS), 2024.arxiv.org/abs/2404.00456
  10. [10]M. A. Berghach, “inkling-1m-mlx: Calibration-free 2-bit SRFT KV-cache compression for 1m-context Inkling-2-Mini on apple silicon,” https://github.com/aminems/inkling-1m-mlx, 2026.

Paper details

vlnc:W_85z87mys
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 0

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

Not recorded for this paper

View statement
Looking for related papers…
Contents