[PR #4178] [CLOSED] [Engine] read DeepSeek-V4.1 pictures with the model's own vision tower #4932

Closed
opened 2026-11-07 16:31:26 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4178
Author: @suifei
Created: 10/26/2026
Status: ❌ Closed

Base: main ← Head: feat/dsv41-engine-vision


📝 Commits (1)

  • f1a8999 serve(dsv41): read pictures with the model's own vision tower

📊 Changes

4 files changed (+250 additions, -12 deletions)

View changed files

➕ serve/dsv41_vision.py (+152 -0)
📝 serve/server.py (+27 -5)
➕ serve/test_dsv41_vision.py (+58 -0)
📝 setup.py (+13 -7)

📄 Description

Problem and result

DeepSeek-V4.1-Flash-1017 is multimodal: config.json carries image_token_id: 129264 and a vision_config (32-layer ViT, patch 14, merge 3, at most 1024 image tokens), and the dsv41 engine already implements that tower (src/dsv41/ds4_vision.cu, --encode-image, --images); tools/dsv41/pack_gguf.py --mmproj packs it from mmproj-BF16.gguf (projector deepseek41v).

Before: the HTTP server's image path always ran the separate strata-vision encoder (llama.cpp mtmd + mmproj). That encoder has no deepseek41v projector, so the family was marked images: false and --vision was ignored with a warning; an image_url request could not work.

After: for arch: deepseek41 the server feeds the pictures to the engine instead. An OpenAI image_url (or Anthropic image block) is accepted, the picture becomes a run of the model's image token in the prompt, and the engine encodes it with its own tower. /health reports "images": true for such a pack.

none — no issue was opened for this. It is a feature (new capability behind the existing image API), so a maintainer's scope decision is welcome; I am happy to turn it into an issue first if that is preferred.

Approach

The engine's GENI request already names a pictures file, but it is a DSI1 file (magic, count, then start i64, width i32, height i32, RGB per picture) that the engine encodes itself - not the embedding rows strata-vision writes for the other families. So:

  • serve/dsv41_vision.py (new) holds the picture side: fit() (both sides on the tower's 42-pixel grid, aspect kept, span inside vision.max_image_tokens), rows() (ceil(h/42) * (ceil(w/42) + 1) + 2, the engine's own count), the prompt marker expansion, the span offsets, the DSI1 writer, and detect() (reads image_token_id / vision.* from the pack's ds4.txt).
  • serve/server.py: Service(native_vision=...). In prepare() the content lists are flattened to text with one marker per picture, the marker becomes a run of the image token before tokenizing, and the request's DSI1 file is passed as GENI's pictures file; the strata-vision branch is skipped for this family. /health, /metrics and /v1/models report image support from the pack.
  • setup.py: the IST-DAS sets fetch the pinned mmproj-BF16.gguf into the shared folder and pass it to pack_gguf.py --mmproj; the family is marked vision: true.
  • serve/test_dsv41_vision.py (new): the geometry against the engine's own measurements, marker expansion, span offsets, DSI1 layout.

Compatibility: the new path runs only when the config's arch is deepseek41 and the pack carries a vision tower (image_token_id in ds4.txt). A pack without one keeps native_vision = None and behaves exactly as before; other families keep the strata-vision path untouched. No strata-vision process is started for this family.

Validation

Revision f1a8999 (feat/dsv41-engine-vision, based on main 4b9e05a). Environment: Ubuntu 24.04 container, Python 3.12.3 (the checkout's .venv), 4 x NVIDIA L20 46 GB, driver 595.71, CUDA 13.2.1, strata-dsv41 0.1.51 built from this tree (-DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_DSV41=ON -DCMAKE_CUDA_ARCHITECTURES=native), pack: IST-DAS 2.25 bpw (IQ2_XS + Engram, 274 GB) with mmproj-BF16.gguf, 1M context.

Passed:

  1. python -m unittest serve.test_dsv41_vision - 6 tests, OK (geometry 420x420->112, 700x700->308, 1008x672->402, 1540x700->648 rows, the values the engine printed; expand/starts/DSI1).
  2. python -m unittest serve.test_dsv41 - 60 tests, OK (skipped=1), no regression in the family's existing tests.
  3. Pack with the tower: python tools/dsv41/pack_gguf.py --model <IST-DAS folder> --shards <4 IQ2_XS files> --engram ... --engram-meta ... --dspark-gguf ... --dspark-noise-token 128799 --dspark-markov-rank 256 --mmproj mmproj-BF16.gguf --out <pack> printed vision tower from mmproj-BF16.gguf: 32 blocks, image token 129264; strata-dsv41 --pack-info --pack <pack> printed dense ... vision 0.97 and files: 7, all present and long enough.
  4. Tower output: strata-dsv41 --pack <pack> --encode-image carrots.rgb --size 1008x672 --dump-image out.span printed vision: 1008 x 672 pixels -> a span of 402 rows in 97 ms; the dump is 402 x 5120 BF16.
  5. HTTP end to end: serve/server.py --engine strata --config <ist-das config> --port 8080, then POST /v1/chat/completions with a data:image/png;base64,... image_url part (the official example photo, 1024x701) and "What vegetable is in this picture? Answer in one word." answered Carrot, usage: prompt_tokens 418 (16 text + 402 image), completion_tokens 3, 1.3 s; GET /health showed "images": true, "max_context": 1048576.
  6. GET /v1/models with the same server: architecture.input_modalities = ["text", "image"].

Failed:

none observed.

Not run:

  • A fresh setup.py install for this family (the new download/pack path): it would fetch the 274 GB set again. The pack produced by hand with the exact recipe setup now uses was validated above; the setup change is the same --mmproj argument.
  • HIP (Radeon), SYCL (Intel Arc), Metal (macOS) and Windows builds: no such hardware here.
  • Multiple pictures in one request, a picture at the 1024-token limit, and a picture URL over the network: the DSI1 layout and the span arithmetic are unit-tested, the single-picture HTTP path was tested.

Limits

  • A picture is resized onto the 42-pixel grid (aspect kept within a rounding step, no letterboxing), so very wide or tall pictures are scaled to fit the 1024-token budget.
  • The engine encodes a picture on first use (~100 ms for 1008x672); repeated pictures rely on the engine's own picture hash, the server sends no image-cache keys for this family.
  • The server still prefers strata-vision whenever a vision encoder is configured for another family; this change is keyed on the arch and the pack, not on a new config option.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4178 **Author:** [@suifei](https://github.com/suifei) **Created:** 10/26/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/dsv41-engine-vision` --- ### 📝 Commits (1) - [`f1a8999`](https://github.com/Niko1221/Strata/commit/f1a89997a67d829ddc05acc9561185e12fbb4745) serve(dsv41): read pictures with the model's own vision tower ### 📊 Changes **4 files changed** (+250 additions, -12 deletions) <details> <summary>View changed files</summary> ➕ `serve/dsv41_vision.py` (+152 -0) 📝 `serve/server.py` (+27 -5) ➕ `serve/test_dsv41_vision.py` (+58 -0) 📝 `setup.py` (+13 -7) </details> ### 📄 Description ## Problem and result DeepSeek-V4.1-Flash-1017 is multimodal: `config.json` carries `image_token_id: 129264` and a `vision_config` (32-layer ViT, patch 14, merge 3, at most 1024 image tokens), and the `dsv41` engine already implements that tower (`src/dsv41/ds4_vision.cu`, `--encode-image`, `--images`); `tools/dsv41/pack_gguf.py --mmproj` packs it from `mmproj-BF16.gguf` (projector `deepseek41v`). Before: the HTTP server's image path always ran the separate `strata-vision` encoder (llama.cpp mtmd + mmproj). That encoder has no `deepseek41v` projector, so the family was marked `images: false` and `--vision` was ignored with a warning; an `image_url` request could not work. After: for `arch: deepseek41` the server feeds the pictures to the engine instead. An OpenAI `image_url` (or Anthropic image block) is accepted, the picture becomes a run of the model's image token in the prompt, and the engine encodes it with its own tower. `/health` reports `"images": true` for such a pack. ## Related discussion none — no issue was opened for this. It is a feature (new capability behind the existing image API), so a maintainer's scope decision is welcome; I am happy to turn it into an issue first if that is preferred. ## Approach The engine's `GENI` request already names a pictures file, but it is a **DSI1** file (magic, count, then `start i64, width i32, height i32, RGB` per picture) that the engine encodes itself - not the embedding rows `strata-vision` writes for the other families. So: * `serve/dsv41_vision.py` (new) holds the picture side: `fit()` (both sides on the tower's 42-pixel grid, aspect kept, span inside `vision.max_image_tokens`), `rows()` (`ceil(h/42) * (ceil(w/42) + 1) + 2`, the engine's own count), the prompt marker expansion, the span offsets, the DSI1 writer, and `detect()` (reads `image_token_id` / `vision.*` from the pack's `ds4.txt`). * `serve/server.py`: `Service(native_vision=...)`. In `prepare()` the content lists are flattened to text with one marker per picture, the marker becomes a run of the image token before tokenizing, and the request's DSI1 file is passed as `GENI`'s pictures file; the `strata-vision` branch is skipped for this family. `/health`, `/metrics` and `/v1/models` report image support from the pack. * `setup.py`: the IST-DAS sets fetch the pinned `mmproj-BF16.gguf` into the shared folder and pass it to `pack_gguf.py --mmproj`; the family is marked `vision: true`. * `serve/test_dsv41_vision.py` (new): the geometry against the engine's own measurements, marker expansion, span offsets, DSI1 layout. Compatibility: the new path runs only when the config's arch is `deepseek41` **and** the pack carries a vision tower (`image_token_id` in `ds4.txt`). A pack without one keeps `native_vision = None` and behaves exactly as before; other families keep the `strata-vision` path untouched. No `strata-vision` process is started for this family. ## Validation Revision `f1a8999` (`feat/dsv41-engine-vision`, based on `main` `4b9e05a`). Environment: Ubuntu 24.04 container, Python 3.12.3 (the checkout's `.venv`), 4 x NVIDIA L20 46 GB, driver 595.71, CUDA 13.2.1, `strata-dsv41 0.1.51` built from this tree (`-DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_DSV41=ON -DCMAKE_CUDA_ARCHITECTURES=native`), pack: IST-DAS 2.25 bpw (IQ2_XS + Engram, 274 GB) with `mmproj-BF16.gguf`, 1M context. **Passed:** 1. `python -m unittest serve.test_dsv41_vision` - 6 tests, `OK` (geometry 420x420->112, 700x700->308, 1008x672->402, 1540x700->648 rows, the values the engine printed; expand/starts/DSI1). 2. `python -m unittest serve.test_dsv41` - 60 tests, `OK (skipped=1)`, no regression in the family's existing tests. 3. Pack with the tower: `python tools/dsv41/pack_gguf.py --model <IST-DAS folder> --shards <4 IQ2_XS files> --engram ... --engram-meta ... --dspark-gguf ... --dspark-noise-token 128799 --dspark-markov-rank 256 --mmproj mmproj-BF16.gguf --out <pack>` printed `vision tower from mmproj-BF16.gguf: 32 blocks, image token 129264`; `strata-dsv41 --pack-info --pack <pack>` printed `dense ... vision 0.97` and `files: 7, all present and long enough`. 4. Tower output: `strata-dsv41 --pack <pack> --encode-image carrots.rgb --size 1008x672 --dump-image out.span` printed `vision: 1008 x 672 pixels -> a span of 402 rows in 97 ms`; the dump is 402 x 5120 BF16. 5. HTTP end to end: `serve/server.py --engine strata --config <ist-das config> --port 8080`, then `POST /v1/chat/completions` with a `data:image/png;base64,...` `image_url` part (the official example photo, 1024x701) and "What vegetable is in this picture? Answer in one word." answered **Carrot**, `usage: prompt_tokens 418 (16 text + 402 image), completion_tokens 3`, 1.3 s; `GET /health` showed `"images": true`, `"max_context": 1048576`. 6. `GET /v1/models` with the same server: `architecture.input_modalities = ["text", "image"]`. **Failed:** none observed. **Not run:** * A fresh `setup.py` install for this family (the new download/pack path): it would fetch the 274 GB set again. The pack produced by hand with the exact recipe setup now uses was validated above; the setup change is the same `--mmproj` argument. * HIP (Radeon), SYCL (Intel Arc), Metal (macOS) and Windows builds: no such hardware here. * Multiple pictures in one request, a picture at the 1024-token limit, and a picture URL over the network: the DSI1 layout and the span arithmetic are unit-tested, the single-picture HTTP path was tested. ## Limits * A picture is resized onto the 42-pixel grid (aspect kept within a rounding step, no letterboxing), so very wide or tall pictures are scaled to fit the 1024-token budget. * The engine encodes a picture on first use (~100 ms for 1008x672); repeated pictures rely on the engine's own picture hash, the server sends no image-cache keys for this family. * The server still prefers `strata-vision` whenever a `vision` encoder is configured for another family; this change is keyed on the arch and the pack, not on a new config option. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:31:26 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4932
No description provided.