Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- fix: honor zero-valued constructor seeds by @remote-controlled-man in #2444
- fix: load cached pretrained models in offline mode by @emme1t in #2396
- fix(ci): install matching NVML headers for CUDA wheel builds

Expand Down
2 changes: 1 addition & 1 deletion llama_cpp/llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def __init__(
self.n_threads_batch = n_threads_batch or multiprocessing.cpu_count()

# Used by the sampler
self._seed = seed or llama_cpp.LLAMA_DEFAULT_SEED
self._seed = seed if seed is not None else llama_cpp.LLAMA_DEFAULT_SEED

# Context Params
self.context_params = llama_cpp.llama_context_default_params()
Expand Down
26 changes: 26 additions & 0 deletions tests/test_llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,32 @@ def logit_processor_func(input_ids, logits):
assert number_1 == number_3


@pytest.mark.parametrize("seed", [0, 1337])
def test_constructor_seed_matches_set_seed(llama_cpp_transformer_model_path, seed):
model = llama_cpp.Llama(
llama_cpp_transformer_model_path,
seed=seed,
n_ctx=128,
n_batch=128,
n_ubatch=128,
n_threads=1,
n_threads_batch=1,
verbose=False,
)
try:
tokens = model.tokenize(b"Once upon a time")
model.eval(tokens)
assert model.save_state().seed == seed

actual = list(itertools.islice(model.generate(tokens, temp=1.0), 16))
model.set_seed(seed)
expected = list(itertools.islice(model.generate(tokens, temp=1.0), 16))

assert actual == expected
finally:
model.close()


def test_real_llama_repeated_prompt_cache(llama_cpp_model_path):
model = llama_cpp.Llama(
llama_cpp_model_path,
Expand Down
Loading