Add model card, metadata, and usage examples

#1
by nielsr HF Staff - opened
Files changed (1) hide show
  1. README.md +91 -0
README.md ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ library_name: transformers
4
+ pipeline_tag: text-generation
5
+ ---
6
+
7
+ # JetSpec: Parallel Tree Drafting
8
+
9
+ JetSpec is an implementation of **parallel tree drafting** designed to accelerate speculative decoding in Large Language Models (LLMs) with up to 10x acceptance length.
10
+
11
+ This repository contains the speculative draft head presented in the paper [JetSpec: Breaking the Scaling Ceiling of Speculative Decoding with Parallel Tree Drafting](https://arxiv.org/abs/2606.18394).
12
+
13
+ - **Project Page:** [hao-ai-lab.github.io/JetSpec](https://hao-ai-lab.github.io/JetSpec)
14
+ - **Repository:** [github.com/hao-ai-lab/JetSpec](https://github.com/hao-ai-lab/JetSpec)
15
+
16
+ ## Method Overview
17
+
18
+ Speculative decoding is fast when the target accepts many draft tokens and drafting remains cheap. JetSpec keeps the **one-pass drafting efficiency and restores causal branch conditioning**. The draft head reads fused hidden states from the frozen target and emits per-depth logits in a single parallel pass. Tree construction spends a draft budget over high-probability branches, and the target verifies every node in one batched/tree-masked forward.
19
+
20
+ ## Installation
21
+
22
+ To run JetSpec, clone the repository and install the package:
23
+
24
+ ```bash
25
+ git clone https://github.com/hao-ai-lab/JetSpec.git
26
+ cd JetSpec
27
+ pip install -e '.[bench,kernel]'
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ### Hugging Face Reference
33
+
34
+ You can run speculative decoding references using the `LLM` entrypoint:
35
+
36
+ ```python
37
+ from jetspec import LLM, SamplingParams
38
+
39
+ llm = LLM("Qwen/Qwen3-8B", attn_implementation="flash_attention_2")
40
+ out = llm.generate(
41
+ "The three primary colors are",
42
+ SamplingParams(temperature=0.0, max_new_tokens=64),
43
+ )
44
+ print(out["text"])
45
+ ```
46
+
47
+ ### JetSpec Inference Engine
48
+
49
+ For optimal latency, the inference engine utilizes a Triton tree-attention backend, compiled verification, and CUDA graphs:
50
+
51
+ ```python
52
+ from jetspec import load_draft_head, DraftHeadTreeDrafter
53
+ from jetspec.inference_engine import JetSpecEngine, SamplingParams
54
+
55
+ engine = JetSpecEngine(
56
+ "Qwen/Qwen3-8B",
57
+ attn_backend="triton_paged_tree_compiled",
58
+ )
59
+ head = load_draft_head("JetSpec/jetspec-qwen3-8b")
60
+ drafter = DraftHeadTreeDrafter(
61
+ head,
62
+ target=engine.model,
63
+ block_size=head.block_size,
64
+ target_layer_ids=head.target_layer_ids,
65
+ )
66
+ out = engine.generate_tree(
67
+ "The three primary colors are",
68
+ drafter,
69
+ block_size=head.block_size,
70
+ tree_depth=20,
71
+ tree_width=7,
72
+ budget=128,
73
+ target_layer_ids=head.target_layer_ids,
74
+ sampling_params=SamplingParams(temperature=0.0, max_new_tokens=64),
75
+ )
76
+ print(out["text"])
77
+ print("tokens per forward:", out["tpf"])
78
+ ```
79
+
80
+ ## Citation
81
+
82
+ ```bibtex
83
+ @inproceedings{jetspec2026,
84
+ title = {JetSpec: Breaking the Scaling Ceiling of Speculative Decoding with Parallel Tree Drafting},
85
+ author = {Hu, Lanxiang and Feng, Zhaoxiang and Wu, Yulun and Yuan, Haoran and Zhao, Yujie and Qian, Yu-Yang and Wang, Bojun and Zhao, Peng and Jiang, Daxin ... [et al.]},
86
+ year = {2026},
87
+ url = {https://arxiv.org/abs/2606.18394},
88
+ eprint = {2606.18394},
89
+ note = {Preprint}
90
+ }
91
+ ```