[PR #473] [CLOSED] DeepSeek GGUF: MAYA_DS4_DENSE_REQ - re-quantize the attention's Q8_0 dense matrices at load (opt-in, +6% decode on a 24 GB card) #548

Closed
opened 2026-10-29 21:26:42 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/473
Author: @cryptedy
Created: 10/25/2026
Status: ❌ Closed

Base: main ← Head: pr/ds4-dense-req


📝 Commits (1)

  • 593136b DeepSeek GGUF: MAYA_DS4_DENSE_REQ - the attention's Q8_0 dense matrices re-quantized at load (opt-in)

📊 Changes

4 files changed (+174 additions, -3 deletions)

View changed files

📝 docs/SETTINGS.md (+26 -0)
📝 src/ds4/ds4_gguf_cpu.hpp (+5 -0)
📝 src/ds4/ds4_iq_cpu.cpp (+39 -0)
📝 src/ds4/ds4_model.cu (+104 -3)

📄 Description

What

A DeepSeek GGUF pack keeps its dense weights in Q8_0. Every decoded token reads all of them, and on a 24 GB card they take VRAM that experts could use. Here, Maya-S's dense weights are 8.46 GB, and the GPU holds only 1,177 of its 15,360 experts.

MAYA_DS4_DENSE_REQ=q5_k (opt-in) re-quantizes the largest of these matrices at load. By default these are the attention's wq_b, wo_a and wo_b, about 5 GB over 40 layers; MAYA_DS4_DENSE_REQ_MATCH changes the list.

  • Conversion. ggml's own quantizer (ggml_quantize_chunk) does it on the CPU threads, from the Q8_0 values.
  • Runtime. The converted matrices then take the path v1.1.27 added for a GGUF's low-bit dense weights: ds4_iq's GEMV for a token, and its FP16 rows for a prompt. There are no new kernels.
  • Cache. The result is kept in the pack, under <pack>/dense-req-<type>/<tensor>.bin. Each file has a header with the source's size, a sampled checksum and the type. The first start converts (about 20 s for DeepSeek-V4.1-Flash); later starts read the cache (about 2 s). A cache whose header does not match is converted again. If the cache cannot be written, the only cost is the conversion on the next start.
  • Other values. q4_k and iq4_xs are also accepted. An unknown value leaves everything in Q8_0 and logs a line saying so. Rows that do not split into 256-value blocks also stay Q8_0, and the reason is logged once.
  • Docs. The settings are documented in docs/SETTINGS.md. The engine reads them as STRATA_DS4_DENSE_REQ* (a config's MAYA_DS4_DENSE_REQ*), with DS4_DENSE_REQ* as a fallback.

This changes the answers a little, so it is off by default.

Measured

Test machine:

  • Ryzen 7 9700X (8 cores, DDR5), 128 GB RAM, RTX 3090 24 GB, Windows 11, NVMe
  • DeepSeek-V4.1-Flash-1017 Maya-S, --mmap-experts off, DS4_COPY_GB=96, MAYA_DS4_DISK_SKIP_W=0.20
  • The speed runs also had MAYA_DS4_COPY_SWAP=1 (PR from 2026-10-24).

VRAM, and chat decode with the calibration workload (2 runs each):

dense weights experts in VRAM chat decode 8K-token answer (1 run)
Q8_0 (off) 8.46 GB 1,177 18.6 / 18.7 tok/s 15.2 tok/s (lowest 7.0)
q5_k 6.70 GB 1,361 19.7 / 19.7 tok/s (+6%) 17.3 tok/s (lowest 11.3)
iq4_xs 5.97 GB 1,407 20.1 / 20.1 tok/s (+8%) 16.6 tok/s (lowest 9.8)

Quality, against the unmodified model (no skip, Q8_0):

KL, 10 questions (decode) same top token KL, 10 questions over a 16K-token document NLL, 4K-token text NLL, 16K-token text
Q8_0 (off) 0.0194 ± 0.0016 96.0% 0.0128 ± 0.0017 1.2574 1.4076
q5_k 0.0270 ± 0.0031 95.3% 0.0159 ± 0.0018 +0.0035 ± 0.0036 +0.0049 ± 0.0017
q4_k 0.0377 ± 0.0034 94.9% - +0.0076 ± 0.0047 -
iq4_xs 0.0429 ± 0.0046 94.5% - −0.0050 ± 0.0050 -
  • q5_k changes the answers about as much as DISK_SKIP_W=0.20 itself does. The two-way difference over the 16K-token document is +0.0032 ± 0.0009.
  • The 16K-token NLL shows no growth with position: the difference is +0.003 to +0.007 in every 4K-token quarter.
  • q4_k and iq4_xs cost two to three times as much KL, for only a little more speed. That is why the docs point to q5_k.
  • The gain comes from the experts the freed VRAM holds. It is largest where the CPU lane computes many experts, and zero where VRAM already holds every expert.

I also tried Q6_K with a kernel of my own. Its 210-byte blocks need byte-wise loads; it gave KL 0.0208 (the same as Q8_0) but no speed gain (18.4 vs 18.7 tok/s), so it is left out.

Notes

  • This is independent of the copy-swap PR; it applies on v1.1.27 as is.
  • The GPU kernels are upstream's (v1.1.27), so every build has them. Only the conversion needs ggml, i.e. the native-experts build. A build without it leaves the matrices in Q8_0 and logs the reason once. A cache another build wrote is still read.
  • Tested on CUDA only (sm_86).

🔄 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/mw00/project-maya/pull/473 **Author:** [@cryptedy](https://github.com/cryptedy) **Created:** 10/25/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/ds4-dense-req` --- ### 📝 Commits (1) - [`593136b`](https://github.com/mw00/project-maya/commit/593136b80427532a20b7a657e9b511e367e7d425) DeepSeek GGUF: MAYA_DS4_DENSE_REQ - the attention's Q8_0 dense matrices re-quantized at load (opt-in) ### 📊 Changes **4 files changed** (+174 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `docs/SETTINGS.md` (+26 -0) 📝 `src/ds4/ds4_gguf_cpu.hpp` (+5 -0) 📝 `src/ds4/ds4_iq_cpu.cpp` (+39 -0) 📝 `src/ds4/ds4_model.cu` (+104 -3) </details> ### 📄 Description ### What A DeepSeek GGUF pack keeps its dense weights in Q8_0. Every decoded token reads all of them, and on a 24 GB card they take VRAM that experts could use. Here, Maya-S's dense weights are 8.46 GB, and the GPU holds only 1,177 of its 15,360 experts. `MAYA_DS4_DENSE_REQ=q5_k` (opt-in) re-quantizes the largest of these matrices at load. By default these are the attention's `wq_b`, `wo_a` and `wo_b`, about 5 GB over 40 layers; `MAYA_DS4_DENSE_REQ_MATCH` changes the list. - **Conversion.** ggml's own quantizer (`ggml_quantize_chunk`) does it on the CPU threads, from the Q8_0 values. - **Runtime.** The converted matrices then take the path v1.1.27 added for a GGUF's low-bit dense weights: ds4_iq's GEMV for a token, and its FP16 rows for a prompt. There are no new kernels. - **Cache.** The result is kept in the pack, under `<pack>/dense-req-<type>/<tensor>.bin`. Each file has a header with the source's size, a sampled checksum and the type. The first start converts (about 20 s for DeepSeek-V4.1-Flash); later starts read the cache (about 2 s). A cache whose header does not match is converted again. If the cache cannot be written, the only cost is the conversion on the next start. - **Other values.** `q4_k` and `iq4_xs` are also accepted. An unknown value leaves everything in Q8_0 and logs a line saying so. Rows that do not split into 256-value blocks also stay Q8_0, and the reason is logged once. - **Docs.** The settings are documented in `docs/SETTINGS.md`. The engine reads them as `STRATA_DS4_DENSE_REQ*` (a config's `MAYA_DS4_DENSE_REQ*`), with `DS4_DENSE_REQ*` as a fallback. This changes the answers a little, so it is off by default. ### Measured Test machine: - Ryzen 7 9700X (8 cores, DDR5), 128 GB RAM, RTX 3090 24 GB, Windows 11, NVMe - DeepSeek-V4.1-Flash-1017 Maya-S, `--mmap-experts off`, `DS4_COPY_GB=96`, `MAYA_DS4_DISK_SKIP_W=0.20` - The speed runs also had `MAYA_DS4_COPY_SWAP=1` (PR from 2026-10-24). VRAM, and chat decode with the calibration workload (2 runs each): | | dense weights | experts in VRAM | chat decode | 8K-token answer (1 run) | | --- | ---: | ---: | ---: | ---: | | Q8_0 (off) | 8.46 GB | 1,177 | 18.6 / 18.7 tok/s | 15.2 tok/s (lowest 7.0) | | `q5_k` | 6.70 GB | 1,361 | 19.7 / 19.7 tok/s (+6%) | 17.3 tok/s (lowest 11.3) | | `iq4_xs` | 5.97 GB | 1,407 | 20.1 / 20.1 tok/s (+8%) | 16.6 tok/s (lowest 9.8) | Quality, against the unmodified model (no skip, Q8_0): | | KL, 10 questions (decode) | same top token | KL, 10 questions over a 16K-token document | NLL, 4K-token text | NLL, 16K-token text | | --- | ---: | ---: | ---: | ---: | ---: | | Q8_0 (off) | 0.0194 ± 0.0016 | 96.0% | 0.0128 ± 0.0017 | 1.2574 | 1.4076 | | `q5_k` | 0.0270 ± 0.0031 | 95.3% | 0.0159 ± 0.0018 | +0.0035 ± 0.0036 | +0.0049 ± 0.0017 | | `q4_k` | 0.0377 ± 0.0034 | 94.9% | - | +0.0076 ± 0.0047 | - | | `iq4_xs` | 0.0429 ± 0.0046 | 94.5% | - | −0.0050 ± 0.0050 | - | - `q5_k` changes the answers about as much as `DISK_SKIP_W=0.20` itself does. The two-way difference over the 16K-token document is +0.0032 ± 0.0009. - The 16K-token NLL shows no growth with position: the difference is +0.003 to +0.007 in every 4K-token quarter. - `q4_k` and `iq4_xs` cost two to three times as much KL, for only a little more speed. That is why the docs point to `q5_k`. - The gain comes from the experts the freed VRAM holds. It is largest where the CPU lane computes many experts, and zero where VRAM already holds every expert. I also tried Q6_K with a kernel of my own. Its 210-byte blocks need byte-wise loads; it gave KL 0.0208 (the same as Q8_0) but no speed gain (18.4 vs 18.7 tok/s), so it is left out. ### Notes - This is independent of the copy-swap PR; it applies on v1.1.27 as is. - The GPU kernels are upstream's (v1.1.27), so every build has them. Only the conversion needs ggml, i.e. the native-experts build. A build without it leaves the matrices in Q8_0 and logs the reason once. A cache another build wrote is still read. - Tested on CUDA only (sm_86). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:26:42 +07:00
Sign in to join this conversation.
No labels
pull-request
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
mw00/project-maya#548
No description provided.