economize
Composable efficiency techniques for Hugging Face language models
economize makes text generation with Hugging Face causal language models faster and cheaper. It implements more
than 50 published efficiency techniques, from speculative decoding and early exit to pruning, quantization and
KV-cache compression, and attaches them, alone or in validated combinations, to an unmodified transformers model
with a single function call. economize.compatible tells which techniques combine.
- One interface for many methods. Drafters such as EAGLE-3 and Medusa, dynamic-depth methods, weight compression and KV-cache compression share the same configuration and decoding API.
- Validated combinations. Techniques can be stacked, for example layer pruning, int4 quantization, an fp8 KV cache and a drafter in one model. economize attaches them in a well-defined order and refuses pairs whose kernels do not fit together.
- The base model stays intact. The model keeps its modules and its
forwardmethod, so it continues to work withgenerate, PEFT, the Hugging Face Hub and the rest of the ecosystem. - Fast, lossless decoding. Batches of prompts of different lengths, chains and draft trees, lossless speculative sampling, CUDA graphs and speculative speculative decoding over several GPUs.
- Training and serving. Drafters and other added components train with a built-in loop or with
transformers.Trainer, and export to vLLM and SGLang. - Extensible. New techniques, model families, verifiers and backends are added by registering a class, without changing the library.
Installation
pip install economize
economize requires Python 3.10 or later, PyTorch 2.4 or later and transformers 5.0 or later. The optional
integrations (PEFT, quantization kernels, training, evaluation, vLLM, SGLang) are extras, listed in
Getting started.
Quick start
A published EAGLE-3 head attached to its base model generates exactly the tokens of the base model, only faster:
import torch
import economize
from transformers import AutoModelForCausalLM, AutoTokenizer
base = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.1-8B-Instruct", dtype=torch.bfloat16,
device_map="cuda")
model = economize.load(base, "yuhuili/EAGLE3-LLaMA3.1-Instruct-8B") # a Hub repository or a local folder
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.1-8B-Instruct")
ids = tokenizer("The water cycle describes", return_tensors="pt").input_ids.cuda()
out = model.generate(ids, max_new_tokens=128)
print(tokenizer.decode(out[0]))
Several techniques combine in one call. Techniques that need calibration data receive it through calibration.
The int4 kernels come with pip install "economize[quant]":
from economize.techniques.eagle3 import Eagle3Config
from economize.techniques.kv_quant import FP8KVConfig
from economize.techniques.prune import DepthPruneConfig
from economize.techniques.quant import DraftQuantConfig, QuantConfig
calibration_ids = ids.repeat(4, 1) # a LongTensor [N, S], an iterable of batches or a callable; use real text in practice
model = economize.apply(
base,
DepthPruneConfig(method="shortgpt", num_blocks=4), # four decoder layers removed
QuantConfig(format="int4", method="gptq", group_size=128), # int4 weights
FP8KVConfig(), # an fp8 KV cache
Eagle3Config(), # a drafter, trained with economize.train.fit
DraftQuantConfig(format="int8"), # int8 weights for the drafter
calibration=calibration_ids,
)
The documentation covers installation, decoding options, training, serving, a tutorial for every technique and how to extend the library.
Supported techniques
| Family | Techniques |
|---|---|
| Drafters for speculative decoding | EAGLE-1/2, EAGLE-3, HASS, Medusa, Hydra, ReDrafter, DFlash, early exit and LayerSkip, Kangaroo, static layer skipping (after Draft & Verify and SWIFT), KnapSpec, FREE, DMTD, Hidden Transfer, separate draft models (also on another GPU), PARD, the Gemma-4 MTP assistant, prompt lookup, Lookahead, REST, SuffixDecoding, FR-Spec, MTP heads of DeepSeek-V3, GLM-4.5, MiMo and Qwen3.5, MagicDec and TriForce for long contexts |
| Dynamic depth | CALM, GateSkip, Mixture-of-Depths, FlexiDepth, SkipDecode, LoRA-Drop |
| Weights and activations | ShortGPT and SLEB, magnitude, Wanda and SparseGPT pruning with 2:4 sparsity, SliceGPT, FLAP width pruning, SVD-LLM, LittleBit, RTN, GPTQ and AWQ to int2-int8 or fp8 with Marlin, Machete, torchao or compressed-tensors kernels, rotations, draft-only quantization, TEAL, CATS and DejaVu activation sparsity |
| KV cache and attention | KIVI, FP8 KV cache, StreamingLLM, H2O and SnapKV eviction, DuoAttention, with fused attention kernels, Quest sparse decoding attention, MInference sparse prefill |
The techniques work on 46 model types, including dense, mixture-of-experts and hybrid attention/Mamba models. Techniques lists every technique with its registered name, its backends and the techniques it combines with.
Reproduction status
Every method economize implements, the result we measured against the number its paper reports, and whether the result reproduces. Partial means the result lies outside a reasonable range of the paper's, with the reason next to the verdict. Reproductions holds each study.
65 methods: 16 reproduced, 5 partial, 44 not yet compared. Results read economize vs paper; the linked studies hold every number, the model, the hardware and the command.
Drafting
| Method | Technique | Result (economize vs paper) | Status |
|---|---|---|---|
| EAGLE-3 (released drafter) | eagle3 |
2.82× mean speedup, τ 3.73 vs 4.44×, τ 6.1-6.7 (Llama-3.1-8B-Instruct, 5 benchmarks) (study 1) | 🟡 Partial: economize drafts EAGLE-3 as a chain of 5; the paper's number uses a dynamic draft tree. |
| EAGLE-3 (Red Hat speculators drafter) | eagle3 |
τ 3.05 / 2.91 / 2.62 vs 3.02 / 2.83 / 2.50 (HumanEval / math / summarization, chain of 3) (study 1) | ✅ Reproduced |
| EAGLE-1 / EAGLE-2 | eagle |
— | ⚪ Not yet compared: No study against the papers' settings yet. |
| HASS | eagle |
— | ⚪ Not yet compared: Needs drafter training at the paper's scale. |
| Medusa-1 | medusa |
MAT 2.30 vs 2.31, speedup 1.51× vs 1.71× (Vicuna-7B, Spec-Bench) (study 1) | 🟡 Partial: Acceptance matches; the leaderboard speedup was measured on a different A100 software stack. |
| Hydra | hydra |
— | ⚪ Not yet compared: No study against the paper's setting yet. |
| ReDrafter | redrafter |
— | ⚪ Not yet compared: No study against the paper's setting yet. |
| DFlash | dflash |
— | ⚪ Not yet compared: No study against the paper's setting yet. |
| PARD | pard |
— | ⚪ Not yet compared: No study against the paper's setting yet. |
| Draft model (speculative sampling) | draft_model |
speedup 1.58× vs 1.52×, MAT 2.48 vs 2.28 (Vicuna-7B with vicuna-68m, Spec-Bench) (study 1) | ✅ Reproduced: economize drafts a fixed 5 tokens where the reference adapts the count, hence the higher MAT. |
| Draft model on another device | placed_draft_model |
— | ⚪ Not yet compared: Same numerics as the draft model; no paper number for the multi-GPU placement. |
| Gemma 4 assistant | gemma4_assistant |
— | ⚪ Not yet compared: No published acceptance numbers to compare with. |
| Vendor MTP heads (DeepSeek-V3, GLM-4.5, MiMo, Qwen3.5) | vendor_mtp |
— | ⚪ Not yet compared: Not yet run at the scale of the published models. |
| Prompt lookup | lookup |
MAT 1.74 vs 1.73, speedup 1.50× (Vicuna-7B, Spec-Bench) (study 1) | ✅ Reproduced |
| Lookup with a fallback drafter | hybrid |
— | ⚪ Not yet compared: A combination of two drafters; no paper number for it. |
| Lookahead decoding | lookahead |
— | ⚪ Not yet compared: No study against the paper's setting yet. |
| REST | rest |
— | ⚪ Not yet compared: No study against the paper's setting yet. |
| SuffixDecoding | suffix_decoding |
— | ⚪ Not yet compared: No study against the paper's setting yet. |
| FR-Spec | frspec |
— | ⚪ Not yet compared: No study against the paper's setting yet. |
| LayerSkip (early-exit self-drafting) | early_exit |
— | ⚪ Not yet compared: The released LayerSkip checkpoints are gated. |
| Draft & Verify / SWIFT / CLaSp (layer-skip self-drafting) | layer_skip |
— | ⚪ Not yet compared: No study against the papers' settings yet. |
| Self-drafting through other techniques | draft_with |
— | ⚪ Not yet compared: A composition of techniques; no single paper number for it. |
| Kangaroo | kangaroo |
— | ⚪ Not yet compared: Needs adapter training at the paper's scale. |
| KnapSpec | knapspec |
— | ⚪ Not yet compared: No study against the paper's setting yet. |
| Hidden Transfer | hidden_transfer |
— | ⚪ Not yet compared: Needs training at the paper's scale. |
| MagicDec | magicdec |
— | ⚪ Not yet compared: Long-context benchmark runs pending. |
| TriForce | triforce |
— | ⚪ Not yet compared: Long-context benchmark runs pending. |
| FREE | free |
— | ⚪ Not yet compared: Needs exit-model training at the paper's scale. |
| DMTD | dmtd |
— | ⚪ Not yet compared: Needs training at the paper's scale. |
Draft compression
| Method | Technique | Result (economize vs paper) | Status |
|---|---|---|---|
| Draft quantization (QSpec-style) | draft_quant |
— | ⚪ Not yet compared: Applied to other drafters; no single paper number for it. |
Dynamic depth
| Method | Technique | Result (economize vs paper) | Status |
|---|---|---|---|
| CALM | calm |
— | ⚪ Not yet compared: The paper trains T5 encoder-decoders; no decoder-only number to compare with. |
| GateSkip | gateskip |
— | ⚪ Not yet compared: Needs gate training at the paper's scale. |
| Mixture-of-Depths | mod |
— | ⚪ Not yet compared: The paper pretrains from scratch; economize adds routers to pretrained models. |
| FlexiDepth | flexidepth |
— | ⚪ Not yet compared: Needs router training at the paper's scale. |
| SkipDecode | skipdecode |
— | ⚪ Not yet compared: The paper fine-tunes OPT models with its schedule; no matching checkpoint. |
| LoRA-Drop | loradrop |
— | ⚪ Not yet compared: Needs LoRA training at the paper's scale. |
Weight compression
| Method | Technique | Result (economize vs paper) | Status |
|---|---|---|---|
| RTN | quant |
INT4 g128 ppl 5.72 vs 5.73, INT3 g128 6.66 vs 6.66 (Llama-2-7B, WikiText-2) (studies 1, 2, 3, 4) | ✅ Reproduced |
| GPTQ | quant |
INT4 g128 ppl 5.67 ± 0.05 vs 5.69, INT3 per channel 8.11 vs 8.07 (Llama-2-7B / LLaMA-7B) (studies 1, 2, 3, 4, 5) | ✅ Reproduced: GPTQ without act-order on LLaMA-7B varies by ±0.34 ppl over calibration seeds; the paper's 6.22 lies inside. |
| AWQ | quant |
INT4 g128 ppl 5.61 vs 5.60, INT3 6.24 vs 6.24 (Llama-2-7B); GSM8K 12.6 ± 0.4 vs 13.6 (studies 1, 2, 3, 4, 5, 6, 7) | ✅ Reproduced: On Mistral-7B-Instruct the absolute perplexities differ (another FP16 evaluation protocol); the drops match. |
| torchao FP8 / INT8 / INT4 weights | quant |
HellaSwag 60.50 vs 59.86 (FP8, Llama-3.1-8B); speedup int4wo 1.94× vs 2.03×, float8dq 0.98× vs 1.26× (study 1) | 🟡 Partial: Quality matches; torchao's speedups use torch.compile, which the eager int8/fp8 paths do not. |
| SmoothQuant, HQQ, NVFP4 | quant |
— | ⚪ Not yet compared: No study against the papers' settings yet. |
| QuaRot rotations | rotate |
— | ⚪ Not yet compared: No study against the paper's setting yet. |
| Wanda | prune |
50% ppl 7.26 vs 7.26 (LLaMA-7B), 2:4 11.29 vs 11.02 (Llama-2-7B); zero-shot 56.2 vs 56.2 (studies 1, 2, 3) | ✅ Reproduced: The 2:4 Llama-2 gap also appears with the official Wanda code on the same software stack. |
| SparseGPT | prune |
50% ppl 7.27 vs 7.22 (LLaMA-7B), 2:4 10.25 vs 10.17 (Llama-2-7B) (studies 1, 2, 3) | ✅ Reproduced |
| Magnitude pruning | prune |
50% ppl 17.22 vs 17.29, 2:4 42.56 vs 42.13 (LLaMA-7B) (studies 1, 2) | ✅ Reproduced |
| SLEB | depth_prune |
20% of blocks, ppl 8.93 ± 0.21 vs 9.14 (WikiText-2), 11.82 ± 0.48 vs 12.32 (C4), Llama-2-7B (studies 1, 2) | ✅ Reproduced |
| ShortGPT | depth_prune |
removes layers 21-29 of Llama-2-7B, the same set as the paper | ✅ Reproduced: Checked on the removed layers; the paper's benchmark mixture is not fully specified. |
| SVD-LLM | lowrank |
20% compression, ppl 7.66 vs 7.94 (LLaMA-7B), 7.30 vs 10.21 (Mistral-7B), 9.49 vs 8.41 (Vicuna-7B) (studies 1, 2, 3) | 🟡 Partial: Four of five settings match or beat the paper; Vicuna-7B is 1.1 ppl worse, for reasons not yet found. |
| SliceGPT | slicegpt |
— | ⚪ Not yet compared: No study against the paper's setting yet. |
| FLAP / LLM-Pruner / Minitron width pruning | width_prune |
— | ⚪ Not yet compared: Runs so far use other models than the papers. |
| LittleBit | littlebit |
— | ⚪ Not yet compared: Needs quantization-aware training at the paper's scale. |
Activation sparsity
| Method | Technique | Result (economize vs paper) | Status |
|---|---|---|---|
| TEAL | teal |
ppl increase at 50% +0.70 vs +0.80 (Llama-3-8B), +0.37 vs +0.36 (Llama-2-7B) (studies 1, 2) | ✅ Reproduced: Absolute perplexities differ because the evaluation text differs; the increases match or are smaller. |
| CATS | cats |
— | ⚪ Not yet compared: No study against the paper's setting yet. |
| Deja Vu | dejavu |
— | ⚪ Not yet compared: Needs predictor training at the paper's scale. |
KV-cache quantization
| Method | Technique | Result (economize vs paper) | Status |
|---|---|---|---|
| KIVI | kivi |
KIVI-2 change on CoQA −0.6 vs −0.8 (Llama-2-7B), −1.3 vs −1.1 (Mistral-7B); GSM8K −0.8 vs −0.8 (Llama-2-7B) (studies 1, 2, 3, 4) | ✅ Reproduced |
| KIVI (fused kernel) | kivi_fused |
— | ⚪ Not yet compared: Same numerics as KIVI; a kernel, so no separate paper number. |
| FP8 KV cache | kv_fp8 |
Mistral-7B ppl +0.007 vs +0.00; Llama-3-8B-Instruct GSM8K drop −1.52 vs −0.46 (studies 1, 2) | 🟡 Partial: The reference uses calibrated KV scales; the unscaled e4m3 run loses more on GSM8K (scaled run pending). |
| FP8 KV cache (fused kernel) | kv_fp8_fused |
— | ⚪ Not yet compared: Same numerics as the FP8 KV cache; a kernel, so no separate paper number. |
KV-cache eviction
| Method | Technique | Result (economize vs paper) | Status |
|---|---|---|---|
| SnapKV | kv_evict |
LongBench 39.87 vs 35.50 (budget 128), 42.86 vs 41.35 (2048), Llama-3-8B-Instruct (study 1) | ✅ Reproduced: Our full-cache baseline is also 1.7 points higher (43.13 vs 41.46). |
| H2O | kv_evict |
LongBench 35.37 vs 35.37 (budget 128), 41.82 vs 39.35 (2048), Llama-3-8B-Instruct (study 1) | ✅ Reproduced: Matches with scores accumulated over the prompt (h2o_prefill), as the reference does. |
| StreamingLLM | kv_evict |
LongBench 34.33 vs 32.00 (budget 128), 40.65 vs 37.82 (2048), Llama-3-8B-Instruct (study 1) | ✅ Reproduced |
| KV eviction (fused kernel) | kv_evict_fused |
— | ⚪ Not yet compared: Same numerics as KV eviction; a kernel, so no separate paper number. |
| DuoAttention | duo_attention |
— | ⚪ Not yet compared: No study against the paper's setting yet. |
Sparse decoding attention
| Method | Technique | Result (economize vs paper) | Status |
|---|---|---|---|
| Quest | quest |
— | ⚪ Not yet compared: No study against the paper's setting yet. |
Sparse prefill attention
| Method | Technique | Result (economize vs paper) | Status |
|---|---|---|---|
| MInference | minference |
— | ⚪ Not yet compared: No study against the paper's setting yet. |
Model zoo
Drafters trained with economize are published on the Hugging Face Hub in the collection economize drafters, for example:
| Checkpoint | Base model | Speedup |
|---|---|---|
flaitenberger/economize-eagle3-gemma-4-31B-it |
Gemma-4-31B-it | 1.94x |
flaitenberger/Llama-3.1-8B-Instruct-economize-eagle3 |
Llama-3.1-8B-Instruct | 1.74x |
flaitenberger/economize-eagle3-Ministral-3-8B-Instruct-2512 |
Ministral-3-8B-Instruct-2512 | 1.59x |
flaitenberger/economize-eagle3-Olmo-3-7B-Instruct |
Olmo-3-7B-Instruct | 1.55x |
Speedup of flaitenberger/economize-eagle3-gemma-4-31B-it over plain decoding, overall and per task group, with a
fixed number of drafts per base-model pass (left) and with drafting that stops below a confidence threshold (right).
The speedups are lossless, at batch size 1 on H100 GPUs, averaged over chat, code, math, summarization and long-context prompts. The model zoo lists every checkpoint with its speedup per task group, and Benchmarks compares economize with the published speedups of other checkpoints.
Limitations
economize does not yet support dynamic draft trees or speculative speculative decoding on models with recurrent layers, trainable hook-based splits on tensor-parallel models (frozen ones are supported), or speculative speculative decoding on tensor-parallel models. Some techniques cannot yet be exported to vLLM, in which case the export raises an error that states the reason.
Development
pip install -e ".[dev]"
pytest # unit, technique, integration and oracle tests on the CPU
pytest -m gpu # batched decoding on a CUDA device
Contributing describes the checks and the design rules for contributions, and Extending how to add a technique, a model family or a backend.
Citation
If you use economize in your research, please cite it:
@software{laitenberger2026economize,
author = {Laitenberger, Filipe},
title = {economize: Composable Efficiency Techniques for Hugging Face Language Models},
year = {2026},
url = {https://github.com/Thiggel/economize},
version = {0.7.1}
}
Please also cite the papers of the techniques you use.
License
economize is released under the Apache License 2.0. See LICENSE for details.
Metadata
Release files for economize 0.7.1
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 |
|---|---|---|---|---|
| economize-0.7.1.tar.gz | 2.7 MB | Without provenance | Details for economize-0.7.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| economize-0.7.1-py3-none-any.whl | Python 3 | none | any | Details for economize-0.7.1-py3-none-any.whl |
Total release size: 4.3 MB
Release files / economize-0.7.1.tar.gz
| Download URL | economize-0.7.1.tar.gz |
|---|---|
| Size | 2.7 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
903b746cb5a3c449a8f7cd0c48dbc9d15bbabe7d374204501018cd609d4acbfb
|
|
BLAKE2b-256 checksum How to use checksums |
2970e8e74153fbcf00f08f3d2d3d15c647c9647db21fa9c49d5db5b53d0e4318
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.12
|
Release files / economize-0.7.1-py3-none-any.whl
| Download URL | economize-0.7.1-py3-none-any.whl |
|---|---|
| Size | 1.7 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0f6ef2536e1e1f8fa4d83042ad7af2a99f5b0032a48c55b49fde4437eff36214
|
|
BLAKE2b-256 checksum How to use checksums |
0393b3e62618ff5ce7ab06401a3333d5874ad95e27d51f615e7799c574b4db6d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.12
|
Security for economize 0.7.1
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.