Draft views¶
At a glance
Self-speculative drafting with the base model as other techniques change it (see DraftWithConfig).
| Registered name | Family | Saves | Lossless | Trainable | Configuration |
|---|---|---|---|---|---|
draft_with |
drafting | latency | yes | no | DraftWithConfig |
Backends (default configuration): transformers: real · gguf: no · mlx: no · onnx: no · sglang: no · trtllm: no · vllm: no
Most techniques that make a forward pass cheaper change the model's outputs: activation sparsity, quantized or
pruned weights, removed layers and an evicted KV cache all trade some quality for speed or memory. economize offers
two ways to use such a technique. Applied to the model, as in economize.apply(base, TealConfig()), it changes every
forward pass, and the generated text changes with it. Wrapped in DraftWith, it changes only the draft path of a
self-speculative drafter: each draft step runs the model with the technique applied, and the unmodified model verifies
the drafted tokens in its next exact pass. Greedy decoding then returns the model's own greedy tokens and sampling
with the rejection verifier keeps the model's distribution, while the technique decides how cheap a draft step is
and how often its tokens are accepted. Draft & Verify (Zhang et al., 2024) and SWIFT (Xia et al., 2025) draft in this way
with skipped layers, QSpec (Zhao et al., 2025) with quantized activations and weights, and MagicDec
(Sadhukhan et al., 2025) with a StreamingLLM cache. DraftWith applies the same construction to any technique that declares how it
runs on a draft path.
The verifying model never changes. Techniques that rewrite weights (quantization, pruning, low rank) transform deep copies of the decoder layers, techniques that add hooks (TEAL) hook shallow copies that share every weight with the model, and a KV-cache technique masks the cache that draft steps read while the exact passes keep reading every entry. The base model's parameters and buffers are compared before and after attach, and a change raises an error.
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¶
TEAL with half of the linear inputs zeroed drafts the tokens, and the dense model verifies them:
from economize.techniques.draft_with import DraftWith
from economize.techniques.sparsity import TealConfig
model = economize.apply(base, DraftWith(TealConfig(sparsity=0.5)), calibration=calibration[:8, :256],
decoding=economize.DecodeConfig(cycle_length=4))
result = model.decode(ids[0], 64)
print(tokenizer.decode(result.tokens))
print(result.mean_accepted) # accepted drafts per verification
print(result.cost_summary()) # exact passes, draft steps and layer-tokens of both
cycle_length=4 drafts three tokens per verification. The held technique calibrates as it does on its own, here on
the calibration rows passed to economize.apply.
Lossy use and draft-view use¶
The same configuration can be applied to the model or held by DraftWith. Applied to the model, TEAL sparsifies
every decoding step and the output departs from the dense model's greedy output. Held by DraftWith, it sparsifies
the draft steps only:
plain = base.generate(ids, max_new_tokens=64, do_sample=False)[0, ids.shape[1]:]
model.detach()
lossy = economize.apply(base, TealConfig(sparsity=0.5), calibration=calibration[:8, :256])
print(tokenizer.decode(lossy.decode(ids[0], 64).tokens)) # TEAL's own output
lossy.detach()
model = economize.apply(base, DraftWith(TealConfig(sparsity=0.5)), calibration=calibration[:8, :256],
decoding=economize.DecodeConfig(cycle_length=4))
print(torch.equal(model.decode(ids[0], 64).tokens.cpu(), plain.cpu()))
In float32 the draft view reproduces plain token for token. In bfloat16 a long output can differ after some tokens,
since the batched kernels of a verification pass round differently from the one-token kernels of plain decoding. This
holds for every drafter. The lossy model saves on every step, the draft view only on the steps whose drafts are
accepted, and it adds one verification pass per cycle. Which use is faster depends on the technique's quality loss,
which sets the acceptance rate, and on how much cheaper a draft step is than a full step.
Techniques a draft view can hold¶
A technique declares how it runs on a draft path in its class attribute draft_copies (see
Writing a technique). The built-in techniques that declare it are:
| Held technique | The draft path runs | Layer modules of the draft path | Added memory |
|---|---|---|---|
teal |
sparsified linear inputs | shallow copies that share every weight | none |
quant |
quantized weights | deep copies, quantized | the quantized weights |
prune |
pruned weights (Wanda, SparseGPT, magnitude) | deep copies, pruned | the pruned weights |
lowrank |
factorized weights | deep copies, factorized | the factors |
depth_prune |
the model minus the removed layers | the model's layers | none |
A copied tensor that the transform leaves equal to the model's tensor (norms, biases, maps outside targets) is shared
with the model again after attach, so the added memory is that of the rewritten weights. A drafter cannot be held,
and neither can a technique without a draft path, such as the KV-cache quantizers and kv_evict, which stores only
the kept entries while the verifying passes read every entry. Both raise ConfigError:
from economize.techniques.kv_quant import KIVIConfig
try:
economize.apply(base, DraftWith(KIVIConfig()))
except economize.ConfigError as error:
print(error)
Combining techniques on the draft path¶
DraftWith takes any number of configurations, at most one per technique. They attach to the draft path in the
order of a recipe (weight transforms first, then hooks, then KV-cache techniques), and economize.compatible applies
the same rules between them as between techniques applied to a model:
from economize.techniques.quant import QuantConfig
model.detach()
view = DraftWith(TealConfig(sparsity=0.5), QuantConfig(format="int4", group_size=128))
model = economize.apply(base, view, calibration=calibration[:8, :256],
decoding=economize.DecodeConfig(cycle_length=4))
print(model.techniques["draft_with"].held_techniques()) # in attach order
print(model.decode(ids[0], 64).mean_accepted)
Layer skipping as a draft view¶
A held depth_prune removes nothing from the model. Its layers are skipped on every draft step, which is
self-speculative layer skipping. With the same skip set, DraftWith(DepthPruneConfig(layers=S)) and
LayerSkipConfig(skip_layers=S) decode the same tokens with the same acceptance and the same cost log. depth_prune
contributes its own criteria (ShortGPT's Block Influence, SLEB) for choosing the set:
from economize.techniques.prune import DepthPruneConfig
model.detach()
model = economize.apply(base, DraftWith(DepthPruneConfig(method="shortgpt", num_blocks=6)),
calibration=calibration[:8, :256], decoding=economize.DecodeConfig(cycle_length=4))
print(model.techniques["draft_with"].config.techniques[0].layers) # the skipped layers, 1-indexed
print(model.techniques["draft_with"].run_layers) # the layers a draft step runs
The skip-set searches of layer skipping (greedy on KL or greedy-token mismatch, uniform) belong
to layer_skip, which remains the drafter to use for them.
Draft views on a compressed model¶
Techniques applied to the model and techniques held by DraftWith can be mixed. The model with the outer techniques
is then the verifier, and the draft path adds the held ones on top. Here the int4 model verifies drafts of the int4
model minus six layers:
model.detach()
model = economize.apply(
AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-0.5B", dtype=torch.bfloat16, device_map="cuda"),
QuantConfig(format="int4", group_size=128),
DraftWith(DepthPruneConfig(num_blocks=6)),
calibration=calibration[:8, :256],
decoding=economize.DecodeConfig(cycle_length=4),
)
The output is the int4 model's greedy output. As with any rewrite of the weights, detach() refuses this model, and the following examples start from base again. A technique cannot be applied to the model and held at once, and a held
weight transform must come after every outer one in the order of a recipe, since it transforms copies of the layers
the outer one already rewrote. Held quantization on a pruned model is therefore accepted, and held pruning on a
quantized model is refused. A held depth_prune rewrites no weights and combines with any outer technique:
print(economize.compatible(TealConfig(), DraftWith(TealConfig()))) # False
print(economize.compatible(QuantConfig(), DraftWith(DepthPruneConfig()))) # True
Cost accounting¶
Draft steps appear in result.cost as events of kind "draft". A held weight or hook technique runs every layer, so
its events count the full depth, and the saving lies in the cheaper kernels of each layer. A held depth_prune
counts only the layers it runs. A held technique whose configuration only simulates its saving (it computes the
technique's outputs with dense kernels) would make the draft path report a speedup it does not have. DraftWith
refuses such a technique with ConfigError when it attaches, and economize.backend_support gives the same reason.
The reason a held technique does not run on a backend is passed on as well, prefixed with the technique's name.
Saving and loading¶
The checkpoint holds the held configurations and their state, for example TEAL's thresholds. Held weight transforms run again when the view attaches, so loading needs the calibration rows a transform reads:
model = economize.apply(base, DraftWith(TealConfig(sparsity=0.5), QuantConfig(format="int4", group_size=128)),
calibration=calibration[:8, :256], decoding=economize.DecodeConfig(cycle_length=4))
model.save_pretrained("draft_view")
model.detach()
model = economize.load(base, "draft_view", calibration=calibration[:8, :256],
decoding=economize.DecodeConfig(cycle_length=4))
Decoding options¶
Every option of the drafting cycle applies. min_confidence ends a cycle when the draft path's top probability falls
below the threshold, and the rejection verifier keeps sampling lossless:
model.decode(ids[0], 64, decoding=economize.DecodeConfig(cycle_length=8, min_confidence=0.6))
sampling = economize.DecodeConfig(cycle_length=4, verifier="rejection")
sampled = model.generate(ids, max_new_tokens=64, do_sample=True, temperature=0.7, top_p=0.9, decoding=sampling)
Memory and limitations¶
A held weight transform deep-copies every decoder layer before it transforms the copies, so attaching needs the
memory of a second dense copy of the layers for a moment. The copies are not submodules of the model, so they are not
part of its state_dict and move with the drafter, not with model.to(...). Hooks of outer techniques present on a
layer at attach (TEAL applied to the model, for example) are copied onto its draft copy. DraftWith runs on the
Hugging Face path, and vLLM, SGLang and the exporters do not serve it.
Related techniques¶
Draft-only quantization quantizes the modules of another drafter, such as an EAGLE-3 head, and MagicDec and TriForce draft over a gathered sparse KV cache, which saves real reads.
Configuration¶
DraftWithConfig
dataclass
¶
DraftWithConfig(techniques: tuple[TechniqueConfig, ...] = ())
A self-speculative drafter that runs the model with other techniques applied.
Each draft step runs the base model as the techniques in :attr:techniques change it (sparse activations,
pruned or quantized weights, skipped layers, an evicted KV cache), and the unmodified model verifies the drafted
tokens. Greedy decoding therefore returns the base model's tokens, and sampling with a rejection verifier keeps
the base model's distribution. Only techniques that declare how they run on a draft path
(:attr:~economize.core.Technique.draft_copies) can be listed.
Attributes:
| Name | Type | Description |
|---|---|---|
techniques |
tuple[TechniqueConfig, ...]
|
The configurations of the techniques the draft path runs, at least one, with distinct technique
names. A list or the JSON form of each entry ( |
References¶
- Sadhukhan, R., Chen, J., Chen, Z., Tiwari, V., Lai, R., Shi, J., Yen, I. E.-H., May, A., Chen, T., & Chen, B. (2025). MagicDec: Breaking the latency-throughput tradeoff for long context generation with speculative decoding. In International Conference on Learning Representations. https://doi.org/10.48550/arXiv.2408.11049
- Xia, H., Li, Y., Zhang, J., Du, C., & Li, W. (2025). SWIFT: On-the-fly self-speculative decoding for LLM inference acceleration. In International Conference on Learning Representations. https://doi.org/10.48550/arXiv.2410.06916
- Zhang, J., Wang, J., Li, H., Shou, L., Chen, K., Chen, G., & Mehrotra, S. (2024). Draft & Verify: Lossless large language model acceleration via self-speculative decoding. In Annual Meeting of the Association for Computational Linguistics. https://doi.org/10.48550/arXiv.2309.08168
- 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