You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Speculative decoding speeds up text generation by predicting multiple tokens ahead and verifying them in a single forward pass. The output is identical to normal decoding — only faster. This feature is only available with the `llama-cpp` backend.
217
+
218
+
There are two approaches:
219
+
220
+
#### Draft Model Speculative Decoding
221
+
222
+
Uses a smaller, faster model from the same model family to draft candidate tokens, which the main model then verifies. Requires a separate GGUF file for the draft model.
223
+
224
+
```yaml
225
+
name: my-model
226
+
backend: llama-cpp
227
+
parameters:
228
+
model: large-model.gguf
229
+
draft_model: small-draft-model.gguf
230
+
n_draft: 8
231
+
options:
232
+
- spec_p_min:0.8
233
+
- draft_gpu_layers:99
234
+
```
235
+
236
+
#### N-gram Self-Speculative Decoding
237
+
238
+
Uses patterns from the token history to predict future tokens — no extra model required. Works well for repetitive or structured output (code, JSON, lists).
239
+
240
+
```yaml
241
+
name: my-model
242
+
backend: llama-cpp
243
+
parameters:
244
+
model: my-model.gguf
245
+
options:
246
+
- spec_type:ngram_simple
247
+
- spec_n_max:16
248
+
```
249
+
250
+
#### Speculative Decoding Options
251
+
252
+
These are set via the `options:` array in the model configuration (format: `key:value`):
253
+
254
+
| Option | Type | Default | Description |
255
+
|--------|------|---------|-------------|
256
+
| `spec_type` | string | `none` | Speculative decoding type (see table below) |
257
+
| `spec_n_max` / `draft_max` | int | 16 | Maximum number of tokens to draft per step |
258
+
| `spec_n_min` / `draft_min` | int | 0 | Minimum draft tokens required to use speculation |
259
+
| `spec_p_min` / `draft_p_min` | float | 0.75 | Minimum probability threshold for greedy acceptance |
260
+
| `spec_p_split` | float | 0.1 | Split probability for tree-based branching |
| `spec_ngram_min_hits` / `ngram_min_hits` | int | 1 | Minimum hits for accepting n-gram proposals |
264
+
| `draft_gpu_layers` | int | -1 | GPU layers for the draft model (-1 = use default) |
265
+
| `draft_ctx_size` | int | 0 | Context size for the draft model (0 = auto) |
266
+
267
+
#### Speculative Type Values
268
+
269
+
| Type | Description |
270
+
|------|-------------|
271
+
| `none` | No speculative decoding (default) |
272
+
| `draft` | Draft model-based speculation (auto-set when `draft_model` is configured) |
273
+
| `eagle3` | EAGLE3 draft model architecture |
274
+
| `ngram_simple` | Simple self-speculative using token history |
275
+
| `ngram_map_k` | N-gram with key-only map |
276
+
| `ngram_map_k4v` | N-gram with keys and 4 m-gram values |
277
+
| `ngram_mod` | Modified n-gram speculation |
278
+
| `ngram_cache` | 3-level n-gram cache |
279
+
280
+
{{% notice note %}}
281
+
Speculative decoding is automatically disabled when multimodal models (with `mmproj`) are active. The `n_draft` parameter can also be overridden per-request.
0 commit comments