RegCache is a CLIP vision-encoder pipeline for register-token prefix caching and token deletion. The public code path focuses on ImageNet classification with three baselines:
naiveptq4vitrepqvit
Other internal baselines are intentionally not part of the public workflow.
- CLIP register candidate extraction
- Top-100 prefix averaging
- Quantization-sensitive block search
- Target-block search over
max(0, k-3)..k - Prefix-count and token-delete-count search
- Final ImageNet classification evaluation
- Optional PTQ4ViT and RepQ-ViT calibration paths
src/open_clip: OpenCLIP model code used by RegCachesrc/open_clip_train/main_RegCache.py: main RegCache entrypointmodels/clip_find_prefix_by_target_block.py: prefix candidate extraction modulesmodels/clip_sweep_config_delete_directly.py: prefix injection, token deletion, and quantized CLIP modulesmodels/custom_utils/sweep_avg.py: prefix cache application utilitiesscripts/run_clip_regcache_pipeline.sh: full end-to-end CLIP RegCache pipelinescripts/eval/classification/clip.sh: classification evaluation launcherscripts/extract_register_candidates/clip.sh: prefix extraction launcherscripts/search_regcache/clip.sh: prefix and delete-count search launcher
conda env create -f environment.yml
conda activate regcacheThe launcher scripts default to the active environment's Python:
pythonOverride it when needed:
PYTHON=/path/to/python bash scripts/eval/classification/clip.shThe scripts set PYTHONPATH internally. For manual python -m ... commands, run:
export PYTHONPATH=/path/to/RegCache/srcExpected datasets:
- ImageNet validation set
- ImageNet train-sample set for prefix extraction and search
- Optional calibration set for PTQ4ViT and RepQ-ViT
Set dataset paths with environment variables:
export DATA_ROOT=/path/to/imagenet
export IMAGENET_VAL=${DATA_ROOT}/val
export TRAIN_SAMPLE=${DATA_ROOT}/train_sample_50_per_class
export CALIB=${DATA_ROOT}/1024calib_train
export COCO_DATA_ROOT=/path/to/cocoOverride any path per command when needed.
Run the full RegCache pipeline:
bash scripts/run_clip_regcache_pipeline.shRun a specific baseline:
BASELINE=naive bash scripts/run_clip_regcache_pipeline.sh
BASELINE=ptq4vit bash scripts/run_clip_regcache_pipeline.sh
BASELINE=repqvit bash scripts/run_clip_regcache_pipeline.shThe pipeline performs:
- Quantization-sensitive block search
- Prefix-extraction block search
- Prefix candidate extraction
- Top-100 prefix averaging
- Prefix-count and token-delete-count search
- Final ImageNet classification evaluation
The final output prints:
- quantization-sensitive block
k - quantization-sensitive layer
- prefix-extraction block candidates
- selected prefix-extraction block
- selected prefix-add blocks
- selected prefix token count
- selected token-delete block
- selected token-delete count
- search accuracy
- final result CSV path
Run classification evaluation directly:
BASELINE=naive bash scripts/eval/classification/clip.sh
BASELINE=ptq4vit bash scripts/eval/classification/clip.sh
BASELINE=repqvit bash scripts/eval/classification/clip.shRun MS-COCO retrieval evaluation:
BASELINE=naive bash scripts/eval/retrieval/clip.shOnly these baselines are supported in the public entrypoint:
naiveptq4vitrepqvit
Passing any other baseline to main_RegCache.py raises an error.
Generated outputs, checkpoints, cached prefixes, logs, and calibration tensors should stay out of Git. The .gitignore excludes:
clip_global_prefix*result*checkpoint*logs*.pt*.pth*.log*.csv__pycache__
This repository builds on OpenCLIP, PTQ4ViT, and RepQ-ViT. Cite the original projects together with RegCache when using this code.
See LICENSE.