Skip to content

MLP Cache: A Post-Hoc Memory-Compute Trade-off for Transformer Inference

Huzheng Yang, Yiqiao Huang, Qingqiao Hu, Dongdi Zhao, Jiaxing Zhang, Di Fu

cs.LG

Abstract

MLPs impose substantial inference cost in Transformers by applying a full, high-capacity transformation to every token. Deployed workloads revisit recurring regions of the MLP input space, which creates an opportunity for compute reuse beyond exact-match caching. We introduce MLP Cache, a post-hoc cache that stores compact local predictors of a frozen MLP without retraining the backbone. The central challenge is to allocate limited memory across region scale and predictor capacity: broader regions cover more inputs but may require larger predictors, while finer regions are easier to approximate but require more entries. MLP Cache constructs a coarse-to-fine hierarchy using shared graph-spectral coordinates, whose signs define candidate regions and whose continuous values provide features for region-specific predictors. Tree dynamic programming selects region-predictor pairs to maximize workload coverage under memory and approximation-error budgets. On frozen Qwen3.5-9B, MLP Cache replaces 24-28% of MLP calls in the cached layers on MME-Coarse and MMStar-Coarse. A cached layer saves time when its hit rate times the time one hit saves exceeds its fixed cost of routing and lookup, so the gain is largest in batch-one decoding, where a hit skips the layer's weight reads. At batch one on an Apple M5 Pro, a cache that holds 1.2 GiB in memory makes decoding 1.20x faster with a 0.56-point change in MME-Coarse accuracy, and one that holds about 8 GiB makes it 1.38x faster at a cost of about 3 points; with this larger cache, decoding stays faster up to batch 8. On an A100, batch-one decoding is 1.09-1.15x faster against a baseline that runs each decode step as one CUDA graph. A controlled single-MLP benchmark shows that the gain grows with the size of the MLP. Project page: https://huzeyann.github.io/mlp-cache.html

Create a lesson

Metadata

Categories
cs.LG, cs.AI
Comments
65 pages, 24 figures, 41 tables. Project page: https://huzeyann.github.io/mlp-cache.html Code: https://github.com/huzeyann/mlp-cache