Skip to content

Commit

Permalink
Un-skip tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abetlen committed May 1, 2023
1 parent bf3d0dc commit c088a2b
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions tests/test_llama.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pytest
import llama_cpp

MODEL = "./vendor/llama.cpp/models/ggml-vocab.bin"
Expand All @@ -15,15 +14,20 @@ def test_llama():
assert llama.detokenize(llama.tokenize(text)) == text


@pytest.mark.skip(reason="need to update sample mocking")
# @pytest.mark.skip(reason="need to update sample mocking")
def test_llama_patch(monkeypatch):
llama = llama_cpp.Llama(model_path=MODEL, vocab_only=True)
n_vocab = int(llama_cpp.llama_n_vocab(llama.ctx))

## Set up mock function
def mock_eval(*args, **kwargs):
return 0

def mock_get_logits(*args, **kwargs):
return (llama_cpp.c_float * n_vocab)(*[llama_cpp.c_float(0) for _ in range(n_vocab)])

monkeypatch.setattr("llama_cpp.llama_cpp.llama_eval", mock_eval)
monkeypatch.setattr("llama_cpp.llama_cpp.llama_get_logits", mock_get_logits)

output_text = " jumps over the lazy dog."
output_tokens = llama.tokenize(output_text.encode("utf-8"))
Expand All @@ -38,7 +42,7 @@ def mock_sample(*args, **kwargs):
else:
return token_eos

monkeypatch.setattr("llama_cpp.llama_cpp.llama_sample_top_p_top_k", mock_sample)
monkeypatch.setattr("llama_cpp.llama_cpp.llama_sample_token", mock_sample)

text = "The quick brown fox"

Expand Down Expand Up @@ -97,15 +101,19 @@ def test_llama_pickle():

assert llama.detokenize(llama.tokenize(text)) == text

@pytest.mark.skip(reason="need to update sample mocking")
def test_utf8(monkeypatch):
llama = llama_cpp.Llama(model_path=MODEL, vocab_only=True)
n_vocab = int(llama_cpp.llama_n_vocab(llama.ctx))

## Set up mock function
def mock_eval(*args, **kwargs):
return 0

def mock_get_logits(*args, **kwargs):
return (llama_cpp.c_float * n_vocab)(*[llama_cpp.c_float(0) for _ in range(n_vocab)])

monkeypatch.setattr("llama_cpp.llama_cpp.llama_eval", mock_eval)
monkeypatch.setattr("llama_cpp.llama_cpp.llama_get_logits", mock_get_logits)

output_text = "😀"
output_tokens = llama.tokenize(output_text.encode("utf-8"))
Expand All @@ -120,7 +128,7 @@ def mock_sample(*args, **kwargs):
else:
return token_eos

monkeypatch.setattr("llama_cpp.llama_cpp.llama_sample_top_p_top_k", mock_sample)
monkeypatch.setattr("llama_cpp.llama_cpp.llama_sample_token", mock_sample)

## Test basic completion with utf8 multibyte
n = 0 # reset
Expand Down

1 comment on commit c088a2b

@su77ungr
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Please sign in to comment.