Skip to content

Latest commit

 

History

History
122 lines (83 loc) · 7.77 KB

usage.md

File metadata and controls

122 lines (83 loc) · 7.77 KB

Installation and evaluation

Project overview · Experiment results

LoopZip is a training-free visual token compression method for looped vision-language models. It constructs a compact visual candidate pool, observes the same shared attention layer twice, and jointly fits a value correction before later calls use the shorter sequence.

Supported models and engines

Model Transformers vLLM SGLang
LoopVL-1B ✓ ✓ ✓
SenseNova-Loop-9B-Preview ✓

The vLLM and SGLang entries use the respective engine for scheduling and generation, with separate recurrent KV slots and model-specific native attention. They run one request at a time on one CUDA GPU. vLLM uses FlashAttention-2 prefill and Triton paged decoding. SGLang uses FlashInfer and the RadixAttention interface. The worker captures a fused CUDA graph for recurrent decoding. The paper's efficiency harness also fixed input shapes and applied allocation controls. These general inference entry points capture a fresh graph for each request.

All eleven benchmark splits in the paper have a manifest and scoring interface. The Transformers path supports both backbones on these inputs. The serving integrations take the same manifests when using LoopVL-1B.

Install

Use Linux, Python 3.11 or 3.12, and an NVIDIA GPU with a driver compatible with the installed PyTorch build. Create a separate virtual environment per engine so each can use its required Torch/CUDA wheels.

Transformers

python -m venv .venv-hf
source .venv-hf/bin/activate
python -m pip install --upgrade pip
# Example for a driver that supports CUDA 13.0:
python -m pip install --index-url https://download.pytorch.org/whl/cu130 torch==2.12.1 torchvision==0.27.1
python -m pip install -e '.[transformers,prepare]'
python -m loopzip list

The paper's LoopVL Transformers environment used PyTorch 2.12.1 and Transformers 5.15.1. The SenseNova adapter uses Transformers' Qwen3.5 implementation and the model snapshot's own recurrent model code. The SenseNova sampling experiment used Transformers 5.18.0. With both snapshots, install a release that includes the HRM Text and Qwen3.5 model modules.

vLLM

python -m venv .venv-vllm
source .venv-vllm/bin/activate
python -m pip install --upgrade pip
python -m pip install 'vllm==0.24.0' 'transformers==5.15.1' accelerate
python -m pip install -e '.[prepare]'

SGLang

python -m venv .venv-sglang
source .venv-sglang/bin/activate
python -m pip install --upgrade pip
python -m pip install 'sglang==0.5.10.post1'
# The SGLang wheel pins an older Transformers version than LoopVL requires.
# Use the newer HRM Text-capable version in this isolated environment.
python -m pip install 'transformers==5.15.1' accelerate
python -m pip install -e '.[prepare]'

The serving integrations target the engine versions above. Install each engine's matched CUDA wheels and libraries before choosing a backend. The SGLang environment deliberately overrides its declared Transformers pin for the custom model.

Checkpoints

Use a local copy of the public snapshot. The model IDs on the model hub are TierFlow/LoopVL and sensenova/SenseNova-Loop-9B-Preview. Obtain the complete snapshots and follow their respective license and access terms.

hf download TierFlow/LoopVL --local-dir models/loopvl
hf download sensenova/SenseNova-Loop-9B-Preview --local-dir models/sensenova

The LoopVL loader expects the single-file checkpoint model.safetensors and its tokenizer and preprocessing metadata. The SenseNova loader expects the released sharded checkpoint, processor, chat template, and snapshot modeling code. Its loader runs the Python model file from the supplied local snapshot, so use a snapshot you trust. Keep the original precision and checkpoint config.

Predict

loopzip predict --model loopvl --snapshot models/loopvl \
  --backend transformers --image path/to/image.png --prompt 'What is shown?' \
  --pruning-ratio 0.875 --max-new-tokens 32

loopzip predict --model sensenova --snapshot models/sensenova \
  --image path/to/image.png --prompt 'Answer with the number in the image.' \
  --pruning-ratio 0.75 --max-new-tokens 1024

For a serving run, use the LoopVL command in the corresponding environment and set --backend vllm or --backend sglang. Select a physical GPU with CUDA_VISIBLE_DEVICES before starting the process. Python users can import load_pipeline from loopzip.pipeline.

--pruning-ratio refers to the target average visual-query reduction over the prefill layer calls. The default candidate-pool dominant fraction is 0.85, the instruction-query cap is 8, and the ridge coefficient is 0.0001. Greedy decoding is the default. --temperature 0.5 --top-p 0.95 --seed 5 selects a single reproducible sampling run. --ignore-eos lets you generate a fixed token budget for timing.

Evaluate datasets

The available split names are MMStar, RealWorldQA, VMCBench_DEV, AI2D_TEST, ChartQA_TEST, HRBench4K, POPE, HallusionBench, MMMU-Pro, MathVision, and LogicVista. Obtain the splits from their public providers. To use VLMEvalKit's optional dataset loaders, install open-compass/VLMEvalKit in a preparation environment, then install this package with python -m pip install -e '.[prepare]' in that environment. The inference environments read the resulting manifests directly.

loopzip prepare --model loopvl --dataset MMStar --output data/MMStar.jsonl

loopzip evaluate --model loopvl --snapshot models/loopvl \
  --manifest data/MMStar.jsonl --output outputs/mmstar.jsonl --pruning-ratio 0.875

loopzip score --dataset MMStar --manifest data/MMStar.jsonl --predictions outputs/mmstar.jsonl

For the official HRBench4K parquet, use loopzip prepare --dataset HRBench4K --hrbench-parquet path/to/hr_bench_4k.parquet --output data/HRBench4K.jsonl. This preserves all four option orders and writes the images alongside the manifest.

You can also prepare a manifest from local datasets or cached prompts. This is useful for versioned splits, custom resolutions, or exact per-item budgets.

{"id":"example-1","index":"example-1","prompt":"Which label appears in the image? Answer with A or B.\nA. Red\nB. Blue","images":["sample.png"],"reference":"A","options":{"A":"Red","B":"Blue"},"budget":32,"metadata":{}}

Use one JSON object per line. --image-root resolves relative image paths. Multi-image records are tiled in manifest order. For HRBench4K, put each of the four option orders in a separate row with its own id, remapped reference, and options. Use metadata.category for POPE's comma-separated category memberships and the original index plus metadata.l2-category for HallusionBench. SenseNova supports per-item min_pixels and budget. Both models accept a per-item max_visual_tokens cap.

The paper uses 800 HRBench4K rows (200 questions × four orders), 5,127 unique POPE predictions pooled over category memberships, and model-specific generation limits. Public exports can differ in paths, prompts, option orders, and per-item budgets. Use the exact manifests when comparing against an existing paper score. The score command prints the row count and checks that each manifest row has one prediction.

ChartQA scores use relaxed accuracy; POPE reports pooled F1; HallusionBench reports the mean of aAcc, fAcc, and qAcc; other splits report percentage accuracy. To split a run across GPUs use --shard 0/4, --shard 1/4, and so on, with separate output files. Concatenate disjoint JSONL outputs before scoring. Repeating an evaluate command resumes its output when the recorded settings match.

Development

python -m unittest discover -s tests -v
python -m loopzip --help

The project license is Apache-2.0. See third-party notices for the model adapters and scoring helpers.