SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2311.04934 · 2023

Prompt Cache: Modular Attention Reuse for Low-Latency Inference

arXiv · PDF · Open in the Atlas

Code that ran

9 of 10 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 2 honoured the contract we drafted, 0 violated it and 1 has no contract verdict; 6 failures of our instrument; 1 no recorded run), measured 2026-11-23; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2311.04934.json · badge: /api/ran/2311.04934.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
yale-sys/prompt-cache canonical (classifier label)
classifier basis: census
9 ran · 1 no recorded run
FunctionStatusWhere it lives
apply_preproc Ran
ran; our contract draft was wrong, not the code
yale-sys/prompt-cache/promptcache/prompt.py
code served (permissive licence) · get_code("7e051b7017cf1d33")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
from abc import ABC, abstractmethod
from typing import List

class Preprocessor(ABC):
    """This class is used to preprocess the prompt before it is passed to the model."""

    def __init__(self):
        pass

    def __call__(self, prompt: str) -> str:
        raise NotImplementedError

class LowercasePreprocessor(Preprocessor):
    """Converts text to lowercase."""
    def __call__(self, prompt: str) -> str:
        return prompt.lower()

class StripPreprocessor(Preprocessor):
    """Strips whitespace from text."""
    def __call__(self, prompt: str) -> str:
        return prompt.strip()

class ReplacePreprocessor(Preprocessor):
    """Replaces specific substrings."""
    def __call__(self, prompt: str) -> str:
        return prompt.replace("hello", "hi")

def apply_preproc(text: str, preprocessors: List[Preprocessor]=None) -> str:
    if preprocessors is not None:
        for p in preprocessors:
            text = p(text)
    return text

ARGS = {
    "text": "  Hello World  ",
    "preprocessors": [
        StripPreprocessor(),
        LowercasePreprocessor(),
        ReplacePreprocessor()
    ]
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
count_score Ran
ran, honoured the contract we drafted
yale-sys/prompt-cache/metrics.py
pointer only (licence: MIT); the stored copy get_code serves, from borealisai/radar-decoding, is pointer only (licence: LGPL-3.0) · get_code("b349b79d9cc2934b")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from borealisai/radar-decoding, and LGPL-3.0, as GitHub detects it on that repository, is not in the permissive set Syntology serves inline. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

escape_tags Ran
ran; our contract draft was wrong, not the code
yale-sys/prompt-cache/benchmark/longbench.py
code served (permissive licence) · get_code("49917353ded2c92d")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

def escape_tags(input_str):
    return input_str.replace('<', '(').replace('>', ')')

ARGS = {
    'input_str': '<hello>world<test>'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
normalize_answer Ran
ran; our contract draft was wrong, not the code
yale-sys/prompt-cache/metrics.py
pointer only (licence: MIT); the stored copy get_code serves, from borealisai/radar-decoding, is pointer only (licence: LGPL-3.0) · get_code("e7e75981cb464788")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from borealisai/radar-decoding, and LGPL-3.0, as GitHub detects it on that repository, is not in the permissive set Syntology serves inline. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

normalize_zh_answer Ran
ran; our contract draft was wrong, not the code
yale-sys/prompt-cache/metrics.py
pointer only (licence: MIT); the stored copy get_code serves, from borealisai/radar-decoding, is pointer only (licence: LGPL-3.0) · get_code("8c5c581f9264c810")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from borealisai/radar-decoding, and LGPL-3.0, as GitHub detects it on that repository, is not in the permissive set Syntology serves inline. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

pad_batch Ran
ran, honoured the contract we drafted
yale-sys/prompt-cache/promptcache/cache_engine.py
code served (permissive licence) · get_code("40430244e49148ca")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple, ndim 3, dtype family int; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np
from typing import List

torch.manual_seed(0)

# Construct arguments for pad_batch function
# batch_list: List[List[int]] - a list of sequences with different lengths
# pad_id: int - the padding token id

batch_list = [
    [1, 2, 3],
    [4, 5],
    [6, 7, 8, 9]
]

pad_id = 0

ARGS = {
    "batch_list": batch_list,
    "pad_id": pad_id
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 3, dtype family int — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
pad_unk Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
yale-sys/prompt-cache/promptcache/cache_engine.py
code served (permissive licence) · get_code("cf63debf81bfcf82")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple, ndim 2, dtype family int; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np

# The function pad_unk takes three parameters:
# - position_ids: List[int] - a list of position indices
# - token_ids: List[int] - a list of token IDs corresponding to the positions
# - unk_token_id: int - the unknown token ID to use for padding

# Looking at the function body:
# - It finds min and max of position_ids
# - Creates a continuous range from pos_min to pos_max
# - Creates padded_token_ids filled with unk_token_id
# - Fills in the actual token_ids at their positions

# Example with a gap: positions [0, 2, 4] with tokens [10, 11, 12]
# Should produce positions [0, 1, 2, 3, 4] with tokens [10, unk, 11, unk, 12]

ARGS = {
    "position_ids": [0, 2, 4],
    "token_ids": [10, 11, 12],
    "unk_token_id": 0
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 2, dtype family int — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
read_file Ran
ran on a synthesized input
yale-sys/prompt-cache/promptcache/prompt.py
code served (permissive licence) · get_code("09ee7b4dcf62d65d")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import tempfile
import os
from abc import ABC, abstractmethod
from typing import List

class Preprocessor(ABC):
    """This class is used to preprocess the prompt before it is passed to the model."""

    def __init__(self):
        pass

    @abstractmethod
    def __call__(self, prompt: str) -> str:
        raise NotImplementedError

class UppercasePreprocessor(Preprocessor):
    def __call__(self, prompt: str) -> str:
        return prompt.upper()

class StripPreprocessor(Preprocessor):
    def __call__(self, prompt: str) -> str:
        return prompt.strip()

# Create a temporary file with some text content
temp_file = tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.txt')
temp_file.write("  hello world  ")
temp_file.close()

# Create preprocessor instances
preprocessors = [StripPreprocessor(), UppercasePreprocessor()]

# Define ARGS dict
ARGS = {
    "filename": temp_file.name,
    "preprocessors": preprocessors
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
repr_indent Ran
ran; our contract draft was wrong, not the code
yale-sys/prompt-cache/promptcache/prompt.py
code served (permissive licence) · get_code("f116e06442e915d7")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np

torch.manual_seed(0)

class CustomObject:
    def __repr__(self):
        return "CustomObject(\n  attr1=value1,\n  attr2=value2\n)"

# Create a simple object with multi-line repr
obj = CustomObject()

# Define arguments for repr_indent
ARGS = {
    "obj": obj,
    "indent": 2
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
create_cache Not yet run
unverified (harvested, no recorded run)
yale-sys/prompt-cache/benchmark_memcpy.py
code served (permissive licence) · get_code("45ead9ded0be27ea")
How it ran

no invocation recorded.

Also present in other papers' code

Of 10 samples lifted from this paper's linked repositories, 10 carry a function identity and 0 do not. Of the 10 distinct functions with an identity, 3 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 3 the same month, 3 later) and 7 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
normalize_answer 133 other papers
51 dated earlier, 3 the same month, 77 later, 1 same year, order not determinable, 1 undated · 1 only as an assembly brick
1508.06615 (2015-08)
Character-Aware Neural Language Models
1606.05250 (2016-06)
SQuAD: 100,000+ Questions for Machine Comprehension of Text
1608.07905 (2016-08)
Machine Comprehension Using Match-LSTM and Answer Pointer
and 130 more not named here
normalize_zh_answer 28 other papers
1 the same month, 26 later, 1 undated
2311.09198 (2023-11)
Never Lost in the Middle: Mastering Long-Context Question Answering with Position-Agnostic Decompositional Training
2024.findings-emnlp.230 (2024 (year only))
CLongEval: A Chinese Benchmark for Evaluating Long-Context Large Language Models
2402.02750 (2024-02)
KIVI: A Tuning-Free Asymmetric 2bit Quantization for KV Cache
and 25 more not named here
count_score 24 other papers
1 the same month, 22 later, 1 undated
2311.09198 (2023-11)
Never Lost in the Middle: Mastering Long-Context Question Answering with Position-Agnostic Decompositional Training
2402.02750 (2024-02)
KIVI: A Tuning-Free Asymmetric 2bit Quantization for KV Cache
2402.04617 (2024-02)
InfLLM: Training-Free Long-Context Extrapolation for LLMs with an Efficient Context Memory
and 21 more not named here

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

We present Prompt Cache, an approach for accelerating inference for large language models (LLM) by reusing attention states across different LLM prompts. Many input prompts have overlapping text segments, such as system messages, prompt templates, and documents provided for context. Our key insight is that by precomputing and storing the attention states of these frequently occurring text segments on the inference server, we can efficiently reuse them when these segments appear in user prompts. Prompt Cache employs a schema to explicitly define such reusable text segments, called prompt modules. The schema ensures positional accuracy during attention state reuse and provides users with an interface to access cached states in their prompt. Using a prototype implementation, we evaluate Prompt Cache across several LLMs. We show that Prompt Cache significantly reduce latency in time-to-first-token, especially for longer prompts such as document-based question answering and recommendations. The improvements range from 8x for GPU-based inference to 60x for CPU-based inference, all while maintaining output accuracy and without the need for model parameter modifications.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2311.04934")
get_code_for_paper("2311.04934")
have("2311.04934")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2311.04934.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2311.04934.svg)](https://syntology.ai/paper/2311.04934)

Connect an agent — have() is free.