Prompt lookup with a fallback drafter¶
At a glance
Prompt lookup (or another primary drafter) where it finds a draft, a fallback drafter elsewhere.
| Registered name | Family | Saves | Lossless | Trainable | Configuration |
|---|---|---|---|---|---|
hybrid |
drafting | latency | yes | fallback | HybridConfig |
Backends (default configuration): transformers: real · gguf: no · mlx: no · onnx: no · sglang: no · trtllm: no · vllm: no
The hybrid technique combines prompt lookup (Saxena, 2023) with a second drafter. Every cycle, each
row first tries the lookup: if its last n committed tokens occurred earlier in the row, for some n between
max_ngram and min_ngram, the tokens that followed the match become the draft. The rows without a match draft with
the fallback drafter in the same cycle, for example an EAGLE-3 head (Li et al., 2025). A lookup runs no network, so the fallback's
draft steps are spent only where copying fails. Both drafters see every exact pass, so the fallback's state stays in
step whether or not it drafted. The model verifies every draft in one forward pass and keeps the longest prefix it
agrees with, which makes greedy decoding lossless. The lookup has no parameters, and the fallback is trained on its
own, with its own objective.
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¶
The fallback is any model drafter of economize, given by its configuration. Token-level drafters, such as a second lookup, are refused as fallbacks:
from economize.techniques.eagle3 import Eagle3Config
from economize.techniques.hybrid import HybridConfig
model = economize.apply(base, HybridConfig(fallback=Eagle3Config(), max_ngram=3, max_proposal=7),
decoding=economize.DecodeConfig(cycle_length=8))
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 and the fallback's draft steps
cycle_length=8 allows up to seven drafts per verification, and max_proposal=7 lets one match fill that budget.
The cost summary counts the fallback's draft steps only, since a lookup cycle calls no layer. The output is the
model's greedy output in every case, but the new EAGLE-3 head drafts poorly until it is trained.
Training¶
The objectives of a drafter find it only when it is attached directly, so the fallback is trained without the
hybrid, and its weights are loaded into the hybrid's fallback afterwards:
from economize.train import fit
model.detach()
model = economize.apply(base, Eagle3Config())
fit(model, "train.bin", steps=2000, batch_size=8, seq_len=1024, output_dir="runs/eagle3")
weights = model.techniques["eagle3"].state_dict()
model.detach()
model = economize.apply(base, HybridConfig(fallback=Eagle3Config(), max_ngram=3, max_proposal=7),
decoding=economize.DecodeConfig(cycle_length=8))
model.techniques["hybrid"].fallback.load_state_dict(weights)
EAGLE-3 describes the head's training-time test objective and its options.
Saving and loading¶
The checkpoint stores the fallback's parameters with the hybrid, under fallback.:
model.save_pretrained("hybrid_eagle3")
model.detach()
model = economize.load(base, "hybrid_eagle3", decoding=economize.DecodeConfig(cycle_length=8))
Decoding options¶
max_drafts bounds the fallback's drafts per cycle independently of the lookup's max_proposal, and
min_confidence ends a fallback chain once the head's top probability falls below the threshold. match and
min_ngram behave as in prompt lookup. Sampling stays lossless with the rejection verifier, where a
copied token has a point-mass draft distribution:
model.detach()
model = economize.apply(base, HybridConfig(fallback=Eagle3Config(), min_ngram=2, match="latest", max_drafts=4),
decoding=economize.DecodeConfig(cycle_length=8, min_confidence=0.3))
model.decode(ids[0], 64)
sampling = economize.DecodeConfig(cycle_length=8, verifier="rejection")
sampled = model.generate(ids, max_new_tokens=64, do_sample=True, temperature=0.7, top_p=0.9, decoding=sampling)
primary replaces the built-in lookup with another drafter that serves some rows without a model call and leaves
the others, such as SuffixDecoding or REST. The n-gram fields keep their defaults
then:
from economize.techniques.suffix_decoding import SuffixDecodingConfig
model.detach()
model = economize.apply(base, HybridConfig(fallback=Eagle3Config(), primary=SuffixDecodingConfig()),
decoding=economize.DecodeConfig(cycle_length=8))
Combining with other techniques¶
Another drafter cannot wrap the hybrid, so a reduced draft vocabulary (FR-Spec) wraps the fallback, and the copied tokens keep the full vocabulary. Techniques that are not drafters, such as a 4-bit KV cache, compose with the hybrid directly:
from economize.techniques.frspec import FRSpecConfig
from economize.techniques.kv_quant.kivi import KIVIConfig
print(economize.compatible("hybrid", "kivi"), economize.compatible("hybrid", "frspec")) # True False
model.detach()
model = economize.apply(base, KIVIConfig(bits=4),
HybridConfig(fallback=FRSpecConfig(drafter=Eagle3Config(), vocab_size=32768)),
calibration=calibration, decoding=economize.DecodeConfig(cycle_length=8))
Serving¶
vLLM and SGLang build one proposer per engine, so neither serves the hybrid. Serve the lookup or the fallback alone through their own exports.
Configuration¶
HybridConfig
dataclass
¶
HybridConfig(fallback: TechniqueConfig, max_ngram: int = 3, min_ngram: int = 1, max_proposal: int | None = None, max_drafts: int | None = None, match: MatchRule = 'earliest', primary: TechniqueConfig | None = None)
Prompt lookup with a fallback drafter.
Every cycle, each row first tries a prompt lookup (see :class:~economize.techniques.lookup.LookupConfig). Rows
whose last n-gram occurred earlier draft the copied tokens; the other rows draft with fallback in the same
cycle. Lookups cost no model call, so the hybrid spends the fallback's draft steps only where copying fails.
The lookup is the default primary drafter. primary replaces it with any technique whose drafter is a
:class:~economize.techniques._drafting.PartialDrafter (it serves some rows without a model call); the n-gram
fields then keep their defaults.
Attributes:
| Name | Type | Description |
|---|---|---|
fallback |
TechniqueConfig
|
Configuration of the drafting technique used where the primary drafts nothing (e.g. an
:class: |
max_ngram |
int
|
Longest suffix the lookup matches. |
min_ngram |
int
|
Shortest suffix the lookup matches. |
max_proposal |
int | None
|
Most tokens one lookup proposes (default: the cycle's budget). |
max_drafts |
int | None
|
Most tokens the fallback drafts per cycle (default: the cycle's budget). |
match |
MatchRule
|
Which earlier occurrence the lookup copies from ( |
primary |
TechniqueConfig | None
|
Configuration of a primary drafter other than the built-in lookup ( |
lookup_config
¶
lookup_config() -> LookupConfig
The configuration of the built-in lookup (from the n-gram fields).
References¶
- Li, Y., Wei, F., Zhang, C., & Zhang, H. (2025). EAGLE-3: Scaling up inference acceleration of large language models via training-time test (arXiv:2503.01840). arXiv. https://doi.org/10.48550/arXiv.2503.01840
- Saxena, A. (2023). Prompt lookup decoding [Computer software]. GitHub. https://github.com/apoorvumang/prompt-lookup-decoding