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

Don't compute it again. Look it up.

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

TikTok

arXiv preprint, coming soon

arXiv (soon) Code

Can an AI model skip work it has already done?

Yes. Ask a model “What is the zebra eating?” and then “What is the giraffe eating?”. Today it works through both questions from scratch, even though most of the words and much of the picture are the same. MLP Cache gives the model a memory. What it has worked out before, it looks up. Only what is new, it computes. The model is not retrained, and on a laptop chip it writes its answers 1.20× to 1.38× faster.

First question

Everything is computed.

Two zebras eating from a bush; a zebra and a patch of grass and bush are circled.

Q: “What is the zebra eating? Concise answer only.”
A: “Grass.”

Later questions

Most of it has been seen before.

A different zebra grazing; the zebra and a patch of grass are circled.

Q: “What is the animal eating? Concise answer only.”
A: “Grass.”

Two giraffes under trees; a bush is circled.

Q: “What is the giraffe eating? Concise answer only.”
A: “Leaves.”

Seen before: look it up New: compute it Picture content that comes back

An illustration of the idea. The giraffe question has a different answer and still repeats most of the work, because MLP Cache remembers pieces of the calculation, not finished answers.
  1. RememberRun the model on past questions and note which calculations keep coming back.
  2. RecognizeFor each new piece of input, check whether it is close to one of them.
  3. ReuseClose enough? Look the result up. If not, compute it as usual.
What we found
  1. A lot of the work repeats. On Qwen3.5-9B, a model that answers questions about pictures, our larger cache looks up about one in four of the calculations it covers, on pictures it has never seen.
  2. The repeats are the predictable parts: fixed question wording such as “Is there … in the image?” and picture backgrounds.
  3. Looking up is faster where computing is slow. On an Apple M5 Pro laptop chip, that cache makes the model write its answer 1.38× faster for about 3 points of accuracy. A smaller cache gives 1.20× for about half a point.

Why would a model repeat itself?

Because it works in small steps, and the same steps keep coming back.

A model cuts a question and a picture into small pieces called tokens: bits of words and patches of the image. Each token passes through a stack of layers, 32 in this model. In every layer a block called the MLP runs a large calculation on the token. That is the MLP in MLP Cache.

The MLP has no memory. It runs in full on every token, even when it did almost the same calculation a moment ago. Look at the example again:

You do not work out 7 × 8 every time. You remember 56. A model could do the same, with one catch: its inputs are almost never exactly the same twice. “Zebra” becomes “giraffe”, the grass is a slightly different green, and a memory that only knows exact repeats is almost never used.

So the real question is: can a model reuse its work on inputs that are only similar, and still get the answer right?

In shortModels keep redoing almost the same small calculations. Almost, and never exactly.

How do you look up something you have never seen exactly?

You store a small shortcut that covers a whole neighborhood of similar inputs.

Over all possible inputs the MLP is complicated. Up close it is simple, the way a winding road looks straight under your feet. So wherever inputs keep landing, we store a stand-in: a tiny formula that gives nearly the same result as the MLP in that neighborhood, for a fraction of the work.

Looked up: a stored stand-in Computed: the original MLP

A sketch with a single input. The blue curve is the MLP. Where inputs pile up (grey), a short straight piece is stored in its place. A dot that lands there is answered at once. The others wait for the full MLP.

A lookup is called a hit. Everything else is a miss and goes to the original MLP, which is left untouched. A stand-in is stored only if it stays within a set error limit on recorded data. The stand-ins sit in ordinary computer memory, which is cheap, and they replace work on the graphics chip, which is not.

The hard part: how big should a neighborhood be?

We let the data decide. Past inputs are sorted into a tree, with broad groups at the top and narrow ones below. A search over the whole tree then chooses, branch by branch, between a broad group and its narrower parts, so that as many inputs as possible are covered within the error limit and the memory budget.

Animation: patches of several photos of a guitar player are grouped into nested regions, each shown in one color.

Photos

Video

A code snippet whose tokens are colored by group; similar tokens such as numbers or the word image share a color.

Text

The same kind of grouping on things you can see. Pieces that belong together get one color, and big groups split into smaller ones. MLP Cache builds such a tree over the inputs of each MLP.

For experts: the tree comes from graph-spectral partitioning (ncut-pytorch), the search is dynamic programming over the tree, and a small network, the Router, finds a token's group at run time.

See stand-ins pass or fail the error check on a toy example
Construction schematic: recorded data on a toy function, groupings at depth 2 and depth 4, a stand-in fitted in each group, an error check that rejects high-error groups and accepts low-error ones, and the resulting area where inputs are cache hits.
Left: a toy function, colored by its value, with recorded inputs. With two big groups (Depth 2), neither stand-in looks like the original, so both are rejected. Split further (Depth 4), four smaller groups match and are accepted. Lookups happen only inside those four (right).
See the overview diagram from the paper
Left: a standard MLP computes every token. Middle: with MLP Cache a Router checks each input; cache hits are answered by a small local function stored in host memory, cache misses run the original MLP. Right: two examples showing which image patches and question words are cache hits. A standard MLP computes every token. With MLP Cache a Router checks each input; cache hits are answered by a small local function stored in host memory, cache misses run the original MLP. Two examples showing which image patches and question words are cache hits.
The paper's names for the same parts: the Router does the checking, a local function is a stand-in, and host memory is ordinary computer memory.

In shortStore small stand-ins where inputs pile up. Send everything else to the original MLP.

What ends up in the cache?

The predictable parts. With our larger cache, that is about one in four of the MLP's calculations.

We built caches for Qwen3.5-9B from one collection of picture questions, and tested them on two others, MME and MMStar. None of the test pictures were used to build the cache. In the 28 layers that have a cache (of 32), this is how much of the MLP's work was answered from memory:

Looked up Computed as usual

MME
27.7% looked up
MMStar
24.1% looked up
The larger of our two caches, on each benchmark's basic questions about what is in the picture. The smaller, stricter cache looks up 7 to 8%.

Which calculations? The ones you would guess:

One benchmark question about a red brick building. Template words in the question and in the model's answer, and many background patches of the photo, are highlighted as cache hits.
A real test question. The darker the orange, the more layers looked that token up. The darkest parts are the fixed wording (“Is there a … in the image?”, “Respond in this format”) and patches of sky and road.

In the zebra example, that would be “What is the … eating? Concise answer only.” and the grass. The cache takes over the routine parts, and the model still computes whatever is specific to this question.

See where in the model the hits happen

Deep inside the model, the question stays easy to look up, while a long written answer does not. The model spends its real effort on writing the answer, and far less on re-reading the question.

Cache hit rate per Transformer layer for image tokens, non-image prompt tokens and generated answer tokens. With answer plus evidence, answer tokens drop to a few percent in later layers while prompt tokens rise to about 40 percent.
Share of tokens looked up in each of the 32 layers. In the right panel the model writes a longer answer: the words it writes (green triangles) are almost never looked up in the middle layers, while the question text (orange squares) is still looked up about 40% of the time near the end.
See how memory and the error limit change the result
Accuracy against cache hit rate on MME-Coarse and MMStar-Coarse for three error targets. Tighter targets stay near the uncached baseline at 8 to 25 percent hit rate; the loosest target reaches 30 to 37 percent hit rate with a few points lower accuracy.
Every point is one cache. Further right means more lookups, higher means more accurate. The numbers are memory in GiB per layer, and the three colors are three error limits, from strict (blue circles) to loose (green triangles). More memory or a looser limit gives more lookups. The loosest caches pass 30% and lose a few points against the model without a cache (grey band).

In shortFixed wording and backgrounds get looked up. Whatever is new still gets computed.

Does looking up actually save time?

On a laptop chip, clearly. On a data-center GPU, a little.

A lookup is not free. Every token has to be checked against the cache first, whether it hits or misses. If checking costs more than the hits save, the cache makes the model slower.

A cached layer pays off when how often it hits × the time one hit saves is larger than the fixed cost of checking.

That is why the hardware matters. The slower the MLP is on a machine, the more each hit saves:

Run one MLP layer (a hit skips this) Check the cache (every token pays this)

Apple M5 Prolaptop chip
1.00 ms
0.08 ms
NVIDIA A100data-center GPU
0.25 ms
0.04 ms
Time per layer for each token the model writes, one request at a time. On the M5 Pro most of the blue bar goes to reading the layer's 302 MB of weights from memory, and a hit skips all of it.

Measured on the whole model while it writes its answer:

1.20× fasterApple M5 Pro, smaller cache60.6 → 50.7 ms per tokenaccuracy 91.25 → 90.69
1.38× fasterApple M5 Pro, larger cache60.6 → 43.8 ms per tokenaccuracy 91.25 → 88.19
1.09–1.15× fasterNVIDIA A100, both caches16.2 → 14.9 and 14.0 ms per tokenaccuracy 91.53 → 90.14 and 88.89

Each compared with the same model without a cache, one request at a time. Accuracy is the share of those MME questions answered correctly, in percent. On the M5 Pro the smaller cache keeps about 1.2 GiB in memory and the larger one about 8 GiB.

The gain is largest when requests arrive one at a time. When many are processed together it fades, because the MLP has to run as soon as one of them misses.

See when a cache stops paying off
  • Under 10% hits: checking costs more than the hits save. No gain.
  • 20 to 40% hits: the saving clearly beats the cost.
  • Over 50% hits: on a fast GPU the lookups themselves become the bottleneck. Bigger MLPs and slower chips keep gaining.
Left: timeline of one cached MLP call on an A100, where the CPU reconstructs cache hits while the GPU computes cache misses. Right: speedup against cache hit rate for A100 prefill, A100 decode and M5 Pro prefill; speedup rises with hit rate and is larger for bigger MLPs.
Left: inside one layer on the A100, the processor answers the hits while the graphics chip computes the misses. Right: one cached MLP on its own, for three MLP sizes. Above the dotted line is faster than no cache. More hits and bigger MLPs gain more.

One cost remains on the A100: reading the question, before the first word is written, takes 41 to 55 ms longer with the cache. The numbers above are for writing the answer.

In shortLookups win when hits are frequent and the calculation they replace is slow. Today that means a laptop-class chip answering one request at a time.

What's next?

  1. Workloads that repeat a lot. Places where many near-identical questions arrive are the natural fit.
  2. Even hits across layers. Today some layers hit 10% of the time and others 70%. We want every layer between 20% and 40%.
  3. Cheaper lookups. A better memory layout, lookups that run in parallel, and popular entries kept ready.

BibTeX

@article{yang2026mlpcache,
  title   = {MLP Cache: A Post-Hoc Memory--Compute Trade-off
             for Transformer Inference},
  author  = {Yang, Huzheng and Huang, Yiqiao and Hu, Qingqiao and
             Zhao, Dongdi and Zhang, Jiaxing and Fu, Di},
  journal = {arXiv preprint},
  year    = {2026}
}