okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
e4309aaf3
main
1"""tools/test_qi21_sampler.py - our Turbo sampler step (src/image/sample/qi21_sampler.cpp) against stable-diffusion.cpp 22988060's own values: tools/image/gate/data/qi21_sampler_fixture.bin holds, for steps 0-6 of one picture (512x512, 3prompt 0, seed 42), 512 values spread over the latent of sd.cpp's DiT input x_k, its DiT output v_k and its next DiT 4input x_{k+1}, with the sigmas and sd.cpp's timestep bits (written by strata-sampler-check --fixture from the stage 5dumps). Our step on x_k, v_k must give x_{k+1} byte for byte, our parsed schedule and timestep the same bits. 6Compiled twice: plain -O2, and -O3 with contraction allowed by default (-ffp-contract=fast; the file must still not 7fuse). No GPU, no sd.cpp, no model file. 8 9python -m pytest tools/test_qi21_sampler.py""" 10import shutil 11import subprocess 12import tempfile 13import unittest 14from pathlib import Path 15 16ROOT = Path (__file__ ).resolve ().parents [1 ] 17CXX = shutil .which ("g++" )or shutil .which ("c++" )or shutil .which ("clang++" ) 18FIXTURE = ROOT / "tools" / "image" / "gate" / "data" / "qi21_sampler_fixture.bin" 19 20 21@ unittest . skipUnless ( CXX , "no C++ compiler" ) 22class SamplerMatchesSdcpp (unittest .TestCase ): 23def build_and_check (self ,flags ): 24with tempfile .TemporaryDirectory ()as td : 25exe = Path (td )/ "strata-sampler-check" 26r = subprocess .run ([CXX ,"-std=c++17" ,* flags ,"-I" ,str (ROOT / "include" ), 27str (ROOT / "src" / "image" / "sample" / "qi21_sampler.cpp" ), 28str (ROOT / "src" / "image" / "sample" / "qi21_sampler_check_main.cpp" ),"-o" ,str (exe )], 29capture_output = True ,text = True ,timeout = 300 ) 30self .assertEqual (r .returncode ,0 ,r .stderr [- 3000 :]) 31r = subprocess .run ([str (exe ),"--fixture-check" ,str (FIXTURE )],capture_output = True ,text = True ,timeout = 60 ) 32self .assertIn ("SAMPLER-FIXTURE PASS" ,r .stdout ,r .stdout [- 3000 :]) 33self .assertEqual (r .stdout .count ("identical" ),7 ,r .stdout ) 34 35def test_o2 (self ): 36self .build_and_check (["-O2" ]) 37 38def test_o3_contract_fast (self ): 39self .build_and_check (["-O3" ,"-ffp-contract=fast" ]) 40 41 42if __name__ == "__main__" : 43unittest .main ()