Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit 9515467

Browse files
committed
tests: add mock_kv_cache placeholder functions
1 parent 0ea2444 commit 9515467

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

tests/test_llama.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,56 @@ def mock_get_logits(ctx: llama_cpp.llama_context_p):
9696
monkeypatch.setattr("llama_cpp.llama_cpp.llama_decode", mock_decode)
9797
monkeypatch.setattr("llama_cpp.llama_cpp.llama_get_logits", mock_get_logits)
9898

99+
def mock_kv_cache_clear(ctx: llama_cpp.llama_context_p):
100+
# Test some basic invariants of this mocking technique
101+
assert ctx == llama._ctx.ctx, "context does not match mock_llama"
102+
return
103+
104+
def mock_kv_cache_seq_rm(
105+
ctx: llama_cpp.llama_context_p,
106+
seq_id: llama_cpp.llama_seq_id,
107+
pos0: llama_cpp.llama_pos,
108+
pos1: llama_cpp.llama_pos,
109+
):
110+
# Test some basic invariants of this mocking technique
111+
assert ctx == llama._ctx.ctx, "context does not match mock_llama"
112+
return
113+
114+
def mock_kv_cache_seq_cp(
115+
ctx: llama_cpp.llama_context_p,
116+
seq_id_src: llama_cpp.llama_seq_id,
117+
seq_id_dst: llama_cpp.llama_seq_id,
118+
pos0: llama_cpp.llama_pos,
119+
pos1: llama_cpp.llama_pos,
120+
):
121+
# Test some basic invariants of this mocking technique
122+
assert ctx == llama._ctx.ctx, "context does not match mock_llama"
123+
return
124+
125+
def mock_kv_cache_seq_keep(
126+
ctx: llama_cpp.llama_context_p,
127+
seq_id: llama_cpp.llama_seq_id,
128+
):
129+
# Test some basic invariants of this mocking technique
130+
assert ctx == llama._ctx.ctx, "context does not match mock_llama"
131+
return
132+
133+
def mock_kv_cache_seq_shift(
134+
ctx: llama_cpp.llama_context_p,
135+
seq_id: llama_cpp.llama_seq_id,
136+
pos0: llama_cpp.llama_pos,
137+
pos1: llama_cpp.llama_pos,
138+
):
139+
# Test some basic invariants of this mocking technique
140+
assert ctx == llama._ctx.ctx, "context does not match mock_llama"
141+
return
142+
143+
monkeypatch.setattr("llama_cpp.llama_cpp.llama_kv_cache_clear", mock_kv_cache_clear)
144+
monkeypatch.setattr("llama_cpp.llama_cpp.llama_kv_cache_seq_rm", mock_kv_cache_seq_rm)
145+
monkeypatch.setattr("llama_cpp.llama_cpp.llama_kv_cache_seq_cp", mock_kv_cache_seq_cp)
146+
monkeypatch.setattr("llama_cpp.llama_cpp.llama_kv_cache_seq_keep", mock_kv_cache_seq_keep)
147+
monkeypatch.setattr("llama_cpp.llama_cpp.llama_kv_cache_seq_shift", mock_kv_cache_seq_shift)
148+
99149
return setup_mock
100150

101151

0 commit comments

Comments
 (0)