okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
150c2394f
main
1"""tools/image/gate/limits.py - TEST-ONLY (OWN-5 gate harness): the gate's limits as constants, each with the sd.cpp 2floor it was set from (measured 2026-11-10, Spark GB10 CUDA / aarch64 CPU, Qwen-Image-2.1-Turbo Q8_0, 1024x1024, 38 pictures per arm unless noted). A limit is about 1.2x the worst floor, rounded; the coordinator accepted them on 411-10. Rule 3's end-to-end picture limits (E2E_* below) still decide; these are the stage checks that keep a 5real bug from hiding in the 8-step amplification. 6 7python -I -B limits.py prints the table (limit, floor, margin) 8 9Each entry: name -> {"limit": {...}, "floor": {...}, "why": text}. A "min" key is a lower bound, a "max" key an upper 10bound. check_limits.py applies them to a compare.py / stage_cmp.py result.""" 11from __future__import annotations 12 13LIMITS = { 14# --- exact: where we control the arithmetic ------------------------------------------------------------------- 15"run_to_run" : { 16"limit" : {"identical_all" :True }, 17"floor" : {"identical_all" :True }, 18"why" :"same build, card and OS twice: noise, cond, velocity, latent and picture bytes identical (sd.cpp: 16/16 " 19"on CUDA, HIP, Vulkan; 4/4 CPU at any thread count)" , 20 }, 21# --- VAE decode of a fixed latent ------------------------------------------------------------------------------- 22"vae_same_tiling" : { 23"limit" : {"psnr_min" :45.0 ,"ssim_min" :0.998 }, 24"floor" : {"psnr_min" :56.58 ,"ssim_min" :0.9988 }, 25"why" :"CPU (aarch64) vs CUDA, same latent, 5 pictures; untiled vs untiled, or tiled vs tiled with the same tile " 26"size and overlap" , 27 }, 28"vae_across_tiling" : { 29"limit" : {"psnr_min" :25.0 }, 30"floor" : {"psnr_min" :27.7 ,"psnr_mean" :35.7 ,"ssim_min" :0.958 }, 31"why" :"256-px tiles at 0.25 overlap vs untiled, CUDA: a different algorithm, a sanity floor only" , 32 }, 33# --- one DiT step ------------------------------------------------------------------------------------------------ 34"velocity" : { 35"limit" : {"rel_l2_max" :1.2e-2 ,"cos_min" :0.9999 }, 36"floor" : {"rel_l2_max" :0.0090 ,"cos_min" :0.99996 }, 37"why" :"step 0, fixed cond and noise: native vs stock 0.0079, our attention vs ggml's 0.0071, CPU vs CUDA 0.0090" , 38 }, 39# --- text encoder hidden states (cond) --------------------------------------------------------------------------- 40"text_encoder_same_backend" : { 41"limit" : {"rel_l2_max" :0.07 ,"cos_min" :0.997 ,"token_cos_min" :0.985 }, 42"floor" : {"rel_l2_max" :0.0603 ,"cos_min" :0.9982 ,"token_cos_min" :0.9909 }, 43"why" :"CUDA, cuBLAS-forced GEMM vs stock (same card): the GEMM path alone moves cond by 5-6% (rel L2). To be " 44"tightened when our own kernel's number exists; token ids must be identical" , 45 }, 46"text_encoder_cross_backend" : { 47"limit" : {"rel_l2_max" :0.11 ,"cos_min" :0.995 ,"token_cos_min" :0.96 }, 48"floor" : {"rel_l2_max" :0.0934 ,"cos_min" :0.9956 ,"token_cos_min" :0.9668 }, 49"why" :"CPU (aarch64) vs CUDA, 6 pictures" , 50 }, 51# --- end to end (rule 3 and rule 5 of the survey; the pictures, not a stage) ----------------------------------- 52"e2e_same_card" : { 53"limit" : {"psnr_mean_min" :34.0 ,"ssim_mean_min" :0.97 ,"psnr_min_min" :18.0 }, 54"floor" : {"psnr_mean_min" :34.2 ,"ssim_mean_min" :0.974 ,"psnr_min_min" :18.6 }, 55"why" :"our engine vs sd.cpp on the same card and noise, 16 pictures at 1024 (sd.cpp stock vs native: CUDA 34.3 / " 56"0.982 / 21.3, HIP 34.2 / 0.974 / 18.6; attention swap alone 35.7 / 0.983 / 20.8)" , 57 }, 58"e2e_gpu_vs_gpu" : { 59"limit" : {"psnr_mean_min" :25.0 ,"ssim_mean_min" :0.91 }, 60"floor" : {"psnr_mean_min" :25.0 ,"ssim_mean_min" :0.919 }, 61"why" :"no worse than sd.cpp's own HIP vs CUDA pair with the same noise (16 pictures at 1024)" , 62 }, 63"e2e_cpu_vs_gpu_512" : { 64"limit" : {"psnr_mean_min" :25.0 ,"ssim_mean_min" :0.88 }, 65"floor" : {"psnr_mean_min" :25.3 ,"ssim_mean_min" :0.884 }, 66"why" :"no worse than sd.cpp's CPU vs HIP pair (4 pictures at 512)" , 67 }, 68} 69 70 71def _bound (key :str ): 72"""-> ("min"|"max", metric) from a limit key like psnr_min or rel_l2_max.""" 73if key .endswith ("_max" ): 74return "max" ,key [:- 4 ] 75if key .endswith ("_min" ): 76return "min" ,key [:- 4 ] 77raise KeyError (key ) 78 79 80def passes (name :str ,got :dict )-> list [str ]: 81"""The limit violations of `got` (metric -> value) against LIMITS[name]; empty means it holds. Keys of the form 82psnr_min mean 'psnr_min >= limit' (the worst picture's PSNR); rel_l2_max means 'rel_l2_max <= limit'.""" 83bad = [] 84for key ,limit in LIMITS [name ]["limit" ].items (): 85if isinstance (limit ,bool ): 86if got .get (key )is not limit : 87bad .append (f" { key } : { got . get ( key ) } != { limit } " ) 88continue 89v = got .get (key ) 90if v is None : 91bad .append (f" { key } : missing" ) 92elif key .startswith (("rel_l2" ,))and v > limit : 93bad .append (f" { key } : { v :.5g } > { limit } " ) 94elif not key .startswith (("rel_l2" ,))and v < limit : 95bad .append (f" { key } : { v :.5g } < { limit } " ) 96return bad 97 98 99def floor_margin (name :str )-> dict : 100"""metric -> (limit, floor): the floor must lie on the passing side of the limit.""" 101return {k : (LIMITS [name ]["limit" ][k ],LIMITS [name ]["floor" ].get (k ))for k in LIMITS [name ]["limit" ]} 102 103 104if __name__ == "__main__" : 105for n ,e in LIMITS .items (): 106f" { n } :" ) 107for k , (lim ,fl )in floor_margin (n ).items (): 108f" { k } : limit { lim } floor { fl } " ) 109f" ( { e [ 'why' ] } )" )