Serving on SGLang¶
economize.backends.sglang.serving turns an EfficientModel, with any servable combination of its techniques, into
what SGLang loads: a target checkpoint, an optional draft model folder, and the server arguments (kv_cache_dtype,
dtype, speculative_algorithm, speculative_draft_model_path, ...). It mirrors the vLLM serving layer
(VLLM_BACKEND.md): the same roles, support levels, check / contribute / export hooks and two-pass plan
builder, so a technique is served by both backends through one adapter class per backend.
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)
from economize.backends.sglang import serving
from economize.techniques.eagle3 import Eagle3Config
from economize.techniques.kv_quant.fp8 import FP8KVConfig
model = economize.apply(base, FP8KVConfig(), Eagle3Config(attention_bias=False))
serving.check_servable(model) # {"kv_fp8": native, "eagle3": native}, or an error
plan = serving.to_sglang(model, "out/qwen-eagle3", num_speculative_tokens=3)
plan.launch_args() # ["python", "-m", "sglang.launch_server", "--model-path", ...]
plan = serving.SglangPlan.load("out/qwen-eagle3") # the saved plan (economize_sglang.json)
engine = plan.engine() # sglang.Engine(**plan.engine_kwargs())
engine = serving.serve(model, "out/qwen-eagle3") # to_sglang, then plan.engine()
SGLang's EAGLE-3 draft head has no attention biases, so the draft head above is built without them
(attention_bias=False); a head with biases is refused and can be served on vLLM.
python -m sglang.launch_server $(plan.launch_args()) starts the same server from a shell. serving.support_table()
lists every technique with its role, support level and what SGLang runs (or why it cannot). Importing the package
imports neither SGLang nor vLLM; only plan.engine() and the plugin do.
Pinned version¶
SGLang 0.5.21 (pip install "economize[sglang]", tested with torch 2.13 and transformers 5.12). Install it
with --prerelease=allow under uv, since some of its pins are pre-releases. Every server argument below was checked against the 0.5.21 source (srt/server_args.py, srt/speculative/*,
srt/models/llama_eagle3.py).
The draft model plugin¶
SGLang has no proposer plugin point like vLLM's custom_class, but its EAGLE-3 worker loads any draft model class
registered in ModelRegistry and passes it the target's auxiliary hidden states. economize registers its draft model
class (backends/sglang/model.py) through the sglang.srt.plugins entry point, so every SGLang process (scheduler
and TP workers) has it; SGLANG_PLUGINS may restrict the loaded plugins and must then name economize. The plan sets
speculative_algorithm="EAGLE3", speculative_num_steps=n, speculative_eagle_topk=1,
speculative_num_draft_tokens=n+1 and the draft folder written by the technique's "sglang/<technique>" exporter.
For early exit, one draft step is the draft step of the HF runtime: the drafter's own copies of the target's layers 1..r
(the target's weights, with LoRA merged, or the trained full copies), the readout adapter when r < L, the final norm and the
target's LM head. SGLang's aux layer id k captures the output of block k+1, so the exported ids are economize's
layers minus one (sglang_aux_ids). Every operation depends on shapes only, so draft and draft-extend run inside
SGLang's CUDA graphs. SGLang verifies every draft greedily, so the output equals plain greedy decoding whatever the
drafter proposes.
The same plugin serves FREE and DMTD (lossless, as on vLLM: their lossy cycles stay on the HF backend) and training-free layer skipping (the skip set at export time).
Classification¶
Classes as in VLLM_BACKEND.md: native (SGLang's own model, kernels and arguments after an export), plugin
(economize's draft model class), unsupported (refused with UnsupportedBackendError and the reason). No technique is
served densified (multiplied out into dense weights that lose its saving).
| technique | role | level | SGLang path |
|---|---|---|---|
| quant (compressed-tensors, marlin, machete, torchao) | weights | native | compressed-tensors checkpoint (SGLang's wNa16 Marlin / fp8 kernels), written by the vLLM serving layer's writer |
| prune (2:4) | weights | unsupported | SGLang has no sparse checkpoint format and no 2:4 GEMM, so the pruned model would run at dense cost |
| depth_prune | weights | native | the shallower checkpoint, config renumbered |
| lowrank | weights | unsupported | no plugin point for a factored linear method, so the factors would be multiplied out and the saving lost (vLLM serves them factored) |
| littlebit | weights | unsupported | no format for the binary factors and no LittleBit GEMM |
| kv_fp8, kv_fp8_fused | kv cache | native | kv_cache_dtype fp8_e4m3 / fp8_e5m2, unscaled casts in all layers; calibrated scales, per-token scales and layer subsets are refused |
| eagle3 | drafter | native | EAGLE3, LlamaForCausalLMEagle3 draft config with eagle_config aux ids; a draft head with attention biases is refused (SGLang's Llama head has none) |
| frspec (around eagle3) | drafter | native | EAGLE3 with draft_vocab_size, d2t (SGLang's hot token ids) and the head rows of the ids |
| draft_model, placed_draft_model | drafter | native | STANDALONE with the draft LM saved to the plan; SGLang runs it on the target's GPUs |
| lookup | drafter | native | NGRAM with BFS breadth 1 (a chain); SGLang's trie drafts from prompt and output, so drafts differ from prompt lookup while the output stays exact |
| dflash | drafter | native | DFLASH with the z-lab DFlashDraftModel checkpoint |
| vendor_mtp | drafter | native | NEXTN with the modules under their vendor names in the target checkpoint (untested on a real checkpoint) |
| gemma4_assistant | drafter | native | NEXTN with the assistant checkpoint |
| draft_quant | draft option | unsupported | the drafter exports write dense float weights, so the drafter would run at dense cost |
| early_exit, free, dmtd, layer_skip | drafter | plugin | economize's draft model class under EAGLE3 (see above); the draft model holds dense copies of its layers, so on a compressed-tensors base only adaptation="full" is served |
| eagle (EAGLE-1/2) | drafter | native, untested | EAGLE with a LlamaForCausalLMEagle folder (exporter sglang/eagle; a zero fc bias when the head has none), drafted as a chain (speculative_eagle_topk=1); not yet run on SGLang by economize |
| medusa, hydra | drafter | unsupported | SGLang 0.5.21 ships no Medusa-style proposer, and its plugin registry (SpeculativeAlgorithm.register) takes a whole V2 worker, which economize does not register |
| redrafter | drafter | unsupported | recurrent drafter with beam search is no SGLang algorithm |
| hidden_transfer, pard | drafter | unsupported | parallel drafting in one pass; SGLang's proposers draft step by step |
| kangaroo | drafter | unsupported | its adapter is an attention layer with its own KV over the state after layer l; economize's SGLang draft model hosts layers and a readout but no adapter attention |
| knapspec | drafter | unsupported | the skip set changes while decoding; the draft model has a fixed layer list |
| rest, suffix_decoding | drafter | unsupported | no suffix-array or suffix-tree proposer; NGRAM's external corpus is JSONL text merged into the request trie, which is not REST's frequency trie over its datastore |
| lookahead | drafter | unsupported | no pool filled by the verifier's Jacobi guesses |
| hybrid | drafter | unsupported | two proposers in one engine |
| kivi, kivi_fused | kv cache | unsupported | 2/4-bit per-channel keys need an own attention backend |
| kv_evict, kv_evict_fused | kv eviction | unsupported | the radix KV pool has no eviction inside a request |
| teal | forward | unsupported | no registry for a custom linear method (SGLang's quantization methods are a fixed table of built-in configs) |
| calm, skipdecode, mod, flexidepth, gateskip, loradrop | forward | unsupported | per-token depth, as on vLLM (class C) |
Every unsupported drafter that vLLM serves names economize.backends.vllm.serving in its error.
How techniques combine¶
to_sglang runs the adapters against one SglangPlanBuilder in the vLLM layer's two passes (all checks and role
claims first, then contribute, then export once the base checkpoint exists), so a refusal is raised before any
file is written. Any number of weight techniques edit the one base checkpoint; at most one KV cache technique and one
drafter (one speculative_algorithm per engine); one owner per server argument. When weight techniques rewrite the
target, a plugin drafter's own layer copies are taken from the rewritten base, so the drafter computes
on the weights SGLang serves.
Registry¶
Each technique has one adapter, a SglangTechnique subclass registered in SGLANG_TECHNIQUES
(@register_sglang_technique, override=True to replace one). Adding a technique never edits a module of this
package; serving/unsupported.py holds the not-yet-served techniques as data. A new drafter exporter is a
DrafterExporter registered as "sglang/<technique>" in economize.backends.EXPORTERS.
Upstream gaps¶
- No proposer plugin point (vLLM's
custom_class): token-level proposers (REST, suffix trees, lookahead) and parallel drafters (PARD, Hidden Transfer) cannot be added without patching SGLang. - No Medusa-style proposer for heads on the target's last state (Medusa, Hydra, ReDrafter).
- No plugin point for custom linear methods (TEAL, factored low-rank maps) or KV layouts (KIVI, eviction).