okami.mom/strata

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

Niko1221Merge f-own-5b adfcf9028 into f-own-int (round 16: the strata-image test program and its parts, DiT runner, sampler, noise, PNG writer; hooked into no build)e4309aaf3

main
3.7 KiB73 linesraw
1"""tools/test_run_strata_image.py - tools/image/gate/run_strata_image.py with a stand-in for strata-image: the command
2line it builds (the three model files, the gate prompt, size, seed, 8 steps, output, report, dump), the files it writes
3(p<i>_s<seed>.png / .log / .json, results.jsonl) and the record (stage times under run_set.py's names, memory per stage,
4rc and the error tail of a failed picture).  POSIX only (the runner uses os.wait4).
5
6    python -m pytest tools/test_run_strata_image.py"""
7import json
8import os
9import subprocess
10import sys
11import tempfile
12import unittest
13from pathlib import Path
14
15ROOT = Path(__file__).resolve().parents[1]
16RUNNER = ROOT / "tools" / "image" / "gate" / "run_strata_image.py"
17sys.path.insert(0, str(RUNNER.parent))
18from run_set import PROMPTS  # noqa: E402
19
20STAND_IN = r'''#!/usr/bin/env python3
21import json, sys
22a = sys.argv[1:]
23open(sys.argv[0] + ".args", "a").write(json.dumps(a) + "\n")
24v = lambda k: a[a.index(k) + 1]
25if v("--seed") == "13":
26    print("strata-image: something broke"); sys.exit(1)
27open(v("-o"), "wb").write(b"\x89PNG fake")
28st = [{"name": n, "wall_ms": ms, "gpu_ms": -1, "ours_gb": 1.5, "driver_gb": 2.0, "host_gb": 0.5, "note": ""}
29      for n, ms in (("open", 700.0), ("encode", 150.0), ("steps", 9800.0), ("decode", 1200.0), ("png", 30.0))]
30json.dump({"plan": "resident", "stages": st}, open(v("--report"), "w"))
31print("STRATA-IMAGE PASS")
32'''
33
34
35@unittest.skipIf(os.name != "posix", "the runner uses os.wait4")
36class RunStrataImage(unittest.TestCase):
37    def test_runs_and_records(self):
38        with tempfile.TemporaryDirectory() as td:
39            t = Path(td)
40            exe = t / "fake-strata-image"
41            exe.write_text(STAND_IN)
42            exe.chmod(0o755)
43            models = t / "models"
44            models.mkdir()
45            r = subprocess.run([sys.executable, "-I", "-B", str(RUNNER), str(t), "set1", "512x512", str(models), "1-2",
46                                "42,13", "--exe", str(exe), "--dump", "--min-free-gb", "0"],
47                               capture_output=True, text=True, timeout=120)
48            self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
49            self.assertIn("RUN-OK", r.stdout)
50            out = t / "pics" / "set1"
51            rows = [json.loads(x) for x in (out / "results.jsonl").read_text().splitlines()]
52            self.assertEqual([(x["prompt"], x["seed"], x["rc"]) for x in rows],
53                             [(1, 42, 0), (1, 13, 1), (2, 42, 0), (2, 13, 1)])
54            ok = rows[0]
55            self.assertEqual((ok["open_s"], ok["text_encode_s"], ok["sampling_s"], ok["vae_decode_s"], ok["png_s"]),
56                             (0.7, 0.15, 9.8, 1.2, 0.03))
57            self.assertEqual((ok["steps_ours_gb"], ok["decode_driver_gb"], ok["plan"]), (1.5, 2.0, "resident"))
58            self.assertIn("something broke", rows[1]["error"])
59            self.assertTrue((out / "p1_s42.png").is_file() and (out / "p2_s42.json").is_file())
60            args = [json.loads(x) for x in Path(str(exe) + ".args").read_text().splitlines()]
61            a = args[0]
62            v = lambda k: a[a.index(k) + 1]
63            self.assertEqual(v("--prompt"), PROMPTS[1])
64            self.assertEqual((v("--width"), v("--height"), v("--seed"), v("--steps")), ("512", "512", "42", "8"))
65            self.assertEqual(Path(v("--dit")).name, "qwen-image-2.1-turbo-Q8_0.gguf")
66            self.assertEqual(Path(v("--vae")).name, "qwen_image_2.1_vae_bf16.safetensors")
67            self.assertEqual(Path(v("--te")).name, "Qwen3-VL-8B-Instruct-UD-Q4_K_XL.gguf")
68            self.assertEqual(Path(v("--dump")).name, "dump_p1_s42")
69            self.assertEqual(Path(v("-o")), out / "p1_s42.png")
70
71
72if __name__ == "__main__":
73    unittest.main()