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

DeepSeek reads pictures by default: strata launch and setup pass --vision on (the engine's own 319 MiB tower, no separate reader), the server sends a picture to that tower as raw RGB in the file of a GENI line (serve/ds_pictures.py: decode with Pillow, both sides a multiple of 42, at most 1024 image tokens, the template's placeholder expanded to the span), --vision off keeps pictures off and the old 400; the plan, the catalog and docs/DEEPSEEK41.md say pictures on; tests for the size rule, the config switch, the prompt expansion and the server route

Niko12219b177f3080a6
diff --git a/docs/DEEPSEEK41.md b/docs/DEEPSEEK41.md
index 418a57e4d..197eb40e5 100644
--- a/docs/DEEPSEEK41.md
+++ b/docs/DEEPSEEK41.md
@@ -109,7 +109,12 @@ The server speaks to the engine as it does for the other models, so `/v1/chat/co
(`STRATA_DS4_SLOT_GB`) and are removed after a week. The system prompt and tools shared by an agent
and its sub-agents are kept as a checkpoint too. `STRATA_DS4_SLOT_KEEP=0` and `STRATA_DS4_AUTO_PIN=0` turn this off.
-Not in this version: several requests at once (`--parallel` is ignored with a warning) and pictures (`--vision` is ignored with a warning).
+Pictures are on by default: the engine reads them with its own vision tower (319 MiB of graphics memory, loaded with the model; no separate
+picture reader). The server decodes each picture, brings it to a size the tower takes (both sides a multiple of 42, at most 1024 image
+tokens) and hands it to the engine; it needs Pillow for that (`python -m pip install pillow`; setup installs it). `--vision no` in `strata launch`
+(or `--vision off` for the engine) turns them off; a request with a picture then gets a 400 that says so.
+
+Not in this version: several requests at once (`--parallel` is ignored with a warning).
## Speed: Faster or Full quality
diff --git a/serve/ds_pictures.py b/serve/ds_pictures.py
new file mode 100644
index 000000000..236a61dcb
--- /dev/null
+++ b/serve/ds_pictures.py
@@ -0,0 +1,199 @@
+"""Pictures for DeepSeek-V4.1-Flash through the engine's OWN vision tower (strata-dsv41 --vision on, the default).
+
+The Qwen engines get pictures from a separate reader process (strata-vision): it turns a picture into embeddings and the server writes
+those into the file a `GENI` line names. strata-dsv41 carries its own 319 MiB tower, so the server only has to
+ 1. decode each picture to RGB and bring it to a size the tower takes (both sides a multiple of 42 = patch 14 x merge 3, at most
+ `vision.max_image_tokens` image tokens, at least `vision.min_pixels` pixels),
+ 2. put one run of image tokens into the prompt where the template wrote its single `<|deepseek_image|>` placeholder: the run is
+ n_h * (n_w + 1) + 2 positions long (the picture's rows, a newline marker per row, the start and end markers), and
+ 3. write the pictures into the file of a `GENI` line (`DSI1`: int32 count, then per picture int64 start, int32 width, int32 height
+ and its height x width x 3 RGB bytes), which the engine reads and encodes on its own GPU.
+Decoding needs Pillow (the server asks for it by name when it is missing). Nothing here starts a process or touches a GPU.
+"""
+from __future__ import annotations
+
+import io
+import os
+import struct
+import tempfile
+from pathlib import Path
+
+PATCH = 14
+MERGE = 3
+MAX_TOKENS = 1024
+MIN_PIXELS = 0
+OFF_WORDS = ("off", "no", "false", "0")
+
+
+def pack_keys(pack_dir) -> dict:
+ """The pack's ds4.txt as {key: value-string} ({} when it cannot be read)."""
+ out = {}
+ try:
+ for line in (Path(pack_dir) / "ds4.txt").read_text(encoding="utf-8", errors="replace").splitlines():
+ k, _, v = line.partition(" ")
+ if k:
+ out[k] = v.strip()
+ except OSError:
+ pass
+ return out
+
+
+def args_after(args, flag):
+ """The value that follows `flag` in an engine argument list (None when absent)."""
+ for i, a in enumerate(args or []):
+ if a == flag and i + 1 < len(args):
+ return str(args[i + 1])
+ return None
+
+
+def vision_wanted(args) -> bool:
+ """`--vision off` (or no/false/0) turns pictures off; everything else, including no flag at all, leaves them on."""
+ v = args_after(args, "--vision")
+ return v is None or v.strip().lower() not in OFF_WORDS
+
+
+def span_length(width: int, height: int, patch: int = PATCH, merge: int = MERGE) -> int:
+ """The image tokens one picture takes in the prompt: n_h * (n_w + 1) + 2 (the engine's own count, ds4_model.cu encode)."""
+ gh, gw = height // patch, width // patch
+ n_h, n_w = -(-gh // merge), -(-gw // merge)
+ return n_h * (n_w + 1) + 2
+
+
+def fit_size(width: int, height: int, max_tokens: int = MAX_TOKENS, min_pixels: int = MIN_PIXELS,
+ patch: int = PATCH, merge: int = MERGE) -> tuple[int, int]:
+ """The size to resize a width x height picture to: its own shape, both sides a multiple of patch * merge, scaled down until its
+ span is within `max_tokens` and up until it has `min_pixels` (when that fits the budget). Never smaller than one cell."""
+ cell = patch * merge
+ if width <= 0 or height <= 0:
+ raise ValueError("the picture has no size")
+
+ def snap(scale: float) -> tuple[int, int]:
+ return max(cell, int(round(width * scale / cell)) * cell), max(cell, int(round(height * scale / cell)) * cell)
+
+ scale = 1.0
+ if width * height < min_pixels:
+ scale = (min_pixels / (width * height)) ** 0.5
+ w, h = snap(scale)
+ while span_length(w, h, patch, merge) > max_tokens: # shrink in small steps until the span fits the engine's limit
+ scale *= 0.95
+ w, h = snap(scale)
+ if w == cell and h == cell:
+ break
+ return w, h
+
+
+class DsPictures:
+ """What the Service holds as `vision` for a DeepSeek-V4.1 engine that reads pictures itself. It has the few members the
+ Service asks of a picture encoder (alive, elastic, restart, unload, dir) and does the DeepSeek-specific work in build()."""
+
+ elastic = False
+ elastic_mib = 0
+
+ def __init__(self, image_token: int, max_tokens: int = MAX_TOKENS, min_pixels: int = MIN_PIXELS, tmp_dir=None,
+ patch: int = PATCH, merge: int = MERGE):
+ self.image_token = int(image_token)
+ self.max_tokens = int(max_tokens)
+ self.min_pixels = int(min_pixels)
+ self.patch, self.merge = int(patch), int(merge)
+ self.dir = Path(tmp_dir) if tmp_dir else Path(tempfile.gettempdir())
+
+ @classmethod
+ def from_config(cls, cfg: dict, tmp_dir=None):
+ """-> DsPictures, or None: pictures are off (`--vision off`), or the pack has no vision tower (no vision.* keys / image token)."""
+ args = cfg.get("args") or []
+ if not vision_wanted(args):
+ return None
+ pack = args_after(args, "--pack")
+ if not pack:
+ return None
+ k = pack_keys(pack)
+ try:
+ if int(k.get("vision.num_hidden_layers", "0")) <= 0 or "image_token_id" not in k:
+ return None
+ return cls(int(k["image_token_id"]), int(k.get("vision.max_image_tokens", MAX_TOKENS)),
+ int(float(k.get("vision.min_pixels", MIN_PIXELS))), tmp_dir,
+ int(k.get("vision.patch_size", PATCH)), int(k.get("vision.downsample_ratio", MERGE)))
+ except ValueError:
+ return None
+
+ # ---- the members the Service asks of any picture encoder
+ def alive(self) -> bool:
+ return True
+
+ def restart(self) -> None:
+ pass
+
+ def unload(self) -> None:
+ pass
+
+ def stop(self) -> None:
+ pass
+
+ # ---- the work
+ @staticmethod
+ def decode(data: bytes):
+ """-> a Pillow RGB image (upright by its EXIF tag; transparency over white)."""
+ try:
+ from PIL import Image, ImageOps
+ except ImportError:
+ raise ValueError("DeepSeek reads pictures with Pillow, which is not installed here (python -m pip install pillow)") from None
+ try:
+ im = Image.open(io.BytesIO(data))
+ im.load()
+ im = ImageOps.exif_transpose(im)
+ except Exception as e: # noqa: BLE001 - any decoder failure is the picture's
+ raise ValueError(f"the image could not be read ({e})") from None
+ if im.mode in ("RGBA", "LA") or (im.mode == "P" and "transparency" in im.info):
+ im = im.convert("RGBA")
+ bg = Image.new("RGB", im.size, (255, 255, 255))
+ bg.paste(im, mask=im.split()[-1])
+ return bg
+ return im if im.mode == "RGB" else im.convert("RGB")
+
+ def prepare(self, data: bytes) -> tuple[int, int, bytes]:
+ """-> (width, height, RGB bytes) of the picture at the size the tower takes."""
+ im = self.decode(data)
+ w, h = fit_size(im.width, im.height, self.max_tokens, self.min_pixels, self.patch, self.merge)
+ if (w, h) != im.size:
+ from PIL import Image
+ im = im.resize((w, h), Image.LANCZOS)
+ return w, h, im.tobytes()
+
+ def encode(self, source) -> None:
+ """Checks that a picture can be read and sized (the Service's pre-check of tool pictures); nothing is stored."""
+ data = source if isinstance(source, bytes) else None
+ if data is None:
+ from serve.server import Vision
+ data = Vision.load(source)
+ self.prepare(data)
+
+ def build(self, ids: list[int], pictures: list[bytes]) -> tuple[list[int], str]:
+ """The prompt ids with each placeholder expanded to its picture's span, and the path of the DSI1 file for the GENI line.
+ `pictures`: the bytes of every image of the request, in prompt order."""
+ marks = [i for i, t in enumerate(ids) if t == self.image_token]
+ if len(marks) != len(pictures):
+ raise ValueError("the prompt and its images do not match")
+ out: list[int] = []
+ entries = []
+ last = 0
+ for pos, data in zip(marks, pictures):
+ w, h, rgb = self.prepare(data)
+ out += ids[last:pos]
+ entries.append((len(out), w, h, rgb))
+ out += [self.image_token] * span_length(w, h, self.patch, self.merge)
+ last = pos + 1
+ out += ids[last:]
+ self.dir.mkdir(parents=True, exist_ok=True)
+ fd, path = tempfile.mkstemp(prefix="strata-ds-pics-", suffix=".dsi", dir=str(self.dir))
+ try:
+ with os.fdopen(fd, "wb") as f:
+ f.write(b"DSI1" + struct.pack("<i", len(entries)))
+ for start, w, h, rgb in entries:
+ f.write(struct.pack("<qii", start, w, h) + rgb)
+ except Exception:
+ try:
+ os.unlink(path)
+ except OSError:
+ pass
+ raise
+ return out, path
diff --git a/serve/server.py b/serve/server.py
index 4276cf529..d502e150f 100644
--- a/serve/server.py
+++ b/serve/server.py
@@ -72,6 +72,7 @@ from strata_control import tls # noqa: E402
tls.install() # #3722: image URLs and tool servers over HTTPS are checked against the operating system's certificates
from strata_control import hipblaslt_tuning # noqa: E402
from strata_control import vision_reader # noqa: E402
+from serve.ds_pictures import DsPictures # noqa: E402
from strata_control import draft_layer # noqa: E402
from strata_control import drafting # noqa: E402
from strata_control import user_args # noqa: E402
@@ -4981,14 +4982,13 @@ class Service:
self.embeddings.path = None
self.embeddings.keys = None
images = images_of(messages)
+ ds_pics = False # DeepSeek pictures (the engine's own tower): the file is already written
if images:
if self.offline and any(src.startswith(("http://", "https://")) for src in images):
raise ValueError("offline mode cannot download an image URL; send a data: image instead")
if self.vision is None:
raise ValueError("this server was started without the vision encoder (run setup again and choose "
"'vision'), so it cannot read images")
- pad = self.tok.encode(IMAGE_PAD, parse_special=True)[0]
- start = self.tok.encode(VISION_START, parse_special=True)[0]
# An image URL is downloaded first, outside the FIFO: under it, a slow server held every other request
# for as long as urlopen waited.
def fetch(src):
@@ -4997,6 +4997,16 @@ class Service:
return fetched[src] if src in fetched else Vision.download(src) \
if src.startswith(("http://", "https://")) else src
images = [fetch(src) for src in images]
+ if isinstance(self.vision, DsPictures):
+ # DeepSeek-V4.1: the engine has its own vision tower. The pictures go to it as raw RGB in the file of a GENI line
+ # (serve/ds_pictures.py); each template placeholder becomes the run of image tokens its picture takes.
+ ids, ds_file = self.vision.build(ids, [Vision.load(src) if isinstance(src, str) else src for src in images])
+ self.embeddings.path = ds_file
+ self.embeddings.keys = None
+ images, ds_pics = [], True
+ if images:
+ pad = self.tok.encode(IMAGE_PAD, parse_special=True)[0]
+ start = self.tok.encode(VISION_START, parse_special=True)[0]
# Encode only while the engine is idle: the engine and the image encoder (a separate process) must not
# run on the GPU at the same time - an encode during a running request left that request stuck at
# "reading the prompt" with CPU and GPU busy, for good (reproduced). So encoding takes its turn in the
@@ -5068,12 +5078,12 @@ class Service:
# (an encoder restart, the cache's eviction) with other bits still matches its checkpoints
self.embeddings.keys = [Path(p).stem[:16] for p, _ in encoded]
write_temporary(combined, [p for p, _ in encoded])
- if self.family == "deepseek41" and req is not None and req.get("strata_prefix") is None and not images:
+ if self.family == "deepseek41" and req is not None and req.get("strata_prefix") is None and not images and not ds_pics:
lead = self.deepseek_shared_start(messages)
if lead:
req["strata_prefix"] = {"messages": lead}
if req is not None and req.get("strata_prefix") is not None:
- req["strata_prefix"] = self.resolve_prefix(req["strata_prefix"], messages, tools, kwargs, ids, bool(images))
+ req["strata_prefix"] = self.resolve_prefix(req["strata_prefix"], messages, tools, kwargs, ids, bool(images) or ds_pics)
return ids, kwargs.get("enable_thinking", True) is not False, max_new
@staticmethod
@@ -8968,6 +8978,13 @@ def main(argv=None, *, lifecycle_event=None, interrupt_exit_code: int = 0) -> in
sampling_defaults=sampling_defaults,
fit_max_tokens=a.fit_max_tokens or (not a.no_fit_max_tokens and cfg.get("fit_max_tokens") is not False))
svc.launch_attestation = launch_attestation
+ if (cfg.get("arch") or "") == "deepseek41" and vision is None and a.engine == "strata":
+ # DeepSeek-V4.1 reads pictures with the engine's own tower (--vision on, the default): no separate reader process.
+ # `--vision off` in the config's args, or a pack without a tower, leaves svc.vision None: pictures are refused with the 400 as before.
+ _dsp = DsPictures.from_config(cfg, tmp_dir=Path(cfg["log"]).parent / "ds-pictures" if cfg.get("log") else None)
+ if _dsp is not None:
+ svc.vision = _dsp
+ print("[strata] pictures: on (DeepSeek-V4.1 reads them with the engine's own vision tower; --vision off turns them off)", flush=True)
svc.offline = a.offline
svc.max_queue = max_queue
svc.queue_timeout_s = float(queue_timeout) if queue_timeout is not None else None
diff --git a/serve/test_ds_pictures.py b/serve/test_ds_pictures.py
new file mode 100644
index 000000000..5f56ff715
--- /dev/null
+++ b/serve/test_ds_pictures.py
@@ -0,0 +1,243 @@
+"""serve/test_ds_pictures.py: DeepSeek-V4.1 pictures through the engine's own tower (serve/ds_pictures.py): the size rule, the span, the
+config switch, the prompt expansion and the DSI1 file the engine reads. CPU only; the decode tests need Pillow and skip without it."""
+import io
+import os
+import struct
+import sys
+import tempfile
+import unittest
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
+from serve import ds_pictures as D # noqa: E402
+
+try:
+ from PIL import Image
+except ImportError: # pragma: no cover
+ Image = None
+
+IMG = 129264
+
+
+def png(w, h, color=(220, 20, 20)) -> bytes:
+ im = Image.new("RGB", (w, h), color)
+ out = io.BytesIO()
+ im.save(out, format="PNG")
+ return out.getvalue()
+
+
+class Geometry(unittest.TestCase):
+ def test_span_matches_the_engine(self):
+ # mkimg.py's 672 x 672 picture: 16 x 17 + 2 = 274 positions
+ self.assertEqual(D.span_length(672, 672), 274)
+ self.assertEqual(D.span_length(42, 42), 1 * 2 + 2)
+ self.assertEqual(D.span_length(14, 14), 1 * 2 + 2) # a partial merge cell still counts one
+
+ def test_sizes_are_multiples_of_42_within_the_budget(self):
+ for w, h in ((100, 100), (672, 672), (4000, 3000), (3000, 4000), (1920, 1080), (50, 3000)):
+ nw, nh = D.fit_size(w, h)
+ self.assertEqual((nw % 42, nh % 42), (0, 0), (w, h))
+ self.assertLessEqual(D.span_length(nw, nh), D.MAX_TOKENS, (w, h))
+ self.assertGreaterEqual(min(nw, nh), 42)
+
+ def test_small_pictures_grow_to_min_pixels(self):
+ w, h = D.fit_size(200, 200, min_pixels=295936)
+ self.assertGreaterEqual(w * h, 295936 * 0.8) # rounded to the 42 grid
+
+ def test_a_huge_picture_shrinks_to_the_limit(self):
+ w, h = D.fit_size(8000, 6000, 1024)
+ self.assertLessEqual(D.span_length(w, h), 1024)
+ self.assertGreater(D.span_length(w, h), 800) # but not far below it
+
+
+class Config(unittest.TestCase):
+ def pack(self, tower=True):
+ d = tempfile.mkdtemp()
+ lines = ["hidden_size 5120"]
+ if tower:
+ lines += ["vision.num_hidden_layers 32", "vision.patch_size 14", "vision.downsample_ratio 3", "vision.max_image_tokens 1024",
+ "vision.min_pixels 295936", f"image_token_id {IMG}"]
+ Path(d, "ds4.txt").write_text("\n".join(lines) + "\n", encoding="utf-8")
+ return d
+
+ def test_on_by_default(self):
+ p = D.DsPictures.from_config({"args": ["--pack", self.pack(), "--max-context", "8192"]})
+ self.assertIsNotNone(p)
+ self.assertEqual((p.image_token, p.max_tokens, p.min_pixels), (IMG, 1024, 295936))
+
+ def test_vision_on_flag(self):
+ self.assertIsNotNone(D.DsPictures.from_config({"args": ["--pack", self.pack(), "--vision", "on"]}))
+
+ def test_vision_off_turns_it_off(self):
+ for word in ("off", "OFF", "no", "false", "0"):
+ self.assertIsNone(D.DsPictures.from_config({"args": ["--pack", self.pack(), "--vision", word]}), word)
+
+ def test_a_pack_without_a_tower_has_none(self):
+ self.assertIsNone(D.DsPictures.from_config({"args": ["--pack", self.pack(tower=False)]}))
+ self.assertIsNone(D.DsPictures.from_config({"args": []}))
+ self.assertIsNone(D.DsPictures.from_config({"args": ["--pack", "/nonexistent"]}))
+
+
[email protected](Image is None, "Pillow is not installed")
+class Build(unittest.TestCase):
+ def setUp(self):
+ self.tmp = tempfile.mkdtemp()
+ self.p = D.DsPictures(IMG, 1024, 0, self.tmp)
+
+ def read(self, path):
+ raw = Path(path).read_bytes()
+ self.assertEqual(raw[:4], b"DSI1")
+ n = struct.unpack("<i", raw[4:8])[0]
+ pos, out = 8, []
+ for _ in range(n):
+ start, w, h = struct.unpack("<qii", raw[pos:pos + 16])
+ pos += 16
+ out.append((start, w, h, raw[pos:pos + w * h * 3]))
+ pos += w * h * 3
+ self.assertEqual(pos, len(raw))
+ return out
+
+ def test_one_picture(self):
+ ids = [5, 6, IMG, 7, 8]
+ out, path = self.p.build(ids, [png(672, 672)])
+ self.assertEqual(out[:2], [5, 6])
+ self.assertEqual(out.count(IMG), 274)
+ self.assertEqual(out[2 + 274:], [7, 8])
+ (start, w, h, rgb), = self.read(path)
+ self.assertEqual((start, w, h), (2, 672, 672))
+ self.assertEqual(rgb[:3], bytes((220, 20, 20)))
+ self.assertEqual(out[start], IMG)
+
+ def test_two_pictures_keep_their_order_and_starts(self):
+ ids = [1, IMG, 2, 3, IMG, 4]
+ out, path = self.p.build(ids, [png(42, 42, (0, 255, 0)), png(84, 42, (0, 0, 255))])
+ a, b = self.read(path)
+ self.assertEqual((a[1], a[2]), (42, 42))
+ self.assertEqual((b[1], b[2]), (84, 42))
+ self.assertEqual(a[0], 1)
+ self.assertEqual(b[0], 1 + D.span_length(42, 42) + 2)
+ self.assertEqual(a[3][:3], bytes((0, 255, 0)))
+ self.assertEqual(b[3][-3:], bytes((0, 0, 255)))
+ self.assertEqual(out[-1], 4)
+
+ def test_counts_must_match(self):
+ with self.assertRaises(ValueError):
+ self.p.build([1, IMG, 2], [png(42, 42), png(42, 42)])
+ with self.assertRaises(ValueError):
+ self.p.build([1, 2], [png(42, 42)])
+
+ def test_odd_sizes_and_transparency_are_brought_to_the_grid(self):
+ im = Image.new("RGBA", (100, 61), (0, 0, 0, 0)) # fully transparent: white
+ buf = io.BytesIO()
+ im.save(buf, format="PNG")
+ w, h, rgb = self.p.prepare(buf.getvalue())
+ self.assertEqual((w % 42, h % 42), (0, 0))
+ self.assertEqual(rgb[:3], b"\xff\xff\xff")
+
+ def test_a_bad_image_is_a_value_error(self):
+ with self.assertRaises(ValueError):
+ self.p.prepare(b"not an image")
+
+ def test_the_engine_limit_holds_for_a_huge_picture(self):
+ w, h, rgb = self.p.prepare(png(3000, 2000))
+ self.assertLessEqual(D.span_length(w, h), 1024)
+ self.assertEqual(len(rgb), w * h * 3)
+
+
+# ---- the server side: a picture reaches the engine as a GENI file, text requests are untouched, pictures off is the old 400
+import base64 # noqa: E402
+import json # noqa: E402
+import urllib.error # noqa: E402
+import urllib.request # noqa: E402
+
+from serve import frontend # noqa: E402
+from serve.frontend import ChatTemplate # noqa: E402
+from serve.server import Service, default_model_name, serve # noqa: E402
+from serve.test_dsv41 import TEMPLATE, DsEngine, mini_tokenizer # noqa: E402
+
+
+class SeenEngine(DsEngine):
+ """Keeps the picture file's bytes while the engine is 'reading' it (the server deletes the file after the run)."""
+
+ def generate(self, ids, max_new, sampling, cancel, embeddings=None):
+ self.seen_file = Path(embeddings).read_bytes() if embeddings else None
+ self.seen_ids = list(ids)
+ yield from super().generate(ids, max_new, sampling, cancel, embeddings)
+
+
[email protected](Image is None, "Pillow is not installed")
+class Serve(unittest.TestCase):
+ @classmethod
+ def setUpClass(cls):
+ cls.tok = mini_tokenizer()
+ cls.img = cls.tok.encode("<|deepseek_image|>", parse_special=True)[0]
+
+ def start(self, pictures=True):
+ engine = SeenEngine(self.tok, "ok")
+ vision = D.DsPictures(self.img, 1024, 0, tempfile.mkdtemp()) if pictures else None
+ svc = Service(engine, self.tok, ChatTemplate(TEMPLATE), model_name=default_model_name({"arch": "deepseek41"}), vision=vision)
+ svc.model_arch = "deepseek41"
+ svc.set_family("deepseek41")
+ httpd = serve(svc, port=0)
+ self.addCleanup(httpd.server_close)
+ self.addCleanup(httpd.shutdown)
+ self.addCleanup(frontend.use_family, None)
+ self.engine, self.svc = engine, svc
+ self.base = f"http://127.0.0.1:{httpd.server_address[1]}"
+
+ def post(self, body):
+ req = urllib.request.Request(self.base + "/v1/chat/completions", data=json.dumps(body).encode(),
+ headers={"Content-Type": "application/json"})
+ try:
+ with urllib.request.urlopen(req, timeout=60) as r:
+ return r.status, json.loads(r.read().decode())
+ except urllib.error.HTTPError as e:
+ return e.code, json.loads(e.read().decode())
+
+ def picture_body(self):
+ url = "data:image/png;base64," + base64.b64encode(png(672, 672)).decode()
+ return {"messages": [{"role": "user", "content": [{"type": "image_url", "image_url": {"url": url}},
+ {"type": "text", "text": "What colour is this?"}]}], "max_tokens": 8}
+
+ def test_a_picture_reaches_the_engine_as_a_geni_file(self):
+ self.start()
+ code, out = self.post(self.picture_body())
+ self.assertEqual(code, 200, out)
+ self.assertEqual(self.engine.seen_ids.count(self.img), 274)
+ raw = self.engine.seen_file
+ self.assertEqual(raw[:4], b"DSI1")
+ n, = struct.unpack("<i", raw[4:8])
+ start, w, h = struct.unpack("<qii", raw[8:24])
+ self.assertEqual((n, w, h), (1, 672, 672))
+ self.assertEqual(self.engine.seen_ids[start], self.img)
+ self.assertEqual(len(raw), 24 + 672 * 672 * 3)
+ left = [p for p in Path(self.svc.vision.dir).glob("strata-ds-pics-*.dsi")]
+ self.assertEqual(left, [], "the picture file is removed after the run")
+
+ def test_text_requests_are_the_same_with_pictures_on(self):
+ body = {"messages": [{"role": "user", "content": "hi"}], "max_tokens": 8}
+ self.start(pictures=True)
+ self.assertEqual(self.post(body)[0], 200)
+ with_pics = list(self.engine.seen_ids)
+ self.assertIsNone(self.engine.seen_file)
+ self.start(pictures=False)
+ self.assertEqual(self.post(body)[0], 200)
+ self.assertEqual(self.engine.seen_ids, with_pics)
+
+ def test_pictures_off_keeps_the_400(self):
+ self.start(pictures=False)
+ code, out = self.post(self.picture_body())
+ self.assertEqual(code, 400)
+ self.assertIn("without the vision encoder", json.dumps(out))
+
+ def test_a_follow_up_with_the_picture_in_history_works(self):
+ self.start()
+ body = self.picture_body()
+ body["messages"] += [{"role": "assistant", "content": "red and blue"}, {"role": "user", "content": "and the middle?"}]
+ code, out = self.post(body)
+ self.assertEqual(code, 200, out)
+ self.assertEqual(self.engine.seen_ids.count(self.img), 274)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/setup.py b/setup.py
index d3cda7ba0..8687f69c8 100644
--- a/setup.py
+++ b/setup.py
@@ -743,7 +743,7 @@ MULTI_FILE_FAMILIES = {
"models": {"UD-Q8_K_XL": {"about": "Unsloth Dynamic 8-bit: the experts in MXFP4 as DeepSeek made them, the rest "
"in BF16 (the checkpoint's own precision)",
"ram_gb": 306, "shards": [DSV41_SHARD.format(i=i) for i in range(1, 10)]}},
- "sha256": DSV41_ALL_FILES, "vision": False}
+ "sha256": DSV41_ALL_FILES, "vision": True} # the engine's own tower (strata-dsv41 --vision on, the default), 0.2.7
}
# The official sets first (a normal PC), Unsloth's 508 GB set last. Each model: its shards, the sub-folder they are in at the repository
# (and in a --gguf-dir folder), the files shared with the other set ("shared"), the pack recipe and the shipped expert profile.
@@ -8273,8 +8273,11 @@ def install_dsv41(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopted,
warn(f"little free disk space in {folder}: {free:.1f} GB free for about {left:.1f} GB. Setup goes on and should fit")
if ctx > 65536:
warn(f"{ctx // 1024}K tokens of context: the engine was checked at 4K and 8K; longer is kept as you chose, but untested")
- if a.vision in ("yes", "gpu", "cpu"):
- warn(f"{fam['title']} cannot read pictures in this Strata version (its picture reader is in development): images off")
+ # Pictures are on by default (owner rule): the engine reads them with its own vision tower (319 MiB, loaded with the model, no separate
+ # reader process). --vision no turns them off (--vision off for the engine); gpu / cpu name a Flash-Next reader and mean "on" here.
+ ds_vision = "off" if a.vision in ("no", "off") else "on"
+ if a.vision in ("gpu", "cpu"):
+ warn(f"{fam['title']} reads pictures with the engine's own tower, so --vision {a.vision} is taken as yes: pictures on")
if a.rope_scaling or a.rope_scale or a.kv or a.resident_budget_gib is not None or a.low_ram not in (None, "auto"):
warn(f"--rope-scaling / --kv / --resident-budget-gib / --low-ram are Flash-Next settings: {fam['title']} does not use them")
@@ -8381,7 +8384,7 @@ def install_dsv41(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopted,
# --dspark-conf 0.65: the drafts' confidence floor (H100 replay, DSPARK-DEFAULTS.md: within 0.01-0.02 of the per-class best,
# never below 0.3). The engine has no flag for the draft block (3 in the same table): it reads the block size from the pack,
# so only the floor is written.
- args = ["--pack", str(pack), "--max-context", str(ctx), "--eos", "1", "--dspark", "auto",
+ args = ["--pack", str(pack), "--max-context", str(ctx), "--eos", "1", "--vision", ds_vision, "--dspark", "auto",
*(["--dspark-conf", "0.65"] if md.get("recipe") == "ista" else []), *dsv41_prefill_chunk_args(cards, ram),
*plan["args"]]
env = dsv41_config_env(cards)
diff --git a/strata_cli/launch/cmd.py b/strata_cli/launch/cmd.py
index bd050072b..6bb6caf95 100644
--- a/strata_cli/launch/cmd.py
+++ b/strata_cli/launch/cmd.py
@@ -346,13 +346,12 @@ def apply_defaults(s: S.LaunchSettings, catalog) -> tuple[S.LaunchSettings, list
if s.vision == "off" and r.images and catalog.reader_state() == "missing":
notices.append(S.Notice("warn", "The engine installed here has no picture reader, so pictures are off.",
"Update the engine to read pictures, or add --vision off to silence this."))
- if catalog.strata.multi_family(s.family): # DeepSeek-V4.1-Flash: one request at a time, no tuning, no pictures yet
+ if catalog.strata.multi_family(s.family): # DeepSeek-V4.1-Flash: one request at a time, no tuning
if s.parallel and s.parallel > 1:
notices.append(S.Notice("warn", f"{s.model} answers one request at a time in this Strata version, so --parallel {s.parallel} is not used.", ""))
s.parallel = None
- if s.vision not in (None, "off"):
- notices.append(S.Notice("warn", "DeepSeek-V4.1-Flash cannot read pictures in this Strata version, so pictures are off.", ""))
- s.vision = "off" # (tuning is DeepSeek's own short tune: tools/dsv41/tune.py, run by the launch)
+ # pictures: on unless the person chose off - the engine reads them with its own vision tower, no separate reader
+ s.vision = "off" if s.vision == "off" else "on" # (tuning is DeepSeek's own short tune: tools/dsv41/tune.py, run by the launch)
elif s.speed:
notices.append(S.Notice("warn", "--speed and --full-quality are for DeepSeek; this model uses all its experts, so they are not used.", ""))
s.speed = None
diff --git a/strata_cli/launch/runner.py b/strata_cli/launch/runner.py
index 5b2a4b3cd..d14619861 100644
--- a/strata_cli/launch/runner.py
+++ b/strata_cli/launch/runner.py
@@ -314,7 +314,10 @@ def apply_choices(cfg: dict, s: S.LaunchSettings) -> dict:
kv = s.kv or ("int8" if (s.context or 32768) > 8192 else "fp16")
if "--kv" in args or s.kv:
put("--kv", kv)
- if s.vision == "off":
+ if cfg.get("arch") == "deepseek41": # the engine's own tower: --vision on / off is its whole picture setting
+ if s.vision:
+ put("--vision", "off" if s.vision == "off" else "on")
+ elif s.vision == "off":
args = [a for a in args if a != "--vision"]
cfg.pop("vision", None) # the picture reader's own settings: the server adds --vision for them
elif s.vision and "--vision" not in args:
diff --git a/tests/terminal/test_launch_dsv41.py b/tests/terminal/test_launch_dsv41.py
index fee3fb0ec..b329ec9bf 100644
--- a/tests/terminal/test_launch_dsv41.py
+++ b/tests/terminal/test_launch_dsv41.py
@@ -40,7 +40,7 @@ class LaunchDeepSeek(unittest.TestCase):
self.assertEqual([r.download_gb for r in rows[:3]], [256.8, 273.8, 239.3])
self.assertEqual(catalog(self.hw).resolve("ist-das-2.25bpw"), ("deepseek41", "IST-DAS-2.25bpw"))
r = rows[3]
- self.assertEqual((r.id, r.download_gb, r.verdict, r.images), ("deepseek-v4.1-flash-ud-q8_k_xl", 508.4, "fits", False))
+ self.assertEqual((r.id, r.download_gb, r.verdict, r.images), ("deepseek-v4.1-flash-ud-q8_k_xl", 508.4, "fits", True)) # 0.2.7: pictures through the engine's own tower
self.assertEqual(catalog(self.hw).resolve("ud-q8_k_xl"), ("deepseek41", "UD-Q8_K_XL"))
self.assertEqual(catalog(self.hw).max_context("deepseek41", "UD-Q8_K_XL"), 8192)
@@ -50,7 +50,7 @@ class LaunchDeepSeek(unittest.TestCase):
self.assertEqual(p["settings"]["family"], "deepseek41")
self.assertEqual(p["settings"]["context"], 8192)
self.assertEqual(p["settings"]["tune"], "skip")
- self.assertEqual(p["settings"]["vision"], "off")
+ self.assertEqual(p["settings"]["vision"], "on") # pictures are on by default (the engine's own tower)
self.assertEqual(pl["verdict"], "fits")
self.assertEqual([c["layers"] for c in pl["cards"]], [[0, 9], [10, 19], [20, 29], [30, 39]])
self.assertEqual(pl["args"], ["--tp", "2"])
@@ -107,10 +107,12 @@ class LaunchDeepSeek(unittest.TestCase):
p = self.plan("--model", "ud-q8_k_xl", "--parallel", "4", "--vision", "on", "--tune", "quick")
s = p["settings"]
self.assertFalse(s.get("parallel"))
- self.assertEqual((s["vision"], s["tune"]), ("off", "quick")) # the DeepSeek tune is real now: the choice stays
+ self.assertEqual((s["vision"], s["tune"]), ("on", "quick")) # the DeepSeek tune is real now: the choice stays; pictures stay on
text = " ".join(p["warnings"])
self.assertIn("one request at a time", text)
- self.assertIn("cannot read pictures", text)
+ self.assertNotIn("cannot read pictures", text)
+ off = self.plan("--model", "ud-q8_k_xl", "--vision", "off")["settings"]
+ self.assertEqual(off["vision"], "off") # --vision off still turns them off
self.assertNotIn("Tuning is not offered", text)
def test_setup_is_asked_for_the_family_and_the_files(self):
diff --git a/tools/strata_mcp.py b/tools/strata_mcp.py
index 48d0d2df6..719634215 100644
--- a/tools/strata_mcp.py
+++ b/tools/strata_mcp.py
@@ -572,7 +572,7 @@ class Strata:
# nine shards; the memory the weights need is VRAM + RAM together WITHOUT the n-gram table (it stays on the SSD)
gb = sum(big["sha256"][n][0] for n in [*big["models"][model]["shards"], *big["models"][model].get("shared", [])]) / 1e9
return {"about": big["models"][model]["about"], "download_gb": round(gb, 1), "ram_gb": big["models"][model]["ram_gb"],
- "arena_gb": round(float(big["models"][model]["ram_gb"]) - 17.0, 1), "mem_total": True, "vision": False,
+ "arena_gb": round(float(big["models"][model]["ram_gb"]) - 17.0, 1), "mem_total": True, "vision": bool(big.get("vision", True)),
"engine": None, "families": (family,), "multi_file": True}
d = (getattr(self.setup_module(), "OWN_PATH_FAMILIES", None) or {}).get(family)
if not d or model not in d["models"]:
diff --git a/tools/test_setup_dsv41.py b/tools/test_setup_dsv41.py
index e2c493806..b08bb5a6c 100644
--- a/tools/test_setup_dsv41.py
+++ b/tools/test_setup_dsv41.py
@@ -220,7 +220,7 @@ class Install(unittest.TestCase):
self.assertEqual(self.cfg["engine_ready_s"], 3600)
self.assertEqual(self.cfg["backend"], "hip")
self.assertTrue(self.cfg["tokenizer"].endswith("tokenizer"))
- self.assertNotIn("--vision", a)
+ self.assertEqual(a[a.index("--vision") + 1], "on") # 0.2.7: the engine reads pictures with its own tower
self.assertNotIn("--mtp", a)
self.assertIn("4 cards, one block of layers on each", out)
self.assertIn("n-gram table", out)
@@ -291,7 +291,9 @@ class Install(unittest.TestCase):
def test_pictures_and_flash_next_settings_are_said(self):
rc, out = self.install(vision="yes", kv="int8", context=131072)
self.assertEqual(rc, 0, out)
- self.assertIn("cannot read pictures in this Strata version", out)
+ self.assertNotIn("cannot read pictures", out) # 0.2.7: the engine's own tower reads them
+ a = self.cfg["args"]
+ self.assertEqual(a[a.index("--vision") + 1], "on")
self.assertIn("Flash-Next settings", out)
self.assertEqual(self.cfg["args"][self.cfg["args"].index("--max-context") + 1], "131072")
self.assertIn("checked at 4K and 8K", out)
@@ -308,7 +310,7 @@ class Catalog(unittest.TestCase):
self.assertEqual((small_sets["IST-DAS-2.00bpw"]["download_gb"], small_sets["IST-DAS-2.25bpw"]["download_gb"]), (256.8, 273.8))
self.assertTrue(small_sets["IST-DAS-2.00bpw"]["on_this_pc"].startswith("fits"))
size = small_sets["UD-Q8_K_XL"]
- self.assertEqual((size["model"], size["id"], size["download_gb"], size["images"]), ("UD-Q8_K_XL", "deepseek-v4.1-flash-ud-q8_k_xl", 508.4, False))
+ self.assertEqual((size["model"], size["id"], size["download_gb"], size["images"]), ("UD-Q8_K_XL", "deepseek-v4.1-flash-ud-q8_k_xl", 508.4, True))
self.assertTrue(size["on_this_pc"].startswith("fits"))
self.assertTrue(size["mem_total"] and size["multi_file"])
self.assertEqual(size["gpu_options"]["recommended"], "all")
@@ -338,7 +340,7 @@ class Catalog(unittest.TestCase):
"cpu": {"avx2": True}}
s.disk_free = lambda p: 2000.0
plan, a = M.Tools(s).install_plan("deepseek41", "UD-Q8_K_XL", None, None, None, None, None, None, None, None, None)
- self.assertEqual((plan["title"], plan["download_gb"], plan["context"], plan["images"]), ("DeepSeek-V4.1-Flash UD-Q8_K_XL", 508.4, 8192, "no"))
+ self.assertEqual((plan["title"], plan["download_gb"], plan["context"], plan["images"]), ("DeepSeek-V4.1-Flash UD-Q8_K_XL", 508.4, 8192, "yes")) # 0.2.7: pictures on by default
self.assertEqual(a[:6], ["--yes", "--no-start", "--family", "deepseek41", "--model", "UD-Q8_K_XL"])
self.assertTrue(plan["ram"].startswith("fits"))
for flag in ("--kv", "--low-ram", "--experimental-speed-projection"):