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
- Add `LlamaNGramMapDecoding` to `llama_speculative.py`, implementing an ultra-fast speculative decoder based on a hash inverted index and incremental updates.
- Achieve O(1) time complexity for draft token generation, completely eliminating the CPU bottleneck present in the legacy Numpy sliding window approach.
- Update `README.md` and `docs/wiki/core/Llama.md` to recommend `LlamaNGramMapDecoding` as the default and fastest speculative decoding method, along with updated initialization examples.
- Add docs comment to the speculative decoding classes for better developer experience.
- Add warnings to the legacy `LlamaPromptLookupDecoding` class regarding its high computational overhead for long contexts.
`llama-cpp-python` supports speculative decoding which allows the model to generate completions based on a draft model.
1372
1372
1373
-
The fastest way to use speculative decoding is through the `LlamaPromptLookupDecoding` class.
1373
+
The fastest way to use speculative decoding is through the `LlamaNGramMapDecoding`(**Recommend**) or `LlamaPromptLookupDecoding` class.
1374
1374
1375
1375
Just pass this as a draft model to the `Llama` class during initialization.
1376
1376
1377
1377
```python
1378
1378
from llama_cpp import Llama
1379
-
from llama_cpp.llama_speculative import LlamaPromptLookupDecoding
1379
+
from llama_cpp.llama_speculative import LlamaNGramMapDecoding
1380
1380
1381
1381
llama = Llama(
1382
-
model_path="path/to/model.gguf",
1383
-
draft_model=LlamaPromptLookupDecoding(num_pred_tokens=10) # num_pred_tokens is the number of tokens to predict 10 is the default and generally good for gpu, 2 performs better for cpu-only machines.
1382
+
model_path="path/to/qwen-3.6-27b.gguf",
1383
+
n_ctx=4096,
1384
+
n_gpu_layers=-1,
1385
+
draft_model=LlamaNGramMapDecoding(
1386
+
ngram_size=3,
1387
+
num_pred_tokens=10
1388
+
)
1389
+
)
1390
+
1391
+
response = llama.create_chat_completion(
1392
+
messages=[{"role": "user", "content": "Write a python script..."}]
1384
1393
)
1385
1394
```
1395
+
Note: `LlamaPromptLookupDecoding.num_pred_tokens` is the number of tokens to predict 10 is the default and generally good for gpu, 2 performs better for cpu-only machines. Now, `LlamaNGramMapDecoding` with the new Hash Map algorithm, draft generation becomes instantaneous $O(1)$, and the time consumption is almost 0 regardless of whether you set the prediction to 2 or 10 words.
from llama_cpp.llama_speculative import LlamaNGramMapDecoding
143
+
144
+
llama = Llama(
145
+
model_path="path/to/qwen-3.6-27b.gguf",
146
+
n_ctx=4096,
147
+
n_gpu_layers=-1,
148
+
draft_model=LlamaNGramMapDecoding(
149
+
ngram_size=3,
150
+
num_pred_tokens=10
151
+
)
152
+
)
145
153
146
154
for chunk in main_llm.create_completion("Explain quantum physics", stream=True):
147
155
print(chunk["choices"][0]["text"], end="")
148
156
```
157
+
Note: `LlamaPromptLookupDecoding.num_pred_tokens`is the number of tokens to predict 10is the default and generally good for gpu, 2 performs better for cpu-only machines. Now, `LlamaNGramMapDecoding`with the new Hash Map algorithm, draft generation becomes instantaneous $O(1)$, and the time consumption is almost 0 regardless of whether you set the prediction to 2or10 words.
0 commit comments