okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
736266e87
main
1"""tools/image/gate/vae_identity.py - TEST-ONLY (OWN-5 gate harness): the row-band decode (what Strata ships) against 2the one-pass reference decode, byte for byte, for every fixed latent of the stage sets named; and run to run. 3 4python -I -B vae_identity.py <strata-vae-decode> <vae.safetensors> <pics root> <latent tag> [<latent tag> ...] 5 6For each <pics root>/<tag>/dump_<name>/latent.bin: decode with --stream off (one pass) and --stream on --repeat 2 7(row bands, twice in one process), and with two other band heights (--band-rows 48 and 100: other positions of the 8pixels in their GEMM blocks than the default 128 rows); prints the peak memory and time and IDENTICAL / DIFFERENT; 9exit 1 if anything differs (gate: all identical at 512, 1024 and 1536x1024, on CUDA and on HIP).""" 10from __future__import annotations 11 12import re 13import subprocess 14import sys 15import tempfile 16from pathlib import Path 17 18OTHER_BAND_ROWS = (48 ,100 ) 19LINE = re .compile (r"decode (\d+)x(\d+) run (\d+): ([\d.]+) ms, peak (\d+) MiB(?:.*(identical|DIFFERS))?" ) 20 21 22def run (exe ,vae ,lat ,out ,extra ): 23r = subprocess .run ([exe ,vae ,str (lat ),str (out )]+ extra ,capture_output = True ,text = True ) 24runs = [m .groups ()for m in map (LINE .search ,r .stdout .splitlines ())if m ] 25return r .returncode ,runs ,r .stderr 26 27 28def main (argv )-> int : 29if len (argv )< 4 : 30__doc__ ) 31return 2 32exe ,vae ,root ,tags = argv [0 ],argv [1 ],Path (argv [2 ]),argv [3 :] 33bad = n = 0 34with tempfile .TemporaryDirectory ()as tmp : 35for tag in tags : 36for d in sorted ((root / tag ).glob ("dump_p*_s*" )): 37name = f" { tag } / { d . name [ len ( 'dump_' ):] } " 38one ,band = Path (tmp )/ "one.f32" ,Path (tmp )/ "band.f32" 39rc1 ,r1 ,e1 = run (exe ,vae ,d / "latent.bin" ,one , ["--stream" ,"off" ]) 40rc2 ,r2 ,e2 = run (exe ,vae ,d / "latent.bin" ,band , ["--stream" ,"on" ,"--repeat" ,"2" ]) 41n += 1 42if rc1 or rc2 or not r1 or not r2 : 43bad += 1 44f" { name } : FAILED rc { rc1 } / { rc2 } { ( e1 + e2 ). strip ()[ - 300 :] } " ) 45continue 46ref = one .read_bytes () 47same = ref == band .read_bytes () 48others = [] 49for rows in OTHER_BAND_ROWS : 50rc3 ,r3 ,e3 = run (exe ,vae ,d / "latent.bin" ,band , ["--stream" ,"on" ,"--band-rows" ,str (rows )]) 51ok = rc3 == 0 and bool (r3 )and band .read_bytes ()== ref 52others .append (f" { rows } rows { 'IDENTICAL' if ok else 'DIFFERENT' } " ) 53same = same and ok 54rtr = all (g [5 ]== "identical" for g in r2 [1 :]) 55bad += (not same )or (not rtr ) 56f" { name } { r1 [ 0 ][ 0 ] } x { r1 [ 0 ][ 1 ] } : one pass { float ( r1 [ 0 ][ 3 ]):.0f } ms peak { r1 [ 0 ][ 4 ] } MiB, " 57f"bands { float ( r2 [ 0 ][ 3 ]):.0f } ms peak { r2 [ 0 ][ 4 ] } MiB: " 58f" { 'IDENTICAL' if same else 'DIFFERENT' } ( { ', ' . join ( others ) } ), bands run to run " 59f" { 'identical' if rtr else 'DIFFERENT' } " ) 60f"VAE-IDENTITY { 'PASS' if bad == 0 else 'FAIL' } : { n - bad } of { n } " ) 61return 0 if bad == 0 else 1 62 63 64if __name__ == "__main__" : 65sys .exit (main (sys .argv [1 :]))