okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
e4309aaf3
main
1"""tools/image/gate/build_variant.py - TEST-ONLY (OWN-5 gate harness): build the stage-hook variant of an existing 2build_sd.py build with exactly its configure line. 3 4python3 -I -B build_variant.py <root> <backend> <variant> [--jobs N] [--noise] [--vae REPO] [--dit REPO] [--def -DNAME=VALUE ...] 5--dit REPO: also Strata's DiT GEMMs in the native runner (REPO/tools/image/sdcpp_dit/apply.py; --model-args strata_dit_gemm=1). 6--vae REPO: the stage hooks plus Strata's VAE decoder from REPO/tools/image/sdcpp_vae/apply.py (a repo copy). 7Makes <root>/sd-<variant> (stage_hooks.py applied to a copy of <root>/sd-<backend>; with --noise instead the product's 8noise generator, <root>/repo/tools/image/sdcpp_noise/apply.py), <root>/build-<variant> and 9<root>/build-<variant>.json (what run_set.py --build <variant> reads).""" 10import json 11import os 12import subprocess 13import sys 14from pathlib import Path 15 16a = sys .argv [1 :] 17root ,backend ,var = Path (a [0 ]).expanduser ().resolve (),a [1 ],a [2 ] 18jobs = a [a .index ("--jobs" )+ 1 ]if "--jobs" in a else "8" 19extra = [a [i + 1 ]for i ,x in enumerate (a )if x == "--def" ]# extra CMake definitions, e.g. -DGGML_CUDA_FORCE_CUBLAS=ON 20info = json .loads ((root / f"build- { backend } .json" ).read_text ()) 21here = Path (__file__ ).resolve ().parent 22if "--noise" in a :# the product's noise generator (tools/image/sdcpp_noise/apply.py from <root>/repo), no stage hooks 23import shutil 24if not (root / f"sd- { var } " ).exists (): 25shutil .copytree (root / f"sd- { backend } " ,root / f"sd- { var } " ,symlinks = True ) 26subprocess .run ([sys .executable ,"-I" ,"-B" ,str (root / "repo" / "tools" / "image" / "sdcpp_noise" / "apply.py" ), 27str (root / f"sd- { var } " )],check = True ) 28else : 29subprocess .run ([sys .executable ,"-I" ,"-B" ,str (here / "stage_hooks.py" ),str (root / f"sd- { backend } " ), 30str (root / f"sd- { var } " )],check = True ) 31if "--vae" in a :# plus the product's VAE decoder (tools/image/sdcpp_vae/apply.py of the repo copy named) 32vrepo = Path (a [a .index ("--vae" )+ 1 ]).expanduser ().resolve () 33subprocess .run ([sys .executable ,"-I" ,"-B" ,str (vrepo / "tools" / "image" / "sdcpp_vae" / "apply.py" ), 34str (root / f"sd- { var } " )],check = True ) 35if "--dit" in a :# plus Strata's DiT GEMMs in the native runner (tools/image/sdcpp_dit/apply.py of that repo copy) 36drepo = Path (a [a .index ("--dit" )+ 1 ]).expanduser ().resolve () 37subprocess .run ([sys .executable ,"-I" ,"-B" ,str (drepo / "tools" / "image" / "sdcpp_dit" / "apply.py" ), 38str (root / f"sd- { var } " )],check = True ) 39conf = [c .replace (str (root / f"sd- { backend } " ),str (root / f"sd- { var } " )).replace (str (root / f"build- { backend } " ), 40str (root / f"build- { var } " )) 41for c in info ["configure" ]]+ extra 42env = dict (os .environ ,PATH = info ["env_path" ]) 43if backend == "hip" :# build_sd.py's ROCm environment (ROCM_PATH / HIP_PATH from the --rocm-path of its HIP flags) 44rocm = next ((c .split ("--rocm-path=" ,1 )[1 ].split ()[0 ]for c in info ["configure" ]if "--rocm-path=" in c ),None ) 45if rocm : 46env .update (HIP_PLATFORM = "amd" ,ROCM_PATH = rocm ,HIP_PATH = rocm ) 47if info .get ("env_ld" ): 48env ["LD_LIBRARY_PATH" ]= info ["env_ld" ] 49"+" ," " .join (conf ),flush = True ) 50subprocess .run (conf ,check = True ,env = env ,stdout = subprocess .DEVNULL ) 51subprocess .run (["nice" ,"-n" ,"15" ,"cmake" ,"--build" ,str (root / f"build- { var } " ),"--target" ,"sd-cli" ,"-j" ,jobs ], 52check = True ,env = env ,stdout = subprocess .DEVNULL ) 53exe = root / f"build- { var } " / "bin" / "sd-cli" 54info .update (configure = conf ,exe = str (exe ),exe_bytes = exe .stat ().st_size ,variant_of = backend ) 55(root / f"build- { var } .json" ).write_text (json .dumps (info ,indent = 1 )) 56"VARIANT-OK" ,exe )