Make Llama instance pickleable. Closes #27

This commit is contained in:
Andrei Betlen
2023-04-05 06:52:17 -04:00
parent 152e4695c3
commit e96a5c5722
2 changed files with 56 additions and 0 deletions

View File

@@ -77,3 +77,20 @@ def test_llama_patch(monkeypatch):
chunks = llama.create_completion(text, max_tokens=2, stream=True)
assert "".join(chunk["choices"][0]["text"] for chunk in chunks) == " j"
assert completion["choices"][0]["finish_reason"] == "length"
def test_llama_pickle():
import pickle
import tempfile
fp = tempfile.TemporaryFile()
llama = llama_cpp.Llama(model_path=MODEL, vocab_only=True)
pickle.dump(llama, fp)
fp.seek(0)
llama = pickle.load(fp)
assert llama
assert llama.ctx is not None
text = b"Hello World"
assert llama.detokenize(llama.tokenize(text)) == text