okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
e4309aaf3
main
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 6python -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": 26print("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": ""} 29for 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 ): 37def test_runs_and_records (self ): 38with tempfile .TemporaryDirectory ()as td : 39t = Path (td ) 40exe = t / "fake-strata-image" 41exe .write_text (STAND_IN ) 42exe .chmod (0o755 ) 43models = t / "models" 44models .mkdir () 45r = 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" ], 47capture_output = True ,text = True ,timeout = 120 ) 48self .assertEqual (r .returncode ,0 ,r .stdout + r .stderr ) 49self .assertIn ("RUN-OK" ,r .stdout ) 50out = t / "pics" / "set1" 51rows = [json .loads (x )for x in (out / "results.jsonl" ).read_text ().splitlines ()] 52self .assertEqual ([(x ["prompt" ],x ["seed" ],x ["rc" ])for x in rows ], 53 [(1 ,42 ,0 ), (1 ,13 ,1 ), (2 ,42 ,0 ), (2 ,13 ,1 )]) 54ok = rows [0 ] 55self .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 )) 57self .assertEqual ((ok ["steps_ours_gb" ],ok ["decode_driver_gb" ],ok ["plan" ]), (1.5 ,2.0 ,"resident" )) 58self .assertIn ("something broke" ,rows [1 ]["error" ]) 59self .assertTrue ((out / "p1_s42.png" ).is_file ()and (out / "p2_s42.json" ).is_file ()) 60args = [json .loads (x )for x in Path (str (exe )+ ".args" ).read_text ().splitlines ()] 61a = args [0 ] 62v = lambda k :a [a .index (k )+ 1 ] 63self .assertEqual (v ("--prompt" ),PROMPTS [1 ]) 64self .assertEqual ((v ("--width" ),v ("--height" ),v ("--seed" ),v ("--steps" )), ("512" ,"512" ,"42" ,"8" )) 65self .assertEqual (Path (v ("--dit" )).name ,"qwen-image-2.1-turbo-Q8_0.gguf" ) 66self .assertEqual (Path (v ("--vae" )).name ,"qwen_image_2.1_vae_bf16.safetensors" ) 67self .assertEqual (Path (v ("--te" )).name ,"Qwen3-VL-8B-Instruct-UD-Q4_K_XL.gguf" ) 68self .assertEqual (Path (v ("--dump" )).name ,"dump_p1_s42" ) 69self .assertEqual (Path (v ("-o" )),out / "p1_s42.png" ) 70 71 72if __name__ == "__main__" : 73unittest .main ()