Blog

How to cache and dedupe LLM eval runs

When you re-run an eval on cases whose input, prompt, model version, and settings did not change, you pay for the same tokens twice. If one stored sample per case is enough, as when you compare prompt or judge changes, key every model and judge call on a hash of everything that can change its output, reuse the stored result on a hit, and re-run only the misses. Drop duplicate cases first, and take fresh samples when you measure run-to-run spread. The figures on this page come from public papers, not Slancha results.

Most of the calls in a repeat eval run send requests you have sent before. An exact cache key and a clean case set let you pay only for what changed, and keep the totals comparable from run to run.

By Slancha. Published .

1. Find the repeated work

Most eval runs re-send cases that did not change. A prompt edit touches one template, but the run sends every case again. A rubric edit changes only the grading, but the run regenerates every output first. Each of those calls costs input tokens, output tokens, and wait time.

The guide to what LLM evals cost breaks a run into calls, tokens per call, and runs. A cache cuts the number of calls without changing the cases or the grading.

2. Build an exact cache key

A cache hit is safe only when the stored call had the same request. So build the key from everything that can change the output, and hash it:

  • the case input, after the same cleanup you apply at run time;
  • the rendered prompt, or the template name and its version;
  • the tool definitions and any retrieved context the call sees;
  • the pinned model version, never a floating alias;
  • the decoding settings: temperature, maximum output tokens, and the seed if you set one;
  • the sample index, when you take more than one sample per case.

A key can be as plain as hash(case_id, input, prompt_v7, tools_v3, model_version, temperature, max_tokens, sample). Same key: reuse the stored output. Any change, even one token in the template, gives a new key and a miss, so the call runs again.

If a field reaches the model, it belongs in the key. A retrieval step can return different documents tomorrow for the same query, so key on the documents it returned. Store the raw output with the key, plus what you need to check a hit later: model version, settings, token counts, latency, and the time of the original call.

3. Cache outputs and judge verdicts apart

With a judge, each case makes two calls: the model under test writes an output, and the judge grades it. Give each its own cache layer. The judge key holds the judge model version, the rubric version, the judge prompt and settings, and a hash of the exact output it grades.

Then each change re-runs only the layer it touches. A new rubric or a new judge model re-grades the stored outputs, with no new generations. A prompt change re-runs the generations for the cases that use that prompt, then grades only those new outputs. Unchanged cases reuse both layers. A new judge is a miss on every case, so check it against your own labels before you switch, as the guide on cheaper LLM judges describes. The guide to cutting eval cost covers the judge calls that still run.

4. Run only what changed

Before each run, compute the keys for the current case set and compare them with the store. The misses are the work: new cases, edited cases, and cases whose prompt, model, settings, or judge changed. Run those, and read the rest from the cache.

Report the run as one result. Put reused and new results in one table, mark the cached ones, and compute totals over the full set, so this run's pass rate stays comparable with the last one. If the case set itself changed, say so next to the total. The post on testing a model upgrade uses the same case-by-case diff to find regressions, and the guide to faster evals covers other ways to shorten a run.

5. Dedupe the case set

A duplicate case costs tokens twice and counts one behavior twice in the average. For exact duplicates, normalize each input (trim whitespace, sort the fields of structured input), hash it, and group equal hashes. Near duplicates, such as the same question with a reworded opening, need a similarity method.

Lee and co-authors (ACL 2022) found many near-duplicate examples and long repeated substrings in common language-model training sets. Their approximate matching tool uses MinHash to estimate n-gram similarity between documents. Removing duplicates also cut train-test overlap, which they found in over 4 percent of the validation set of standard datasets. The same method works on an eval set. Read the clusters before you drop anything.

Keep one case per cluster, or keep them all with weights that add up to one per cluster. Either choice changes the average, so say which one you made in the report.

Duplicates are not the only redundancy. Vivek and co-authors (EACL 2024) found that model confidence on pairs of cases is strongly correlated across models, and that a small chosen subset can rank models better than a uniform sample of the same size. The guide to how many examples an eval needs shows how small a set can get before the margin grows too wide.

6. Reuse the shared prompt prefix

Every miss still sends the same long system prompt, judge rubric, and worked examples. Prefix caching at the serving layer reuses the work already done on that shared text. Gim and co-authors (MLSys 2024) reuse precomputed attention states for repeated prompt segments, such as system messages, templates, and documents. They report time-to-first-token gains of 8 times on GPU and 60 times on CPU. Kwon and co-authors (SOSP 2023) built a paged design for that attention-state memory that cuts waste from fragmentation and duplication and allows sharing within and across requests.

To get those hits, put the fixed parts of the prompt first and the case-specific parts last, and keep the prefix byte-identical from call to call, as the post on cutting agent token spend explains.

7. Know when not to cache

A cache returns one stored sample. That is wrong when the spread is what you want to know. If you measure run-to-run spread, key on the sample index so each sample gets its own entry, or turn the cache off for that run. Atil and co-authors (2024) saw accuracy vary by up to 15 percent across 10 runs of five LLMs configured to be deterministic. A cached single run hides that spread. How to measure run-to-run spread is the subject of a later post.

Invalidate after any change behind an alias. If a provider moves a model name to a new version, every entry built on the old version is stale. Pin the version in the key, so the move shows up as misses, not as hits on old outputs.

Do not use fuzzy or semantic cache hits for evals. A semantic cache returns a stored answer for a request that is close to an earlier one, not equal to it. Gill and co-authors (IPDPS 2025) define a false hit as a cached answer returned for a query that is not similar to the cached one, and report high false hit rates for existing semantic caches on contextual queries. In an eval, a false hit grades an answer to a different case. Use exact keys.

Where Slancha fits

Slancha aims to make the expensive part of evals faster and cheaper. The judge calls and the repeat runs over the same cases are that expensive part, and you pay for them again on every prompt, rubric, or model change. You keep your current eval or observability platform for traces and review. Pilots by arrangement.

Related: the guide to what LLM evals cost and the eval cost calculator.

Questions people ask

How do I cache LLM eval runs to save tokens?

Hash everything that can change a call's output: the case input, the rendered prompt, tools and retrieved context, the pinned model version, the decoding settings, and the sample index. Reuse the stored output when the key matches, and re-run the call when it does not. Keep model outputs and judge verdicts in separate layers.

How do I avoid re-running the same eval cases?

Compute the keys for the current case set before each run, compare them with the stored keys, and run only the misses. Report reused and new results together, with totals over the full set, so the run stays comparable with the last one.

Is it safe to cache LLM judge results?

Yes, if the judge key includes the judge model version, the rubric version, the judge prompt and settings, and the exact output being graded. A change to any of those must be a miss. Never reuse a verdict for an output that differs, even by one token.

How do I find duplicate eval cases?

Normalize and hash each input to catch exact duplicates, then use a near-duplicate method such as MinHash to find near-identical text with high word overlap. Rewrites in different words need a separate check, such as a manual review of the clusters. Keep one case per cluster or weight them, and say which you did.

When should I turn the eval cache off?

When you measure run-to-run spread, since a cache returns one stored sample. Key on the sample index or turn the cache off for that run. Also invalidate entries when a model alias moves to a new version, and never use fuzzy or semantic matches for eval results.

Sources

  • Deduplicating Training Data Makes Language Models Better, Katherine Lee, Daphne Ippolito, Andrew Nystrom, Chiyuan Zhang, Douglas Eck, Chris Callison-Burch and Nicholas Carlini, ACL 2022 (Proceedings of the 60th Annual Meeting of the ACL, Volume 1: Long Papers, pages 8424-8445), arXiv:2107.06499, 2021. Claims used: existing language modeling datasets contain many near-duplicate examples and long repetitive substrings; deduplication reduces train-test overlap, which affects over 4% of the validation set of standard datasets (abstract); the approximate near-duplicate tool uses MinHash to estimate n-gram similarity (section 4.2, "Approximate Matching with MinHash").
  • Anchor Points: Benchmarking Models with Much Fewer Examples, Rajan Vivek, Kawin Ethayarajh, Diyi Yang and Douwe Kiela, EACL 2024 (Proceedings of the 18th Conference of the European Chapter of the ACL, Volume 1: Long Papers, pages 1576-1601), arXiv:2309.08638, 2023. Claims used: model confidence on pairs of points is strongly correlated across models; small selected subsets rank models better than uniform sampling (abstract).
  • Prompt Cache: Modular Attention Reuse for Low-Latency Inference, In Gim, Guojun Chen, Seung-seob Lee, Nikhil Sarda, Anurag Khandelwal and Lin Zhong, MLSys 2024, arXiv:2311.04934, 2023. Claims used: precomputed attention states of frequently repeated text segments, such as system messages, prompt templates and documents, are reused; time-to-first-token improvements range from 8x for GPU-based inference to 60x for CPU-based inference (abstract).
  • Efficient Memory Management for Large Language Model Serving with PagedAttention, Woosuk Kwon, Zhuohan Li, Siyuan Zhuang, Ying Sheng, Lianmin Zheng, Cody Hao Yu, Joseph E. Gonzalez, Hao Zhang and Ion Stoica, SOSP 2023, arXiv:2309.06180, 2023. Claims used: key-value cache memory is wasted by fragmentation and redundant duplication; the paged design reaches near-zero waste in key-value cache memory and allows flexible sharing of the key-value cache within and across requests (abstract).
  • Non-Determinism of "Deterministic" LLM Settings, Berk Atil, Sarp Aykent, Alexa Chittams, Lisheng Fu, Rebecca J. Passonneau, Evan Radcliffe, Guru Rajan Rajagopal, Adam Sloan, Tomasz Tudrej, Ferhan Ture, Zhe Wu, Lixinyu Xu and Breck Baldwin, arXiv:2408.04667, 2024 (v5, April 2025). Claims used: five LLMs configured to be deterministic, eight common tasks, 10 runs; accuracy variations up to 15% across runs (abstract).
  • MeanCache: User-Centric Semantic Caching for LLM Web Services, Waris Gill, Mohamed Elidrisi, Pallavi Kalapatapu, Ammar Ahmed, Ali Anwar and Muhammad Ali Gulzar, IEEE IPDPS 2025, arXiv:2403.02694, 2024. Claims used: a false hit is a query found and returned from the cache that is not similar to it (section III-A1); existing semantic caches are effective only on standalone queries, with high false hit rates for contextually different but semantically similar queries (section I).

Checked against arXiv (2107.06499, 2309.08638, 2311.04934, 2309.06180, 2408.04667, 2403.02694; abstract pages, plus the HTML full text of 2107.06499 for section 4.2 and of 2403.02694 for sections I and III-A1) and the ACL Anthology (2022.acl-long.577, 2024.eacl-long.95) on 11 November 2026.