MLP Cache: Post-Hoc Spectral Tree Caching for Transformer Inference

MLP Cache (arXiv:2612.02874) accelerates frozen Transformer inference without retraining by replacing recurring MLP calls with compact local predictors organized in a graph-spectral binary partition tree. On Qwen3.5-9B evaluated on MME-Coarse and MMStar-Coarse, MLP Cache bypasses 24-28% of MLP weight reads in cached layers, speeding up batch-1 decoding by 1.20-1.38x on Apple M5 Pro and 1.09-1.15x on NVIDIA A100.
MLP Cache: Post-Hoc Spectral Tree Caching for Transformer Inference: MLP Cache (arXiv:2612.02874) accelerates frozen Transformer inference without retraining by replacing recurring MLP calls with compact local predictors organized in a graph-spectral binary partition tree. On Qwen3.5-9B evaluated on MME-Coarse and MMStar-Coarse, MLP Cache bypasses 24-28% of MLP weight reads in cached layers, speeding up batch-1 decoding by 1.20-1.38x on Apple M5 Pro and 1.09-1.15x on NVIDIA A100. Designed as a zero-dependency, open-source TypeScript architecture under the MIT License with native Model Context Protocol (MCP) support and deterministic phase state machines.
- Zero Backbone Retraining: Attaches post-hoc to frozen models like Qwen3.5-9B using calibration activations from HuggingFaceM4/the_cauldron.
- 1.20-1.38x Faster Batch-1 Decode on Apple M5 Pro: A 1.2 GiB cache hits 1.20x speedup with only 0.56-point MME-Coarse change; an 8 GiB cache reaches 1.38x and stays faster up to batch 8.
- 1.09-1.15x Faster Against A100 CUDA Graphs: Beats a single-CUDA-graph-per-step baseline by skipping HBM weight reads on MLP cache hits.
- Tree Dynamic Programming Allocation: Optimizes region scale vs predictor rank under explicit memory and approximation-error budgets.
import { createAgent } from '@smoke-monkey/harness';// Low-latency batch-1 coding/multimodal agent backed by an MLP-Cached Qwen3.5-9B endpointconst agent = createAgent({agentId: 'mlp-cache-fast-agent',provider: 'openai-compatible',baseUrl: 'http://127.0.0.1:8082/v1',model: 'Qwen/Qwen3.5-9B-mlp-cache-1.2g',workspacePath: process.cwd(),permissions: {read_file: 'allow',write_file: 'ask',run_command: 'ask',},});async function main() {const result = await agent.run('Analyze the UI screenshot diffs and output a structured JSON accessibility regression list.');console.log('MLP-Cached Inference Result:', result.summary);}main().catch(console.error);
Watch: Related Video Guides
What is Prompt Caching? Optimize LLM Latency with AI Transformers
The KV Cache: Memory Usage in Transformers
What Is MLP Cache and Why Does It Beat Batch-1 Weight Reads?
MLP Cache (Yang et al., arXiv:2612.02874) is a post-hoc inference cache that approximates recurring regions of a frozen Transformer MLP's input space using lightweight local linear predictors. During batch-1 autoregressive decoding, every token normally streams gigabytes of MLP projection matrices from memory; by hitting on 24-28% of MLP calls in cached layers, MLP Cache skips those full weight reads whenever the hit rate times saved memory bandwidth exceeds routing and lookup overhead.
The method uses shared graph-spectral coordinates—whose signs define hierarchical binary tree regions and whose continuous coordinates serve as low-dimensional input features—paired with tree dynamic programming to choose the optimal region depth and predictor rank within a fixed RAM budget.
| Hardware & Cache Budget | Model Tested | MLP Cache Hit Rate | Decode Speedup (Batch 1) | MME-Coarse Accuracy Impact |
|---|---|---|---|---|
| Apple M5 Pro (1.2 GiB cache) | Frozen Qwen3.5-9B | 24-28% in cached layers | 1.20x | -0.56 points |
| Apple M5 Pro (~8 GiB cache) | Frozen Qwen3.5-9B | Higher coverage (up to batch 8) | 1.38x | ~3.0 points |
| NVIDIA A100 (vs CUDA Graph baseline) | Frozen Qwen3.5-9B | 24-28% in cached layers | 1.09-1.15x | Preserved within MSE budget |
Graph-Spectral Routing and Tree Dynamic Programming Allocation
Uniform caching wastes memory because some activation regions are dense and simple while others span wide manifolds. MLP Cache solves this memory-compute trade-off in three steps:
- Shared Graph-Spectral Coordinates: Anchor points drawn from calibration data (e.g.,
the_cauldron) construct spectral embeddings whose sign bitspi_h(x)agree with principal components 90-92% of the time in deeper layers (Layer 16 text tokens) while revealing low intrinsic dimensionality (18-19 vs 140 for matched Gaussians). - Coarse-to-Fine Region Predictors: Each candidate node
vin the binary tree stores a low-rank predictorg_{v,r}(x) = c_{v,r} + W_{v,r} s_hat(x)at payload sizes of 80 KiB, 144 KiB, or 272 KiB (pairing ranks 4/2, 8/4, and 16/8). - Tree Dynamic Programming Budget Solver: A DP pass over the partition tree selects exact
(region, predictor_rank)pairs to maximize expected workload hit coverage without exceeding the operator's memory cap or per-layer MSE tolerance.
Memory Bandwidth Determines the Batch-Size Break-Even
MLP Cache delivers its largest wall-clock wins in memory-bandwidth-bound batch-1 decoding because skipping a hit skips reading the entire frozen MLP weight matrix. On the 8 GiB M5 Pro configuration, positive speedups hold up to batch size 8; above that, compute-bound batching narrows the win.
Reproducible Spectral Calibration and Batch-1 Decode Benchmarking
Calibrate anchor coordinates on a frozen Qwen/Qwen3.5-9B checkpoint and evaluate hit rate and token latency against an uncached CUDA graph / Metal baseline:
# 1. Pull Qwen3.5-9B weights and calibration slice
hf download Qwen/Qwen3.5-9B --local-dir ./models/qwen3.5-9b
hf download HuggingFaceM4/the_cauldron --repo-type dataset --local-dir ./data/cauldron
# 2. Build the spectral partition tree and solve the Tree-DP memory budget (1.2 GiB target)
python3 -m mlp_cache.calibrate \
--model ./models/qwen3.5-9b \
--calib-data ./data/cauldron \
--memory-budget-gib 1.2 \
--output ./caches/qwen35_9b_1g2.bin
# 3. Benchmark batch-1 decode latency vs baseline
python3 -m mlp_cache.bench_decode --model ./models/qwen3.5-9b --cache ./caches/qwen35_9b_1g2.bin --batch-size 1Frequently Asked Questions
Q:Does MLP Cache require retraining or fine-tuning the Transformer weights?
No. MLP Cache is strictly post-hoc: it keeps the backbone weights 100% frozen and builds lightweight local predictors from calibration forward passes.
Q:Why does MLP Cache speed up batch-1 decoding more than large batches?
At batch size 1, Transformer decoding is memory-bandwidth-bound on reading MLP weight matrices from HBM or unified memory. A cache hit skips reading that layer’s weights entirely, whereas large batches amortize weight reads across many tokens.
Q:What speedup and accuracy trade-off does MLP Cache achieve on Qwen3.5-9B?
On an Apple M5 Pro, a 1.2 GiB cache runs 1.20x faster with only a 0.56-point change on MME-Coarse, and an 8 GiB cache reaches 1.38x faster (staying faster up to batch 8) at ~3 points.
Q:Does MLP Cache still beat CUDA Graph baselines on NVIDIA GPUs?
Yes. On an NVIDIA A100, batch-1 decoding with MLP Cache runs 1.09-1.15x faster than a baseline executing each decode step as a single CUDA graph.
Related Alternatives & Comparisons
Related Architecture Guides
View all guidesBest Open Source Coding Agents in 2026: Free, Local & Fully Hackable Harnesses
MCP Server Security Best Practices: Hardening Model Context Protocol Agents in 2026
Open Source Coding Agent Harness: Build a Forkable, Local AI Engineering Runtime
Build with Smoke Monkey Harness
Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.