[PR #5256] [Engine] Cache DeepSeek-V4.1 image conversations across slots and shared starts #5366

Open
opened 2026-11-07 16:34:39 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5256
Author: @Moeblack
Created: 11/4/2026
Status: 🔄 Open

Base: main ← Head: feat/dsv41-image-slots


📝 Commits (1)

  • f138e79 [Engine] cache DeepSeek image conversations across slots and sequences

📊 Changes

8 files changed (+471 additions, -142 deletions)

View changed files

📝 docs/DEEPSEEK41.md (+6 -0)
📝 serve/ds_pictures.py (+8 -3)
📝 serve/server.py (+23 -10)
➕ src/dsv41/ds4_images.hpp (+45 -0)
📝 src/dsv41/ds4_main.cpp (+101 -83)
📝 src/dsv41/ds4_model.cu (+186 -18)
📝 src/dsv41/ds4_model.hpp (+8 -2)
📝 src/dsv41/ds4_slotmeta.hpp (+94 -26)

📄 Description

Problem and result

In strata-dsv41, conversations containing images were excluded from conversation slots (if (held.empty()) slot_put("")) and could not reuse shared starts (slot_save rejected states when !imgs.empty(), even at restore points before the first image). In addition, held image records lived in a single variable in ds4_main.cpp rather than per-sequence state under --parallel.

With this change:

  • Image conversations are saved to and restored from RAM and disk slots (DS4SLOT2 / DS4META3), storing each image's {start, len, hash} so prefix matching stops safely before any changed image.
  • Shared starts (prefixes) work for image requests when the shared prefix precedes the first image or contains identical images.
  • Per-sequence image spans and embeddings move with seq_park() / seq_unpark() under --parallel.

none

Approach

  • Track ImageSpan { start, len, hash } inside Model (and SeqState for --parallel) instead of a global held vector in ds4_main.cpp.
  • Bound token prefix reuse across live state, prefixes, and slots by comparing image {start, len, hash} spans (image_prefix).
  • Allow slot_save at restore point at when no image precedes at, or serialize the active ImageSpan list into DS4SLOT2 / DS4META3 when saving full image conversations.
  • Compute expected image token span length from (width, height) before invoking the vision encoder so cached image spans skip re-encoding on restore.

Validation

Passed:

  • Built strata-dsv41 on Linux (sm_89, CUDA 13.0) and ran deepseek-v4.1-flash-ist-das-2.25bpw with --vision on --vision-resident --parallel 4 and STRATA_DS4_SLOT_KEEP=1:
    • Shared-start reuse across different images: Two single-turn requests sharing a 366-token system prompt with different images (red square, then blue circle) answered red square and blue circle, reusing the 366-token system prefix on the second request:
      ds4: kept a 366-token shared start
      maya ds4 serve: request 2: prompt 571 tokens = 366 reused + 205 read
      
    • RAM slot eviction and restore: Sending 5 concurrent/interleaved conversations (A1..E1) under --parallel 4 evicted image conversation A to a RAM slot; follow-up A2 restored all 583 tokens without re-reading the image:
      ds4 slots: took back a 583-token conversation from RAM (0.0 s); 19 new tokens to read
      maya ds4 serve: 1 pictures, 0 read (0 ms)
      
    • Disk slot persistence across restart: After unloading and reloading the engine, follow-up A3 restored the 605-token image conversation from disk (DS4META3) without re-encoding the image:
      ds4 slots: folder /data/deepseek-v41/slots: 7 conversation(s) kept from earlier runs (0.11 GB)
      ds4 slots: took back a 605-token conversation from the folder (0.0 s); 21 new tokens to read
      maya ds4 serve: 1 pictures, 0 read (0 ms)
      

Failed:

  • none observed

Not run:

  • HIP, SYCL, and Metal builds.

Limits

  • Existing DS4SLOT1 / DS4META2 slot files from earlier runs are not migrated and will be re-read once after upgrading.

🔄 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/5256 **Author:** [@Moeblack](https://github.com/Moeblack) **Created:** 11/4/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/dsv41-image-slots` --- ### 📝 Commits (1) - [`f138e79`](https://github.com/Niko1221/Strata/commit/f138e79699b852bd5c22348c30ef3a22d38298ab) [Engine] cache DeepSeek image conversations across slots and sequences ### 📊 Changes **8 files changed** (+471 additions, -142 deletions) <details> <summary>View changed files</summary> 📝 `docs/DEEPSEEK41.md` (+6 -0) 📝 `serve/ds_pictures.py` (+8 -3) 📝 `serve/server.py` (+23 -10) ➕ `src/dsv41/ds4_images.hpp` (+45 -0) 📝 `src/dsv41/ds4_main.cpp` (+101 -83) 📝 `src/dsv41/ds4_model.cu` (+186 -18) 📝 `src/dsv41/ds4_model.hpp` (+8 -2) 📝 `src/dsv41/ds4_slotmeta.hpp` (+94 -26) </details> ### 📄 Description ## Problem and result In `strata-dsv41`, conversations containing images were excluded from conversation slots (`if (held.empty()) slot_put("")`) and could not reuse shared starts (`slot_save` rejected states when `!imgs.empty()`, even at restore points before the first image). In addition, `held` image records lived in a single variable in `ds4_main.cpp` rather than per-sequence state under `--parallel`. With this change: - Image conversations are saved to and restored from RAM and disk slots (`DS4SLOT2` / `DS4META3`), storing each image's `{start, len, hash}` so prefix matching stops safely before any changed image. - Shared starts (`prefixes`) work for image requests when the shared prefix precedes the first image or contains identical images. - Per-sequence image spans and embeddings move with `seq_park()` / `seq_unpark()` under `--parallel`. ## Related discussion none ## Approach - Track `ImageSpan { start, len, hash }` inside `Model` (and `SeqState` for `--parallel`) instead of a global `held` vector in `ds4_main.cpp`. - Bound token prefix reuse across live state, `prefixes`, and `slots` by comparing image `{start, len, hash}` spans (`image_prefix`). - Allow `slot_save` at restore point `at` when no image precedes `at`, or serialize the active `ImageSpan` list into `DS4SLOT2` / `DS4META3` when saving full image conversations. - Compute expected image token span length from `(width, height)` before invoking the vision encoder so cached image spans skip re-encoding on restore. ## Validation **Passed:** - Built `strata-dsv41` on Linux (`sm_89`, CUDA 13.0) and ran `deepseek-v4.1-flash-ist-das-2.25bpw` with `--vision on --vision-resident --parallel 4` and `STRATA_DS4_SLOT_KEEP=1`: - **Shared-start reuse across different images**: Two single-turn requests sharing a 366-token system prompt with different images (red square, then blue circle) answered `red square` and `blue circle`, reusing the 366-token system prefix on the second request: ```text ds4: kept a 366-token shared start maya ds4 serve: request 2: prompt 571 tokens = 366 reused + 205 read ``` - **RAM slot eviction and restore**: Sending 5 concurrent/interleaved conversations (`A1..E1`) under `--parallel 4` evicted image conversation `A` to a RAM slot; follow-up `A2` restored all 583 tokens without re-reading the image: ```text ds4 slots: took back a 583-token conversation from RAM (0.0 s); 19 new tokens to read maya ds4 serve: 1 pictures, 0 read (0 ms) ``` - **Disk slot persistence across restart**: After unloading and reloading the engine, follow-up `A3` restored the 605-token image conversation from disk (`DS4META3`) without re-encoding the image: ```text ds4 slots: folder /data/deepseek-v41/slots: 7 conversation(s) kept from earlier runs (0.11 GB) ds4 slots: took back a 605-token conversation from the folder (0.0 s); 21 new tokens to read maya ds4 serve: 1 pictures, 0 read (0 ms) ``` **Failed:** - none observed **Not run:** - HIP, SYCL, and Metal builds. ## Limits - Existing `DS4SLOT1` / `DS4META2` slot files from earlier runs are not migrated and will be re-read once after upgrading. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#5366
No description provided.