okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
11c8c701a
main
1"""tools/image/gate/te_tok_collect.py - TEST-ONLY (OWN-5 gate harness): stable-diffusion.cpp's own token ids for every 2case of te_tok_cases.py, from a stage_hooks.py build: one sd-cli process per prompt with OWN5_EXIT_AFTER_TOKENS=1, so 3it stops right after LLMEmbedder built the ids (no model weights are loaded). 4 5python3 -I -B te_tok_collect.py <sd-cli> <models dir> <cases dir> <out.json> 6 7out.json: [{"name", "prompt_b64", "ids": [...], "weights": [...], "n_system": int} or {..., "error": "<last log line>"}]; 8the command is the server's (the three model files, 8 steps, Turbo sigmas), at 256x256.""" 9import json 10import os 11import shutil 12import subprocess 13import sys 14import tempfile 15from pathlib import Path 16 17import numpy as np 18 19SIGMAS = "1.0,0.978453,0.95418,0.926626,0.89508,0.845148,0.704534,0.414568,0.0" 20 21 22def main ()-> int : 23exe ,models ,cdir ,out = sys .argv [1 ],Path (sys .argv [2 ]),Path (sys .argv [3 ]),Path (sys .argv [4 ]) 24man = json .loads ((cdir / "cases.json" ).read_text ()) 25res ,errors = [],0 26with tempfile .TemporaryDirectory (dir = str (out .parent ))as td : 27for c in man : 28d = Path (td )/ c ["name" ] 29d .mkdir () 30cmd = [exe ,"--diffusion-model" ,str (models / "qwen-image-2.1-turbo-Q8_0.gguf" ), 31"--vae" ,str (models / "qwen_image_2.1_vae_bf16.safetensors" ), 32"--llm" ,str (models / "Qwen3-VL-8B-Instruct-UD-Q4_K_XL.gguf" ), 33"--prompt-file" ,str (cdir / f" { c [ 'name' ] } .txt" ),"--steps" ,"8" ,"--cfg-scale" ,"1.0" , 34"--sampling-method" ,"euler" ,"-W" ,"256" ,"-H" ,"256" ,"--sigmas" ,SIGMAS ,"-s" ,"42" , 35"-o" ,str (d / "img_%d.png" ),"--diffusion-fa" ] 36env = dict (os .environ ,OWN5_DUMP_DIR = str (d ),OWN5_EXIT_AFTER_TOKENS = "1" ) 37p = subprocess .run (cmd ,env = env ,cwd = str (d ),capture_output = True ,text = True ,errors = "replace" ,timeout = 600 ) 38r = dict (c ) 39if (d / "tokens.bin" ).is_file (): 40r ["ids" ]= np .fromfile (d / "tokens.bin" ,dtype = "<i4" ).tolist () 41r ["weights" ]= [float (x )for x in np .fromfile (d / "tokens.weights" ,dtype = "<f4" )] 42r ["n_system" ]= int ((d / "tokens.start" ).read_text ().split ()[0 ]) 43else : 44lines = [ln for ln in (p .stdout + p .stderr ).splitlines ()if ln .strip ()] 45r ["error" ]= (lines [- 1 ]if lines else f"rc { p . returncode } " )[:300 ] 46r ["rc" ]= p .returncode 47errors += 1 48res .append (r ) 49shutil .rmtree (d ,ignore_errors = True ) 50out .write_text (json .dumps (res ,ensure_ascii = True )) 51f" { len ( res ) } cases, { len ( res ) - errors } with ids, { errors } without (sd.cpp refused or failed)" ) 52for r in res : 53if "error" in r : 54f" { r [ 'name' ] } : rc { r [ 'rc' ] } : { r [ 'error' ] } " ) 55return 0 56 57 58if __name__ == "__main__" : 59sys .exit (main ())