zip2zip: Inference-Time Adaptive Vocabularies for Language Models via Token Compression
zip2zip enables inference-time adaptive token vocabularies for large language models (LLMs). It allows vocabularies to be dynamically augmented at inference time, leading to reduced decoding steps and faster inference.
News
- 2026-05-03: Evaluation now works with standard lm-evaluation-harness (
pip install lm_eval) — no custom fork needed.
Features
- Dynamic vocabulary adaptation during inference
- LZW-based token compression
- Support for various encoder configurations
- Integration with Hugging Face's transformers library
- Compatible with PEFT (Parameter-Efficient Fine-Tuning) models
Installation
You can install zip2zip using pip:
pip install zip2zip
With evaluation support:
pip install zip2zip[eval]
Or with the lm-eval extra:
pip install zip2zip[eval]
Usage
Same API as Hugging Face
| zip2zip | Corresponding HF class |
|---|---|
| Zip2ZipModel | AutoModelForCausalLM |
| Zip2ZipTokenizer | AutoTokenizer |
| Zip2ZipConfig | AutoConfig |
| Zip2ZipModel.from_pretrained | AutoModelForCausalLM.from_pretrained |
| Zip2ZipTokenizer.from_pretrained | AutoTokenizer.from_pretrained |
| Zip2ZipConfig.from_pretrained | AutoConfig.from_pretrained |
Pretrained model weights
| Size | Model | HF Hub |
|---|---|---|
| 3.8B | Phi-3.5-mini-instruct-v0.1 | epfl-dlab/zip2zip-Phi-3.5-mini-instruct-v0.1 |
| 14B | Llama-3.1-8B-Instruct-v0.1 | epfl-dlab/zip2zip-Phi-3-medium-instruct-v0.1 |
| ... | ... | epfl-dlab/zip2zip-models |
Run a pretrained model
import torch
from zip2zip import Zip2ZipModel, Zip2ZipTokenizer
pretrained_model_url = "epfl-dlab/zip2zip-Phi-3.5-mini-instruct-v0.1"
device = "cuda" if torch.cuda.is_available() else "cpu"
# Initialize tokenizer
tokenizer = Zip2ZipTokenizer.from_pretrained(pretrained_model_url)
# Initialize model
model = Zip2ZipModel.from_pretrained(pretrained_model_url, device_map=device)
# Generate text
inputs = tokenizer("Write a MultiHeadAttention layer in PyTorch", return_tensors="pt").to(device)
outputs = model.generate(**inputs)
# Print the coloried
generated_text = tokenizer.color_decode(outputs)
You can apply quantization to the model to reduce the memory usage just as you would do with HF models.
model = Zip2ZipModel.from_pretrained(pretrained_model_url, device_map="auto", load_in_8bit=True)
Examples
We provide some examples in the examples folder.
Evaluation
We provide a script to evaluate the performance of the model, compatible with lm-evaluation-harness.
pip install lm_eval==0.4.9
Then, you can run the evaluation:
python bench/run_harness_pretrained.py <model_path> --tasks hellaswag piqa winogrande --limit 100
Citation
@misc{geng2025zip2zipinferencetimeadaptivevocabularies,
title={zip2zip: Inference-Time Adaptive Vocabularies for Language Models via Token Compression},
author={Saibo Geng and Nathan Ranchin and Yunzhen yao and Maxime Peyrard and Chris Wendler and Michael Gastpar and Robert West},
year={2025},
eprint={2506.01084},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2506.01084},
}
Metadata
Release files for zip2zip 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| zip2zip-0.2.0.tar.gz | 46.1 kB | Without provenance | Details for zip2zip-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| zip2zip-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for zip2zip-0.2.0-py3-none-any.whl |
Total release size: 93.8 kB
Release files / zip2zip-0.2.0.tar.gz
| Download URL | zip2zip-0.2.0.tar.gz |
|---|---|
| Size | 46.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6c57306daa1750915baa46d3980af3dab08bbccf24c49d06a15ea6d2dbc32bf7
|
|
BLAKE2b-256 checksum How to use checksums |
852e694dac944977db0fe7e467b16ed6bba4b95e3fddb88f6e9e2eceb78a900e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.12
|
Release files / zip2zip-0.2.0-py3-none-any.whl
| Download URL | zip2zip-0.2.0-py3-none-any.whl |
|---|---|
| Size | 47.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e8b39e4955860dd3bb32d9686b42c5c64b9e1a3dc46c5ecd621c8a58e886d877
|
|
BLAKE2b-256 checksum How to use checksums |
4ebbb2631211c7cbe0f97ee917b96fe240dbc3860551408a60e019def1d8f959
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.12
|
Security for zip2zip 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.