okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
150c2394f
main
1"""tools/image/gate/floor_table.py - TEST-ONLY (OWN-5 gate harness): the floor table (sd.cpp against itself) from kept 2picture sets, by running compare.py for each pair and printing one markdown row per pair. 3 4python -I -B floor_table.py <pics root> [--check] 5 6<pics root> holds the sets run_set.py wrote (one folder per tag). --check compares the result with FLOOR below (the 7survey's numbers, 2026-11-10) and exits 1 if any pair differs by more than rounding.""" 8import json 9import math 10import subprocess 11import sys 12from pathlib import Path 13 14HERE = Path (__file__ ).resolve ().parent 15# (label, set A, set B, the survey's numbers: byte-identical, max abs, mean abs, PSNR min, PSNR mean, SSIM min, SSIM mean) 16FLOOR = [ 17 ("same build twice, stock, GB10 CUDA Q8_0 1024" ,"cuda_q8_stock_A" ,"cuda_q8_stock_B" , (16 ,0 ,0 ,math .inf ,math .inf ,1 ,1 )), 18 ("same build twice, native, GB10 CUDA" ,"cuda_q8_native_A" ,"cuda_q8_native_B" , (16 ,0 ,0 ,math .inf ,math .inf ,1 ,1 )), 19 ("same build twice, stock, R9700 HIP" ,"hip_q8_stock_A" ,"hip_q8_stock_B" , (16 ,0 ,0 ,math .inf ,math .inf ,1 ,1 )), 20 ("same build twice, native, R9700 HIP" ,"hip_q8_native_A" ,"hip_q8_native_B" , (16 ,0 ,0 ,math .inf ,math .inf ,1 ,1 )), 21 ("same build twice, A750 Vulkan Q4_K_M" ,"vk_q4_stock_A" ,"vk_q4_stock_B" , (16 ,0 ,0 ,math .inf ,math .inf ,1 ,1 )), 22 ("same build twice, CPU 512" ,"cpu_q8_512_A" ,"cpu_q8_512_B" , (4 ,0 ,0 ,math .inf ,math .inf ,1 ,1 )), 23 ("CPU 4 vs 8 threads" ,"cpu_q8_512_A" ,"cpu_q8_512_t4" , (2 ,0 ,0 ,math .inf ,math .inf ,1 ,1 )), 24 ("attention kernel only (native, ours vs ggml)" ,"cuda_q8_native_A" ,"cuda_q8_native_ggmlattn" , (0 ,251 ,1.57 ,20.8 ,35.7 ,0.914 ,0.983 )), 25 ("stock vs native, GB10" ,"cuda_q8_stock_A" ,"cuda_q8_native_A" , (0 ,250 ,1.63 ,21.3 ,34.3 ,0.923 ,0.982 )), 26 ("stock vs native, R9700" ,"hip_q8_stock_A" ,"hip_q8_native_A" , (0 ,255 ,2.45 ,18.6 ,34.2 ,0.900 ,0.974 )), 27 ("noise only: x86 vs aarch64, 512" ,"cuda_q8_512_A" ,"cuda_q8_512_noise_x86" , (0 ,183 ,0.80 ,36.6 ,41.0 ,0.991 ,0.994 )), 28 ("noise only: Linux vs Windows" ,"cuda_q8_noise_x86" ,"cuda_q8_noise_msvc" , (0 ,248 ,1.06 ,25.4 ,37.7 ,0.961 ,0.990 )), 29 ("HIP vs CUDA, same noise" ,"hip_q8_stock_A" ,"cuda_q8_noise_x86" , (0 ,255 ,7.10 ,17.1 ,25.0 ,0.825 ,0.919 )), 30 ("HIP native vs CUDA, same noise" ,"hip_q8_native_A" ,"cuda_q8_noise_x86" , (0 ,255 ,6.47 ,18.9 ,25.4 ,0.826 ,0.923 )), 31 ("HIP vs CUDA, same noise, 512" ,"hip_q8_512_A" ,"cuda_q8_512_noise_x86" , (0 ,202 ,3.00 ,23.8 ,32.1 ,0.901 ,0.965 )), 32 ("CPU vs HIP, 512" ,"cpu_q8_512_A" ,"hip_q8_512_A" , (0 ,226 ,9.09 ,15.2 ,25.3 ,0.785 ,0.884 )), 33 ("CPU vs CUDA, same noise, 512" ,"cpu_q8_512_A" ,"cuda_q8_512_noise_x86" , (0 ,225 ,7.83 ,15.3 ,25.4 ,0.789 ,0.904 )), 34 ("CUDA vs Vulkan, Q4_K_M" ,"cuda_q4_stock_A" ,"vk_q4_stock_A" , (0 ,255 ,7.68 ,12.1 ,27.3 ,0.792 ,0.925 )), 35] 36 37 38def close (a ,b ,tol ): 39if math .isinf (a )or math .isinf (b ): 40return a == b 41return abs (a - b )<= tol 42 43 44def main (): 45root = Path (sys .argv [1 ]) 46bad = 0 47"| comparison | identical | max abs | mean abs | PSNR min / mean dB | SSIM min / mean |" ) 48"|---|---|---|---|---|---|" ) 49for label ,a ,b ,want in FLOOR : 50if not (root / a ).is_dir ()or not (root / b ).is_dir (): 51f"| { label } | not here ( { a } / { b } ) | | | | |" ) 52continue 53r = subprocess .run ([sys .executable ,"-I" ,"-B" ,str (HERE / "compare.py" ),str (root ),a ,b ], 54capture_output = True ,text = True ,check = True ) 55s = json .loads (r .stdout .strip ().splitlines ()[- 1 ]) 56got = (s ["bytes_equal" ],s .get ("max_abs" ,0 ),s .get ("mean_abs" ,0 ),s .get ("psnr_min" ,math .inf ), 57s .get ("psnr_mean" ,math .inf ),s .get ("ssim_min" ,1 ),s .get ("ssim_mean" ,1 )) 58f"| { label } | { got [ 0 ] } / { s [ 'pairs' ] } | { got [ 1 ]:.0f } | { got [ 2 ]:.2f } | { got [ 3 ]:.1f } / { got [ 4 ]:.1f } | " 59f" { got [ 5 ]:.3f } / { got [ 6 ]:.3f } |" ) 60tols = (0 ,0.5 ,0.006 ,0.06 ,0.06 ,0.0006 ,0.0006 ) 61if "--check" in sys .argv and not all (close (g ,w ,t )for g ,w ,t in zip (got ,want ,tols )): 62f" DIFFERS from the survey: { want } " ) 63bad += 1 64if "--check" in sys .argv : 65"FLOOR-OK" if not bad else f"FLOOR-DIFFERS in { bad } pairs" ) 66sys .exit (1 if bad else 0 ) 67 68 69if __name__ == "__main__" : 70main ()