Reduce token count by 15-40% at inference through context-adaptive compression, merging frequent token sequences into hypertokens using online Lempel-Ziv-Welch compression without retraining entire models.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
Reduce token count by 15-40% at inference through context-adaptive compression, merging frequent token sequences into hypertokens using online Lempel-Ziv-Welch compression without retraining entire models.
zip2zip: Inference-Time Adaptive Vocabularies for Language Models via Token Compression
Core Concept
zip2zip addresses the inefficiency of static, general-purpose tokenizers in language models. Rather than using a fixed vocabulary optimized for average cases, zip2zip dynamically adapts tokenization at inference time by identifying and merging frequently co-occurring token sequences into compact "hypertokens."
The approach uses Lempel-Ziv-Welch (LZW) compression on-the-fly to detect compression patterns in the current context and create hypertokens that match the input's actual token distribution. A lightweight dynamic embedding layer computes representations for newly formed hypertokens at runtime, reducing both input and output token counts by 15-40% without full model retraining.
Architecture Overview
Online LZW Compression: Dynamically identify and merge frequent token sequences during inference
Hypertokenization: Replace multiple fragmented tokens with single merged tokens
Dynamic Embedding Layer: Compute embeddings for novel hypertokens without precomputed vocabulary
Context-Adaptive Encoding: Adjust compression strategy to match current input distribution
Minimal Retraining: Fine-tune embedding layer in ~10 GPU-hours; preserve base model weights
Seamless Integration: Works with existing LLM architectures (Transformers, etc.)
Implementation
The following steps outline how to implement adaptive tokenization via online compression:
Monitor token stream - Track input tokens as they arrive during inference
Context switching: Compression patterns valid for one domain may not transfer; reset dictionaries for new domains
Embedding quality: Poor dynamic embedding training reduces hypertoken representation quality
Latency overhead: Compression computation can exceed savings from fewer tokens; profile carefully
Reference
zip2zip demonstrates 15-40% token reduction across diverse models and domains, with particularly strong gains on repetitive inputs. The fine-tuning requirement is minimal (approximately 10 GPU-hours), making it practical to deploy on existing models.
Original paper: "zip2zip: Inference-Time Adaptive Vocabularies for Language Models via Token Compression" (arxiv.org/abs/2506.01084)