Draft-only quantization¶
At a glance
Round-to-nearest quantization of the drafter's own modules (see DraftQuantConfig).
| Registered name | Family | Saves | Lossless | Trainable | Configuration |
|---|---|---|---|---|---|
draft_quant |
draft-compression | latency | yes | no | DraftQuantConfig |
Backends (default configuration): transformers: no · gguf: no · mlx: no · onnx: no · sglang: no · trtllm: no · vllm: no
Draft-only quantization rounds the weights of a drafter to a low-bit grid and leaves the base model in full
precision. It follows the idea of QSpec (Zhao et al., 2025), which drafts with a low-precision version of the
computation and verifies in high precision. In economize the drafter is a separate technique, such as an EAGLE-3
head, and draft_quant quantizes the linear maps that this drafter adds: the drafter's draft_modules() when it
defines them, otherwise every nn.Linear in its module tree. Maps whose weight is a base-model parameter and LoRA
factors are left alone. Quantization is round-to-nearest with one scale per group of group_size input columns.
Since the full-precision model verifies every drafted token, the output does not change and the technique is
lossless. What changes is the cost of a draft step, which reads fewer weight bytes, and possibly the acceptance
rate. Nothing is trained.
Setup¶
Every tutorial starts from the same model and prompt:
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
import economize
device = "cuda" if torch.cuda.is_available() else "cpu"
base = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-0.5B", dtype=torch.bfloat16, device_map=device)
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-0.5B")
ids = tokenizer("Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May. "
"How many clips did Natalia sell altogether?", return_tensors="pt").input_ids.to(device)
Training data is a flat file of uint32 token ids, the format of nanoGPT-style pretraining shards, and calibration
data is a [N, S] tensor of token ids. Both are made here from GSM8K:
import numpy as np
from datasets import load_dataset
texts = [f"{row['question']}\n{row['answer']}" for row in load_dataset("openai/gsm8k", "main", split="train")]
tokens = np.concatenate([tokenizer(t + tokenizer.eos_token).input_ids for t in texts]).astype(np.uint32)
tokens[: len(tokens) * 9 // 10].tofile("train.bin")
tokens[len(tokens) * 9 // 10 :].tofile("val.bin")
calibration = torch.from_numpy(tokens[: 128 * 2048].astype(np.int64)).view(128, 2048)
Quick start¶
draft_quant needs exactly one drafter with modules of its own in the same recipe, and it attaches after it:
from economize.techniques.eagle3 import Eagle3Config
from economize.techniques.quant import DraftQuantConfig
model = economize.apply(base, Eagle3Config(), DraftQuantConfig(format="int8", group_size=128),
decoding=economize.DecodeConfig(cycle_length=6))
print(model.techniques["draft_quant"].summary) # quantized modules, weights and bits per weight
result = model.decode(ids[0], 64)
print(tokenizer.decode(result.tokens))
print(result.mean_accepted) # accepted drafts per verification
The output is the model's greedy output token for token. detach() restores the drafter's original weights bit for
bit. A drafter without modules of its own, such as prompt lookup, REST or a separate draft model, is refused:
from economize.techniques.lookup import LookupConfig
print(economize.compatible(DraftQuantConfig(), Eagle3Config())) # True
print(economize.compatible(DraftQuantConfig(), LookupConfig())) # False
Quantizing a trained drafter¶
A drafter is trained in full precision and quantized afterwards. Train and save it as in EAGLE-3:
from economize.train import fit
model.detach()
model = economize.apply(base, Eagle3Config(), decoding=economize.DecodeConfig(cycle_length=6))
fit(model, "train.bin", steps=2000, batch_size=8, seq_len=1024, seed=0)
model.save_pretrained("eagle3_head")
full = model.decode(ids[0], 64)
model.detach()
A checkpoint holds a list of configurations and the weights of each technique. Adding DraftQuantConfig to the
list quantizes the loaded head when it attaches:
checkpoint = economize.read_checkpoint("eagle3_head")
checkpoint.configs.append(DraftQuantConfig(format="int4", group_size=128))
model = economize.attach(base, checkpoint, economize.DecodeConfig(cycle_length=6))
quantized = model.decode(ids[0], 64)
print(full.mean_accepted, quantized.mean_accepted) # acceptance of the full-precision and the int4 head
Comparing mean_accepted on the prompts of the target workload is the way to choose a format. The registered
formats are int2, int3, int4, int8 and fp8. group_size=None uses one scale per output channel,
symmetric=False adds a zero point, and targets and exclude are globs over module names inside the drafter.
Kernels¶
The default backend="auto" stores the codes with the fastest installed kernel that fits the format and the
drafter's device and dtype, and runs the draft step with a low-bit GEMM: "machete" (int4 and int8 on sm90),
"marlin" (int4, int8 and fp8 on sm80 and newer) or "torchao". When none fits, it raises a ConfigError that names
the package to install. Each kernel can also be named. (The page's tests run on a CPU with the dequantized reference
of the test suite, which reproduces the numerics of the integer kernels and with them the acceptance rate.)
model.detach()
checkpoint = economize.read_checkpoint("eagle3_head")
checkpoint.configs.append(DraftQuantConfig(format="int4", group_size=128, backend="marlin"))
model = economize.attach(base.to("cuda", torch.bfloat16), checkpoint, economize.DecodeConfig(cycle_length=6))
Combining with other techniques¶
draft_quant composes with techniques that change the base model, such as weight quantization of the model itself
or KV-cache quantization. Here the base model runs in int8 and the drafter in int4:
from economize.techniques.quant import QuantConfig
model.detach()
model = economize.apply(
AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-0.5B", dtype=torch.bfloat16, device_map="cuda"),
QuantConfig(format="int8"),
Eagle3Config(),
DraftQuantConfig(format="int4", group_size=128),
decoding=economize.DecodeConfig(cycle_length=6),
)
result = model.decode(ids[0], 64)
A drafter trained on the full-precision model sees shifted hidden states once the base model is quantized, so train it after the base model's weight transforms, as EAGLE-3 describes.
Serving¶
vLLM and SGLang load hidden-state drafters (EAGLE-3, Medusa, DFlash heads) only with dense float weights, so their
exports refuse a quantized drafter, and economize.backend_support("draft_quant") gives the reason. A separate
draft model is quantized with quant on the draft model itself, which both engines serve with real kernels.
Configuration¶
DraftQuantConfig
dataclass
¶
DraftQuantConfig(format: str = 'int8', group_size: int | None = 128, symmetric: bool = True, backend: str = 'auto', targets: tuple[str, ...] = ('*',), exclude: tuple[str, ...] = ('*lora*',))
Round-to-nearest quantization of the drafter's own modules only (the verified base model is untouched).
Lossless: every drafted token is still verified by the full-precision model, so only the acceptance rate changes. The drafter's predictor, readout and full layer copies are quantized; LoRA factors and modules whose weights are shared with the base model are skipped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
format
|
str
|
Registered number format ( |
'int8'
|
group_size
|
int | None
|
Input columns per scale ( |
128
|
symmetric
|
bool
|
Integer grids without a zero point. |
True
|
backend
|
str
|
|
'auto'
|
targets
|
tuple[str, ...]
|
Globs over module names inside the drafter ( |
('*',)
|
exclude
|
tuple[str, ...]
|
Globs removed from |
('*lora*',)
|
References¶
- Zhao, J., Lu, W., Wang, S., Kong, L., & Wu, C. (2025). QSpec: Speculative decoding with complementary quantization schemes. In Conference on Empirical Methods in Natural Language Processing. https://doi.org/10.48550/arXiv.2410.11305