arXiv(opens in a new tab)cs.LGOct 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2610.25431

MOSAIC: Multi-Objective Search for Allocating Inference Cache Across LLM Decoder Layers

Sravanth Kodavanti, Manjunath Arveti

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

The Key-Value (KV) cache is the main memory bottleneck of long-context LLM inference. Token eviction methods such as SnapKV, H2O, AdaKV and L2Norm shrink it, but they give every transformer layer the same budget, although layers differ in which tokens they need. We present MOSAIC, a multi-objective neural architecture search that learns per-layer KV-cache budgets for any eviction method. One search maps the trade-off between average budget and task score; its best allocation transfers to every target budget without further search, and an optional budget-constrained search refines it. Across four eviction methods on Llama-3-8B-Instruct and Mistral-7B-Instruct-v0.2, MOSAIC beats uniform allocation in 146 of 154 (task, method, budget) settings, by up to +48 points on RULER and +11.9 on LongBench (LCC). It reaches the score of uniform allocation with up to 4× less KV cache (75% smaller), and with half the cache or less in 17 Llama settings. The transferred allocation alone beats uniform in 75 of 87 Llama settings, so a single 9–40 GPU-hour search serves every budget. Against EvolKV, MOSAIC explores a ~10^{40}× larger search space with 4× fewer evaluations and 18% fewer GPU-hours per budget, and scores higher in 5 of 6 settings. The learned allocations consistently favour a small set of middle layers.

1 Introduction

Long-context inference with large language models (LLMs) is limited by the memory of the key-value (KV) cache, which grows linearly with sequence length and batch size (Kwon et al., 2023): a 30B-parameter model with batch size 128 and sequence length 1024 already needs 180 GB of KV cache (Zhang et al., 2023). Token eviction methods like H2O (Zhang et al., 2023), SnapKV (Li et al., 2024) and L2Norm (Devoto et al., 2024) address this by selectively dropping cache entries based on token importance, and AdaKV (Feng et al., 2025) builds on them by distributing a layer's budget adaptively across its attention heads. However, these methods apply the same memory budget to every transformer layer. Layer-wise allocation schemes exist, but they either fix the shape of the allocation in advance (Cai et al., 2025), derive it from attention statistics (Qin et al., 2025), or optimize layer budgets one group at a time at one budget and rescale the result to others (Yu and Chai, 2025). These schemes already exploit layer differences; MOSAIC instead searches all layers jointly once and transfers the result to every budget. In our searches, a few middle layers consistently receive more than their uniform share, so a uniform allocation spends cache on layers that need little while starving the ones that need more.

This paper introduces MOSAIC, a method that automatically optimizes per-layer KV-cache budgets under a target memory constraint using multi-objective neural architecture search. Rather than hand-tuning layer-specific heuristics or optimizing layers group by group, MOSAIC searches the per-layer budget space jointly, one budget per decoder layer (32 for Llama-3-8B, up to 102710^{27} configurations on its search grid), using Bayesian optimization guided by a surrogate MLP (Figure 1). MOSAIC is to KV-cache allocation what static quantization is to model quantization: just as post-training quantization calibrates offline on a small calibration set (Frantar et al., 2023; Xiao et al., 2023), MOSAIC fixes each layer's budget offline on calibration data, so inference adds no per-prompt allocation step. Methods such as CAKE and Ada-KV instead adapt the budget to each prompt at inference time, as dynamic quantization computes its ranges at run time. We evaluate MOSAIC across four eviction methods (SnapKV, H2O, AdaKV, L2Norm) on Llama-3-8B-Instruct and Mistral-7B-Instruct-v0.2 (all four methods; on LongBench Summarization, SnapKV, H2O and AdaKV ran Stage 1

Input: frozen LLM (L decoder layers) · eviction policy · calibration subset (search) · full task data (selection)

Figure

Once per (task, eviction policy) – reused at every budget

Per target budget

Figure 1: The MOSAIC pipeline. Stages 1–3 run once per (task, eviction policy): an unconstrained search on a calibration subset yields a Pareto front of per-layer allocations, full-data re-evaluation selects a winner, and the winner is rescaled to every target budget without further search. Stage 4 optionally refines each budget with constrained BO seeded by the rescaled winner. Bar profiles are schematic.

only), on two benchmarks: LongBench (4 task categories) and RULER (11 in-context retrieval subtasks). On RULER, per-layer allocation yields large gains over uniform (+2.3 to +47.9 points), concentrated on the hardest needle-retrieval subtasks. On LongBench, MOSAIC improves every Code setting, with dataset-level gains of up to +11.9 points on LCC (L2Norm), +3.5 on LCC for SnapKV, and +3.0 on MultiFieldQA-en (H2O) and Qasper (AdaKV) (Section 4.2).

MOSAIC versus EvolKV. The closest prior work, EvolKV (Yu and Chai, 2025), searches per-layer budgets with CMA-ES (Hansen and Ostermeier, 2001) group by group, eight layers at a time, at a target budget fixed in advance. MOSAIC instead searches all layer budgets jointly, so one search spans about 104010^{40} times more allocations than one EvolKV group search, across a budget-score Pareto front, selects a reusable anchor, and optionally refines it at each deployment budget; on Code it beats EvolKV at every budget, both searching once (+1.3 to +2.1) and per budget at EvolKV's compute (+0.8 to +1.7, Appendix D), and even searched once, MOSAIC's winner outperforms EvolKV's per-budget searches at every budget where both ran (Section 6).

Our contributions are: (i) MOSAIC, a four-stage workflow (joint per-layer search, budget-score exploration, winner rescaling, optional per-budget refinement) whose single search yields a winner that transfers across budgets without further search; (ii) an evaluation across four eviction methods, two models and two benchmarks, where MOSAIC improves over uniform allocation for every method, with gains of up to +48 points on RULER; and (iii) an analysis of the learned allocations, which favour a small set of middle layers.

References (39)

  • The Llama 3 Herd of Models
  • Dalton Jones, Junyoung Park, Matthew Morse, Mingu Lee, Chris Lott, and Harper Langston. 2026. QUOKA: Query-oriented KV selection for efficient LLM prefill. arXiv preprint arXiv:2602.08722. (opens arXiv in a new tab)
  • RULER uses its 11 subtasks (NIAH-Single-1/2/3, NIAH-MultiKey-1/2/3, NIAH-MultiQuery, NIAH-MultiValue, CommonWords Extraction, Frequent-Words Extraction and Variable Tracking) at 4K context, 500 samples each; the RULER score is the mean over the 11 subtasks
  • For each task they give three rows: uniform allocation, the rescaled Stage 2 winner (Winner, Stage 3) and NAS-refined, the best configuration of the Stage 4 search
  • Figure 6 shows why both are needed: calibration orders configurations broadly like the full data, but the configuration it ranks first is often not the full-data best, and selection keeps only the first
  • All candidates of a Stage 4 cell share one average budget, so their ranking tests calibration directly
  • Per task: uniform, the rescaled Stage 2 winner (Winner) and NAS-refined (best of the Stage 4 search); bold: best in each column
  • Layout as in Table 5; the number under each method is its winner's natural average budget
  • Layout as in Table 5
  • Panels (c) and (d) compare each Stage 1 Pareto front's calibration scores with its Stage 2 full-data re-evaluation
  • Layout as in Table 6
  • Rows: eviction method; columns: task
  • The tests cover SnapKV and H2O on Code and Single-Doc QA at B128, B512 and B1024
  • SnapKV's Code shape applied to Single-Doc QA, and its Single-Doc QA shape applied to Code, score below uniform at every budget (by 0.33 to 1.08 and 0.63 to 1.22 points), while each task's own Winner beats uniform in the same six cells
  • Circles: LongBench; triangles: RULER; bars: medians
  • On Code, H2O's shape under SnapKV and SnapKV's shape under H2O beat uniform in all six cells (+0.06 to +1.66)
  • EvolKV runs 60 generations × population 10, 600 evaluations on 30 calibration samples each
  • Each point is a gain over the receiving cell's uniform allocation at the same budget (dashed line): the transferred shape, rescaled as in Stage 3; the receiving cell's own rescaled Winner; and its own final configuration (the better of Winner and NAS-refined)
  • SnapKV, H2O and AdaKV have no LongBench Summarization cells
  • Stage 2 re-evaluates the Stage 1 front on full data: 3.6 GPU-hours on Single-Doc QA (20 configurations) and 8.0 on Code (11 configurations)
  • Cells: (task, budget) pairs
  • Gap: mean calibration minus full-data score
  • At a floor of 16, only 8 tokens are chosen from contexts of thousands
  • >Code</td><td>SnapKV</td><td>16</td><td>15</td><td>0</td><td>1</td></tr><tr><td>H2O</td><td>18</td><td>8</td><td>2</td><td>1</td></tr><tr><td rowspan=
  • Negative $\Delta$ (bold): floor 64 is better
  • AdaKV shows a weaker version of the middle-layer preference: layer 10 receives more than its uniform share in $95\%$ of the 19 AdaKV allocations and layers 13–16 in $68–89\%$, but over the whole middle block (layers 10 and 14–20) the share is $55\%$, against $65\%$ for SnapKV and H2O
  • (a) Stage 2 winners at their natural average budget (left)
  • ><tr><td rowspan=
  • EvolKV: 600 evaluations plus one final evaluation
  • This compares single searches: the allocations of both methods lie in the same space [64, 4096]$^{32}$
  • The per-layer cap is 4096
  • NAS-refined is the best of these other candidates, so it excludes uniform and the Winner and can score below the Winner; MOSAIC’s final configuration is the better of the two
  • multiquery; MV: multivalue; CWE/FWE: common/frequent-word extraction; VT: variable tracking; NIAH: mean of the eight needle subtasks; All: mean of all 11), comparing uniform with MOSAIC's final configuration; Figures 13 and 14 show the same gains as heatmaps
  • the largest gains are on niah_multikey_3 at B1024 and above
  • AdaKV B64 has only the rescaled winner, compared with uniform-64 from Stage 2
  • Rows: subtasks and their mean; columns: budget
  • Rows: datasets grouped by category; columns: budget; grey: no cell
  • Top: SnapKV, H2O and AdaKV, which have no Summarization cells; bottom: L2Norm, all four tasks
  • the better of the two in each column