mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4228] [Engine] dsv41: read Engram tables stored as ggml Q5_K #4963
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4963
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/4228
Author: @melchisedekko
Created: 10/26/2026
Status: 🔄 Open
Base:
main← Head:feat/dsv41-engram-q5k📝 Commits (1)
b24c6a1[Engine] dsv41: read Engram tables stored as ggml Q5_K📊 Changes
8 files changed (+224 additions, -9 deletions)
View changed files
📝
CMakeLists.txt(+19 -0)📝
docs/DEEPSEEK41.md(+2 -0)📝
src/dsv41/ds4_engram_io.hpp(+1 -1)📝
src/dsv41/ds4_kernels.cu(+11 -0)📝
src/dsv41/ds4_kernels.cuh(+3 -1)📝
src/dsv41/ds4_model.cu(+11 -7)➕
src/dsv41/ds4_q5k.cuh(+38 -0)➕
tests/dsv41/q5k_engram_test.cpp(+139 -0)📄 Description
Problem and result
Unsloth's lower DeepSeek-V4.1-Flash-1017 GGUFs (seen on
UD-IQ2_XXS) store the Engram table (per_layer_token_embd.weight, 135 GB) as Q5_K.pack_gguf.pypacks them without complaint (it already knows Q5_K), butstrata-dsv41stops at load (observed on4b9e05a2, exit code 2):With this change those packs load and answer. Every other Engram format reads exactly as before.
Related discussion
None found. I searched the open and closed issues and PRs for Q5_K / Engram / UD-IQ2_XXS. It is a small, self-contained format addition next to Q6_K, so I am opening it as a focused PR. It is a draft because I could not build the CUDA backend (see "Not run").
Approach
Q5_K becomes Engram row format
4(3is already the old two-tensor FP8 pack). It follows the Q6_K path step by step:ds4_model.cu, format pick:dtype == "Q5_K"selects format 4;eg_hd % 256);ds4_model.cu,eg_issue: a Q5_K row ishd / 256 * 176bytes, read into the row's code bytes like Q6_K and IQ4_NL. The row slot (hd + hd/32) is big enough.ds4_q5k.cuh(new):q5k_value(block, i), one value of a ggmlblock_q5_K, computed the same way asdequantize_row_q5_Kandget_scale_min_k4. Each product is rounded on its own (__fmul_rn, then__fsub_rn), asds4_q6k.cuhdoes for Q6_K.ds4_kernels.cu: afmt == 4branch inengram_dequant_kernelandengram_dequant_tok_kernel.tests/dsv41/q5k_engram_test.cppand theds4_q5k_testtarget: random valid superblocks go through both kernels and are compared bit for bit with a copy of ggml'sdequantize_row_q5_K. The test needs a GPU and returns 77 without one. It sits outside theSTRATA_NATIVE_EXPERTSblock because it needs no native experts.docs/DEEPSEEK41.md: one sentence naming the formats the Engram reader accepts.Compatibility: the existing formats' code paths are not changed. This was checked by reading the diff, which only adds
else if/if (fmt == 4)branches. I did not run an end-to-end check on an MXFP8, Q6_K or IQ4_NL pack; see "Not run".AI assistance: the code was drafted by DeepSeek V4.1 (via an agent harness). I reviewed it and wrote the validation tooling with Claude. I have read every changed line and can answer for it. All numbers below are from runs on my machine.
Validation
Environment: AMD Radeon RX 6800 XT (gfx1030, RDNA2; HIP, system ROCm 7.1, clang 21), Intel Core Ultra 9 285HX, 256 GB RAM, Ubuntu, Linux 7.0. Base revision
4b9e05a2. Model:unsloth/DeepSeek-V4.1-Flash-1017-GGUFUD-IQ2_XXS, 6 shards, packed withtools/dsv41/pack_gguf.py --model <dir> --out <pack>(no other options; no DSpark drafter, no vision).Passed
Builds, HIP gfx1030:
-DSTRATA_ENABLE_HIP=ON -DSTRATA_BUILD_DSV41=ON -DSTRATA_BUILD_TESTS=ON -DCMAKE_HIP_ARCHITECTURES=gfx1030-DSTRATA_NATIVE_EXPERTS=ONTargets
strata-dsv41,ds4_q5k_test,ds4_tq_testandds4_pick_rule_testbuild and link in both configurations.ds4_q5k_test:engram_dequant: 2048 values, 0 differ from ggml,engram_dequant_tok: 2048 values, 0 differ from ggml. Same result in both builds and throughctest -R ds4.ds4_tq_test:ALL OK.ds4_pick_rule_test: ok.python -m unittest serve.test_dsv41: 60 tests OK (1 skipped).strata-dsv41 --pack <pack> --pack-info: every tensor has a device type, and all files are present and long enough. Engram layers 1 and 14, Q5_K.Correctness against the reference implementation of Q5_K (llama.cpp reading the same GGUF).
data/quant_quality/v1(code, docs, english, multilingual, agent), tokenized with this GGUF's tokenizer. Note:set.ids.jsonitself holds Qwen ids; on DeepSeek it fails withtoken 188912 out of range.strata-dsv41 --score.b72050d03), Vulkan, all 6 experts.--experts 6id^1(throwaway build)The ablations show that the Engram matters on this model: a wrong-row or wrong-decode bug would sit about 10× further from the reference than this PR does. Per set, with
--experts 6, the ppl ratios are 1.072 / 0.983 / 0.985 / 1.028 / 1.011, so Strata is lower on two of the five.Server (
serve.server --engine strata,arch: deepseek41,--max-context 262144). Measurements are from this machine only, not a claim for other hardware:--n-cpu-moe 40), same files, same day: 19.0 / 8.0 at 4.2k and 18.6 / 7.5 at 24.7k. That comparison is between engines, not a before/after of this PR, which has no "before" since the pack was refused.Failed
None observed with the final code. During development, the first version of the test laid out the chunked buffer with a per-row stride where the kernel takes a per-token stride. Only the test was wrong; the kernel was not changed.
Not run
ds4_kernels.cuand the new header are shared CUDA/HIP code with no HIP-only constructs, but that is unconfirmed static analysis. I would appreciate a CUDA build andds4_q5k_testrun from someone with a card.Limits
CMakeLists.txt; all GPU results above are from that architecture.🤖 Generated with Claude Code
https://claude.ai/code/session_01GoernqqT5SefEMknYTo8Xx
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.