SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2502.17599 · NAACL · 2025

MEDA: Dynamic KV Cache Allocation for Efficient Multimodal Long-Context Inference

Mi Zhang, Xin Wang, Zhongwei Wan, Che Liu, Zheda Mai, Hui Shen

arXiv · PDF · Open in the Atlas

Code that ran

3 of 5 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (1 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 0 violated it and 1 has no contract verdict; 1 failure of our instrument; 2 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/2502.17599.json · badge: /api/ran/2502.17599.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
aiot-mlsys-lab/meda marked official in Papers with Code
Papers with Code archive
3 ran · 2 no recorded run
FunctionStatusWhere it lives
LlamaConfig Ran
ran on a synthesized input · constructed an object; no result was computed
aiot-mlsys-lab/meda/Dynamic-MLLMs/LLaVA-mix_merge_v1/llava/model/kv_token_merge/modify_llama.py
code served (permissive licence) · get_code("2e14541ab89507cc")
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 an instance of its own class, LlamaConfig: the run constructed the object and did not call it, so no result was computed. 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 torch.nn as nn

torch.manual_seed(0)

ARGS = {
    "vocab_size": 32000,
    "hidden_size": 4096,
    "intermediate_size": 11008,
    "num_hidden_layers": 32,
    "num_attention_heads": 32,
    "num_key_value_heads": 32,
    "hidden_act": "silu",
    "max_position_embeddings": 2048,
    "initializer_range": 0.02,
    "rms_norm_eps": 1e-6,
    "use_cache": True,
    "pad_token_id": 0,
    "bos_token_id": 1,
    "eos_token_id": 2,
    "pretraining_tp": 1,
    "tie_word_embeddings": False,
    "rope_theta": 10000.0,
    "rope_scaling": None,
    "attention_bias": False,
    "attention_dropout": 0.0,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, transformers — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type LlamaConfig — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a LlamaConfig 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
_make_causal_mask Ran
ran, honoured the contract we drafted
aiot-mlsys-lab/meda/Dynamic-MLLMs/LLaVA-mix_merge_v1/llava/model/kv_token_merge/modify_llama.py
code served (permissive licence) · get_code("f3114ee33d500c6c")
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 4, dtype family float, shape (2, 1, 3, 7) 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)

ARGS = {
    "bsz": 2,
    "tgt_len": 3,
    "past_key_values_length": 4,
    "dtype": torch.float32,
    "device": torch.device("cpu"),
}
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 4, dtype family float, shape (2, 1, 3, 7) — shape (2, 1, 3, 7) 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_single Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
aiot-mlsys-lab/meda/Dynamic-MLLMs/LLaVA-mix_merge_v1/llava/model/kv_token_merge/modify_llama.py
code served (permissive licence) · get_code("c0fa64892f2fc8ee")
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 3, dtype family float, shape (2, 5, 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)

# Analyze the function:
# - x: tensor that gets multiplied by cos and sin, needs shape (..., hidden_dim)
# - cos: tensor that gets squeezed twice then indexed by position_ids, needs shape (1, 1, seq_len, hidden_dim)
# - sin: tensor that gets squeezed twice then indexed by position_ids, needs shape (1, 1, seq_len, hidden_dim)
# - position_ids: indices into cos/sin, shape (batch_size,)

batch_size = 2
seq_len = 5
hidden_dim = 4

# x: shape (batch, seq, hidden_dim)
x = torch.randn(batch_size, seq_len, hidden_dim)

# cos: shape (1, 1, seq_len, hidden_dim)
cos = torch.randn(1, 1, seq_len, hidden_dim)

# sin: shape (1, 1, seq_len, hidden_dim)
sin = torch.randn(1, 1, seq_len, hidden_dim)

# position_ids: indices to select from the seq_len dimension
position_ids = torch.tensor([0, 2])

ARGS = {
    "x": x,
    "cos": cos,
    "sin": sin,
    "position_ids": position_ids,
}
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 3, dtype family float, shape (2, 5, 4) — shape (2, 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
AttnEntropyTextPivotMerge_LayerWise Not yet run
unverified (harvested, no recorded run)
aiot-mlsys-lab/meda/Dynamic-MLLMs/LLaVA-mix_merge_v1/llava/model/kv_token_merge/modify_llama.py
code served (permissive licence) · get_code("46067e9c33ae2a58")
How it ran

no invocation recorded.

DynamicLlamaAttention_drop Not yet run
unverified (harvested, no recorded run)
aiot-mlsys-lab/meda/Dynamic-MLLMs/LLaVA-mix_merge_v1/llava/model/kv_token_merge/modify_llama.py
code served (permissive licence) · get_code("c11c5eb9ee9537da")
How it ran

no invocation recorded.

Also present in other papers' code

Of 5 samples lifted from this paper's linked repositories, 5 carry a function identity and 0 do not. Of the 5 distinct functions with an identity, 1 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 1 later) and 4 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
apply_rotary_pos_emb_single
brick of this paper's assembly: helper
3 other papers
2 dated earlier, 1 later
2405.12528 (2024-05)
SirLLM: Streaming Infinite Retentive LLM
2406.12018 (2024-06)
CItruS : Chunked Instruction-aware State Eviction for Long Sequence Modeling
2603.04759 (2026-03)
Stacked from One: Multi-Scale Self-Injection for Context Window Extension

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

Long-context Multimodal Large Language Models (MLLMs) that incorporate long textimage and text-video modalities, demand substantial resources as their multimodal Key-Value (KV) caches grow with increasing input lengths, challenging inference efficiency. Existing methods for KV cache compression, in both text-only and multimodal LLMs, have neglected attention density variations across layers, thus often adopting uniform or progressive reduction strategies for layer-wise cache allocation. In this work, we propose MEDA, a dynamic layer-wise KV cache allocation method for efficient multimodal long-context inference. As its core, MEDA utilizes cross-modal attention entropy to determine the KV cache size at each MLLMs layer. Given the dynamically allocated KV cache size at each layer, MEDA also employs a KV pair selection scheme to identify which KV pairs to select and a KV pair merging strategy that merges the selected and non-selected ones to preserve information from the entire context. MEDA achieves up to 72% KV cache memory reduction and 2.82 times faster decoding speed, while maintaining or enhancing performance on various multimodal tasks in long-context settings, including multi-images and long-video scenarios. Our code is released at https://github.com/ AIoT-MLSys-Lab/MEDA.

For agents

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

get_harvested_code_for_paper("2502.17599")
get_code_for_paper("2502.17599")
have("2502.17599")

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

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

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

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

Connect an agent — have() is free.