mirror of
https://github.com/mw00/project-maya.git
synced 2026-12-03 19:04:50 +07:00
[PR #624] ds4 GGUF: Q5_K GEMVs of >= N activations on int8 tensor cores (DS4_Q5K_IMMA, opt-in, sm_80+), bit for bit the dp4a kernel #632
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
mw00/project-maya#632
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/mw00/project-maya/pull/624
Author: @SeriousRising
Created: 10/28/2026
Status: 🔄 Open
Base:
main← Head:ds4-q5k-imma-gemv📝 Commits (1)
1872501ds4 GGUF: Q5_K GEMVs of >= N activations on int8 tensor cores (DS4_Q5K_IMMA, opt-in, sm_80+), bit for bit the dp4a kernel📊 Changes
4 files changed (+312 additions, -0 deletions)
View changed files
📝
docs/SETTINGS.md(+14 -0)📝
src/ds4/ds4_iq.cu(+177 -0)📝
src/ds4/ds4_iq.cuh(+3 -0)📝
tests/ds4_gguf_test.cu(+118 -0)📄 Description
What. On GGUF packs like DeepSeek-V4.1-Flash GSQ-RCO, the dense matrices that run once per verify-window row are Q5_K: wq_b, wo_a, wo_b, the shared expert, Engram wkv and the head. They go through
gg::mv->iq::mv_nc->mv_kernel<kQ5_K, NC>(dp4a). That kernel is not arithmetic-bound: at one column it already runs at 2.5-3.5x the weight-read floor, and each extra column costs ~27 µs on wq_b and ~390 µs on the head, because every warp re-reads the activations and redoes the half sums and the F32 epilogue per row. A verify window of T rows pays that T times.mv_q5k_imma_kernel<NG>(new, aftermv_kernelinsrc/ds4/ds4_iq.cu): a block of 4 warps over 16 rows x 8 activations (NG = 2 for 9-16):mma.m16n8k32.s8a 32-value sub-block gives the exact int32 dots;mv_ncdispatches to it for Q5_K when every job has >= N activations, 16-byte-aligned rows and 8-byte-aligned activations, on sm_80+ and not HIP (aSTRATA_USE_HIPbuild keeps the dp4a kernel; NVIDIA's path is unchanged with the setting off).Setting:
MAYA_DS4_Q5K_IMMA=N(the engine readsSTRATA_DS4_Q5K_IMMA, thenDS4_Q5K_IMMA), off by default: unset or 0 = today's kernel. A start line says when it is on. A section and row indocs/SETTINGS.md. At one activation the tensor-core kernel is slower, so it is a threshold, not a replacement;2is the value measured below.Output: unchanged (bit-identical). The integer dots are exact in any order (k is permuted the same way in A and B). Each output's F32 work is
mv_kernel's, operation for operation:sub_dot<kQ5_K>'s__fmul_rn(d, (float)(sc * dot)) - (m * sl + m * sh)per (row, column, sub-block);fmaf(xd, v, acc)into lane kb % 32's running sum in kb order;warp_sum's xor tree over the 32 sums;alpha * v + bias. Warp q keeps the running sums of the super-blocks with sb % 4 == q in registers, and the tree reads all 32 from shared memory.ds4_gguf_test --imma(also in the full suite) compares it with the dp4a kernel at every activation count 1-16 on three shapes, memcmp-equal: Q5_K 136 x 768 (rows past a tile, < 32 sub-blocks), 61 x 1280 (several lane rounds, a partial tile), 40 x 5120 with bias and alpha 0.5.Measured. 2x NVIDIA CMP 170HX 64 GB (GA100, sm_80, CUDA 12.8; card 0 PCIe Gen2 x16, card 1 Gen2 x4: a mining card, platform-specific), 16-vCPU Xeon E5-2697 v4 VM. DeepSeek-V4.1-Flash-1017 GSQ-RCO IQ2_XXS, layer split CUDA0 [0,20) / CUDA1 [20,40) + head,
--tp 1 --gpus 0,1 --dspark on --cpu-threads 14 --suffix-draft 0.The
maya-ds4CLI on this branch, 2000 fixed prompt ids + 256 greedy tokens, one binary, one run each (a quick check):DS4_Q5K_IMMA=2Per call,
ds4_gguf_test --bench-cols, CUDA0, µs, dp4a / tensor cores. On this branch: wq_b 32768 x 1280 at 1 / 2 / 4 / 8 columns 77.3 / 90.6, 113.8 / 120.9, 183.7 / 122.3, 325.9 / 114.5; wo_b 5120 x 8192 at 2 / 8: 79.7 / 75.5, 265.2 / 77.0; head 129280 x 5120 at 2 / 8: 1158.6 / 760.4, 3511.9 / 783.7. So at 2 columns wq_b is still slower on the tensor cores and the other shapes are faster. The full sweep, on our v1.1.30-based fork (back to back on one GPU; absolute values drift between runs, the ratios hold):Through the server on that fork (5 prompts x 512 tokens, temperature 0, thinking off; ms a verify window from the engine's timer; its other patches the same in every arm): off 41.96 ms, 46.32 tok/s;
=339.24 ms (-6.5 %);=238.77 ms (-7.6 %), 50.14 tok/s; the same text hashes.--dspark none(every step one column): 24.46 vs 24.40 ms a step, unchanged.Hardware classes. sm_80 (2x CMP 170HX): measured above. Other sm_80+ (A100, RTX 30 / 40, Hopper): not measured; the one-column loss and the break-even count depend on the GPU's dp4a : int8-mma ratio, so it stays off until measured on e.g. a consumer sm_86 / sm_89 card. HIP and < sm_80: not compiled in.
Limits. At 1 column the tensor-core kernel loses (fixed cost ~70 µs vs 60 on wq_b). At 8 columns it is still ~5x the weight-read floor (wq_b 100 µs vs ~17), so more rows a block or a pipelined loop could go further. Q5_K only; a Q8_0 twin would follow the same plan. Tested on random data at three shapes plus end-to-end token ids, not tensor by tensor on the live pack.
Checks (as
.github/workflows/tests.yml):tools/check_hip_compat.pyOK; server tests 463 OK (12 skipped); installer and tools tests 584 OK (31 skipped) - the same counts as v1.1.35.🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.