xinfer-ai 0.14.4 → 0.14.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -4
- package/docs/get_started.md +18 -1
- package/docs/speculative_decoding.md +129 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -61,11 +61,23 @@ xinfer --m /home/Qwen3.6-35B-A3B --d 0,1 --ui-server
|
|
|
61
61
|
python3 -m xinfer.server --m Qwen/Qwen3.6-27B-FP8 --kvcache-dtype turbo4 --ui-server
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
**MTP**
|
|
64
|
+
**Speculative decoding (MTP & DFlash2)**
|
|
65
|
+
|
|
66
|
+
Built-in MTP (model must include MTP heads):
|
|
67
|
+
|
|
65
68
|
```bash
|
|
66
|
-
xinfer --
|
|
69
|
+
xinfer --m Qwen/Qwen3.5-35B-A3B --d 0,1 --ui-server --num-speculative-tokens 3
|
|
67
70
|
```
|
|
68
71
|
|
|
72
|
+
External DFlash2 draft model:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
xinfer --m Qwen/Qwen3.8-... --d 0,1 --ui-server \
|
|
76
|
+
--draft-model <dflash2-draft-id-or-path> --num-speculative-tokens 7
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
See [docs/speculative_decoding.md](docs/speculative_decoding.md) for details.
|
|
80
|
+
|
|
69
81
|
> **Tip:** Open `http://IP:8001` for the built-in chat UI, or use `http://IP:8000/v1/` as your API `Base URL`.
|
|
70
82
|
|
|
71
83
|
---
|
|
@@ -134,6 +146,7 @@ Add `--kvcache-dtype` to compress KV cache and extend context length:
|
|
|
134
146
|
* ✅ Qwen2/Qwen3 MoE
|
|
135
147
|
* ✅ Qwen3 Next
|
|
136
148
|
* ✅ Qwen3.5/3.6/3.8 Dense/MoE (27B, 35B, 122B, 397B, Multimodal model)
|
|
149
|
+
* ✅ Qwen3.8-Next/Qwen4
|
|
137
150
|
* ✅ Mistral v1, v2
|
|
138
151
|
* ✅ Mistral-3-VL Reasoning (3B, 8B, 14B, Multimodal model)
|
|
139
152
|
* ✅ GLM4 (0414)
|
|
@@ -529,7 +542,8 @@ xinfer --m Qwen/Qwen3.6-27B-FP8 --ui-server --enable-tool-grammar
|
|
|
529
542
|
| `--frequency-penalty` | Penalize frequent tokens (−2 to 2) |
|
|
530
543
|
| `--mcp-config` | MCP servers JSON config |
|
|
531
544
|
| `--mcp-command` / `--mcp-args` | Single MCP server command + args |
|
|
532
|
-
| `--
|
|
545
|
+
| `--num-speculative-tokens` | Speculative draft tokens per decode step. Enables **built-in MTP** on models with MTP heads (e.g. Qwen3.5). Example: `--num-speculative-tokens 3` |
|
|
546
|
+
| `--draft-model` | External **DFlash2** draft model (HuggingFace id or local directory). When set, uses DFlash2 instead of built-in MTP. |
|
|
533
547
|
|
|
534
548
|
### Environment Variables
|
|
535
549
|
|
|
@@ -591,7 +605,7 @@ SM90_LOWER_PRECISION_GDN_PREFILL=1 xinfer --m Qwen/Qwen3.5-35B-A3B-FP8 --ui-serv
|
|
|
591
605
|
* [x] **MXFP4/NVFP4 Model Support**
|
|
592
606
|
* [x] **Support Turboquant (4-bit, 3-bit) KvCache**
|
|
593
607
|
* [ ] TentorRT-LLM
|
|
594
|
-
* [x] **Multi-token
|
|
608
|
+
* [x] **Multi-token Prediction (MTP) & DFlash2 speculative decoding**
|
|
595
609
|
|
|
596
610
|
---
|
|
597
611
|
|
package/docs/get_started.md
CHANGED
|
@@ -67,10 +67,27 @@ cargo build --release --features metal
|
|
|
67
67
|
target/release/xinfer --m Qwen/Qwen3-VL-8B-Instruct --ui-server
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
Common runtime knobs: `--max-model-len`, `--max-num-seqs`, `--kv-fraction` (CUDA KV share), `--cpu-mem-fold` (CPU swap ratio), `--port`, `--kvcache-dtype` (fp8/turbo8/turbo4/turbo3), `--prefix-cache`, `--prefix-cache-max-tokens`, `--ui-server`, `--batch` (perf test).
|
|
70
|
+
Common runtime knobs: `--max-model-len`, `--max-num-seqs`, `--kv-fraction` (CUDA KV share), `--cpu-mem-fold` (CPU swap ratio), `--port`, `--kvcache-dtype` (fp8/turbo8/turbo4/turbo3), `--prefix-cache`, `--prefix-cache-max-tokens`, `--ui-server`, `--batch` (perf test), `--num-speculative-tokens` (built-in MTP), `--draft-model` (DFlash2).
|
|
71
71
|
|
|
72
72
|
Reasoning defaults to enabled when a request omits `thinking` / `enable_thinking`. Use `--disable-reasoning` on the Rust CLI to make the default be disabled instead; explicit request values still override the server default.
|
|
73
73
|
|
|
74
|
+
### Speculative decoding (MTP & DFlash2)
|
|
75
|
+
|
|
76
|
+
Speed up decode with speculative token drafting + target verification. See [speculative_decoding.md](./speculative_decoding.md) for full details.
|
|
77
|
+
|
|
78
|
+
- **Built-in MTP** (Qwen3.5 / Qwen3.6 with MTP weights): `--num-speculative-tokens N`
|
|
79
|
+
```bash
|
|
80
|
+
target/release/xinfer --m Qwen/Qwen3.5-35B-A3B --d 0,1 \
|
|
81
|
+
--num-speculative-tokens 3 --ui-server
|
|
82
|
+
```
|
|
83
|
+
- **DFlash2** (external draft checkpoint): `--draft-model <hf_id_or_local_path>` plus optional `--num-speculative-tokens`
|
|
84
|
+
```bash
|
|
85
|
+
target/release/xinfer --m Qwen/Qwen3.8-... --d 0,1 \
|
|
86
|
+
--draft-model <dflash2-draft> --num-speculative-tokens 7 --ui-server
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
If `--draft-model` is set, DFlash2 is used instead of built-in MTP. Build with `cuda,nccl,flashinfer,cutlass` for best performance.
|
|
90
|
+
|
|
74
91
|
## 4) Multi-rank (single node)
|
|
75
92
|
- **NCCL multi-GPU**
|
|
76
93
|
```bash
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Speculative Decoding (MTP & DFlash2)
|
|
2
|
+
|
|
3
|
+
xInfer speeds up autoregressive decode with **speculative decoding**: a small set of candidate tokens is proposed each step, then verified by the target model in a single batched forward pass. Accepted drafts advance the sequence without extra per-token decode rounds.
|
|
4
|
+
|
|
5
|
+
Two modes are supported:
|
|
6
|
+
|
|
7
|
+
| Mode | When to use | CLI |
|
|
8
|
+
|------|-------------|-----|
|
|
9
|
+
| **Built-in MTP** | Target model ships MTP prediction heads (e.g. Qwen3.5 / Qwen3.6 with MTP weights) | `--num-speculative-tokens N` |
|
|
10
|
+
| **DFlash2** | External DFlash2 draft model (separate safetensors checkpoint) | `--draft-model <id_or_path>` |
|
|
11
|
+
|
|
12
|
+
**Rule:** If `--draft-model` is set, xInfer uses **DFlash2** (DFlash1 checkpoints are not supported). Otherwise, `--num-speculative-tokens` enables **built-in MTP** when the target model has MTP layers.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Built-in MTP
|
|
17
|
+
|
|
18
|
+
MTP (Multi-Token Prediction) uses lightweight heads bundled in the target checkpoint. Each decode step:
|
|
19
|
+
|
|
20
|
+
1. Target model produces one **anchor** token and a hidden state.
|
|
21
|
+
2. MTP head drafts `N` tokens autoregressively (no extra KV growth).
|
|
22
|
+
3. Target model verifies `[anchor, draft₀, …, draftₙ₋₁]` in one forward pass.
|
|
23
|
+
4. Matching prefix is accepted; GDN/Mamba state is rolled back on partial rejection (Qwen3.5 hybrid models).
|
|
24
|
+
|
|
25
|
+
### CLI
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Qwen3.5 35B with 3 speculative tokens per step
|
|
29
|
+
xinfer --m Qwen/Qwen3.5-35B-A3B --d 0,1 \
|
|
30
|
+
--num-speculative-tokens 3 --ui-server
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Typical values: **3–7** draft tokens. Higher values increase acceptance variance and KV verify width.
|
|
34
|
+
|
|
35
|
+
### Requirements
|
|
36
|
+
|
|
37
|
+
- Target weights must include MTP layers (`mtp.*` or GGUF `nextn.*` tensors).
|
|
38
|
+
- Model types with MTP support today: **Qwen3.5**, **Qwen3.5 MoE**, **Qwen3-VL** (Qwen3.5 text backbone).
|
|
39
|
+
- Recommended build: `./build.sh --release --features cuda,nccl,flashinfer,cutlass`
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## DFlash2
|
|
44
|
+
|
|
45
|
+
[DFlash2](https://github.com/z-lab/dflash) uses a **separate draft model** that consumes projected intermediate hidden states from selected target layers. Draft tokens are chosen with a top-k candidate lattice (`selector_top_k` in the draft config).
|
|
46
|
+
|
|
47
|
+
### CLI
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# Qwen3.8 target + DFlash2 draft (HuggingFace id or local path)
|
|
51
|
+
xinfer --m Qwen/Qwen3.8-... --d 0,1 \
|
|
52
|
+
--draft-model <your-dflash2-draft-repo-or-path> \
|
|
53
|
+
--num-speculative-tokens 7 --ui-server
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`--draft-model` accepts either:
|
|
57
|
+
|
|
58
|
+
- A **HuggingFace model id** (downloads `config.json` + safetensors), or
|
|
59
|
+
- A **local directory** containing `config.json` and `model.safetensors` (or sharded index).
|
|
60
|
+
|
|
61
|
+
`--num-speculative-tokens` is the number of draft tokens proposed per step (excluding the anchor). If omitted, xInfer uses the draft model config (`block_size - 1`).
|
|
62
|
+
|
|
63
|
+
Draft weights must be **safetensors** (GGUF draft models are not supported). The checkpoint must be **DFlash2** (`architectures` contains `DFlash2` or `dflash_config.selector_top_k` is set).
|
|
64
|
+
|
|
65
|
+
### Requirements
|
|
66
|
+
|
|
67
|
+
- Target: **Qwen3.5**, **Qwen3.5 MoE**, **Qwen3-VL**, or **Qwen3.8** (dense) today.
|
|
68
|
+
- Draft: matching-family **DFlash2** checkpoint.
|
|
69
|
+
- Recommended build: `cuda,nccl,flashinfer,cutlass` (CUDA graphs optional; disable with `--disable-cuda-graph` for debugging).
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Python API
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from xinfer import Engine, EngineConfig
|
|
77
|
+
|
|
78
|
+
# Built-in MTP
|
|
79
|
+
cfg = EngineConfig(
|
|
80
|
+
model_id="Qwen/Qwen3.5-35B-A3B",
|
|
81
|
+
num_speculative_tokens=3,
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
# DFlash2 (draft_model enables DFlash2 instead of MTP)
|
|
85
|
+
cfg = EngineConfig(
|
|
86
|
+
model_id="Qwen/Qwen3.8-...",
|
|
87
|
+
draft_model="<dflash2-draft-id-or-path>",
|
|
88
|
+
num_speculative_tokens=7,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
engine = Engine(cfg, "bf16")
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## Flags reference
|
|
97
|
+
|
|
98
|
+
| Flag | Description |
|
|
99
|
+
|------|-------------|
|
|
100
|
+
| `--num-speculative-tokens N` | Draft tokens per decode step. Enables **MTP** when the target has MTP heads and `--draft-model` is unset. With `--draft-model`, sets DFlash2 draft width (optional; defaults from draft config). |
|
|
101
|
+
| `--draft-model <id_or_path>` | External **DFlash2** draft model. Enables DFlash2 and disables built-in MTP. |
|
|
102
|
+
|
|
103
|
+
**Removed:** `--mtp` (use `--num-speculative-tokens`), `--draft-model-id` / `--draft-model-path` (use `--draft-model`).
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Tips & limitations
|
|
108
|
+
|
|
109
|
+
- **Throughput:** Speedup depends on draft acceptance rate and model size. Monitor logs for `MTP Stats` / `DFlash2 Stats` acceptance summaries.
|
|
110
|
+
- **Memory:** Verify passes append up to `N+1` tokens per step; ensure KV budget via `--kv-fraction` and `--max-num-seqs`.
|
|
111
|
+
- **Hybrid models:** Qwen3.5 GDN layers require state rollback on rejected drafts; this is handled automatically.
|
|
112
|
+
- **Batching:** Speculative decode is optimized for `batch_size=1` decode steps; larger batches use a batched DFlash2 path.
|
|
113
|
+
- **PD disaggregation:** Do not combine speculative decode with PD client/server modes on hybrid Mamba models.
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Quick test
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
# 1. Health check
|
|
121
|
+
curl -s http://localhost:8000/v1/models
|
|
122
|
+
|
|
123
|
+
# 2. Short completion (MTP or DFlash2 server)
|
|
124
|
+
curl -s http://localhost:8000/v1/chat/completions \
|
|
125
|
+
-H "Content-Type: application/json" \
|
|
126
|
+
-d '{"model":"Qwen/Qwen3.5-35B-A3B","messages":[{"role":"user","content":"Hello"}],"max_tokens":64}'
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
See also [test_model.md](./test_model.md) for full model validation workflows.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xinfer-ai",
|
|
3
|
-
"version": "0.14.
|
|
4
|
-
"assetVersion": "0.14.
|
|
3
|
+
"version": "0.14.5",
|
|
4
|
+
"assetVersion": "0.14.5",
|
|
5
5
|
"description": "xInfer — a high-performance LLM inference engine in Rust with CUDA/Metal acceleration",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/guoqingbao/xinfer#readme",
|