dayuwang401/SCR-VL
Machine LearningResearch code that reuses KV cache after mid-context edits in video LLMs, cutting cache rebuild time for Qwen-VL models.
What it does
SCR-VL accompanies the paper Editable Video Context: Mid-Context KV-Cache Reuse for Context-Managing Video LLMs (arXiv 2611.18718, paper PDF). A long video is kept as timestamped segments; the model names the segments it needs, those are re-decoded at 4x frame rate, and the others are deleted. Normally, editing the middle of the context forces recomputation of everything after the first changed token. SCR-VL avoids that for video LLMs with M-RoPE: when a segment moves as a whole, its temporal, height and width positions shift by the same offset, so a single rotation of cached keys relocates it exactly at layer 0 in bf16. A content-hashed cache of vision-encoder outputs additionally skips ViT work for surviving segments.
It targets Qwen2.5-VL-7B and Qwen3-VL-8B (Instruct and Thinking), and passes correctness tests on Qwen3-VL-30B-A3B (MoE). On Qwen2.5-VL-7B the reported rebuild is 1.7–1.8x faster than full recomputation with 96–97% answer agreement, saving roughly 30% of prefill tokens (summary numbers).
Setup and correctness check
Requirements: Python 3.10, PyTorch 2.7 CUDA 12.6 wheels, and one 80 GB GPU for the 7–8B models. Two virtual environments are needed because Qwen2.5-VL and Qwen3-VL require different transformers versions.
git clone https://github.com/dayuwang401/SCR-VL && cd SCR-VL
python3.10 -m venv .venvs/vctx && .venvs/vctx/bin/pip install -r env/requirements_vctx.txt
python3.10 -m venv .venvs/vctx3 && .venvs/vctx3/bin/pip install -r env/requirements_vctx3.txt
Download weights into models/ or point VCTX_MODELS elsewhere, then source the matching env script (env.sh, env3.sh, env3t.sh, env3moe.sh) to set the interpreter, model and cuDNN path. Run the GPU correctness tests before experiments:
source env.sh; CUDA_VISIBLE_DEVICES=0 $PY -m pytest -q tests
source env3.sh; CUDA_VISIBLE_DEVICES=0 $PY -m pytest -q tests/test_correctness.py
The tests check per-segment position consistency, layer-0 key exactness after rotation, no-edit equivalence and prefix exactness; results go to results/test_numbers*.json. Then build data under data/ and run an experiment, for example the V-NIAH set:
source env.sh
$PY scripts/run_vniah.py --shard 0 --num-shards 1 --n-per-cell 80 --tag vniah
Every script resumes by skipping questions already in results/<tag>_shard*.jsonl and supports GPU sharding with --shard and --num-shards. bash scripts/build_paper.sh regenerates tables, figures and the PDF from the results.
Data and benchmark harness
No video is redistributed. V-NIAH haystacks are built from three public-domain Internet Archive films, decoded to 2 fps frame banks with scripts/build_bank.py; the needle cards and questions are generated deterministically from seed 0. Video-MME long uses the first 60 long videos from lmms-lab/Video-MME for academic research; LongVideoBench is gated on Hugging Face and requires accepting terms and setting HF_TOKEN. Each source keeps its own license.
python -m vctx.cli exposes a two-track harness: the edit track evaluates context-edit policies with the rebuild frozen, and the infra track evaluates KV rebuilders with the edit frozen. New policies register under vctx/edit/policies/; new rebuild algorithms register in vctx/infra/contrib.py. The infra evaluation guide and harness rules describe the frozen splits and evaluation protocol.
Constraints
An 80 GB GPU is required for the 7–8B models, and Qwen2.5-VL and Qwen3-VL cannot share one environment. Per-question records are not released because they contain benchmark questions and answers. Code is Apache-2.0, but datasets and weights carry their own licenses. The project reports honest negative results in the paper: densifying the needle-containing segment raises V-NIAH accuracy more than the model's own segment choice.
HotRepo's take
The repository appeared on the HotRepo new-project list for Python on 2026-11-28, adding 5 stars in its first recorded hourly window and reaching 106 stars shortly after. That is a small sample with no daily all-language rank, so it says little about broader traction. The more substantive signal is packaging: a reproducible pipeline where every table and figure is generated from results/summary.csv, plus a benchmark harness with frozen splits and registry-based extension points for both edit policies and rebuild algorithms. For a research repository, that combination is what makes the results checkable and extensible beyond the paper's own models.
Written by AI from the project's public information and HotRepo's records, updated . The project's own docs are the source of truth.