Skip to content

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++

Images (I2): setup builds the native DiT runner into sd-cli on CUDA / HIP; --image-native on|off (off by default) and the config's "native" add --model-args qwen_image_2_1_native=1

Niko1221c711ba071f3b
diff --git a/serve/images.py b/serve/images.py
index de155286c..f322a571e 100644
--- a/serve/images.py
+++ b/serve/images.py
@@ -20,7 +20,8 @@ The config's "images" section (written by setup --images, tools/image/install.py
{"exe": "engine-image/sd-cli", "backend": "vulkan", "diffusion_model": "...Q8_0.gguf", "vae": "...",
"llm": "...Qwen3-VL-8B-Instruct-UD-Q4_K_XL.gguf", "quant": "Q8_0", "args": ["--diffusion-fa"],
"gpu_policy": "auto", "reload": "lazy"|"eager", "max_n": 4, "max_side": 2048, "timeout_s": 3600,
- "lib_dirs": [...], "uma": false, "need_mib": null, "out_dir": null, "keep_files": 64}
+ "lib_dirs": [...], "uma": false, "need_mib": null, "out_dir": null, "keep_files": 64,
+ "native": false} (native: Strata's own DiT runner, tools/image/sdcpp_native; CUDA / HIP builds)
"""
from __future__ import annotations
@@ -122,6 +123,8 @@ def sd_cli_args(cfg: dict, job: dict, out_pattern: str) -> list[str]:
cmd += ["-b", str(job["n"])]
cmd += ["-o", out_pattern]
cmd += [str(a) for a in (cfg.get("args") or [])]
+ if cfg.get("native") is True: # Strata's DiT runner inside sd-cli (CUDA / HIP builds)
+ cmd += ["--model-args", "qwen_image_2_1_native=1"]
return cmd
diff --git a/serve/test_images.py b/serve/test_images.py
index 5d9a78703..2842e5230 100644
--- a/serve/test_images.py
+++ b/serve/test_images.py
@@ -86,6 +86,13 @@ class Command(unittest.TestCase):
self.assertNotIn("--sigmas", cmd) # Turbo's sigmas are an 8-step schedule
self.assertEqual(cmd[cmd.index("-b") + 1], "3")
+ def test_native_switch(self):
+ cfg = {"exe": "sd-cli", "diffusion_model": "d", "vae": "v", "llm": "l", "native": True}
+ job = {"prompt": "p", "width": 512, "height": 512, "n": 1, "steps": 8, "seed": 1}
+ self.assertEqual(images_api.sd_cli_args(cfg, job, "x")[-2:], ["--model-args", "qwen_image_2_1_native=1"])
+ cfg["native"] = False
+ self.assertNotIn("--model-args", images_api.sd_cli_args(cfg, job, "x"))
+
def test_env(self):
env = images_api.image_env({"backend": "cuda", "gpu": 1, "env": {"X": 2}}, {"PATH": "p"})
self.assertEqual((env["CUDA_VISIBLE_DEVICES"], env["CUDA_DEVICE_ORDER"], env["X"]), ("1", "PCI_BUS_ID", "2"))
diff --git a/setup.py b/setup.py
index b561c8782..4b9d80def 100644
--- a/setup.py
+++ b/setup.py
@@ -2782,6 +2782,16 @@ def vulkan_sdk() -> Path | None:
return sdk
+def apply_native_runner(src: Path) -> None:
+ """I2: tools/image/sdcpp_native's runner into the stable-diffusion.cpp source (idempotent)."""
+ import importlib.util
+ QI = _qimage()
+ spec = importlib.util.spec_from_file_location("strata_sdcpp_native_apply", QI.NATIVE_DIR / "apply.py")
+ mod = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(mod)
+ mod.apply(src)
+
+
def build_image_engine(backend: str, gpu: dict) -> tuple[Path, list[str]]:
"""Compile sd-cli for `backend` into engine-image/ (again only when the pins or the backend changed) -> (its path,
the library folders it runs with)."""
@@ -2796,6 +2806,8 @@ def build_image_engine(backend: str, gpu: dict) -> tuple[Path, list[str]]:
ok(f"image generator already built ({backend})")
return exe, lib_dirs
src = get_sd_cpp()
+ if backend in QI.NATIVE_BACKENDS: # Strata's DiT runner (inert unless the config asks for it)
+ apply_native_runner(src)
vcvars, lib_dirs = None, []
if backend == "cuda":
nvcc, cuda_v = find_nvcc()
@@ -2878,7 +2890,7 @@ def setup_images(a, gpu: dict, hip: bool, models_dir: Path) -> dict | None:
download(QI.file_url(name, hf_endpoint()), dst, f"image model: {Path(path).name}")
verify_sha256(dst, size, sha)
cfg = QI.image_config(backend, quant, exe, models_dir, uma=QI.is_apu(gpu), lib_dirs=lib_dirs,
- policy=a.image_gpu_policy or "auto")
+ policy=a.image_gpu_policy or "auto", native=getattr(a, "image_native", None) == "on")
ok(f"image generation: {quant} on {backend}, GPU policy {cfg['gpu_policy']}")
return cfg
@@ -5026,6 +5038,9 @@ def main() -> int:
ap.add_argument("--image-backend", choices=["cuda", "hip", "vulkan", "cpu"],
help="where images are made (default: cuda on NVIDIA, hip on an AMD card, vulkan on an APU/iGPU "
"and Intel)")
+ ap.add_argument("--image-native", choices=["on", "off"],
+ help="EXPERIMENTAL (I2): Strata's own DiT runner inside stable-diffusion.cpp on CUDA / HIP "
+ "(faster denoise; off by default)")
ap.add_argument("--image-gpu-policy", choices=["auto", "keep", "shrink", "unload"],
help="what the text model does during an image job (default auto: stays loaded when both fit, "
"else gives VRAM back or is unloaded and its conversation restored afterwards)")
diff --git a/tools/image/install.py b/tools/image/install.py
index 3bb64bb3f..647096975 100644
--- a/tools/image/install.py
+++ b/tools/image/install.py
@@ -51,6 +51,8 @@ def main(argv=None) -> int:
ap.add_argument("--config", help="a run config (strata-<model>.json) to write the \"images\" section into")
ap.add_argument("--gpu-policy", choices=["auto", "keep", "shrink", "unload"], default="auto")
ap.add_argument("--gpu", type=int, help="the GPU's number for the image job (default: the backend's first)")
+ ap.add_argument("--native", choices=["on", "off"], default="off",
+ help="EXPERIMENTAL: Strata's own DiT runner on CUDA / HIP (the config's \"native\")")
ap.add_argument("--build-only", action="store_true", help="compile sd-cli only")
ap.add_argument("--print", action="store_true", help="print the images section instead of writing it")
ap.add_argument("--yes", action="store_true")
@@ -83,7 +85,7 @@ def main(argv=None) -> int:
S.download(QI.file_url(name, S.hf_endpoint()), dst, f"image model: {Path(path).name}")
S.verify_sha256(dst, size, sha)
section = QI.image_config(backend, quant, exe, models, uma=QI.is_apu(gpu), gpu=a.gpu, lib_dirs=lib_dirs,
- policy=a.gpu_policy)
+ policy=a.gpu_policy, native=a.native == "on")
if a.print or not a.config:
print(json.dumps({"images": section}, indent=1))
return 0
diff --git a/tools/image/qimage.py b/tools/image/qimage.py
index f57b12b0a..560a38be3 100644
--- a/tools/image/qimage.py
+++ b/tools/image/qimage.py
@@ -166,17 +166,36 @@ def source_ok(src: Path) -> bool:
and (Path(src) / "ggml" / "CMakeLists.txt").is_file()
+NATIVE_DIR = Path(__file__).resolve().parent / "sdcpp_native"
+NATIVE_BACKENDS = ("cuda", "hip") # where the native DiT runner (I2) is built in
+
+
+def native_hash() -> str:
+ """A fingerprint of the native runner's sources (a change compiles sd-cli again)."""
+ import hashlib
+ h = hashlib.sha256()
+ for f in sorted(NATIVE_DIR.glob("*")):
+ if f.is_file() and f.suffix in (".cu", ".hpp", ".py"):
+ h.update(f.name.encode() + b"\0" + f.read_bytes().replace(b"\r\n", b"\n"))
+ return h.hexdigest()[:16]
+
+
def build_stamp(backend: str, arch) -> dict:
- return {"sd_cpp": SD_CPP_COMMIT, "ggml": SD_GGML_COMMIT, "backend": backend, "arch": str(arch or "")}
+ stamp = {"sd_cpp": SD_CPP_COMMIT, "ggml": SD_GGML_COMMIT, "backend": backend, "arch": str(arch or "")}
+ if backend in NATIVE_BACKENDS:
+ stamp["native"] = native_hash()
+ return stamp
def image_config(backend: str, quant: str, exe: Path, models_dir: Path, *, uma: bool = False, gpu=None,
- lib_dirs=(), policy: str = "auto") -> dict:
+ lib_dirs=(), policy: str = "auto", native: bool = False) -> dict:
"""The run config's "images" section (serve/images.py reads it)."""
cfg = {"model_name": "qwen-image-2.1-turbo", "exe": str(exe), "backend": backend, "quant": quant,
"diffusion_model": str(local_path(models_dir, quant)), "vae": str(local_path(models_dir, "vae")),
"llm": str(local_path(models_dir, "llm")), "args": default_args(backend), "gpu_policy": policy,
"uma": bool(uma), "sd_cpp": SD_CPP_COMMIT[:7]}
+ if backend in NATIVE_BACKENDS:
+ cfg["native"] = bool(native) # Strata's DiT runner (--model-args qwen_image_2_1_native=1)
if gpu is not None:
cfg["gpu"] = gpu
if lib_dirs:
diff --git a/tools/test_qimage.py b/tools/test_qimage.py
index 9c6ef5dff..fdc81d6af 100644
--- a/tools/test_qimage.py
+++ b/tools/test_qimage.py
@@ -128,6 +128,7 @@ class Build(unittest.TestCase):
cb.assert_not_called()
self.assertEqual((exe, libs), (Path(d) / QI.SD_EXE, [d]))
with mock.patch.object(setup, "cmake_build") as cb, mock.patch.object(setup, "get_sd_cpp"), \
+ mock.patch.object(setup, "apply_native_runner"), \
mock.patch.object(setup, "find_nvcc", return_value=(None, None)):
with self.assertRaises(SystemExit): # another arch: compiled again (here: no nvcc, so it stops)
quiet(setup.build_image_engine, "cuda", {"arch": 89})
@@ -162,5 +163,40 @@ class Config(unittest.TestCase):
self.assertRegex(src, re.escape(f'ap.add_argument("{flag}"'))
+class Native(unittest.TestCase):
+ """I2: the native DiT runner's patch for the pinned stable-diffusion.cpp, and its config switch."""
+
+ def test_stamp_and_config(self):
+ self.assertIn("native", QI.build_stamp("cuda", 86))
+ self.assertIn("native", QI.build_stamp("hip", "gfx1103"))
+ self.assertNotIn("native", QI.build_stamp("vulkan", None))
+ c = QI.image_config("hip", "Q8_0", Path("/e/sd-cli"), Path("/m"), native=True)
+ self.assertIs(c["native"], True)
+ self.assertNotIn("native", QI.image_config("vulkan", "Q8_0", Path("/e/sd-cli"), Path("/m")))
+
+ def test_apply_is_idempotent(self):
+ sys.path.insert(0, str(QI.NATIVE_DIR))
+ import apply as A
+ with tempfile.TemporaryDirectory() as d:
+ sd = Path(d)
+ (sd / "ggml" / "src" / "ggml-cuda").mkdir(parents=True)
+ (sd / "src" / "model" / "diffusion").mkdir(parents=True)
+ (sd / "src" / "pipeline").mkdir(parents=True)
+ (sd / "src" / "pipeline" / "model_builders.cpp").write_text(
+ "#include <x>\n" + A.INCLUDE_OLD + "int a;\n" + A.BUILDER_OLD + " }\n", encoding="utf-8")
+ (sd / "CMakeLists.txt").write_text("x\n" + A.CMAKE_OLD + "y\n", encoding="utf-8")
+ A.apply(sd)
+ first = [(sd / f).read_text(encoding="utf-8") for f in ("src/pipeline/model_builders.cpp", "CMakeLists.txt")]
+ A.apply(sd)
+ again = [(sd / f).read_text(encoding="utf-8") for f in ("src/pipeline/model_builders.cpp", "CMakeLists.txt")]
+ self.assertEqual(first, again)
+ self.assertIn("QwenImage21NativeRunner", first[0])
+ self.assertEqual(first[1].count("SD_QI_NATIVE"), 1)
+ self.assertTrue((sd / "ggml/src/ggml-cuda/qi21-native.cu").is_file())
+ (sd / "CMakeLists.txt").write_text("something else\n", encoding="utf-8")
+ with self.assertRaises(SystemExit): # another sd.cpp: refused, not half-patched
+ A.apply(sd)
+
+
if __name__ == "__main__":
unittest.main()