[PR #4820] [Engine] Native support for DeepSeek-V4-Flash (0731 release) in strata-dsv41 #5196

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4820
Author: @code-martin
Created: 10/31/2026
Status: 🔄 Open

Base: main ← Head: feature/deepseek4-support


📝 Commits (1)

  • 6eea5a4 [Engine] Native support for DeepSeek-V4-Flash 0731, on-the-fly Q4_K dense quantization, and scaled route_prior

📊 Changes

12 files changed (+959 additions, -306 deletions)

View changed files

📝 serve/frontend.py (+7 -2)
📝 serve/server.py (+42 -13)
📝 serve/test_family_name.py (+2 -1)
📝 serve/web/app.js (+10 -2)
📝 serve/web/index.html (+5 -0)
📝 setup.py (+17 -0)
📝 src/dsv41/ds4_kernels.cu (+310 -145)
📝 src/dsv41/ds4_kernels.cuh (+17 -9)
📝 src/dsv41/ds4_main.cpp (+21 -1)
📝 src/dsv41/ds4_model.cu (+499 -124)
📝 src/dsv41/ds4_model.hpp (+6 -0)
📝 tools/dsv41/pack_gguf.py (+23 -9)

📄 Description

Problem and result

Problem:
Strata's strata-dsv41 engine was strictly configured for the DeepSeek-V4.1-Flash (1017 release) layout (general.architecture = "deepseek41"). Running original DeepSeek-V4-Flash (0731 release) models (general.architecture = "deepseek4" — e.g. DwarfStar/antirez or Unsloth GGUFs) failed due to architectural differences:

  1. 0731 uses non-lagged hyper-connections (hc_split into a_pre/f_pre passed directly into same-sublayer hc_pre_norm, plus final output.hc_* pre-norm before norm.weight).
  2. Unweighted per-head Q RMSNorm (unit_norm) on Q heads (128 heads of 256 dims).
  3. 64-element block FP8 E4M3 rounding (quant = 4) and BF16 compressed KV cache.
  4. 2-lane compressor (coff = 2, R = 4 with c_ape) and dedicated indexer compressor with Walsh-Hadamard transform (hadamard128).
  5. Early-layer token-ID hash routing on layers 0..2 (ffn.gate.tid2eid).
  6. Mandatory requirement of a 111 GB Engram table (absent in 0731).
  7. Dense weights in Q8_0/F16 occupied 7.90 GB, leaving no VRAM on 10–12 GB GPUs (e.g. RTX 3080 10GB) for expert caching and choking context capacity.

Result:
Full native support for DeepSeek-V4-Flash 0731 (deepseek4) in strata-dsv41:

  1. Native forward pass, CUDA kernels, and packing support for all 0731 architectural primitives without requiring an Engram table.
  2. On-the-fly multithreaded CPU transcoding of dense weights (Q8_0 -> Q4_K and F16 -> Q8_0) during load on <= 12 GB GPUs, cutting dense footprint from 7.90 GB to 4.61 GB (saving 3.29 GB VRAM).
  3. 4-bit FP4 KV cache with host-offloaded CKV/IK, enabling full 240K context (245,760 tokens) while freeing 1.95 GB VRAM for 231 resident VRAM experts.
  4. Scaled MoE residency routing (kDs4RoutePriorScale = 0.1f), controllable via --route-prior, server API, and Chat settings drawer (0.0–1.0 slider, default 0.1), boosting cold decode throughput from 4.7 tok/s to 13.3 tok/s (+183%) with 100% fluent output.

none

Approach

  • Model & Packing (tools/dsv41/pack_gguf.py, src/dsv41/ds4_model.cu): Mapped 0731 tensors (tid2eid, attn.indexer.ape.weight, attn.indexer.wgate.weight), enabled optional Engram bypass (engram_layer_ids = []), and supported F16/BF16 dense uploads. Implemented 0731 forward pass with hc_split, output.hc_* pre-norm, unit_norm, indexer Hadamard transform, and early-layer token routing.
  • On-The-Fly Dense Transcoding (src/dsv41/ds4_model.cu): Added parallel CPU conversion of dense layers from Q8_0 to Q4_K and F16 to Q8_0 when GPU memory <= 12 GiB (or DS4_DENSE_Q4K=1).
  • Memory & Cache Layout: Offloaded compressed KV and indexer cache to pinned host memory (cudaHostAllocMapped / hmap) with 4-bit FP4 quantization.
  • Residency Routing: Added kDs4RoutePriorScale = 0.1f inside router kernels so that user values [0.0, 1.0] map safely to score deltas [0.0, 0.10], plus Web UI settings slider and REST API.

Validation

Passed:
- Build: ninja -C M:/Strata/build-dsv41 strata-dsv41 on Windows 11 x64, MSVC v143, CUDA 13.1 (0 errors).
- Smoke test: smoke.py --exe strata-dsv41.exe --pack maya-ds4-0731 --tokens 64 -> "The capital of France is Paris."
- Full 240K context allocation (245,760 tokens) with 231 VRAM resident experts on RTX 3080 10GB.
- Route prior sweep benchmark (Prompt: "Briefly describe the architecture and main instruments of the James Webb Space Telescope (JWST).", max_tokens = 60, temp = 0.0):
* prior 0.0 (off): 4.7 tok/s (12,725 ms, 100% fluent)
* prior 0.1 (default): 9.7 tok/s (6,182 ms, 100% fluent, +106% speedup)
* prior 0.3: 7.2 tok/s (8,337 ms, 100% fluent)
* prior 0.5: 9.3 tok/s (6,432 ms, 100% fluent)
* prior 0.7: 13.3 tok/s (4,521 ms, 100% fluent, +183% speedup)
* prior 1.0: 12.3 tok/s (4,868 ms, 100% fluent)

Failed: none observed

Not run: Non-CUDA backends (HIP / SYCL / Metal) — strata-dsv41 engine targets CUDA (sm_80+).

Limits

  • Dense Q4_K transcoding requires ~2.5 seconds on multithreaded CPU during startup.
  • Host-offloaded KV cache throughput depends on PCIe bandwidth at long contexts.

🔄 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/4820 **Author:** [@code-martin](https://github.com/code-martin) **Created:** 10/31/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feature/deepseek4-support` --- ### 📝 Commits (1) - [`6eea5a4`](https://github.com/Niko1221/Strata/commit/6eea5a4420facab676c5adf7ed8f08a7ececfb5c) [Engine] Native support for DeepSeek-V4-Flash 0731, on-the-fly Q4_K dense quantization, and scaled route_prior ### 📊 Changes **12 files changed** (+959 additions, -306 deletions) <details> <summary>View changed files</summary> 📝 `serve/frontend.py` (+7 -2) 📝 `serve/server.py` (+42 -13) 📝 `serve/test_family_name.py` (+2 -1) 📝 `serve/web/app.js` (+10 -2) 📝 `serve/web/index.html` (+5 -0) 📝 `setup.py` (+17 -0) 📝 `src/dsv41/ds4_kernels.cu` (+310 -145) 📝 `src/dsv41/ds4_kernels.cuh` (+17 -9) 📝 `src/dsv41/ds4_main.cpp` (+21 -1) 📝 `src/dsv41/ds4_model.cu` (+499 -124) 📝 `src/dsv41/ds4_model.hpp` (+6 -0) 📝 `tools/dsv41/pack_gguf.py` (+23 -9) </details> ### 📄 Description ## Problem and result Problem: Strata's `strata-dsv41` engine was strictly configured for the DeepSeek-V4.1-Flash (1017 release) layout (`general.architecture = "deepseek41"`). Running original DeepSeek-V4-Flash (0731 release) models (`general.architecture = "deepseek4"` — e.g. DwarfStar/antirez or Unsloth GGUFs) failed due to architectural differences: 1. 0731 uses non-lagged hyper-connections (`hc_split` into `a_pre`/`f_pre` passed directly into same-sublayer `hc_pre_norm`, plus final `output.hc_*` pre-norm before `norm.weight`). 2. Unweighted per-head Q RMSNorm (`unit_norm`) on Q heads (128 heads of 256 dims). 3. 64-element block FP8 E4M3 rounding (`quant = 4`) and BF16 compressed KV cache. 4. 2-lane compressor (`coff = 2`, `R = 4` with `c_ape`) and dedicated indexer compressor with Walsh-Hadamard transform (`hadamard128`). 5. Early-layer token-ID hash routing on layers 0..2 (`ffn.gate.tid2eid`). 6. Mandatory requirement of a 111 GB Engram table (absent in 0731). 7. Dense weights in Q8_0/F16 occupied 7.90 GB, leaving no VRAM on 10–12 GB GPUs (e.g. RTX 3080 10GB) for expert caching and choking context capacity. Result: Full native support for DeepSeek-V4-Flash 0731 (`deepseek4`) in `strata-dsv41`: 1. Native forward pass, CUDA kernels, and packing support for all 0731 architectural primitives without requiring an Engram table. 2. On-the-fly multithreaded CPU transcoding of dense weights (`Q8_0 -> Q4_K` and `F16 -> Q8_0`) during load on <= 12 GB GPUs, cutting dense footprint from 7.90 GB to 4.61 GB (saving 3.29 GB VRAM). 3. 4-bit FP4 KV cache with host-offloaded CKV/IK, enabling full 240K context (245,760 tokens) while freeing 1.95 GB VRAM for 231 resident VRAM experts. 4. Scaled MoE residency routing (`kDs4RoutePriorScale = 0.1f`), controllable via `--route-prior`, server API, and Chat settings drawer (0.0–1.0 slider, default 0.1), boosting cold decode throughput from 4.7 tok/s to 13.3 tok/s (+183%) with 100% fluent output. ## Related discussion none ## Approach - Model & Packing (`tools/dsv41/pack_gguf.py`, `src/dsv41/ds4_model.cu`): Mapped 0731 tensors (`tid2eid`, `attn.indexer.ape.weight`, `attn.indexer.wgate.weight`), enabled optional Engram bypass (`engram_layer_ids = []`), and supported F16/BF16 dense uploads. Implemented 0731 forward pass with `hc_split`, `output.hc_*` pre-norm, `unit_norm`, indexer Hadamard transform, and early-layer token routing. - On-The-Fly Dense Transcoding (`src/dsv41/ds4_model.cu`): Added parallel CPU conversion of dense layers from Q8_0 to Q4_K and F16 to Q8_0 when GPU memory <= 12 GiB (or `DS4_DENSE_Q4K=1`). - Memory & Cache Layout: Offloaded compressed KV and indexer cache to pinned host memory (`cudaHostAllocMapped` / `hmap`) with 4-bit FP4 quantization. - Residency Routing: Added `kDs4RoutePriorScale = 0.1f` inside router kernels so that user values [0.0, 1.0] map safely to score deltas [0.0, 0.10], plus Web UI settings slider and REST API. ## Validation Passed: - Build: `ninja -C M:/Strata/build-dsv41 strata-dsv41` on Windows 11 x64, MSVC v143, CUDA 13.1 (0 errors). - Smoke test: `smoke.py --exe strata-dsv41.exe --pack maya-ds4-0731 --tokens 64` -> `"The capital of France is Paris."` - Full 240K context allocation (245,760 tokens) with 231 VRAM resident experts on RTX 3080 10GB. - Route prior sweep benchmark (Prompt: "Briefly describe the architecture and main instruments of the James Webb Space Telescope (JWST).", max_tokens = 60, temp = 0.0): * prior 0.0 (off): 4.7 tok/s (12,725 ms, 100% fluent) * prior 0.1 (default): 9.7 tok/s (6,182 ms, 100% fluent, +106% speedup) * prior 0.3: 7.2 tok/s (8,337 ms, 100% fluent) * prior 0.5: 9.3 tok/s (6,432 ms, 100% fluent) * prior 0.7: 13.3 tok/s (4,521 ms, 100% fluent, +183% speedup) * prior 1.0: 12.3 tok/s (4,868 ms, 100% fluent) Failed: none observed Not run: Non-CUDA backends (HIP / SYCL / Metal) — strata-dsv41 engine targets CUDA (sm_80+). ## Limits - Dense Q4_K transcoding requires ~2.5 seconds on multithreaded CPU during startup. - Host-offloaded KV cache throughput depends on PCIe bandwidth at long contexts. --- <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#5196
No description provided.