Files
leleka/engine/strata/tests/terminal/test_import_projector.py
T
Pavlo RatushnyiandClaude Sonnet 5.5 87e2633afe engine/strata: bring the Strata subtree to upstream 41cf05a0 (engine 0.1.50) with the local patches re-applied
Documented tree replacement (the history has no git-subtree metadata): 3-way merge of the old subtree
(570201a:engine/strata) against upstream 41cf05a06a25dd29103b7b27a2279a3f60c21876 (2026-10-25), merge base =
the old pin d9ab8435 (tree-identical to upstream 5b734e42; d9ab8435 is not an ancestor of upstream main).

Local patches re-applied by hand where they conflicted (15 files): STRATA_CUDA_STATIC profile, experimental KAR
experts and KAR PLE arms, keyless V-only arm (now beside upstream's K8V4 hybrid KV and fused norm+rope). Details,
conflict table and left-out files are in docs/upstream.md.

Left out (weights, captures, logs, media): new bench/results (2022 files), binary media and app assets (61),
docs/work/evidence (24), *.bin / *.gguf data files, and the 7 files the first import already left out.

scripts/build-cpu.sh: build the 11 CPU tests upstream registered since the old pin (they ran as "Not Run").
Checked: build-cpu.sh 16/16 ctest in WSL; sm_86 CUDA objects of the patched files compile, also with the KAR
macros on. No GPU run, no quality gate.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 12:49:15 +01:00

108 lines
4.6 KiB
Python

"""Importing a model together with its picture reader (mmproj), and the plain words when a model type is not ours."""
import io
import json
import struct
import tempfile
import unittest
from contextlib import redirect_stdout
from pathlib import Path
from unittest import mock
from strata_cli.cli import main
from strata_control import models
from tests.terminal.test_models import gguf_fixture
def projector_fixture(projector_type="qwen3vl_merger", architecture="clip") -> bytes:
def string(value):
raw = value.encode()
return struct.pack("<Q", len(raw)) + raw
pairs = [("general.architecture", 8, string(architecture)), ("clip.projector_type", 8, string(projector_type))]
header = (b"GGUF" + struct.pack("<IQQ", 3, 1, len(pairs)) +
b"".join(string(key) + struct.pack("<I", kind) + value for key, kind, value in pairs))
header += string("v.blk.0.attn_q.weight") + struct.pack("<IQIQ", 1, 64, 1, 0)
return header + b"\x00" * (-len(header) % 32) + b"\x00" * 128
class ImportProjectorTests(unittest.TestCase):
def setUp(self):
self.temp = tempfile.TemporaryDirectory()
self.addCleanup(self.temp.cleanup)
self.source = Path(self.temp.name) / "model"
self.source.mkdir()
def plan(self, path):
output = io.StringIO()
with redirect_stdout(output):
main(["models", "import", str(path), "--plan", "--output", "json"])
return json.loads(output.getvalue())["plan"]
def model(self, **kwargs):
first = self.source / "Qwen3.8-Flash-Next-GSQ-RCO-Q2_0-00001-of-00001.gguf"
first.write_bytes(gguf_fixture(**kwargs))
return first
def test_pinned_projector_next_to_a_model_means_pictures(self):
self.model()
file = self.source / "mmproj-Qwen3.8-Flash-Next-BF16.gguf"
file.write_bytes(projector_fixture())
with mock.patch.dict(models.PINNED_PROJECTORS, {file.name.lower(): file.stat().st_size}):
plan = self.plan(self.source)
self.assertTrue(plan["reads_pictures"])
self.assertEqual(plan["projectors"][0]["status"], "ok")
self.assertIn("pictures will work", plan["messages"][0])
def test_same_name_but_another_size_is_not_called_official(self):
self.model()
(self.source / "mmproj-Qwen3.8-Flash-Next-BF16.gguf").write_bytes(projector_fixture())
plan = self.plan(self.source)
self.assertEqual(plan["projectors"][0]["status"], "other_name")
def test_projector_beside_a_chosen_model_file_is_found(self):
first = self.model()
(self.source / "mmproj-F16.gguf").write_bytes(projector_fixture())
plan = self.plan(first)
self.assertEqual([p["name"] for p in plan["projectors"]], ["mmproj-F16.gguf"])
self.assertTrue(plan["reads_pictures"])
def test_projector_of_another_kind_is_not_used(self):
self.model()
(self.source / "mmproj-other.gguf").write_bytes(projector_fixture("mlp"))
plan = self.plan(self.source)
self.assertFalse(plan["reads_pictures"])
self.assertEqual(plan["projectors"][0]["status"], "unsupported")
self.assertIn("Custom model API", plan["projectors"][0]["plain"])
def test_other_name_projector_of_our_kind_is_explained(self):
self.model()
(self.source / "mmproj-mine.gguf").write_bytes(projector_fixture())
plan = self.plan(self.source)
self.assertEqual(plan["projectors"][0]["status"], "other_name")
self.assertTrue(plan["reads_pictures"])
def test_unsupported_model_type_says_custom_api(self):
first = self.source / "SmolVLM-256M-Q8_0.gguf"
first.write_bytes(gguf_fixture(architecture="llama"))
(self.source / "mmproj-SmolVLM-256M-Instruct-Q8_0.gguf").write_bytes(projector_fixture("idefics3"))
plan = self.plan(self.source)
self.assertEqual(plan["file_set_status"], "invalid_or_incomplete")
self.assertFalse(plan["reads_pictures"])
self.assertEqual(plan["messages"], ["This model type isn't supported by the Strata engine. "
"Add it as a Custom model API (llama-server) instead."])
def test_choosing_the_projector_itself_says_so(self):
projector = self.source / "mmproj-F16.gguf"
projector.write_bytes(projector_fixture())
output = io.StringIO()
with redirect_stdout(output):
code = main(["models", "import", str(projector), "--plan", "--output", "json"])
self.assertEqual(code, 5)
self.assertIn("picture reader", json.dumps(json.loads(output.getvalue())))
if __name__ == "__main__":
unittest.main()