Skip to main content

economize

PyPI Python versions Documentation License

Composable efficiency techniques for Hugging Face language models

by Filipe Laitenberger

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 forward method, so it continues to work with generate, 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.

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 the EAGLE-3 drafter for Gemma-4-31B-it at every measured decoding setting

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.6.0}
}

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.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for economize 0.6.0
File Size Uploaded Provenance Actions
economize-0.6.0.tar.gz 2.6 MB Without provenance Details for economize-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for economize 0.6.0
File Interpreter ABI Platform Actions
economize-0.6.0-py3-none-any.whl Python 3 none any Details for economize-0.6.0-py3-none-any.whl

Total release size: 4.3 MB

Release files / economize-0.6.0.tar.gz

Download URL economize-0.6.0.tar.gz
Size 2.6 MB
Tags Source
SHA-256 checksum
How to use checksums
05d747fad709b26c4eb80ecdb23e1ebb4658b5625d5bde8ede049e900301ac23
BLAKE2b-256 checksum
How to use checksums
065a68dc1dc40ed264bda5a8e8ecde94dbf2eb25da57054da8bf5db1f911343d
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.6.0-py3-none-any.whl

Download URL economize-0.6.0-py3-none-any.whl
Size 1.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
53420ed52bdc4caf6b194a4d463e9c1848c242a69028f6829475660114472646
BLAKE2b-256 checksum
How to use checksums
d3ae199101e064e3141c7978f2fcf75551a4bb55bf8be249418eab848600f640
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.6.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page