MCPcopy Create free account
hub / github.com/abetlen/llama-cpp-python / test_real_llama

Function test_real_llama

tests/test_llama.py:159–258  ·  view source on GitHub ↗
(llama_cpp_model_path)

Source from the content-addressed store, hash-verified

157
158
159def test_real_llama(llama_cpp_model_path):
160 model = llama_cpp.Llama(
161 llama_cpp_model_path,
162 n_ctx=32,
163 n_batch=32,
164 n_ubatch=32,
165 n_threads=multiprocessing.cpu_count(),
166 n_threads_batch=multiprocessing.cpu_count(),
167 logits_all=False,
168 flash_attn=True,
169 )
170
171 output = model.create_completion(
172 "The quick brown fox jumps over the lazy dog. The quick brown fox",
173 max_tokens=6,
174 top_k=50,
175 top_p=0.9,
176 temperature=0.0,
177 seed=1337,
178 )
179 assert output["choices"][0]["text"] == " jumps over the lazy dog."
180
181 output = model.create_completion(
182 "The capital of france is paris, 'true' or 'false'?:\n",
183 max_tokens=4,
184 top_k=50,
185 top_p=0.9,
186 temperature=0.8,
187 seed=1337,
188 grammar=llama_cpp.LlamaGrammar.from_string("""
189root ::= "true" | "false"
190"""),
191 )
192 assert output["choices"][0]["text"] == "true"
193
194 suffix = b"rot"
195 tokens = model.tokenize(suffix, add_bos=True, special=True)
196
197 def logit_processor_func(input_ids, logits):
198 for token in tokens:
199 logits[token] *= 1000
200 return logits
201
202 logit_processors = llama_cpp.LogitsProcessorList([logit_processor_func])
203
204 output = model.create_completion(
205 "The capital of france is par",
206 max_tokens=4,
207 top_k=50,
208 top_p=0.9,
209 temperature=0.8,
210 seed=1337,
211 logits_processor=logit_processors,
212 )
213 assert output["choices"][0]["text"].lower().startswith("rot")
214
215 model.set_seed(1337)
216

Callers

nothing calls this directly

Calls 6

create_completionMethod · 0.95
tokenizeMethod · 0.95
set_seedMethod · 0.95
save_stateMethod · 0.95
load_stateMethod · 0.95
from_stringMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…