Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
setup: AMD layer splits with --gpus (every chosen card a supported AMD arch; the engine compiled for each)
Niko1221ebe52edd8b49
diff --git a/README.md b/README.mdindex bc1eb30c3..a55318085 100644--- a/README.md+++ b/README.md@@ -87,7 +87,7 @@ It needs an explicit packing conversion and is not an installer menu option.An **AMD Radeon RX 7900 XT / XTX, RX 9070 / 9070 XT or Radeon AI PRO R9700 on Linux** works too (experimental; theRX 7800 XT / 7700 XT and RX 9060 XT were validated by their owners):`./setup.sh --backend hip`, chosen by itself on a PC with no NVIDIA card Strata can use. It installs ROCm without sudo-and compiles the engine (one GPU, no images yet). Details: [AMD HIP](docs/AMD_HIP.md).+and compiles the engine (no images yet; several cards with `--gpus`). Details: [AMD HIP](docs/AMD_HIP.md).## Installdiff --git a/docs/AMD_HIP.md b/docs/AMD_HIP.mdindex 3d6695d5d..862b0e759 100644--- a/docs/AMD_HIP.md+++ b/docs/AMD_HIP.md@@ -36,7 +36,13 @@ the kernel's amdgpu driver (no ROCm install needed):card's architecture and the installed hipBLASLt version (read from `hipblaslt-version.h`; 1.2.0 is `100200`).Otherwise it says so and the prompt's dense matrix products use plain hipBLAS (slower prompts, same answers).A table's solution ids are valid only for that pair, and the engine refuses any other table.-- **Limits for now:** one GPU, no images, no calibration. The Monitor shows no GPU statistics.+- **Several cards:** setup takes one card (the one with the most VRAM, or `--gpu N`) unless you name more:+ `./setup.sh --backend hip --gpus 1,0` splits the model's layers across them, the first one the main card (numbers+ as setup lists them; `--gpus all` = every supported card, the most VRAM first). Every chosen card must be one of the+ architectures above; the engine is compiled for each of them (cards of two families, e.g. gfx1100 + gfx1201, need+ a system ROCm 7: AMD's wheels hold one family). A split pays only when no single card holds the model's experts+ (see RDNA4 below).+- **Limits for now:** no images, no calibration. The Monitor shows no GPU statistics.The rest of setup is the same as on NVIDIA: the model download, the start script, the server.@@ -115,8 +121,7 @@ The 4K context is a smoke-test starting point, not a model limit. The expert cacsizes itself automatically and leaves 1 GiB of VRAM headroom.The installer supports this backend (see "Install with setup" above). The vision helper is NVIDIA-only for now.-Setup installs one AMD card; the engine's layer split also runs on two AMD cards when the config is written by hand-(see RDNA4 below).+Setup installs one AMD card, or several with `--gpus` (the engine's layer split; see RDNA4 below).## RDNA4 (gfx1201)@@ -153,7 +158,7 @@ an RX 9070 XT 16 GB and a Radeon AI PRO R9700 32 GB (both gfx1201), a Ryzen 9 39(hipBLASLt 1.4.1; 0.98-1.76x per GEMM over hipBLAS) changed the end-to-end prompt speed by 0-3%, within noise,so none is shipped: on gfx1201 the plain hipBLAS path is already close.- **Both cards in one run (layer split, engine 0.1.30):** the config's `"backend": "hip", "gpu": [1, 0]` (R9700- first) runs through `serve/server.py`; setup does not offer it yet. Auto split put layers 0-27 on the R9700 and+ first) runs through `serve/server.py` (setup writes it with `--gpus 1,0` since 0.1.31). Auto split put layers 0-27 on the R9700 and28-47 on the 9070 XT. With every expert on the GPUs the split gives exactly the tokens of the R9700 alone (4K and16K prompts); checkpoints on the split (second turn, rewind, a prompt sharing a prefix, a cancelled promptretried) give exactly the tokens of a fresh read. The conversation cache refuses a split at start (exit 2).diff --git a/docs/MULTI_GPU.md b/docs/MULTI_GPU.mdindex 61ec5291e..53d8ec3de 100644--- a/docs/MULTI_GPU.md+++ b/docs/MULTI_GPU.md@@ -44,8 +44,8 @@ now on; the answer is kept.- a card older than the RTX 20 series (compute capability below 7.5: GTX 10 and older);- a card with less than 8 GB of VRAM, together with others (each card holds a copy of the dense weights and itsown prompt buffers);-- AMD and Intel GPUs, and a mix of NVIDIA with them. (Two AMD RDNA4 cards run the split from a hand-written- config; see [AMD_HIP.md](AMD_HIP.md#rdna4-gfx1201).)+- Intel GPUs, and a mix of NVIDIA and AMD cards. (AMD cards share a model among themselves: `./setup.sh --backend+ hip --gpus 1,0`, see [AMD_HIP.md](AMD_HIP.md).)Or edit an existing config (`strata-*.json`), then restart:diff --git a/setup.py b/setup.pyindex b17031f1d..93eafc59b 100644--- a/setup.py+++ b/setup.py@@ -414,6 +414,15 @@ def engine_archs():return [int(x) for x in meta.get("archs", [])], bool(meta.get("ptx"))+def engine_archs_hip():+ """The AMD architectures the installed HIP engine was compiled for ("gfx1201", ...), or None."""+ try:+ meta = json.loads((ROOT / "engine" / "BUILD.json").read_text())+ except (OSError, ValueError):+ return None+ return [str(x) for x in meta.get("archs", [])] if meta.get("backend") == "hip" else None++def engine_runs_on(g) -> bool:ea = engine_archs()if ea is None or not ea[0]:@@ -422,6 +431,18 @@ def engine_runs_on(g) -> bool:return int(g["arch"]) in archs or (ptx and int(g["arch"]) > max(archs))+def start_gpus(text):+ """--gpus when starting an installed model: NVIDIA cards as nvidia-smi numbers them, or on a PC whose AMD cards+ are the ones Strata can use, AMD cards as setup lists them ("all": every supported AMD card)."""+ if not text:+ return None+ if str(text).strip().lower() == "all" and not WIN and not together_ok(gpus()):+ amd = amd_gpus()+ if len([g for g in amd if amd_problem(g) is None]) >= 2:+ return [g["index"] for g in amd_parse_gpus("all", amd)]+ return parse_gpus(text, gpus())++def choose_gpus(a, found) -> list:"""Which cards this install uses: --gpus / --gpu, or asked when two or more can share the model (the two besttogether recommended), else the supported card with the most VRAM. Returns their numbers, the main one first."""@@ -775,6 +796,33 @@ def amd_problem(g):return None+def amd_parse_gpus(text, amd) -> list:+ """--gpus with AMD cards, numbered as HIP numbers them (setup's list): "1,0", or "all" (every supported card, the+ most VRAM first). Every chosen card must be one Strata supports (AMD_ARCHS; they may be of different+ architectures: the engine is compiled for each). Returns the cards, the main one first."""+ usable = [g for g in amd if amd_problem(g) is None]+ if str(text).strip().lower() == "all":+ sel = [g["index"] for g in sorted(usable, key=lambda x: (-round(x["vram_gb"]), x["index"]))]+ else:+ try:+ sel = [int(x) for x in str(text).split(",") if x.strip()]+ except ValueError:+ fail(f"--gpus takes AMD GPU numbers as setup lists them, e.g. --gpus 1,0 (or --gpus all), not {text!r}")+ if len(sel) < 2 or len(set(sel)) != len(sel):+ fail("--gpus takes two or more different GPUs, e.g. --gpus 1,0 (one GPU: --gpu 1)",+ "this PC has " + (f"{len(usable)} AMD card{'s' if len(usable) != 1 else ''} Strata can use"+ + (": " + ", ".join(f"GPU {g['index']} ({g['name']})" for g in usable) if usable else "")))+ byid = {g["index"]: g for g in amd}+ for i in sel:+ g = byid.get(i)+ p = "not found on this PC" if g is None else amd_problem(g)+ if p is not None:+ fail(f"AMD GPU {i}{'' if g is None else ' (' + g['name'] + ')'} cannot be used: {p}",+ ("use these together: --gpus " + ",".join(str(x["index"]) for x in usable)) if len(usable) >= 2 else+ ("use one card: --gpu " + str(usable[0]["index"])) if usable else f"the AMD backend runs on {AMD_CARDS}")+ return [byid[i] for i in sel]++def rocm_version(root):"""(major, minor) of a ROCm install, from rocm-core's header; None when it has none."""try:@@ -784,9 +832,11 @@ def rocm_version(root):return None-def rocm_root(arch):- """ROCm for compiling and running the HIP engine for `arch`: (root, library folders). A system ROCm 7 with hipcc- and hipBLAS, else AMD's TheRock wheels (ROCM_VERSION, from the card family's index) installed into .venv."""+def rocm_root(archs):+ """ROCm for compiling and running the HIP engine for `archs` (one arch or a list: the cards of a layer split):+ (root, library folders). A system ROCm 7 with hipcc and hipBLAS, else AMD's TheRock wheels (ROCM_VERSION, from the+ card family's index) installed into .venv."""+ archs = [archs] if isinstance(archs, str) else list(archs)sysroot = Path(os.environ.get("ROCM_PATH") or "/opt/rocm")if (sysroot / "bin" / "hipcc").exists() and list((sysroot / "lib").glob("libhipblas.so*")):ver = rocm_version(sysroot)@@ -794,7 +844,11 @@ def rocm_root(arch):return sysroot, [str(sysroot / "lib")]warn(f"the ROCm in {sysroot} is {ver[0]}.{ver[1]}; Strata needs {ROCM_SYSTEM_MIN[0]}.{ROCM_SYSTEM_MIN[1]} or ""newer: using AMD's wheels in .venv instead")- index = rocm_index(arch)+ indexes = list(dict.fromkeys(rocm_index(a) for a in archs))+ if len(indexes) > 1: # TheRock's wheels hold one GPU family's libraries+ fail(f"cards of two GPU families ({', '.join(archs)}) need a system ROCm 7 (in /opt/rocm): AMD's Python "+ "wheels come per family", "install ROCm 7 system-wide, or use cards of one family (--gpu N for one card)")+ index = indexes[0]stamp = Path(sys.prefix) / ".strata-rocm.json"have = json.loads(stamp.read_text()) if stamp.exists() else {}if have.get("version") != ROCM_VERSION or have.get("index") != index:@@ -854,19 +908,22 @@ def hipblaslt_table(arch, lib_dirs):def build_engine_hip(gpu, llama) -> Path:- """Compile the HIP engine for this AMD GPU into engine/ (again only when its source changed: a `git pull`)."""+ """Compile the HIP engine for this AMD GPU into engine/ (again only when its source changed: a `git pull`).+ gpu["archs"]: every architecture it needs code for (the cards of a layer split), else gpu["arch"]."""eng = ROOT / "engine"eng.mkdir(exist_ok=True)stamp = eng / "BUILD.json"meta = json.loads(stamp.read_text()) if stamp.exists() else {}src = source_hash(ENGINE_SOURCES)- if meta.get("backend") == "hip" and (eng / EXE).exists() and meta.get("src") == src and gpu["arch"] in meta.get("archs", []):+ archs = sorted(set(gpu.get("archs") or [gpu["arch"]]))+ has_archs = set(archs) <= set(meta.get("archs", []))+ if meta.get("backend") == "hip" and (eng / EXE).exists() and meta.get("src") == src and has_archs:ok("engine already built for this PC")return engif not (shutil.which("c++") or shutil.which("g++")) or not shutil.which("git"):fail("a C++ compiler and git are needed to compile the AMD engine","Ubuntu/Debian: sudo apt install build-essential git Fedora: sudo dnf install gcc-c++ git")- root, dirs = rocm_root(gpu["arch"])+ root, dirs = rocm_root(archs)libs = [str(Path(d).parent) for d in dirs[1:]]bitcode = next((p for p in (root / "lib" / "llvm" / "amdgcn" / "bitcode", root / "amdgcn" / "bitcode") if p.is_dir()),root / "amdgcn" / "bitcode")@@ -875,18 +932,19 @@ def build_engine_hip(gpu, llama) -> Path:os.environ["LD_LIBRARY_PATH"] = os.pathsep.join(dirs + [os.environ.get("LD_LIBRARY_PATH", "")]).rstrip(os.pathsep)os.environ["PATH"] = os.pathsep.join([str(root / "bin"), str(root / "llvm" / "bin"), os.environ.get("PATH", "")])say(" The engine's source changed: compiling it again (only what changed, a few minutes) ..."- if meta.get("backend") == "hip" and (eng / EXE).exists() and gpu["arch"] in meta.get("archs", [])- else " Compiling the Strata engine for your AMD GPU (10-20 minutes, once) ...")+ if meta.get("backend") == "hip" and (eng / EXE).exists() and has_archs+ else f" Compiling the Strata engine for your AMD GPU{'s' if len(archs) > 1 else ''} ({', '.join(archs)}; "+ "10-20 minutes, once) ...")cmake_build(ROOT, ROOT / "build-hip", "strata",["-DSTRATA_ENABLE_HIP=ON", "-DSTRATA_ENABLE_CUDA=OFF", "-DSTRATA_BUILD_TESTS=OFF",- "-DSTRATA_PREFILL_MMQ=ON", f"-DCMAKE_HIP_ARCHITECTURES={gpu['arch']}",+ "-DSTRATA_PREFILL_MMQ=ON", "-DCMAKE_HIP_ARCHITECTURES=" + ";".join(archs),f"-DCMAKE_HIP_COMPILER={root / 'llvm' / 'bin' / 'clang++'}", f"-DCMAKE_HIP_COMPILER_ROCM_ROOT={root}","-DCMAKE_PREFIX_PATH=" + ";".join([str(root), *libs]),f"-DCMAKE_HIP_FLAGS=--rocm-path={root} --rocm-device-lib-path={bitcode}",f"-DSTRATA_GGML_DIR={llama}"], None, "")shutil.copy2(ROOT / "build-hip" / EXE, eng / EXE)stamp.write_text(json.dumps({"source": "local-hip", "backend": "hip", "version": source_version(),- "archs": [gpu["arch"]], "vision": "none", "lib_dirs": dirs, "src": src}, indent=1))+ "archs": archs, "vision": "none", "lib_dirs": dirs, "src": src}, indent=1))ok(f"engine compiled: {eng / EXE}")return eng@@ -993,7 +1051,9 @@ def update_installed_engine(url_base) -> None:g = next((x for x in usable if x["arch"] in meta.get("archs", [])), usable[0] if usable else None)if g is None:raise RuntimeError("no supported AMD GPU found")- build_engine_hip(g, get_llama_cpp())+ # every architecture it was built for (a layer split across two families keeps both)+ build_engine_hip({**g, "archs": [x for x in meta.get("archs", []) if x in AMD_ARCHS] or [g["arch"]]},+ get_llama_cpp())except (Exception, SystemExit) as e:warn(f"could not compile the updated engine{'' if isinstance(e, SystemExit) else f' ({e})'}: ""starting the installed one")@@ -1557,17 +1617,32 @@ def start(cfg_path: Path, port: int | None, gpu: int | list | None = None, open_refresh_draft_vocab(Path(cfg["args"][cfg["args"].index("--mtp") + 1]), cfg.get("draft_vocab", "cjk"))cmd = [sys.executable, str(ROOT / "serve" / "server.py"), "--engine", "strata", "--config", str(cfg_path),"--port", str(port or cfg.get("port", 8080))]- if cfg.get("backend") == "hip": # AMD: one card, numbered as HIP numbers them- if isinstance(gpu, list):- fail("several GPUs sharing one model: NVIDIA only for now", "use one AMD card (--gpu N)")- if gpu is not None:+ if cfg.get("backend") == "hip": # AMD, numbered as HIP numbers them (setup's KFD order)+ amd = amd_gpus()+ if isinstance(gpu, list): # --gpus: saved, this model runs on these cards from now on+ cards = amd_parse_gpus(",".join(str(i) for i in gpu), amd)+ built = (engine_archs_hip() or [])+ miss = [x for x in cards if built and x["arch"] not in built]+ if miss:+ fail("the installed engine has no code for " + ", ".join(f"{x['name']} ({x['arch']})" for x in miss),+ "set it up for these cards: ./setup.sh --setup --backend hip --gpus " + ",".join(map(str, gpu)))+ cfg["gpu"], cfg["gpus_asked"] = gpu, True+ cfg["layer_split"] = layer_split or cfg.get("layer_split") or "auto"+ cfg_path.write_text(json.dumps(cfg, indent=1), encoding="utf-8")+ gpu = None+ elif gpu is not None:cmd += ["--gpu", str(gpu)]found = []use = gpu if gpu is not None else cfg.get("gpu")- g = next((x for x in amd_gpus() if x["index"] == (use if use is not None else x["index"])- and amd_problem(x) is None), None)- if g is not None:- ok(f"GPU: {g['name']} ({g['vram_gb']:.0f} GB, AMD)")+ if isinstance(use, list):+ byid = {x["index"]: x for x in amd}+ ok("GPUs: " + " + ".join(gpu_name(byid[i]) if i in byid else f"GPU {i} (not found)" for i in use)+ + f" together, AMD (layers split {cfg.get('layer_split') or 'auto'})")+ else:+ g = next((x for x in amd if x["index"] == (use if use is not None else x["index"])+ and amd_problem(x) is None), None)+ if g is not None:+ ok(f"GPU: {g['name']} ({g['vram_gb']:.0f} GB, AMD)")else:found = gpus()if cfg.get("backend") == "hip":@@ -1744,9 +1819,9 @@ def main() -> int:ap.add_argument("--port", type=int, help="the server's port (default: the one the install was set up with, 8080 for a new one)")ap.add_argument("--gpu", help="one GPU, numbered as nvidia-smi numbers them (default: asked when several can be ""used; with --setup it is saved, when starting it is for that start only)")- ap.add_argument("--gpus", help="several GPUs sharing one model, as nvidia-smi numbers them: \"0,2\", or \"all\" "- "(every card that can); the first is the main one. Saved, also when starting "- "(see docs/MULTI_GPU.md)")+ ap.add_argument("--gpus", help="several GPUs sharing one model, as nvidia-smi numbers them (AMD: as setup lists "+ "them): \"0,2\", or \"all\" (every card that can); the first is the main one. "+ "Saved, also when starting (see docs/MULTI_GPU.md)")ap.add_argument("--layer-split", help="with --gpus: where each later GPU's layers start (\"18\", \"16,32\"); ""default auto, placed from each GPU's free VRAM")ap.add_argument("--host", help="where the server listens: 127.0.0.1 = this PC only (default), 0.0.0.0 = also other "@@ -1817,7 +1892,7 @@ def main() -> int:# starting an installed model: --gpus 0,2 (or all) saves those cards for it and starts on them (it used to start# on the first one alone unless given with --setup), --gpu N runs this start on one card; neither: the saved# choice, and asked once when the PC has cards that could share the model- run_gpu = (parse_gpus(a.gpus, gpus()) if a.gpus else None) or a.gpu+ run_gpu = start_gpus(a.gpus) or a.gpuport = a.port or 8080 # a new install's port (issue #32: --port for an existing one)if have and a.calibrate and not (a.setup or a.model or a.family or a.check):if not a.build:@@ -1860,11 +1935,11 @@ def main() -> int:say(" 1) NVIDIA: " + ", ".join(f"{g['name']} ({g['vram_gb']:.0f} GB)" for g in found if gpu_problem(g) is None)+ " (recommended)")say(" 2) AMD: " + ", ".join(f"{g['name']} ({g['vram_gb']:.0f} GB)" for g in amd_ok)- + " (experimental: compiled here, one GPU, no images - docs/AMD_HIP.md)")+ + " (experimental: compiled here, no images - docs/AMD_HIP.md)")hip = ask("Which cards?", ["1", "2"], "1", a.yes or a.check) == "2"if a.check and not hip:say(" (the AMD card: ./setup.sh --backend hip)")- if hip: # AMD (experimental): one card, compiled here+ if hip: # AMD (experimental): compiled hereif WIN:fail("Strata's AMD backend runs on Linux only", "use an NVIDIA RTX 20 series or newer card on Windows")say(" Your AMD GPUs:" if amd else " No AMD GPU found (the amdgpu driver's KFD topology is empty).")@@ -1873,17 +1948,25 @@ def main() -> int:usable = [g for g in amd if amd_problem(g) is None]if not usable:fail("no AMD GPU Strata can use", f"the AMD backend runs on {AMD_CARDS} on Linux")- if a.gpus:- fail("several GPUs sharing one model: NVIDIA only for now", "use one AMD card (--gpu N)")- if a.gpu is not None:+ if a.gpus: # a layer split across these cards, the first one the main+ chosen = amd_parse_gpus(a.gpus, amd)+ gpu = chosen[0]+ elif a.gpu is not None:gpu = next((g for g in usable if g["index"] == a.gpu), None)if gpu is None:fail(f"AMD GPU {a.gpu} cannot be used", "use one of: " + ", ".join(f"--gpu {g['index']}" for g in usable))+ chosen = [gpu]else:gpu = max(usable, key=lambda x: (round(x["vram_gb"]), -x["index"]))- gpu = {**gpu, "count": len(amd), "archs": [gpu["arch"]]}- sel, multi, chosen = [gpu["index"]], [], [gpu]+ chosen = [gpu]+ # the engine is compiled for every chosen card's architecture+ gpu = {**gpu, "count": len(amd), "archs": sorted({g["arch"] for g in chosen})}+ chosen = [gpu] + chosen[1:]+ sel = [g["index"] for g in chosen]+ multi = sel if len(sel) > 1 else []a.gpu = gpu["index"] if len(amd) > 1 else a.gpu+ if multi:+ ok("GPUs: " + " + ".join(gpu_name(x) for x in chosen) + " together (the model's layers are split across them)")ok(f"GPU: {gpu['name']}, {gpu['vram_gb']:.1f} GB VRAM, {gpu['arch']} (AMD, experimental: docs/AMD_HIP.md)")else:if not found:diff --git a/tools/test_setup_amd.py b/tools/test_setup_amd.pyindex 99bb90f4e..6c82c35f8 100644--- a/tools/test_setup_amd.py+++ b/tools/test_setup_amd.py@@ -77,5 +77,80 @@ class KfdDetection(unittest.TestCase):self.assertEqual(setup.ROCM_INDEXES["gfx1200"], setup.ROCM_INDEXES["gfx1201"])+class GpuLists(unittest.TestCase):+ """--gpus with AMD cards: every chosen card must be supported; the first is the main one."""+ AMD = [{"index": 0, "name": "AMD Radeon RX 9070 XT", "vram_gb": 16.0, "arch": "gfx1201"},+ {"index": 1, "name": "AMD Radeon AI PRO R9700", "vram_gb": 32.0, "arch": "gfx1201"},+ {"index": 2, "name": "AMD Radeon (gfx1036)", "vram_gb": 0.5, "arch": "gfx1036"},+ {"index": 3, "name": "AMD Radeon RX 7900 XTX", "vram_gb": 24.0, "arch": "gfx1100"}]++ def setUp(self):+ self.say = setup.say+ setup.say = lambda *a, **k: None++ def tearDown(self):+ setup.say = self.say++ def test_list_in_order(self):+ self.assertEqual([g["index"] for g in setup.amd_parse_gpus("1,0", self.AMD)], [1, 0])+ self.assertEqual([g["index"] for g in setup.amd_parse_gpus(" 0, 3 ", self.AMD)], [0, 3])++ def test_all_is_every_supported_card_most_vram_first(self):+ self.assertEqual([g["index"] for g in setup.amd_parse_gpus("all", self.AMD)], [1, 3, 0])++ def test_refusals(self):+ for text in ("1,2", "1,7", "1", "1,1", "x,y"):+ with self.assertRaises(SystemExit, msg=text):+ setup.amd_parse_gpus(text, self.AMD)++ def test_wheels_hold_one_family(self):+ with tempfile.TemporaryDirectory() as d: # no system ROCm there: the wheels would be needed+ old = setup.os.environ.get("ROCM_PATH")+ setup.os.environ["ROCM_PATH"] = d+ try:+ with self.assertRaises(SystemExit):+ setup.rocm_root(["gfx1100", "gfx1201"])+ finally:+ if old is None:+ del setup.os.environ["ROCM_PATH"]+ else:+ setup.os.environ["ROCM_PATH"] = old++ def test_build_for_every_arch(self):+ """build_engine_hip compiles for the set of the chosen cards' archs and records it in BUILD.json."""+ calls = {}+ saved = {k: getattr(setup, k) for k in ("ROOT", "rocm_root", "cmake_build", "source_hash", "source_version",+ "ok", "shutil")}+ with tempfile.TemporaryDirectory() as d:+ root = Path(d)++ def fake_build(src, bdir, target, defs, vcvars, bat):+ calls["defs"] = defs+ (bdir).mkdir(parents=True, exist_ok=True)+ (bdir / setup.EXE).write_text("engine")++ class Sh:+ which = staticmethod(lambda name: "/usr/bin/" + name)+ copy2 = staticmethod(lambda a, b: Path(b).write_text(Path(a).read_text()))+ setup.ROOT, setup.cmake_build, setup.ok, setup.shutil = root, fake_build, lambda *a: None, Sh+ setup.source_hash, setup.source_version = (lambda *a: "h"), (lambda: "0.1.31")+ setup.rocm_root = lambda archs: (calls.setdefault("archs", archs) and root, [str(root / "lib")])+ try:+ setup.build_engine_hip({"arch": "gfx1201", "archs": ["gfx1201", "gfx1100", "gfx1201"]}, root)+ self.assertEqual(calls["archs"], ["gfx1100", "gfx1201"])+ self.assertIn("-DCMAKE_HIP_ARCHITECTURES=gfx1100;gfx1201", calls["defs"])+ import json+ self.assertEqual(json.loads((root / "engine" / "BUILD.json").read_text())["archs"],+ ["gfx1100", "gfx1201"])+ calls.clear() # one of those cards alone: already built, no compile+ setup.build_engine_hip({"arch": "gfx1100"}, root)+ self.assertNotIn("defs", calls)+ setup.build_engine_hip({"arch": "gfx1101"}, root) # another arch: compiled again+ self.assertIn("-DCMAKE_HIP_ARCHITECTURES=gfx1101", calls["defs"])+ finally:+ for k, v in saved.items():+ setattr(setup, k, v)++if __name__ == "__main__":unittest.main()