okami.mom/strata

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

Niko1221Auto on the 12 GB / streaming CUDA class: IQ3_S starts the MTP, UD-IQ4_XS-v31 starts DFlash2 with the tuned pack at the class's own 0.8cc3f9142e

main
8.0 KiB139 linesraw
1"""Auto on HIP gfx1201 (RX 9070 / R9700 class) starts the MTP until PE-RDNA4's fix for the open DFlash2 prompt stall lands (owner 11-06 ~10:30; drafting.AUTO_MTP, ONE entry).
2
3Only Auto changes. DFlash2 chosen by name still starts DFlash2; gfx1151, other AMD cards, CUDA, Metal and SYCL are what they were; the confidence tables are untouched.
4"""
5
6from __future__ import annotations
7
8import json
9import tempfile
10import unittest
11from pathlib import Path
12from unittest import mock
13
14from strata_control import drafting
15
16ROOT = Path(__file__).resolve().parents[2]
17IQ3S = "qwen3.8-flash-next-iq3_s"
18Q4 = "qwen3.8-flash-next-unsloth-ud-q4_k_xl"
19V31 = "qwen3.8-flash-next-unsloth-ud-iq4_xs-v31"
20GYRO = "qwen3.8-flash-next-gyro-gyro-s"
21R9700 = ("hip", ["gfx1201"], 32768)
22
23
24def flag(args, name):
25    return args[args.index(name) + 1] if name in args and args.index(name) + 1 < len(args) else None
26
27
28class Base(unittest.TestCase):
29    def setUp(self):
30        self.tmp = tempfile.TemporaryDirectory()
31        self.addCleanup(self.tmp.cleanup)
32        self.root = Path(self.tmp.name)
33        self.data = self.root / "data"
34        for sub in ("dflash2", "mtp/rt", "packs/tag"):
35            (self.data / sub).mkdir(parents=True)
36        (self.data / "dflash2" / drafting.PACK_NAME).write_bytes(b"s" * (2 << 20))
37        (self.data / "dflash2" / drafting.VOCAB_NAME).write_bytes(b"v" * 100)
38        (self.data / "mtp" / "rt" / "experts.bin").write_bytes(b"e" * 100)
39        (self.data / "mtp" / "rt" / drafting.VOCAB_NAME).write_bytes(b"v" * 100)
40        self.exe = self.root / "strata"
41        self.exe.write_bytes(b"--mtp-draft-vocab FILE (or --mtp DIR ... --draft-fallback ... selector codebooks: Q4_0 rows")
42        self.args = ["--native", "m.gguf", "--pack", str(self.data / "packs" / "tag"), "--mtp", str(self.data / "mtp" / "rt"), "--spec", "4", "--max-context", "65536"]
43        patcher = mock.patch.object(drafting, "ENGINE_SERVES_DFLASH2", True)
44        patcher.start()
45        self.addCleanup(patcher.stop)
46
47    def apply(self, name, hardware, **extra):
48        backend, archs, vram = hardware
49        cfg = {"model_name": name, "args": list(self.args), **extra}
50        decision = drafting.apply(cfg, data_dir=self.data, backend=backend, archs=archs, engine=self.exe, vram_mib=vram)
51        return decision, cfg["args"]
52
53
54class Gfx1201(Base):
55    def test_auto_is_the_mtp_for_every_set(self):
56        for name in (IQ3S, Q4, V31, GYRO):
57            for extra in ({}, {"drafting": "auto"}):
58                before = list(self.args)
59                d, args = self.apply(name, R9700, **extra)
60                self.assertEqual((d.drafter, d.note), ("mtp", ""), (name, extra))
61                self.assertFalse([a for a in args if a.startswith("--draft")], (name, extra))
62                self.assertEqual(args, before, "the MTP arguments exactly as saved")
63
64    def test_dflash2_chosen_by_name_still_wins(self):
65        d, args = self.apply(IQ3S, R9700, drafting="dflash2")
66        self.assertEqual((d.drafter, d.note), ("dflash2", ""))
67        self.assertEqual(flag(args, "--draft"), "dflash2")
68        self.assertEqual(flag(args, "--draft-conf"), "0.35", "the R9700's own conf (12,570 slots)")
69        self.assertNotIn("--mtp", args)
70        mine = ["--draft-conf", "0.5"]
71        d, args = self.apply(IQ3S, R9700, drafting="dflash2", user_args=mine)
72        self.assertEqual(flag(args, "--draft-conf"), "0.5", "and the person's own conf over it")
73
74    def test_the_other_choices_are_as_they_were(self):
75        for mode, drafter in (("mtp", "mtp"), ("off", "off")):
76            d, args = self.apply(IQ3S, R9700, drafting=mode)
77            self.assertEqual(d.drafter, drafter, mode)
78
79    def test_with_no_mtp_layer_on_disk_auto_is_not_dflash2_either(self):
80        (self.data / "mtp" / "rt" / "experts.bin").unlink()
81        d, args = self.apply(IQ3S, R9700)
82        self.assertEqual((d.drafter, d.note), ("off", drafting.NONE_HERE))
83        self.assertFalse([a for a in args if a.startswith("--draft")])
84        d, args = self.apply(IQ3S, R9700, drafting="dflash2")
85        self.assertEqual(d.drafter, "dflash2", "named: DFlash2 as before")
86
87    def test_what_gets_fetched(self):
88        kw = dict(model_name=IQ3S, backend="hip", archs=["gfx1201"], data_dir=self.root / "empty")
89        self.assertFalse(drafting.needs_pack("auto", **kw), "no DFlash2 download for Auto")
90        self.assertTrue(drafting.needs_pack("dflash2", **kw), "but one for DFlash2 named")
91        self.assertFalse(drafting.needs_tuned("auto", **kw))
92        self.assertTrue(drafting.needs_mtp("auto", mtp_here=False, **{k: v for k, v in kw.items() if k != "data_dir"}))
93        self.assertFalse(drafting.wants_one_request("auto", model_name=IQ3S, backend="hip", archs=["gfx1201"]))
94        self.assertTrue(drafting.wants_one_request("dflash2", model_name=IQ3S, backend="hip", archs=["gfx1201"]))
95
96    def test_the_support_line_says_it_in_plain_words(self):
97        support = drafting.hardware_support("hip", ["gfx1201"], IQ3S)
98        self.assertEqual((support.can_run, support.level, support.line), (True, "tested", drafting.LINE_AUTO_MTP))
99        self.assertEqual(drafting.LINE_AUTO_MTP, "DFlash2 is off by default on this graphics card for now; choose it in Drafting to use it.")
100        for word in ("recommend", "best", "better", "should", "avoid"):
101            self.assertNotIn(word, drafting.LINE_AUTO_MTP.lower())
102        en = json.loads((ROOT / "apps" / "host" / "src" / "locales" / "df2-en.json").read_text(encoding="utf-8"))
103        self.assertEqual(en["df22"], drafting.LINE_AUTO_MTP)
104
105    def test_it_is_one_entry_and_removing_it_puts_auto_back(self):
106        self.assertEqual(list(drafting.AUTO_MTP), [("hip", "gfx1201")])
107        self.assertIn("stall", drafting.AUTO_MTP[("hip", "gfx1201")])
108        with mock.patch.dict(drafting.AUTO_MTP, clear=True):
109            d, args = self.apply(IQ3S, R9700)
110            self.assertEqual((d.drafter, flag(args, "--draft")), ("dflash2", "dflash2"))
111            self.assertEqual(drafting.hardware_support("hip", ["gfx1201"], IQ3S).line, drafting.LINE_TESTED)
112
113
114class EverythingElseIsUnchanged(Base):
115    def test_gfx1151_cuda_other_amd_metal_and_sycl_still_start_dflash2_under_auto(self):
116        for hardware in (("hip", ["gfx1151"], None), ("hip", ["gfx1100"], 24576), ("hip", ["gfx1200"], 16384), ("cuda", ["sm_120"], 73728), ("cuda", ["sm_86"], 49152),      # (a 12 GB card has its own entry: test_drafting_streaming_class.py)
117                         
118                         ("cuda", ["sm_121"], None), ("sycl", ["arc_a"], None)):
119            d, args = self.apply(IQ3S, hardware)
120            self.assertEqual((d.drafter, flag(args, "--draft")), ("dflash2", "dflash2"), hardware)
121        d, args = self.apply(Q4, ("metal", [], None))
122        self.assertEqual((d.drafter, flag(args, "--draft")), ("dflash2", "dflash2"))
123
124    def test_the_confidence_tables_and_the_other_entries_are_what_they_were(self):
125        self.assertEqual(drafting.CONF_STEPS, ((12000, 0.35), (7500, 0.5), (3000, 0.7), (0, 0.8)))
126        self.assertEqual(drafting.BACKEND_CONF, {"sycl": 0.6, "metal": 0.5})
127        self.assertEqual((drafting.DRAFT_CONF, drafting.SPEC_WINDOW), (0.35, 6))
128        self.assertEqual(drafting.conf_for("hip", drafting.slots_of(self.args, 32768)), 0.35)
129        self.assertEqual(drafting.choice_of("auto", model_name=IQ3S, backend="hip", archs=["gfx1151"]), "dflash2")
130        self.assertEqual(drafting.choice_of("auto", model_name=IQ3S, backend="hip", archs=["gfx1201"]), "mtp")
131        self.assertEqual(drafting.choice_of("dflash2", model_name=IQ3S, backend="hip", archs=["gfx1201"]), "dflash2")
132        self.assertEqual(drafting.choice_of("auto", family="qwen", backend="hip"), "dflash2", "no architecture known: as before")
133        self.assertEqual(drafting.choice_of("auto", model_name=IQ3S, backend="cuda", archs=["gfx1201"]), "dflash2", "the family matters: only hip")
134        self.assertEqual(drafting.hardware_support("hip", ["gfx1151"], IQ3S).line, drafting.LINE_TESTED)
135        self.assertEqual(drafting.hardware_support("cuda", ["sm_120"], IQ3S).line, drafting.LINE_TESTED)
136
137
138if __name__ == "__main__":
139    unittest.main()