okami.mom/strata

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

Niko1221The four owner-approved strings (11-07), word for wordd8db7ced3

main
3.2 KiB66 linesraw
1"""The four strings the owner approved word for word (11-07), and the rule for the third."""
2from __future__ import annotations
3
4import argparse
5import os
6import time
7import unittest
8from pathlib import Path
9from tempfile import TemporaryDirectory
10
11from strata_control import drafting
12from strata_cli.launch import cmd as launch_cmd
13
14ROOT = Path(__file__).resolve().parents[2]
15
16
17class Wording(unittest.TestCase):
18    def test_launch_help_and_the_docs_row_say_the_size_depends_on_the_model(self):
19        top = argparse.ArgumentParser()
20        parsers = launch_cmd.add_parsers(top.add_subparsers(dest="command"))
21        helptext = " ".join(" ".join(p.format_help() for p in parsers).split())
22        self.assertIn("dflash2 (downloads its drafter once, 0.3 to 1.2 GB depending on the model; the size is shown before the download)", helptext)
23        self.assertNotIn("1.2 GB drafter once", helptext)
24        docs = (ROOT / "docs" / "TERMINAL_LAUNCH.md").read_text(encoding="utf-8")
25        self.assertIn("and downloads its drafter once (0.34 GB for the models that have a tuned drafter, 0.52 GB on Intel Arc, else 1.2 GB).", docs)
26
27    def test_the_arc_launch_line_names_what_was_not_downloaded(self):
28        src = (ROOT / "strata_cli" / "launch" / "runner.py").read_text(encoding="utf-8")
29        self.assertIn("({path.name}). No model files were downloaded.\")", src)
30        self.assertNotIn("({path.name}). Nothing was downloaded.", src)
31
32
33class FetchHint(unittest.TestCase):
34    NONE = drafting.Decision("auto", "off", drafting.NONE_HERE)
35
36    def hint(self, data, decision=None, **kw):
37        kw = {"model_name": "qwen3.8-flash-next-iq3_s", "backend": "cuda", "archs": ["sm_120"], "args": [], "vram_mib": 73728.0, **kw}
38        return drafting.fetch_hint(decision or self.NONE, data_dir=data, **kw)
39
40    def miss(self, data, age=0):
41        mark = Path(data) / drafting.FOLDER / drafting.MISS_MARK
42        mark.parent.mkdir(parents=True, exist_ok=True)
43        mark.write_text("x")
44        if age:
45            old = time.time() - age
46            os.utime(mark, (old, old))
47
48    def test_only_with_a_recent_miss_and_a_tuned_set(self):
49        with TemporaryDirectory() as d:
50            self.assertEqual(self.hint(d), "", "no miss mark")
51            self.miss(d)
52            self.assertEqual(self.hint(d), "Run strata drafting fetch to get the DFlash2 drafter now.")
53            self.assertEqual(self.hint(d, drafting.Decision("dflash2", "off", drafting.NONE_HERE)), "Run strata drafting fetch to get the DFlash2 drafter now.")
54            self.assertEqual(self.hint(d, drafting.Decision("mtp", "off", drafting.NONE_HERE)), "", "MTP chosen: nothing to fetch")
55            self.assertEqual(self.hint(d, drafting.Decision("auto", "mtp", "")), "", "a drafter runs")
56            self.assertEqual(self.hint(d, drafting.Decision("auto", "off", drafting.DIDNT_FIT)), "", "off for another reason")
57            self.assertEqual(self.hint(d, model_name="qwen3.8-flash-next-coder-iq1_m"), "", "a set with no tuned drafter")
58
59    def test_an_old_miss_says_nothing(self):
60        with TemporaryDirectory() as d:
61            self.miss(d, age=drafting.RETRY_AFTER_S + 60)
62            self.assertEqual(self.hint(d), "")
63
64
65if __name__ == "__main__":
66    unittest.main()