Skip to content

Commit 42938dd

Browse files
authored
feat(jetspec): validate SGLang export and decode acceptance (#65)
* feat(jetspec): validate SGLang export and decode acceptance Export JetSpec for SGLang with explicit causal attention, map it to the DFLASH runtime, and record bounded verifier-acceptance and published-checkpoint compatibility evidence. * docs(jetspec): clarify checkpoint conversion and timing limits Document the FSDP stub needed to compare the published checkpoint, state per-repeat token counts, and disclose the evaluator's fixed-order timing. * test(jetspec): add published checkpoint export harness Provide the runnable conversion path used for the published-checkpoint compatibility comparison and require the Target embedding it borrows. * docs(jetspec): link the published export harness * fix(jetspec): reject non-SiLU serving export and guard harness paths Fail closed before SGLang startup for unsupported activations, document the direct causal config override, and reject overlapping validation output paths before loading weights.
1 parent 5ec684f commit 42938dd

14 files changed

Lines changed: 403 additions & 30 deletions

File tree

‎aspec/commands/convert_to_hf.py‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,26 @@ def _serving_config(raw_config: dict) -> dict:
203203
raise ValueError("SGLang Domino serving requires a boolean shift_label")
204204
return config
205205

206+
if raw_config.get("architectures") == ["JetSpecDraftModel"]:
207+
from aspec.models.draft.jetspec import JetSpecConfig, official_jetspec_config
208+
209+
effective = JetSpecConfig.from_dict(raw_config).to_dict()
210+
config = official_jetspec_config(effective)
211+
if effective.get("fc_norm"):
212+
raise NotImplementedError(
213+
"SGLang JetSpec export cannot represent per-layer fc_norm; "
214+
"use --format aspec"
215+
)
216+
if effective.get("hidden_act", "silu") != "silu":
217+
raise NotImplementedError(
218+
"SGLang 0.5.21 DFlash loader only supports SiLU; "
219+
"use --format aspec for another activation"
220+
)
221+
# SGLang 0.5.21 reads top-level is_causal for DFlash full-attention
222+
# layers; it does not read dflash_config.causal_head.
223+
config["is_causal"] = True
224+
return config
225+
206226
if raw_config.get("architectures") == ["MedusaDraftModel"]:
207227
raise NotImplementedError(
208228
"Medusa heads require native --format aspec export; "
@@ -213,10 +233,6 @@ def _serving_config(raw_config: dict) -> dict:
213233
native["architectures"] = ["Qwen3_5ForCausalLMMTP"]
214234
native["mtp_num_hidden_layers"] = 1
215235
return native
216-
if raw_config.get("architectures") == ["JetSpecDraftModel"]:
217-
raise NotImplementedError(
218-
"JetSpec requires --format aspec; SGLang 0.5.21 has no JetSpec serving loader"
219-
)
220236
attention = resolve_draft_attention(raw_config)
221237
if attention["csa"] is not None:
222238
raise NotImplementedError(
@@ -372,7 +388,7 @@ def _draft_structure_manifest(raw_config: dict) -> dict:
372388
"runtime": "sglang",
373389
"validated_version": "0.5.21",
374390
"speculative_algorithm": (
375-
"DFLASH" if algorithm in {"dflash2", "domino"} else
391+
"DFLASH" if algorithm in {"dflash2", "domino", "jetspec"} else
376392
"EAGLE" if algorithm == "mtp" else algorithm.upper()
377393
),
378394
"required_patch_features": (

‎aspec/commands/evaluate_draft.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"dflash": "DFLASH",
2929
"dflash2": "DFLASH",
3030
"domino": "DFLASH",
31+
"jetspec": "DFLASH",
3132
"eagle3": "EAGLE3",
3233
"mtp": "EAGLE",
3334
}

‎configs/recipes/jetspec_qwen3_8b.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Formal single-node JetSpec recipe: causal parallel Draft training, exact
2-
# recovery and native export. Hyperparameters are a starting point, not a
2+
# recovery and SGLang/native export. Hyperparameters are a starting point, not a
33
# convergence or acceptance claim.
44
model:
55
target_model_path: ${oc.env:ASPEC_TARGET_MODEL,Qwen/Qwen3-8B}

‎docs/benchmarks/jetspec-decode.md‎

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# JetSpec bounded decode compatibility
2+
3+
This is a bounded decode integration check, not a throughput benchmark, convergence
4+
result or serving-quality claim. It verifies that an ASpec-exported JetSpec asset is
5+
loaded by official SGLang 0.5.21, that the causal head is active, and that exporting
6+
the published checkpoint through ASpec preserves the decode result.
7+
8+
## Setup
9+
10+
- Host: one H100 PCIe 80GB, `sglang==0.5.21`, torch 2.13.0+cu130.
11+
- Target: `Qwen/Qwen3-8B` (`/public/models/Qwen3-8B`).
12+
- Data: 16 prompts from the held-out validation split.
13+
- Decode: greedy, 32 new tokens, two complete repeats, normal radix cache.
14+
- Draft: JetSpec block size 16, five Target feature layers `[1, 9, 17, 25, 33]`.
15+
- Export: `aspec export` default SGLang layout with top-level `is_causal=true` and
16+
`dflash_config.causal_head=true`.
17+
18+
SGLang 0.5.21 reads the top-level `is_causal` flag for DFlash full-attention layers;
19+
`dflash_config.causal_head` alone leaves those layers bidirectional.
20+
21+
## Direct published asset
22+
23+
The "loaded directly" row did **not** use the stock published config. SGLang 0.5.21
24+
ignores `dflash_config.causal_head`, so the direct copy also needs top-level
25+
`is_causal=true`:
26+
27+
```bash
28+
cp -r /models/jetspec-qwen3-8b /tmp/jetspec-direct
29+
python - <<'PY'
30+
import hashlib, json
31+
from pathlib import Path
32+
33+
root = Path("/tmp/jetspec-direct")
34+
config = json.loads((root / "config.json").read_text())
35+
config["is_causal"] = True
36+
(root / "config.json").write_text(json.dumps(config, indent=2, sort_keys=True) + "\n")
37+
38+
def sha(path):
39+
digest = hashlib.sha256()
40+
with path.open("rb") as stream:
41+
for chunk in iter(lambda: stream.read(8 * 1024 * 1024), b""):
42+
digest.update(chunk)
43+
return digest.hexdigest()
44+
45+
manifest = {
46+
"schema_version": "aspec.serving-export/v1",
47+
"storage_format": "sglang",
48+
"algorithm": "jetspec",
49+
"model_sha256": sha(root / "model.safetensors"),
50+
"config_sha256": sha(root / "config.json"),
51+
"draft_structure": {"loader_contract": {
52+
"runtime": "sglang", "validated_version": "0.5.21",
53+
"speculative_algorithm": "DFLASH", "validation": "required_per_artifact",
54+
}},
55+
}
56+
(root / "export_manifest.json").write_text(
57+
json.dumps(manifest, indent=2, sort_keys=True) + "\n"
58+
)
59+
PY
60+
```
61+
62+
Then run `aspec evaluate` on `/tmp/jetspec-direct`. The stock config alone is a
63+
bidirectional baseline and is not comparable to the causal ASpec export matching on
64+
these prompts; verifier equality alone does not prove the draft proposals were equal.
65+
66+
## Results
67+
68+
| Draft | Acceptance length | Verifications | Median speedup | Greedy equal | Repeats stable |
69+
| --- | ---: | ---: | ---: | --- | --- |
70+
| ASpec 8-step checkpoint | 1.032 | 992 | 0.795x | yes | yes |
71+
| Published `JetSpec/jetspec-qwen3-8b` loaded directly | 2.723 | 376 | 1.823x | yes | yes |
72+
| Published checkpoint exported through ASpec | 2.723 | 376 | 1.823x | yes | yes |
73+
74+
Acceptance length follows `aspec evaluate`: completion tokens divided by real
75+
verifier calls, including Target tokens. Each repeat produced 512 completion tokens;
76+
the two repeats produced 1024 tokens total, which is the numerator used above.
77+
78+
Both published-checkpoint rows used top-level `is_causal=true`. The ASpec-exported
79+
published checkpoint matched the directly loaded checkpoint's acceptance length,
80+
verification count and speedup in this bounded setup. That checks
81+
config/weight/layout compatibility; it does not establish convergence or a trained
82+
quality comparison.
83+
84+
Timing is fixed-order: the evaluator completes all Target-only repeats before all
85+
speculative repeats. Two repeats do not counterbalance that order, so the speedup
86+
column is a bounded decode observation with an uncontrolled order-dependent
87+
limitation, not an unbiased throughput result.
88+
89+
The 8-step ASpec checkpoint was trained only as a functional smoke test on synthetic
90+
data. Its lower acceptance and slower speculative decode are expected and are not
91+
evidence against the method.
92+
93+
## Reproduction
94+
95+
```bash
96+
aspec export --input-dir outputs/jetspec/checkpoints/iter_0000009 \
97+
--output-dir outputs/jetspec-sglang
98+
99+
CUDA_VISIBLE_DEVICES=0 aspec evaluate \
100+
--target /models/Qwen3-8B --draft outputs/jetspec-sglang \
101+
--data held-out.jsonl --output outputs/jetspec-decode.json \
102+
--samples 16 --max-new-tokens 32 --repeats 2
103+
```
104+
105+
The command above applies to an ASpec FSDP training checkpoint. For the published
106+
draft head, use the reproducible validation harness:
107+
108+
```bash
109+
python -m tools.validation.jetspec_published_export \
110+
--checkpoint /models/jetspec-qwen3-8b \
111+
--target-model /models/Qwen3-8B \
112+
--output outputs/jetspec-official-sglang
113+
```
114+
115+
The harness loads the published tensors through `load_initial_draft_weights`, writes
116+
the minimal distributed-checkpoint layout the converter expects, and calls
117+
`convert_checkpoint(..., artifact_format="sglang")`. The published checkpoint omits
118+
`embed_tokens`, so `--target-model` supplies the borrowed embedding; converting only
119+
the config is not sufficient.

‎docs/contributing/validation.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,28 @@ python -m tools.validation.domino_anchor_protocol verify \
109109
its source sample. Consuming the same file in both trainers is still required before
110110
claiming a matched loss-curve comparison; an identical seed alone is not enough.
111111

112+
## JetSpec decode acceptance
113+
114+
Export a JetSpec checkpoint for SGLang and run the bounded greedy decode check:
115+
116+
```bash
117+
aspec export --input-dir outputs/jetspec/checkpoints/iter_0000009 \
118+
--output-dir outputs/jetspec-sglang
119+
120+
aspec evaluate --target /models/Qwen3-8B --draft outputs/jetspec-sglang \
121+
--data held-out.jsonl --output outputs/jetspec-decode.json \
122+
--samples 16 --max-new-tokens 32 --repeats 2
123+
```
124+
125+
SGLang 0.5.21 needs the exported config to carry top-level `is_causal=true`; the
126+
published `dflash_config.causal_head` field alone leaves DFlash full-attention layers
127+
bidirectional. The evaluator checks greedy equality against Target-only decoding and
128+
repeat stability, and reports acceptance length including Target tokens. Exporting the
129+
published `JetSpec/jetspec-qwen3-8b` checkpoint with
130+
`python -m tools.validation.jetspec_published_export --checkpoint ... --target-model ...`
131+
reproduced the direct checkpoint's bounded acceptance and fixed-order timing; this is a
132+
decode integration check, not throughput or convergence evidence.
133+
112134
## Algorithm, capacity and fault checks
113135

114136
| Scope | Required additional evidence |

‎docs/support.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ and tests do not imply CPU training support.
1616
| Medusa heads-only | Parallel full-vocabulary future-token heads on the frozen Target post-norm state; training, exact recovery and native export; greedy and typical/nucleus sampling candidate-tree acceptance via a standalone Hugging Face evaluator; SDPA CP1, MBS1, non-packing, REPLICATE, one node | No packing/CP or warmstart; no SGLang Medusa integration or production-serving claim; see [scope](user-guide/medusa.md) |
1717
| EAGLE4 | Dense and selected upstream MoE; Draft/candidate stages; packing/CP and native assets | Candidate Top-K forward-KL is explicitly implemented from public semantics, not an unpublished official recipe; no serving integration |
1818
| DFlash2 | Experimental full/causal/SWA training with Flex, cuDNN THD or FA4 packing/CP | Experimental objective; no claim to reproduce an official training recipe |
19-
| JetSpec | Qwen3-style causal parallel Draft head and temperature-scaled forward-KL objective, reused DFlash block machinery; chunked full-vocabulary KL, explicit causal visibility, exact recovery with FlexAttention, CP1, padded/non-packing, native export/strict reload and a proposal consumer | No SGLang export, tree builder or real decoding-acceptance claim yet; CPU causal packing and direct unmasked Draft calls fail closed; see [scope](user-guide/jetspec.md) |
19+
| JetSpec | Qwen3-style causal parallel Draft head and temperature-scaled forward-KL objective, reused DFlash block machinery; chunked full-vocabulary KL, explicit causal visibility, exact recovery with FlexAttention, CP1, padded/non-packing, SGLang/native export, strict reload and a proposal consumer | No tree builder or long-run convergence claim; CPU causal packing and direct unmasked Draft calls fail closed; see [scope](user-guide/jetspec.md) |
2020
| MTP-conditioned DSpark / DFlash | Target-side frozen native Qwen3.5 features, token/hidden dual-anchor training, exact recovery and strict native assets; legacy Draft-side assets retained | Dense full GQA, CP1, MBS1, REPLICATE, one node, non-packing, decay objective; Target capture PP1/unquantized; no generic serving consumer |
2121
| Native MTP | Qwen3.5-9B native single predictor, same-Target frozen embedding/head, multi-step training, recovery and export/stitch | Text-only Dense MTP; SDPA CP1 or independently validated FA4 packing/CP; no generic multi-layer/MoE MTP |
2222
| Dense / Qwen MoE / Ling MoE | Structure-specific FFNs, routing state, checkpointing and strict assets | No promise of every algorithm × structure combination |

‎docs/user-guide/algorithms.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ frozen Target features. `JetSpecConfig` forces that causal contract and rejects
123123
incompatible structures. The ASpec training CLI selects the algorithm through a
124124
shipped Qwen3-8B Draft config and a JetSpec trainer that reuses the DFlash
125125
optimizer/checkpoint path. FlexAttention, CP1, padded/non-packing execution and
126-
exact recovery are the initial scope. Native export, strict reload and a proposal
127-
consumer are supported; tree construction, SGLang export and verifier-acceptance
128-
runs remain pending.
126+
exact recovery are the initial scope. SGLang/native export, strict reload, a
127+
proposal consumer and bounded verifier-acceptance runs are supported; tree
128+
construction and long-run convergence evidence remain pending.
129129

130130
## Native MTP conditioning for DSpark/DFlash
131131

‎docs/user-guide/jetspec.md‎

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Target GPU plus two Draft GPUs at 4K (three GPUs total).
1717
`block_size=16`, `is_causal=true`).
1818
- Formal recipe: `configs/recipes/jetspec_qwen3_8b.yaml` (FlexAttention, CP1,
1919
non-packing, REPLICATE, Store/TCP transport, held-out evaluation and
20-
`inference.store_last_hidden_states=true`). It is catalogued as `jetspec`; its
21-
export boundary is native-only.
20+
`inference.store_last_hidden_states=true`). It is catalogued as `jetspec`; both
21+
SGLang and native export are validated.
2222
- Smoke example: `configs/examples/jetspec_qwen3_8b_4k_tcp.yaml` (shorter
2323
functional run with bundled data).
2424
- The supported path fails closed outside dense full attention, padded inputs,
@@ -76,18 +76,27 @@ and exact resume still need a hardware run before making quality claims.
7676

7777
## Export and strict reload
7878

79-
Export a trained checkpoint with the native ASpec artifact format:
79+
Export a trained checkpoint for SGLang serving (default) or as a native ASpec
80+
artifact:
8081

8182
```bash
83+
aspec export \
84+
--input-dir outputs/jetspec_qwen3_8b_4k_tcp_resumed/checkpoints/iter_0000009 \
85+
--output-dir outputs/jetspec-qwen3-8b-sglang
86+
8287
aspec export \
8388
--input-dir outputs/jetspec_qwen3_8b_4k_tcp_resumed/checkpoints/iter_0000009 \
8489
--output-dir outputs/jetspec-qwen3-8b-asset --format aspec
8590
```
8691

87-
JetSpec deliberately rejects the SGLang artifact format: SGLang 0.5.21 has no
88-
validated JetSpec loader, so a DFlash-style serving export could silently lose the
89-
causal block contract. The native manifest records the JetSpec algorithm, trained
90-
`block_size`, Target feature layers, temperature, KL chunk size and weighting.
92+
The SGLang export maps JetSpec to the published DFlash draft layout and sets both
93+
`dflash_config.causal_head=true` and top-level `is_causal=true`. SGLang 0.5.21 reads
94+
the top-level flag for DFlash full-attention layers; `causal_head` alone would leave
95+
the draft bidirectional. The manifest records runtime `DFLASH`; SGLang loads the
96+
exported `fc`/`hidden_norm`/`norm`/`layers.*` tensors.
97+
98+
The native manifest records the JetSpec algorithm, trained `block_size`, Target
99+
feature layers, temperature, KL chunk size and weighting.
91100
`aspec.draft_artifact.load_native_draft` validates the checksums and semantics, then
92101
loads every tensor strictly and preserves dtypes.
93102

@@ -102,6 +111,21 @@ produces the flat `JetSpecDraftModel`/`model_type="jetspec"` config. The publish
102111
weight layout matches ASpec's export names; `load_initial_draft_weights` loads the
103112
draft tensors strictly and borrows the missing Target embedding.
104113

114+
### Decode acceptance
115+
116+
Run real decode acceptance against the SGLang export with `aspec evaluate`:
117+
118+
```bash
119+
aspec evaluate --target /path/to/Qwen3-8B \
120+
--draft outputs/jetspec-qwen3-8b-sglang \
121+
--data /path/to/held-out-prompts.jsonl --output outputs/jetspec-decode.json
122+
```
123+
124+
The evaluator reports measured acceptance length (including Target tokens), checks
125+
greedy equality against Target-only decoding and verifies repeat stability. A
126+
16-prompt, 32-new-token, two-repeat check on one H100 loaded the asset and produced stable greedy output; the bounded run is a
127+
decode integration check, not throughput or convergence evidence.
128+
105129
### Native proposal component
106130

107131
`aspec.draft_artifact.JetSpecConsumer` loads a native JetSpec asset and proposes one
@@ -119,8 +143,14 @@ against independent equations, explicit-mask and packed fail-closed paths,
119143
anchor/loss-mask exclusion, empty supervision and next-token label/teacher
120144
alignment. Native export, strict reload and the proposal consumer have focused CPU
121145
coverage, including causal visibility and anchor-feature isolation. GPU attention
122-
execution, convergence, acceptance length and serving performance are not certified
123-
by those checks.
146+
execution, convergence and serving throughput are not certified by those checks.
147+
Bounded SGLang decode was run on 16 held-out prompts (32 new tokens, greedy, two
148+
repeats): the 8-step checkpoint produced greedy-equal, repeat-stable output. The published `JetSpec/jetspec-qwen3-8b` checkpoint measured 2.723
149+
tokens/verification and 1.823x fixed-order median speedup in the same bounded setup; exporting
150+
that checkpoint through ASpec reproduced the same numbers, confirming tensor/layout
151+
compatibility. The 8-step checkpoint measured 1.032
152+
tokens/verification and 0.795x, so this is not a convergence or quality claim. See
153+
[bounded decode compatibility](../benchmarks/jetspec-decode.md).
124154

125155
## Reference and selected method
126156

@@ -238,9 +268,12 @@ denominator. Per-position loss now reports KL rather than CE.
238268

239269
- Native export, strict reload and a native proposal consumer are supported; the
240270
published Qwen3-8B config/weight layout maps into ASpec.
241-
- This integration does not provide tree construction, SGLang serving export, a
242-
real verifier-acceptance run or a same-budget comparison with the official
243-
implementation. Those remain follow-up work under the issue's expected outcomes.
271+
- SGLang serving export, native export/strict reload and a bounded real
272+
verifier-acceptance run are supported.
273+
- This integration does not provide tree construction or a same-budget trained
274+
comparison with the official implementation. The official repository publishes an
275+
inference checkpoint but no comparable training loop; the bounded check therefore
276+
compares asset loading and decode acceptance rather than training curves.
244277
- The default tests are in `tests/cpu/test_jetspec.py`,
245278
`tests/cpu/test_jetspec_integration.py`, `tests/cpu/test_jetspec_export.py`,
246279
`tests/cpu/test_jetspec_consumer.py` and `tests/cpu/test_jetspec_official.py`.

‎docs/user-guide/recipes.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ connections on your hardware before training.
1919
| `dspark` | Qwen3-8B / Dense DSpark | 1 node, 8 GPUs: 4T + 4D; 4K | Train on your data with packing and NVLink |
2020
| `dflash` | Qwen3-8B / DFlash | 1 node, 3 GPUs: 1T + 2D; 4K | Train a block-parallel DFlash Draft |
2121
| `domino` | Qwen3-8B / Domino | 1 node, 3 GPUs: 1T + 2D; 4K | Train a DFlash backbone with a GRU correction head |
22-
| `jetspec` | Qwen3-8B / JetSpec | 1 node, 3 GPUs: 1T + 2D; 4K | Train a causal parallel block Draft and export a native asset |
22+
| `jetspec` | Qwen3-8B / JetSpec | 1 node, 3 GPUs: 1T + 2D; 4K | Train a causal parallel block Draft and export for SGLang or native use |
2323
| `medusa` | Qwen3-8B / heads-only Medusa | 1 node, 2 GPUs: 1T + 1D; 4K | Train parallel future-token heads and export a native heads asset |
2424
| `eagle3` | Qwen3-8B / EAGLE3 | 1 node, 3 GPUs: 1T + 2D; 4K | Train a recurrent EAGLE3 Draft |
2525
| `eagle4` | Qwen3-8B / EAGLE4 | 1 node, 3 GPUs: 1T + 2D; 4K; sequential stages | Train a Draft, then candidate retrieval projections |

0 commit comments

Comments
 (0)