SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2312.03414 · ICLR · 2024

Compressed Context Memory For Online Language Model Interaction

Sangdoo Yun, Jang-Hyun Kim, Hyun Song, Junyoung Yeom

arXiv · PDF · Open in the Atlas

Code that ran

9 of 13 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; 0 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 9 failures of our instrument; 4 no recorded run); 1 of them was also run on the host, not in the jail, by the peer-agreement lane that set its level, measured 2026-11-21; 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/2312.03414.json · badge: /api/ran/2312.03414.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
snu-mllab/context-memory canonical (classifier label)
classifier basis: census
9 ran · 4 no recorded run
FunctionStatusWhere it lives
repeat_kv Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
snu-mllab/context-memory/src/arch/ccm_mistral.py
code served (permissive licence) · get_code("30d7eec482ebf6b1")
How it ran

Ran in Syntology's jail on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned Tensor, ndim 4, dtype family float, shape (2, 6, 5, 4) as a later run recorded it. The image it ran in was not recorded. The comparison behind this sample's level is a different run: the peer-agreement lane ran it again on the host, not in the jail (report dated 2026-09-04T23:09:20Z). If your copy returns the same type, ndim and shape 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

torch.manual_seed(0)

# Create a tensor with shape (batch, num_key_value_heads, seqlen, head_dim)
# Using distinct sizes: batch=2, num_key_value_heads=3, seqlen=5, head_dim=4
hidden_states = torch.randn(2, 3, 5, 4)

# n_rep is the repetition factor
n_rep = 2

ARGS = {
    "hidden_states": hidden_states,
    "n_rep": n_rep,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 4, dtype family float, shape (2, 6, 5, 4) — shape (2, 6, 5, 4) as a later run recorded it
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
apply_rotary_pos_emb Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
snu-mllab/context-memory/src/arch/ccm_mistral.py
code served (permissive licence) · get_code("d61c483a3c2b3156")
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) and returned tuple, ndim 5, dtype family float; 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

torch.manual_seed(0)

# Construct tiny tensors for the function
batch_size = 2
seq_len = 3
num_heads = 4
head_dim = 8

# Query and key tensors: [batch_size, num_heads, seq_len, head_dim]
q = torch.randn(batch_size, num_heads, seq_len, head_dim)
k = torch.randn(batch_size, num_heads, seq_len, head_dim)

# Cosine and sine embeddings: [seq_len, head_dim]
# These will be indexed by position_ids
cos = torch.randn(seq_len, head_dim)
sin = torch.randn(seq_len, head_dim)

# Position IDs: [batch_size, seq_len]
position_ids = torch.tensor([[0, 1, 2], [0, 1, 2]], dtype=torch.long)

# unsqueeze_dim parameter
unsqueeze_dim = 1

ARGS = {
    "q": q,
    "k": k,
    "cos": cos,
    "sin": sin,
    "position_ids": position_ids,
    "unsqueeze_dim": unsqueeze_dim,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 5, dtype family float — 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
first_mismatch Ran
ran; our contract draft was wrong, not the code
snu-mllab/context-memory/src/utils.py
code served (permissive licence) · get_code("5695c3c3dfeb3e3f")
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. 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 itertools
from typing import Any, List

torch.manual_seed(0)

# Construct two lists with some matching and one mismatching element
list_a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "mismatch_a", 12, 13, 14, 15]
list_b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "mismatch_b", 12, 13, 14, 15]

ARGS = {
    "a": list_a,
    "b": list_b,
    "window": 10
}
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 tuple — a tuple output has no array shape of its own; none is 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
map_config Ran
ran; our contract draft was wrong, not the code
snu-mllab/context-memory/path_config.py
code served (permissive licence) · get_code("14c6ecb20ee83621")
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

def map_config(model_name):
    is_llama = 'llama' in model_name.lower() or 'mistral' in model_name.lower()
    if 'debug' in model_name:
        config = 'llama-debug'
    elif is_llama and '7b' in model_name:
        config = 'llama-7b'
    elif is_llama and '13b' in model_name:
        config = 'llama-13b'
    elif 'flan-t5' in model_name:
        config = model_name
    else:
        raise ValueError(f'Unknown model name: {model_name}')
    return config

# Test with a valid llama-7b model name
ARGS = {
    'model_name': 'llama-7b'
}
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
model_path Ran
ran; our contract draft was wrong, not the code
snu-mllab/context-memory/path_config.py
code served (permissive licence) · get_code("c0d66785e485f1f9")
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 os

LLAMADIR = '/storage/shared/janghyun'

def model_path(model_name):
    if model_name == 'llama-7b':
        path = os.path.join(LLAMADIR, 'llama-7b-hf')
    elif model_name == 'llama-13b':
        path = os.path.join(LLAMADIR, 'llama-13b-hf')
    elif model_name == 'llama-2-7b-chat':
        path = 'meta-llama/Llama-2-7b-chat-hf'
    elif model_name == 'llama-2-13b-chat':
        path = 'meta-llama/Llama-2-13b-chat-hf'
    elif model_name == 'llama-2-7b':
        path = 'meta-llama/Llama-2-7b-hf'
    elif model_name == 'llama-2-13b':
        path = 'meta-llama/Llama-2-13b-hf'
    elif model_name == 'mistral-7b':
        path = 'mistralai/Mistral-7B-v0.1'
    elif model_name == 'mistral-7b-inst':
        path = 'mistralai/Mistral-7B-Instruct-v0.2'
    elif 'flan-t5' in model_name:
        path = f'google/{model_name}'
    elif model_name == 'llama-debug':
        path = 'meta-llama/Llama-2-7b-chat-hf'
    elif model_name == 'mistral-debug':
        path = 'mistralai/Mistral-7B-Instruct-v0.2'
    else:
        raise ValueError(f'Unknown model name: {model_name}')
    return path

ARGS = {
    'model_name': 'llama-7b'
}
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
rotate_half Ran
ran; our contract draft was wrong, not the code
snu-mllab/context-memory/src/arch/ccm_mistral.py
code served (permissive licence) · get_code("b99eea6376d1e212")
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) and returned Tensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape 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

torch.manual_seed(0)

# The function rotate_half takes a single parameter 'x' which is a tensor
# It accesses x.shape[-1] to get the last dimension
# It uses indexing with [..., :] slicing notation
# It calls torch.cat() to concatenate tensors

# Create a small tensor with shape (2, 4) - batch size 2, hidden dim 4
x = torch.randn(2, 4)

ARGS = {
    "x": x
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) as a later run recorded it
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
simple_basename Ran
ran; our contract draft was wrong, not the code
snu-mllab/context-memory/src/arguments.py
pointer only (licence: MIT); the stored copy get_code serves, from sjunhongshen/Tag-LLM, is pointer only (licence: NONE) · get_code("d73f2cdc8a6da456")
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 sjunhongshen/Tag-LLM, and GitHub detected no licence in that repository when it was checked. 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.

transpose Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
snu-mllab/context-memory/src/utils.py
code served (permissive licence) · get_code("8f1a49e9d8b29d83")
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 Tensor, ndim 2, dtype family float, shape (3, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape 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

torch.manual_seed(0)

# The function takes:
# 1. weight: a tensor that has a .T attribute (transpose)
# 2. fan_in_fan_out: a boolean flag

weight = torch.randn(4, 3)  # Small tensor with distinct dimensions
fan_in_fan_out = True  # Boolean flag

ARGS = {
    "weight": weight,
    "fan_in_fan_out": fan_in_fan_out,
}
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 Tensor, ndim 2, dtype family float, shape (3, 4) — shape (3, 4) as a later run recorded it
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
update_position_ids Ran
ran; our contract draft was wrong, not the code
snu-mllab/context-memory/src/arch/ccm_llama.py
code served (permissive licence) · get_code("ec53310b0e0ad465")
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 Tensor, ndim 2, dtype family int, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape 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

torch.manual_seed(0)

# Create small test tensors
batch_size = 2
seq_len = 4

# comp_mask: [batch_size, seq_len] - binary mask indicating compression tokens
comp_mask = torch.tensor([
    [0, 1, 0, 1],
    [1, 0, 0, 1]
], dtype=torch.float32)

# comp_token: list/sequence of compression tokens
comp_token = [101, 102]  # arbitrary token ids, only length matters

# attention_mask: [batch_size, seq_len] - binary mask for valid positions
attention_mask = torch.tensor([
    [1, 1, 1, 0],
    [1, 1, 0, 1]
], dtype=torch.long)

# type_: string parameter
type_ = 'skip'

ARGS = {
    'comp_mask': comp_mask,
    'comp_token': comp_token,
    'attention_mask': attention_mask,
    'type_': type_
}
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 Tensor, ndim 2, dtype family int, shape (2, 4) — shape (2, 4) as a later run recorded it
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
extract_comp_results Not yet run
unverified (harvested, no recorded run)
snu-mllab/context-memory/src/utils.py
code served (permissive licence) · get_code("e1c94faaa4993ea9")
How it ran

no invocation recorded.

get_conditional_lora Not yet run
unverified (harvested, no recorded run)
snu-mllab/context-memory/src/model.py
code served (permissive licence) · get_code("eb6f2ebdeb4cd0ca")
How it ran

no invocation recorded.

get_lora Not yet run
unverified (harvested, no recorded run)
snu-mllab/context-memory/src/model.py
code served (permissive licence) · get_code("6cc12d12ed256c22")
How it ran

no invocation recorded.

get_traininable_state_dict Not yet run
unverified (harvested, no recorded run)
snu-mllab/context-memory/src/model.py
code served (permissive licence) · get_code("ba83723330c0338e")
How it ran

no invocation recorded.

Also present in other papers' code

Of 13 samples lifted from this paper's linked repositories, 13 carry a function identity and 0 do not. Of the 13 distinct functions with an identity, 5 are also present in other papers whose code we hold (4 with at least one paper dated earlier, 3 the same month, 5 later) and 8 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
rotate_half 360 other papers
47 dated earlier, 10 the same month, 300 later, 3 undated · 30 only as an assembly brick
1901.02860 (2019-01)
Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context
2203.08913 (2022-03)
Memorizing Transformers
2302.13971 (2023-02)
LLaMA: Open and Efficient Foundation Language Models
and 357 more not named here
repeat_kv 243 other papers
19 dated earlier, 4 the same month, 218 later, 2 undated · 22 only as an assembly brick
1901.02860 (2019-01)
Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context
2203.08913 (2022-03)
Memorizing Transformers
2305.17888 (2023-05)
LLM-QAT: Data-Free Quantization Aware Training for Large Language Models
and 240 more not named here
apply_rotary_pos_emb 75 other papers
1 dated earlier, 5 the same month, 69 later · 2 only as an assembly brick
2309.11499 (2023-09)
DreamLLM: Synergistic Multimodal Comprehension and Creation
2312.02051 (2023-12)
TimeChat: A Time-sensitive Multimodal Large Language Model for Long Video Understanding
2312.08168 (2023-12)
Chat-Scene: Bridging 3D Scene and Large Language Models with Object Identifiers
and 72 more not named here
transpose 13 other papers
2 dated earlier, 11 later · 9 only as an assembly brick
2106.09685 (2021-06)
LoRA: Low-Rank Adaptation of Large Language Models
2304.08177 (2023-04)
Efficient and Effective Text Encoding for Chinese LLaMA and Alpaca
2024.findings-emnlp.619 (2024 (year only))
MEDCARE: Advancing Medical LLMs through Decoupling Clinical Alignment and Knowledge Aggregation
and 10 more not named here
simple_basename 1 other paper
1 later
2402.05140 (2024-02)
Tag-LLM: Repurposing General-Purpose LLMs for Specialized Domains

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-21.

Repositories linked to this paper

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

Abstract

This paper presents a context key/value compression method for Transformer language models in online scenarios, where the context continually expands. As the context lengthens, the attention process demands increasing memory and computations, which in turn reduces the throughput of the language model. To address this challenge, we propose a compressed context memory system that continually compresses the accumulating attention key/value pairs into a compact memory space, facilitating language model inference in a limited memory space of computing environments. Our compression process involves integrating a lightweight conditional LoRA into the language model's forward pass during inference, without the need for fine-tuning the model's entire set of weights. We achieve efficient training by modeling the recursive compression process as a single parallelized forward computation. Through evaluations on conversation, personalization, and multi-task learning, we demonstrate that our approach achieves the performance level of a full context model with 5× smaller context memory size. We further demonstrate the applicability of our approach in a streaming setting with an unlimited context length, outperforming the sliding window approach. Codes are available at https://github.com/snu-mllab/context-memory.

For agents

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

get_harvested_code_for_paper("2312.03414")
get_code_for_paper("2312.03414")
have("2312.03414")

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

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

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

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

Connect an agent — have() is free.