okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge main (87dfca0e7) into f-own-int: the 0.2.14 app branch, fixtures and CI fixes, the Qwen4-readiness tools, the shape-engine build scriptsffb3d9b31

main
3.4 KiB60 linesraw
1"""The app's setup, the app's first load and the Terminal's start pick the same drafter for Auto (lane APP-LIN 0.2.14 item 7).
2
3Before: the app prepared every DFlash2-capable model for DFlash2 (the host's own rule), so on a card where Control's Auto means the MTP the setup skipped the MTP layer and the
4first load ran undrafted. Now the app asks `strata drafting plan` at the install (no run config yet: --family/--model) and at the load (--config). This pins that both answers
5equal the start's own decision (drafting.choice_of, what serve/server.py's drafting.apply runs) on the card classes where they differ: a 12 GB CUDA card streaming IQ3_S (MTP)
6and a 24 GB one (DFlash2).
7
8Plain unittest, no pytest fixtures (tmp_path, capsys, monkeypatch): the Windows gate of f-0214-app reported both cases as ERROR at setup with the pytest version.
9"""
10import argparse
11import contextlib
12import io
13import json
14import tempfile
15import unittest
16from pathlib import Path
17from unittest import mock
18
19from strata_cli import drafting_cmd
20from strata_control import drafting
21
22
23def _plan(**kw) -> dict:
24    a = argparse.Namespace(drafting_command="plan", data_dir=None, config=None, family=None, model=None, mode=None, no_split=False,
25                           engines_unloading=False, output="json")
26    for k, v in kw.items():
27        setattr(a, k, v)
28    out = io.StringIO()
29    with contextlib.redirect_stdout(out):
30        code = drafting_cmd.run(a)
31    assert code == 0, out.getvalue()
32    return json.loads(out.getvalue().strip().splitlines()[-1])
33
34
35class SetupFirstLoadAndStartAgree(unittest.TestCase):
36    def test_on_a_12_gb_and_a_24_gb_cuda_card(self):
37        for vram_mib, expected in ((12288, "mtp"), (24576, "dflash2")):
38            with self.subTest(vram_mib=vram_mib), tempfile.TemporaryDirectory() as tmp, \
39                    mock.patch.object(drafting_cmd, "_hardware", return_value=("cuda", ["sm_86"])), \
40                    mock.patch.object(drafting, "card_vram_mib", return_value=float(vram_mib)), \
41                    mock.patch.object(drafting_cmd, "_split_expected", return_value=False), \
42                    mock.patch.object(drafting_cmd, "_installed_dflash2_configs", return_value=[]):
43                data = Path(tmp) / "data"
44                mtp = data / "mtp" / "rt"
45                mtp.mkdir(parents=True)
46                # 1. the app's setup: no run config yet
47                self.assertEqual(_plan(family="qwen", model="IQ3_S", mode="auto", data_dir=str(data))["choice"], expected)
48                # 2. the app's first load: the run config setup wrote (Auto: no "drafting" key)
49                (mtp / "experts.bin").write_bytes(b"x" * 2048)
50                cfg = {"model_name": "qwen3.8-flash-next-iq3_s", "backend": "cuda",
51                       "args": ["--pack", str(data / "packs" / "iq3_s"), "--native", str(Path(tmp) / "IQ3_S-00001-of-00002.gguf"), "--mtp", str(mtp), "--max-context", "131072"]}
52                path = Path(tmp) / "strata-iq3_s.json"
53                path.write_text(json.dumps(cfg), encoding="utf-8")
54                self.assertEqual(_plan(config=str(path))["choice"], expected)
55                # 3. the start (serve/server.py runs drafting.apply on the same config): the same choice
56                self.assertEqual(drafting.choice_of("auto", model_name=cfg["model_name"], backend="cuda", archs=["sm_86"], args=cfg["args"], vram_mib=float(vram_mib)), expected)
57
58
59if __name__ == "__main__":
60    unittest.main()