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

serve: the image encoder on its own GPU, "cuda_device" in the vision section (#408, Efs-O)

Niko122137fe5b532856
diff --git a/docs/DETAILS.md b/docs/DETAILS.md
index 08737ec2c..8386716f4 100644
--- a/docs/DETAILS.md
+++ b/docs/DETAILS.md
@@ -624,6 +624,11 @@ helper (`strata-vision`, from llama.cpp's `mtmd` library) and adds it to your st
A picture becomes up to 1,024 tokens of the context (a 640x480 photo: 300). The same picture sent again, as chat apps
do on every turn, is encoded only once.
+**A spare GPU for the encoder (0.1.33, #408):** with a card the engine doesn't use, add `"cuda_device": 2` (numbered
+like `nvidia-smi`) to the `"vision"` section of `strata-<model>.json`: the encoder then runs on that card alone. Lower
+`--vram-reserve-mib` in `"args"` to 700 as well, so the engine's cards keep that VRAM for the expert cache. The
+encoder's card needs code in the ready-made encoder (RTX 20/30/40/50).
+
### Sending a picture
**Terminal chat:** type `/image <path to a picture>`, press Enter, then type your question.
diff --git a/serve/server.py b/serve/server.py
index 0b02e7295..9b07375d7 100644
--- a/serve/server.py
+++ b/serve/server.py
@@ -649,6 +649,22 @@ def child_env(cfg: dict) -> dict:
return env
+def vision_env(cfg: dict, env: dict) -> dict:
+ """The image encoder's environment: the engine's, unless the config's vision section names its own "cuda_device"
+ (numbered like nvidia-smi) - then the encoder runs on that card alone, so a spare GPU can hold it while the engine
+ keeps all of its own cards' VRAM (#408, Efs-O). Without it, nothing changes."""
+ dev = (cfg.get("vision") or {}).get("cuda_device")
+ if dev is None:
+ return env
+ env = dict(env)
+ if cfg.get("backend") == "hip":
+ env["HIP_VISIBLE_DEVICES"] = str(dev)
+ else:
+ env["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
+ env["CUDA_VISIBLE_DEVICES"] = str(dev)
+ return env
+
+
class ByteTokenizer:
"""Tiny stand-in tokenizer for tests without the pack: one id per UTF-8 byte, specials as ids >= 256."""
SPECIALS = ["<|im_start|>", "<|im_end|>", "<|endoftext|>", "<|vision_start|>", "<|image_pad|>", "<|vision_end|>"]
@@ -2414,7 +2430,8 @@ def main() -> int:
vcfg = {k: (os.path.abspath(os.path.join(cfg.get("cwd") or ".", v))
if k in ("exe", "mmproj", "model") and isinstance(v, str) and not os.path.isabs(v) else v)
for k, v in cfg["vision"].items()}
- vision = Vision(vcfg, log=open(cfg["log"], "a", encoding="utf-8") if cfg.get("log") else None, env=env)
+ vision = Vision(vcfg, log=open(cfg["log"], "a", encoding="utf-8") if cfg.get("log") else None,
+ env=vision_env(cfg, env))
print("model unloaded; the first request loads it ..." if lazy else
"loading the model (the first start takes a minute or two) ...", flush=True)
if len(gpu_list(cfg)) > 1:
diff --git a/serve/test_server.py b/serve/test_server.py
index c52b095e1..46fea89cb 100644
--- a/serve/test_server.py
+++ b/serve/test_server.py
@@ -540,6 +540,18 @@ class GpuChoice(unittest.TestCase):
self.assertEqual(plain.get("CUDA_VISIBLE_DEVICES"), os.environ.get("CUDA_VISIBLE_DEVICES"))
self.assertEqual(plain.get("CUDA_DEVICE_ORDER"), os.environ.get("CUDA_DEVICE_ORDER"))
+ def test_vision_device(self):
+ # #408: the image encoder on its own card; the engine's environment stays as it was
+ from serve.server import child_env, vision_env
+ cfg = {"gpu": [0, 1], "vision": {"exe": "v", "cuda_device": 2}}
+ env = child_env(cfg)
+ venv = vision_env(cfg, env)
+ self.assertEqual(venv["CUDA_VISIBLE_DEVICES"], "2")
+ self.assertEqual(venv["CUDA_DEVICE_ORDER"], "PCI_BUS_ID")
+ self.assertEqual(env["CUDA_VISIBLE_DEVICES"], "0,1")
+ plain = {"gpu": [0, 1], "vision": {"exe": "v"}}
+ self.assertIs(vision_env(plain, env), env) # no cuda_device: the engine's environment, unchanged
+
class RecordingPrompt(MockEngine):
def generate(self, ids, max_new, sampling, cancel, embeddings=None):