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

Multi-GPU in the config: "gpu": [0, 2] (setup --gpus 0,2) runs the layer split across the cards

Niko1221500eb977a9cd
diff --git a/serve/server.py b/serve/server.py
index 2f58241d0..2cdd84f76 100644
--- a/serve/server.py
+++ b/serve/server.py
@@ -456,13 +456,32 @@ class Vision:
self.proc.kill()
+def gpu_list(cfg: dict) -> list[int]:
+ """The config's "gpu": one card (2), or several for a layer split ([0, 2] or "0,2"), numbered as nvidia-smi
+ numbers them; [] when it names none."""
+ g = cfg.get("gpu")
+ if g is None or g == "":
+ return []
+ items = g if isinstance(g, (list, tuple)) else str(g).split(",")
+ return [int(str(x).strip()) for x in items if str(x).strip() != ""]
+
+
+def engine_args(cfg: dict) -> list[str]:
+ """The engine's arguments: the config's, and with several GPUs the layer split across them ("layer_split" in the
+ config: "auto" by default, or the first layer of each later GPU's share, e.g. "18" or "16,32")."""
+ args = list(cfg["args"])
+ if len(gpu_list(cfg)) > 1 and "--layer-split" not in args:
+ args += ["--layer-split", str(cfg.get("layer_split") or "auto")]
+ return args
+
+
def child_env(cfg: dict) -> dict:
"""The engine's environment: the CUDA libraries setup installed (pip's nvidia packages, or the toolkit that
compiled it) first on the library search path."""
env = dict(os.environ)
- if cfg.get("gpu") is not None: # issue #51: the GPU to run on, numbered as nvidia-smi does; CUDA's
+ if gpu_list(cfg): # issue #51: the GPU(s) to run on, numbered as nvidia-smi does; CUDA's
env["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" # own default order (fastest first) can number the cards otherwise
- env["CUDA_VISIBLE_DEVICES"] = str(cfg["gpu"])
+ env["CUDA_VISIBLE_DEVICES"] = ",".join(str(i) for i in gpu_list(cfg))
dirs = [d for d in cfg.get("lib_dirs") or [] if Path(d).is_dir()]
if dirs:
var = "PATH" if os.name == "nt" else "LD_LIBRARY_PATH"
@@ -1463,7 +1482,8 @@ def main() -> int:
help="the mock engine's answer (default: a short greeting); given more than once, requests get "
"them in turn and the last one repeats")
ap.add_argument("--port", type=int, default=8095)
- ap.add_argument("--gpu", type=int, help="the GPU to run on, as nvidia-smi numbers them (also \"gpu\" in the config)")
+ ap.add_argument("--gpu", help="the GPU to run on, as nvidia-smi numbers them, or several for a layer split "
+ "(\"0,2\"; also \"gpu\" in the config)")
ap.add_argument("--tokenizer", default=str(ROOT / "pack/full/tokenizer"),
help="pack tokenizer directory (falls back to a byte tokenizer if absent)")
ap.add_argument("--open", action="store_true", help="open the local page in the browser once the model is ready")
@@ -1478,7 +1498,7 @@ def main() -> int:
a = ap.parse_args()
cfg = json.loads(Path(a.config).read_text(encoding="utf-8-sig")) if a.config else {} # Notepad adds a BOM
if a.gpu is not None:
- cfg["gpu"] = a.gpu
+ cfg["gpu"] = int(a.gpu) if a.gpu.strip().isdigit() else a.gpu
a.host = a.host or cfg.get("host") or "127.0.0.1" # issue #26: the run scripts pass no --host, the config can
try: # before the minutes of loading: is the port free?
Server((a.host, a.port), BaseHTTPRequestHandler).server_close()
@@ -1515,7 +1535,9 @@ def main() -> int:
vision = Vision(cfg["vision"], log=open(cfg["log"], "a", encoding="utf-8") if cfg.get("log") else None,
env=env)
print("loading the model (the first start takes a minute or two) ...", flush=True)
- engine = StrataEngine(cfg["exe"], cfg["args"], cwd=cfg.get("cwd"), log=cfg.get("log"), env=env)
+ if len(gpu_list(cfg)) > 1:
+ print(f"[strata] layer split across GPUs {gpu_list(cfg)} ({cfg.get('layer_split') or 'auto'})", flush=True)
+ engine = StrataEngine(cfg["exe"], engine_args(cfg), cwd=cfg.get("cwd"), log=cfg.get("log"), env=env)
warn_tight_ram(engine.info.get("arena_mib"))
else:
engine, vision, sampling_defaults = MockEngine(tok, a.script or [
@@ -1527,7 +1549,7 @@ def main() -> int:
sampling_defaults=sampling_defaults,
fit_max_tokens=a.fit_max_tokens or cfg.get("fit_max_tokens") is True)
svc.api_key = a.api_key or cfg.get("api_key", "")
- svc.gpu_index = cfg.get("gpu") or 0 # the Monitor reads the card the engine runs on (issue #51)
+ svc.gpu_index = (gpu_list(cfg) or [0])[0] # the Monitor reads the card the engine runs on (issue #51)
if a.config: # the Chat settings shared with other apps, from last time
svc.shared_path = str(Path(a.config).with_suffix("")) + ".shared-settings.json"
try:
diff --git a/setup.py b/setup.py
index e24da5339..fdb3eb5d0 100644
--- a/setup.py
+++ b/setup.py
@@ -1085,6 +1085,11 @@ 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", type=int, help="the GPU to use, numbered as nvidia-smi numbers them (default: the one with the "
"most VRAM; with --setup it is saved, when starting it overrides the saved one)")
+ ap.add_argument("--gpus", help="several GPUs for one model, as nvidia-smi numbers them (\"0,2\"): the layers are "
+ "split across them, the first GPU is the main one (saved with --setup; 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 "
"devices on your network (issue #26; set --api-key too)")
ap.add_argument("--api-key", help="require this key from clients (recommended with --host 0.0.0.0)")
@@ -1128,6 +1133,11 @@ def main() -> int:
a.gpu = a.gpu if a.gpu is not None else ch.get("gpu")
a.yes = True
global GPU_PICK
+ multi = [int(x) for x in a.gpus.split(",") if x.strip()] if a.gpus else []
+ if multi:
+ if len(multi) < 2 or len(set(multi)) != len(multi):
+ fail("--gpus takes two or more different GPUs, e.g. --gpus 0,2")
+ a.gpu = multi[0] # the main GPU: the checks and the sizing below are its
GPU_PICK = a.gpu
port = 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):
@@ -1415,6 +1425,14 @@ def main() -> int:
"lib_dirs": lib_dirs, "port": port}
if gpu["count"] > 1 or a.gpu is not None:
cfg["gpu"] = gpu["index"] # the engine is told this card (issue #51)
+ if multi: # a layer split across these cards (the server adds the flag)
+ for i in multi[1:]:
+ x = gpu_info(i)
+ if int(x["arch"]) < 80:
+ fail(f"GPU {i} ({x['name']}) is older than the RTX 30 series (compute capability 8.0 is required)")
+ cfg["gpu"] = multi
+ cfg["layer_split"] = a.layer_split or "auto"
+ ok(f"layer split across GPUs {multi} ({cfg['layer_split']})")
if a.host:
cfg["host"] = a.host
if a.api_key: