okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-own-5b adfcf9028 into f-own-int (round 16: the strata-image test program and its parts, DiT runner, sampler, noise, PNG writer; hooked into no build)e4309aaf3

main
3.7 KiB56 linesraw
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
4    python3 -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
23    import shutil
24    if not (root / f"sd-{var}").exists():
25        shutil.copytree(root / f"sd-{backend}", root / f"sd-{var}", symlinks=True)
26    subprocess.run([sys.executable, "-I", "-B", str(root / "repo" / "tools" / "image" / "sdcpp_noise" / "apply.py"),
27                    str(root / f"sd-{var}")], check=True)
28else:
29    subprocess.run([sys.executable, "-I", "-B", str(here / "stage_hooks.py"), str(root / f"sd-{backend}"),
30                    str(root / f"sd-{var}")], check=True)
31    if "--vae" in a:     # plus the product's VAE decoder (tools/image/sdcpp_vae/apply.py of the repo copy named)
32        vrepo = Path(a[a.index("--vae") + 1]).expanduser().resolve()
33        subprocess.run([sys.executable, "-I", "-B", str(vrepo / "tools" / "image" / "sdcpp_vae" / "apply.py"),
34                        str(root / f"sd-{var}")], check=True)
35    if "--dit" in a:     # plus Strata's DiT GEMMs in the native runner (tools/image/sdcpp_dit/apply.py of that repo copy)
36        drepo = Path(a[a.index("--dit") + 1]).expanduser().resolve()
37        subprocess.run([sys.executable, "-I", "-B", str(drepo / "tools" / "image" / "sdcpp_dit" / "apply.py"),
38                        str(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}"),
40                                                                                str(root / f"build-{var}"))
41        for 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)
44    rocm = next((c.split("--rocm-path=", 1)[1].split()[0] for c in info["configure"] if "--rocm-path=" in c), None)
45    if rocm:
46        env.update(HIP_PLATFORM="amd", ROCM_PATH=rocm, HIP_PATH=rocm)
47if info.get("env_ld"):
48    env["LD_LIBRARY_PATH"] = info["env_ld"]
49print("+", " ".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],
52               check=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))
56print("VARIANT-OK", exe)