summaryrefslogtreecommitdiff
path: root/llama.cpp/tools/server/tests/unit/test_slot_save.py
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2026-02-12 20:57:17 +0100
committerMitja Felicijan <mitja.felicijan@gmail.com>2026-02-12 20:57:17 +0100
commitb333b06772c89d96aacb5490d6a219fba7c09cc6 (patch)
tree211df60083a5946baa2ed61d33d8121b7e251b06 /llama.cpp/tools/server/tests/unit/test_slot_save.py
downloadllmnpc-b333b06772c89d96aacb5490d6a219fba7c09cc6.tar.gz
Engage!
Diffstat (limited to 'llama.cpp/tools/server/tests/unit/test_slot_save.py')
-rw-r--r--llama.cpp/tools/server/tests/unit/test_slot_save.py98
1 files changed, 98 insertions, 0 deletions
diff --git a/llama.cpp/tools/server/tests/unit/test_slot_save.py b/llama.cpp/tools/server/tests/unit/test_slot_save.py
new file mode 100644
index 0000000..1b428cc
--- /dev/null
+++ b/llama.cpp/tools/server/tests/unit/test_slot_save.py
@@ -0,0 +1,98 @@
+import pytest
+from utils import *
+
+server = ServerPreset.tinyllama2()
+
+@pytest.fixture(autouse=True)
+def create_server():
+ global server
+ server = ServerPreset.tinyllama2()
+ server.slot_save_path = "./tmp"
+ server.temperature = 0.0
+
+
+def test_slot_save_restore():
+ global server
+ server.start()
+
+ # First prompt in slot 1 should be fully processed
+ res = server.make_request("POST", "/completion", data={
+ "prompt": "What is the capital of France?",
+ "id_slot": 1,
+ "cache_prompt": True,
+ })
+ assert res.status_code == 200
+ assert match_regex("(Whiskers|Flana)+", res.body["content"])
+ assert res.body["timings"]["prompt_n"] == 21 # all tokens are processed
+
+ # Save state of slot 1
+ res = server.make_request("POST", "/slots/1?action=save", data={
+ "filename": "slot1.bin",
+ })
+ assert res.status_code == 200
+ assert res.body["n_saved"] == 84
+
+ # Since we have cache, this should only process the last tokens
+ res = server.make_request("POST", "/completion", data={
+ "prompt": "What is the capital of Germany?",
+ "id_slot": 1,
+ "cache_prompt": True,
+ })
+ assert res.status_code == 200
+ assert match_regex("(Jack|said)+", res.body["content"])
+ assert res.body["timings"]["prompt_n"] == 6 # only different part is processed
+
+ # Loading the saved cache into slot 0
+ res = server.make_request("POST", "/slots/0?action=restore", data={
+ "filename": "slot1.bin",
+ })
+ assert res.status_code == 200
+ assert res.body["n_restored"] == 84
+
+ # Since we have cache, slot 0 should only process the last tokens
+ res = server.make_request("POST", "/completion", data={
+ "prompt": "What is the capital of Germany?",
+ "id_slot": 0,
+ "cache_prompt": True,
+ })
+ assert res.status_code == 200
+ assert match_regex("(Jack|said)+", res.body["content"])
+ assert res.body["timings"]["prompt_n"] == 6 # only different part is processed
+
+ # For verification that slot 1 was not corrupted during slot 0 load, same thing should work
+ res = server.make_request("POST", "/completion", data={
+ "prompt": "What is the capital of Germany?",
+ "id_slot": 1,
+ "cache_prompt": True,
+ })
+ assert res.status_code == 200
+ assert match_regex("(Jack|said)+", res.body["content"])
+ assert res.body["timings"]["prompt_n"] == 1
+
+
+def test_slot_erase():
+ global server
+ server.start()
+
+ res = server.make_request("POST", "/completion", data={
+ "prompt": "What is the capital of France?",
+ "id_slot": 1,
+ "cache_prompt": True,
+ })
+ assert res.status_code == 200
+ assert match_regex("(Whiskers|Flana)+", res.body["content"])
+ assert res.body["timings"]["prompt_n"] == 21 # all tokens are processed
+
+ # erase slot 1
+ res = server.make_request("POST", "/slots/1?action=erase")
+ assert res.status_code == 200
+
+ # re-run the same prompt, it should process all tokens again
+ res = server.make_request("POST", "/completion", data={
+ "prompt": "What is the capital of France?",
+ "id_slot": 1,
+ "cache_prompt": True,
+ })
+ assert res.status_code == 200
+ assert match_regex("(Whiskers|Flana)+", res.body["content"])
+ assert res.body["timings"]["prompt_n"] == 21 # all tokens are processed