Commit 16f090f92 for llama.cpp
commit 16f090f92c0e2ac6dfddcaf93589a9b158c598c7
Author: Pascal <admin@serveurperso.com>
Date: Sat Nov 28 14:08:45 2026 +0100
server tests : add small-test, a 95M multimodal fixture covering toolcalls, vision and MTP (#28815)
* server tests: add the small-test fixture, a 95M multimodal model with tool calling, OCR and MTP
Add ServerPreset.small_test(), a pruned Qwen3.5-0.8B (6 of 31 layers,
82M text params, 12.6M MTP head, 6 block vision tower) hosted at
Serveurperso/small-test, trained specifically to be a deterministic CI
fixture. The idea and the first version are from Xuan-Son Nguyen; the
recovery training, data pipeline and evaluation are documented on the
model card.
unit/test_small_test.py runs 19 greedy tests through the server:
required and auto tool calls with argument checks, a tool result turn,
no tool call cases, OCR on a rendered PNG through mmproj, and MTP draft
equivalence with the target under --spec-type draft-mtp. The suite
takes about 12 s on CPU and passes identically run after run.
* server tests: fetch the small-test OCR images from the Hub
The OCR test rendered its images with Pillow and a DejaVu font path,
neither of which exists on the CI runners. The two PNGs are now hosted
next to the model and fetched with requests, like the tinygemma3
vision test does.
* cmake: remove the stray precompiled header option
The option is unrelated to the server tests and belongs to its own change.
* Revert "cmake: remove the stray precompiled header option"
This reverts commit c218d11903d2261542024319d7ded57566020b24.
* cleaning: download small-test through load_all like the other presets
Mark the preset offline so load_all fetches it once before the tests,
and let the Hub registry pick the mmproj from the F16 tag instead of a
hardcoded URL.
* cleaning: move the small-test cases into the existing test files
Instead of a dedicated file, small-test now backs the fast variants of
the tool call tests (required tool, weather, calc result, hello world),
which only ran as slow tests on 1B to 8B models, plus OCR in the vision
tests and MTP drafting in the speculative tests.
* server tests: move small-test to ggml-org-dev
* server tests: point the small-test preset to ggml-org-dev
* server tests: run the tool and multi image cases on small-test
The Anthropic tool tests ran on tinyllama2, which never calls a tool,
so their checks sat behind an if that was never taken. They now run on
small-test and require the tool_use block, its streamed arguments and
the tool_use stop reason.
Add a vision test with two images in one message, which small-test
reads through to the year of the second image.
diff --git a/tools/server/tests/unit/test_compat_anthropic.py b/tools/server/tests/unit/test_compat_anthropic.py
index 0b65ad1ab..046c9327b 100644
--- a/tools/server/tests/unit/test_compat_anthropic.py
+++ b/tools/server/tests/unit/test_compat_anthropic.py
@@ -37,6 +37,15 @@ def vision_server():
return server
+@pytest.fixture
+def tool_server():
+ """Separate fixture for tool tests that require a model which actually calls tools"""
+ global server
+ server = ServerPreset.small_test()
+ server.n_slots = 1
+ return server
+
+
# Basic message tests
def test_anthropic_messages_basic():
@@ -259,9 +268,10 @@ def test_anthropic_count_tokens_no_max_tokens():
# Tool use tests
-def test_anthropic_tool_use_basic():
+def test_anthropic_tool_use_basic(tool_server):
"""Test basic tool use"""
- server.jinja = True
+ global server
+ server = tool_server
server.start()
res = server.make_request("POST", "/v1/messages", data={
@@ -288,22 +298,14 @@ def test_anthropic_tool_use_basic():
assert res.status_code == 200
assert res.body["type"] == "message"
- assert len(res.body["content"]) > 0
-
- # Check if model used the tool (it might not always, depending on the model)
- content_types = [block.get("type") for block in res.body["content"]]
+ assert res.body["stop_reason"] == "tool_use"
- if "tool_use" in content_types:
- # Model used the tool
- assert res.body["stop_reason"] == "tool_use"
-
- # Find the tool_use block
- tool_block = next(b for b in res.body["content"] if b.get("type") == "tool_use")
- assert "id" in tool_block
- assert "name" in tool_block
- assert tool_block["name"] == "get_weather"
- assert "input" in tool_block
- assert isinstance(tool_block["input"], dict)
+ tool_blocks = [b for b in res.body["content"] if b.get("type") == "tool_use"]
+ assert len(tool_blocks) == 1, f"Expected one tool_use block, got {res.body['content']}"
+ tool_block = tool_blocks[0]
+ assert tool_block["id"]
+ assert tool_block["name"] == "get_weather"
+ assert match_regex("Paris", tool_block["input"]["location"])
def test_anthropic_tool_result():
@@ -546,9 +548,10 @@ def test_anthropic_tool_reference():
assert anthropic.body["input_tokens"] == oai.body["input_tokens"]
-def test_anthropic_tool_streaming():
+def test_anthropic_tool_streaming(tool_server):
"""Test streaming with tool use"""
- server.jinja = True
+ global server
+ server = tool_server
server.start()
res = server.make_stream_request("POST", "/v1/messages", data={
@@ -577,26 +580,26 @@ def test_anthropic_tool_streaming():
event_types = [e["type"] for e in events]
- # Should have basic events
- assert "message_start" in event_types
- assert "message_stop" in event_types
-
- # If tool was used, check for proper tool streaming
- if any(e.get("type") == "content_block_start" and
- e.get("content_block", {}).get("type") == "tool_use"
- for e in events):
- # Find tool use block start
- tool_starts = [e for e in events if
- e.get("type") == "content_block_start" and
- e.get("content_block", {}).get("type") == "tool_use"]
-
- assert len(tool_starts) > 0, "Should have tool_use content_block_start"
-
- # Check index is correct (should be 0 if no text, 1 if there's text)
- tool_start = tool_starts[0]
- assert "index" in tool_start
- assert tool_start["content_block"]["type"] == "tool_use"
- assert "name" in tool_start["content_block"]
+ assert event_types[0] == "message_start"
+ assert event_types[-1] == "message_stop"
+
+ tool_starts = [e for e in events if e["type"] == "content_block_start" and e["content_block"]["type"] == "tool_use"]
+ assert len(tool_starts) == 1, f"Expected one tool_use content_block_start, got {events}"
+ tool_start = tool_starts[0]
+ assert tool_start["content_block"]["name"] == "calculator"
+ assert tool_start["content_block"]["id"]
+
+ # The arguments stream as input_json_delta events on the index of the tool_use block
+ index = tool_start["index"]
+ partial_json = "".join(
+ e["delta"]["partial_json"] for e in events
+ if e["type"] == "content_block_delta" and e["index"] == index and e["delta"]["type"] == "input_json_delta"
+ )
+ assert match_regex("2 *\\+ *2", json.loads(partial_json)["expression"])
+
+ message_deltas = [e for e in events if e["type"] == "message_delta"]
+ assert len(message_deltas) == 1
+ assert message_deltas[0]["delta"]["stop_reason"] == "tool_use"
# Vision/multimodal tests
diff --git a/tools/server/tests/unit/test_speculative.py b/tools/server/tests/unit/test_speculative.py
index 10597fdb0..82e97f5d0 100644
--- a/tools/server/tests/unit/test_speculative.py
+++ b/tools/server/tests/unit/test_speculative.py
@@ -265,3 +265,21 @@ def test_draft_token_probs():
assert abs(tok_draft["logprob"] - tok_no_draft["logprob"]) < 0.25
# real logprobs are not all exactly 0.0 (prob 1.0)
assert any(tok["logprob"] < -1e-4 for tok in probs_draft)
+
+
+def test_mtp_draft_matches_target():
+ # greedy tokens are identical with and without the MTP head of small-test, and the draft is actually used
+ global server
+ server = ServerPreset.small_test()
+ server.start()
+ req = {"prompt": "<|im_start|>user\nList three colors.<|im_end|>\n<|im_start|>assistant\n", "n_predict": 48, "temperature": 0.0, "top_k": 1, "return_tokens": True}
+ res = server.make_request("POST", "/completion", data=req)
+ assert res.status_code == 200
+ tokens_no_draft = res.body["tokens"]
+ server.stop()
+ server.spec_type = "draft-mtp"
+ server.start()
+ res = server.make_request("POST", "/completion", data=req)
+ assert res.status_code == 200
+ assert res.body["timings"]["draft_n"] > 0
+ assert res.body["tokens"] == tokens_no_draft
diff --git a/tools/server/tests/unit/test_tool_call.py b/tools/server/tests/unit/test_tool_call.py
index 80a1cae62..8860485d4 100755
--- a/tools/server/tests/unit/test_tool_call.py
+++ b/tools/server/tests/unit/test_tool_call.py
@@ -125,27 +125,14 @@ def do_test_completion_with_required_tool_tiny(server: ServerProcess, tool: dict
actual_arguments = json.loads(actual_arguments)
assert argument_key in actual_arguments, f"tool arguments: {actual_arguments}, expected: {argument_key}"
-# PR #22654: commented out since we're now allowing content before tool calls in tool_call: required, so we can't force this
-# in the tiny model just by using the grammar
-#
-# @pytest.mark.parametrize("stream", [CompletionMode.NORMAL, CompletionMode.STREAMED])
-# @pytest.mark.parametrize("template_name,tool,argument_key", [
-# ("Qwen3-Coder", TEST_TOOL, "success"),
-# ("Qwen3-Coder", TEST_TOOL, "success"),
-# ("meta-llama-Llama-3.3-70B-Instruct", TEST_TOOL, "success"),
-# ("meta-llama-Llama-3.3-70B-Instruct", TEST_TOOL, "success"),
-# ("meta-llama-Llama-3.3-70B-Instruct", PYTHON_TOOL, "code"),
-# ("meta-llama-Llama-3.3-70B-Instruct", PYTHON_TOOL, "code"),
-# ])
-# def test_completion_with_required_tool_tiny_fast(template_name: str, tool: dict, argument_key: str | None, stream: CompletionMode):
-# global server
-# n_predict = 1024
-# # server = ServerPreset.stories15m_moe()
-# server.jinja = True
-# server.n_predict = n_predict
-# server.chat_template_file = f'../../../models/templates/{template_name}.jinja'
-# server.start()
-# do_test_completion_with_required_tool_tiny(server, tool, argument_key, n_predict, stream=stream == CompletionMode.STREAMED, temperature=0.0, top_k=1, top_p=1.0)
+# the grammar of tool_choice: required allows content before the call, so this needs a model trained on tool calls like small-test
+@pytest.mark.parametrize("stream", [CompletionMode.NORMAL, CompletionMode.STREAMED])
+@pytest.mark.parametrize("tool,argument_key", [(TEST_TOOL, "success"), (PYTHON_TOOL, "code")])
+def test_completion_with_required_tool_fast(tool: dict, argument_key: str, stream: CompletionMode):
+ global server
+ server = ServerPreset.small_test()
+ server.start()
+ do_test_completion_with_required_tool_tiny(server, tool, argument_key, 256, stream=stream == CompletionMode.STREAMED, temperature=0.0, top_k=1, top_p=1.0)
# @pytest.mark.slow
# @pytest.mark.parametrize("stream", [CompletionMode.NORMAL, CompletionMode.STREAMED])
@@ -423,6 +410,14 @@ def do_test_weather(server: ServerProcess, **kwargs):
assert re.match('^Istanbul(( |, ?)(TR|Turkey|Türkiye))?$', location), f'Expected Istanbul for location, got {location}'
+@pytest.mark.parametrize("stream", [CompletionMode.NORMAL, CompletionMode.STREAMED])
+def test_weather_fast(stream: CompletionMode):
+ global server
+ server = ServerPreset.small_test()
+ server.start()
+ do_test_weather(server, stream=stream == CompletionMode.STREAMED, max_tokens=256, temperature=0.0, top_k=1, top_p=1.0)
+
+
@pytest.mark.slow
@pytest.mark.parametrize("stream", [CompletionMode.NORMAL, CompletionMode.STREAMED])
@pytest.mark.parametrize("result_override,n_predict,hf_repo,template_override", [
@@ -519,6 +514,14 @@ def do_test_calc_result(server: ServerProcess, result_override: str | None, n_pr
f'Expected something like "The y coordinate is 0.56.", got {content}'
+@pytest.mark.parametrize("stream", [CompletionMode.NORMAL, CompletionMode.STREAMED])
+def test_calc_result_fast(stream: CompletionMode):
+ global server
+ server = ServerPreset.small_test()
+ server.start()
+ do_test_calc_result(server, None, 256, stream=stream == CompletionMode.STREAMED, temperature=0.0, top_k=1, top_p=1.0)
+
+
@pytest.mark.slow
@pytest.mark.parametrize("stream", [CompletionMode.NORMAL, CompletionMode.STREAMED])
@pytest.mark.parametrize("n_predict,reasoning_format,expect_reasoning_content,expect_content,hf_repo,template_override", [
@@ -644,6 +647,14 @@ def do_test_hello_world(server: ServerProcess, **kwargs):
assert re.match(r'''print\(("[Hh]ello,? [Ww]orld!?"|'[Hh]ello,? [Ww]orld!?')\)''', re.sub(r'#.*\n?', '', code)), f'Expected hello world, got {code}'
+@pytest.mark.parametrize("stream", [CompletionMode.NORMAL, CompletionMode.STREAMED])
+def test_hello_world_fast(stream: CompletionMode):
+ global server
+ server = ServerPreset.small_test()
+ server.start()
+ do_test_hello_world(server, stream=stream == CompletionMode.STREAMED, max_tokens=256, temperature=0.0, top_k=1, top_p=1.0)
+
+
SEARCH_TOOL = {
"type": "function",
"function": {
diff --git a/tools/server/tests/unit/test_vision_api.py b/tools/server/tests/unit/test_vision_api.py
index 3c835fd6d..b33987e45 100644
--- a/tools/server/tests/unit/test_vision_api.py
+++ b/tools/server/tests/unit/test_vision_api.py
@@ -245,3 +245,50 @@ def test_vision_image_url_private_address(allow_private: bool):
finally:
target.shutdown()
target.server_close()
+
+
+def get_ocr_image_part(name: str) -> dict:
+ response = requests.get(f"https://huggingface.co/ggml-org-dev/small-test/resolve/main/test/{name}.png")
+ response.raise_for_status()
+ return {"type": "image_url", "image_url": {"url": "data:image/png;base64," + base64.b64encode(response.content).decode("utf-8")}}
+
+
+@pytest.mark.parametrize("name,text", [("hello_world", "HELLO WORLD"), ("invoice_2026", "Invoice 2026")])
+def test_vision_ocr(name: str, text: str):
+ # small-test reads black text on white in a common truetype font, the kind of image it is trained on
+ global server
+ server = ServerPreset.small_test()
+ server.start()
+ body = server.make_any_request("POST", "/v1/chat/completions", data={
+ "max_tokens": 32,
+ "messages": [{"role": "user", "content": [
+ get_ocr_image_part(name),
+ {"type": "text", "text": "What is written in this image?"},
+ ]}],
+ "temperature": 0.0,
+ "top_k": 1,
+ "top_p": 1.0,
+ })
+ content = body["choices"][0]["message"]["content"]
+ assert text.lower() in content.lower(), f"expected {text!r} in {content!r}"
+
+
+def test_vision_ocr_two_images():
+ # both images in one message: small-test is trained on one image per message, so it only reads the year of the second one
+ # "2026" is only in the second image, which proves that both images reach the model
+ global server
+ server = ServerPreset.small_test()
+ server.start()
+ body = server.make_any_request("POST", "/v1/chat/completions", data={
+ "max_tokens": 64,
+ "messages": [{"role": "user", "content": [
+ get_ocr_image_part("hello_world"),
+ get_ocr_image_part("invoice_2026"),
+ {"type": "text", "text": "What is written in these two images?"},
+ ]}],
+ "temperature": 0.0,
+ "top_k": 1,
+ "top_p": 1.0,
+ })
+ content = body["choices"][0]["message"]["content"].lower()
+ assert "hello world" in content and "2026" in content, f"expected the text of both images in {content!r}"
diff --git a/tools/server/tests/utils.py b/tools/server/tests/utils.py
index a9f9fba2e..607ba5275 100644
--- a/tools/server/tests/utils.py
+++ b/tools/server/tests/utils.py
@@ -796,6 +796,23 @@ class ServerPreset:
server.seed = 42
return server
+ @staticmethod
+ def small_test() -> ServerProcess:
+ # ~95M Qwen3.5 based VLM with MTP head: chat, tool calling, OCR and draft-mtp in one fixture
+ server = ServerProcess()
+ server.offline = True # will be downloaded by load_all()
+ # mmproj is already provided by HF registry API
+ server.model_hf_file = None
+ server.model_hf_repo = "ggml-org-dev/small-test:F16"
+ server.model_alias = "small-test"
+ server.jinja = True
+ server.n_ctx = 8192
+ server.n_batch = 2048
+ server.n_slots = 2
+ server.n_predict = 512
+ server.seed = 42
+ return server
+
@staticmethod
def router() -> ServerProcess:
server = ServerProcess()