[PR #643] [CLOSED] DeepSeek on gfx1151: the prompt's routed experts through the fused int8 experts (prefill +9-10% on Strix Halo) #646

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

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/643
Author: @mrsirg97-rgb
Created: 10/28/2026
Status: ❌ Closed

Base: main ← Head: ds4-expert-pipeline


📝 Commits (1)

  • 9d1a34c DeepSeek on gfx1151: the prompt's routed experts through GLM's fused int8 experts

📊 Changes

10 files changed (+540 additions, -40 deletions)

View changed files

📝 CMakeLists.txt (+4 -0)
📝 docs/SETTINGS.md (+1 -0)
📝 include/strata/prefill/moe_fused_rdna4.hpp (+10 -0)
📝 src/ds4/ds4_iq.cu (+122 -0)
📝 src/ds4/ds4_iq.cuh (+12 -0)
📝 src/ds4/ds4_model.cu (+1 -0)
📝 src/prefill/moe_fused_rdna4.cu (+122 -28)
📝 tests/ds4_gguf_test.cu (+75 -0)
➕ tests/hip/prefill_fused_bench.cpp (+130 -0)
📝 tests/hip/prefill_fused_parity.cpp (+63 -12)

📄 Description

On gfx1151 (Strix / Gorgon Halo), maya-ds4's prompt now runs its routed experts through GLM's fused int8 prompt experts (moe_fused_rdna4.cu, MAYA_GLM_PREFILL_FUSED's kernels), ported to DeepSeek-V4.1's shape. This is about +9–10% prompt reading on a Radeon 8060S, with perplexity essentially unchanged.

Why. DeepSeek's prompt experts run set_tc_kernel: FP16 rocWMMA tiles that dequantize each 32-value K chunk into shared memory. On this APU that kernel reaches 12–16 TFLOP/s, and the experts are ~38% of a prompt's GPU time. GLM's fused kernel (int8 decode in the WMMA tiles, int8 activations) reaches 18–21 TOPS at DeepSeek's shape. Bit-identical attempts on set_tc_kernel itself (larger K steps per barrier, register prefetch of the next chunk) were mixed or slower, because the kernel is occupancy-bound. So this PR reuses the faster kernel instead.

Changes

  • moe_fused_rdna4.cu / .hpp
    • Shape: the model's shape is now a template parameter: GLM's 4096 / 2048 (instantiation and arithmetic unchanged; hip_prefill_fused_bench's output hash is identical) and DeepSeek's 5120 / 2304.
    • New formats:
      • IQ1_M for gate/up and down. It uses the int8 codes 8 g ± 1 from DeepSeek's own iq1_decode, from the nibble-packed iq1s_grid_gpu (8 KB in LDS, like IQ2_S's grid), with scales per 16 values.
      • IQ2_XXS and IQ2_XS downs.
    • Split passes: experts_gate_up / experts_down run separately; experts() still runs both. Rows can be gathered and rounded in their own order (quantize_rows, no src), and H can be written at a caller's row stride (Geometry::h_ld).
  • ds4_iq.cu: fused_wanted, fused_gate_up, fused_down
    • Which sets: a prompt set takes the fused path where it covers both of a layer's expert formats, before the opt-in MMQ path. Both passes of a set make the same decision.
    • No new VRAM: the int8 activation rows go into the set's down output (c.y, unused until the down writes it), passed through a FusedScratchScope from run_set next to MmqRowsScope. H goes into the set's FP16 rows at their stride. Only a small tile list is allocated per device.
    • Switch: MAYA_DS4_PREFILL_FUSED. Unset means on for gfx1151; 0 turns it off; 1 turns it on for gfx1100 and RDNA4 as well, which I haven't measured.
  • Tests and benches
    • hip_prefill_fused_parity:
      • Runs both shapes and all 49 type pairs at two clamp limits: 196 runs.
      • Checks that the split passes reproduce the combined ones bit for bit.
      • MMQ doesn't cover IQ1_M, so its pairs are bounded at 1.5× the largest MMQ error of the covered pairs, which use the same int8 activations.
      • The fixture now writes IQ1_M's FP16 scale into its scale words.
    • ds4_gguf_test --bench-set [rows]: times the FP16 tiles' IQ1_M / IQ2_XXS / IQ2_XS sets, with an output hash.
    • hip_prefill_fused_bench [tokens] [reps] [gu] [down] [ds4]: the bench from #634, plus a DeepSeek mode.

Measured. Radeon 8060S (Ryzen AI MAX+ 395, 128 GB with 108 GB GTT, ROCm 7.15). The GSQ-RCO IQ2_XXS GGUF of DeepSeek-V4.1-Flash-1017 (IQ1_M / IQ2_XXS / IQ2_XS experts; 11,705 of 15,744 in VRAM, the rest streamed from the SSD), 512K context, v1.1.36.

./maya.sh --bench with the same binary and the switch off / on, two runs each, alternating:

off (FP16 tiles) on (fused int8)
prefill, 2K tokens 234 / 234 tok/s 257 / 257 (+10%)
prefill, 8K tokens 432 / 429 tok/s 466 / 471 (+9%)
decode 25.5 / 27.6 27.0 / 27.9 (no decode path sets the scope; run-to-run noise)
  • Experts' GPU time, ~9.5K-token prompt (DS4_PROF): 8.95 → 7.35 s. The rest of the expert stage is the streamed experts' arrival, which the GPU's pace sets at ~1.4 GB/s from the SSD.
  • Perplexity (maya-ds4 --ppl, 8 sequences from Maya's docs, 7,699 tokens): 8.4907 off (identical on two runs) vs 8.4937 on (+0.035%). Per sequence the difference is ±1% in both directions.
  • Per expert row:
    • fused at DeepSeek's shape, 9.5K tokens: 3.8–4.0 µs
    • FP16 tiles (--bench-set, 128 rows per expert): 4.9–5.5 µs
  • Checks: hip_prefill_fused_parity PASS (196 runs, the split passes bit for bit), ds4_gguf_test ALL OK, tools/check_hip_compat.py passes.
  • Not measured: gfx1100, RDNA4, Windows, other DeepSeek quants (Maya-S / XS use other formats, and those keep the existing path unless covered), and NVIDIA (the path is HIP only and NVIDIA is unchanged).

With #634.

  • The conflict: #634 sets 3 blocks per multiprocessor for every pair on gfx1151, measured on GLM's shape. At DeepSeek's shape, 3 slows IQ1_M: 223 → 281 ms at 9.5K tokens, and prompts 497 → 477 tok/s.
  • Here: DeepSeek's shape keeps today's factors, with a comment at the grid sizing.
  • Rebase rule: whichever PR merges second should apply #634's factor only to GLM's shape.
  • Shared bench file: both PRs add tests/hip/prefill_fused_bench.cpp; this version is #634's plus the ds4 mode.

🔄 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/643 **Author:** [@mrsirg97-rgb](https://github.com/mrsirg97-rgb) **Created:** 10/28/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `ds4-expert-pipeline` --- ### 📝 Commits (1) - [`9d1a34c`](https://github.com/mw00/project-maya/commit/9d1a34ce5e8ea359cefc703a073d05f7dad6aeca) DeepSeek on gfx1151: the prompt's routed experts through GLM's fused int8 experts ### 📊 Changes **10 files changed** (+540 additions, -40 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+4 -0) 📝 `docs/SETTINGS.md` (+1 -0) 📝 `include/strata/prefill/moe_fused_rdna4.hpp` (+10 -0) 📝 `src/ds4/ds4_iq.cu` (+122 -0) 📝 `src/ds4/ds4_iq.cuh` (+12 -0) 📝 `src/ds4/ds4_model.cu` (+1 -0) 📝 `src/prefill/moe_fused_rdna4.cu` (+122 -28) 📝 `tests/ds4_gguf_test.cu` (+75 -0) ➕ `tests/hip/prefill_fused_bench.cpp` (+130 -0) 📝 `tests/hip/prefill_fused_parity.cpp` (+63 -12) </details> ### 📄 Description On gfx1151 (Strix / Gorgon Halo), maya-ds4's prompt now runs its routed experts through GLM's fused int8 prompt experts (`moe_fused_rdna4.cu`, `MAYA_GLM_PREFILL_FUSED`'s kernels), ported to DeepSeek-V4.1's shape. This is about **+9–10% prompt reading** on a Radeon 8060S, with perplexity essentially unchanged. **Why.** DeepSeek's prompt experts run `set_tc_kernel`: FP16 rocWMMA tiles that dequantize each 32-value K chunk into shared memory. On this APU that kernel reaches 12–16 TFLOP/s, and the experts are ~38% of a prompt's GPU time. GLM's fused kernel (int8 decode in the WMMA tiles, int8 activations) reaches 18–21 TOPS at DeepSeek's shape. Bit-identical attempts on `set_tc_kernel` itself (larger K steps per barrier, register prefetch of the next chunk) were mixed or slower, because the kernel is occupancy-bound. So this PR reuses the faster kernel instead. **Changes** - **`moe_fused_rdna4.cu` / `.hpp`** - **Shape:** the model's shape is now a template parameter: GLM's 4096 / 2048 (instantiation and arithmetic unchanged; `hip_prefill_fused_bench`'s output hash is identical) and DeepSeek's 5120 / 2304. - **New formats:** - IQ1_M for gate/up and down. It uses the int8 codes `8 g ± 1` from DeepSeek's own `iq1_decode`, from the nibble-packed `iq1s_grid_gpu` (8 KB in LDS, like IQ2_S's grid), with scales per 16 values. - IQ2_XXS and IQ2_XS downs. - **Split passes:** `experts_gate_up` / `experts_down` run separately; `experts()` still runs both. Rows can be gathered and rounded in their own order (`quantize_rows`, no `src`), and H can be written at a caller's row stride (`Geometry::h_ld`). - **`ds4_iq.cu`: `fused_wanted`, `fused_gate_up`, `fused_down`** - **Which sets:** a prompt set takes the fused path where it covers both of a layer's expert formats, before the opt-in MMQ path. Both passes of a set make the same decision. - **No new VRAM:** the int8 activation rows go into the set's down output (`c.y`, unused until the down writes it), passed through a `FusedScratchScope` from `run_set` next to `MmqRowsScope`. H goes into the set's FP16 rows at their stride. Only a small tile list is allocated per device. - **Switch:** `MAYA_DS4_PREFILL_FUSED`. Unset means on for gfx1151; `0` turns it off; `1` turns it on for gfx1100 and RDNA4 as well, which I haven't measured. - **Tests and benches** - **`hip_prefill_fused_parity`:** - Runs both shapes and all 49 type pairs at two clamp limits: 196 runs. - Checks that the split passes reproduce the combined ones bit for bit. - MMQ doesn't cover IQ1_M, so its pairs are bounded at 1.5× the largest MMQ error of the covered pairs, which use the same int8 activations. - The fixture now writes IQ1_M's FP16 scale into its scale words. - **`ds4_gguf_test --bench-set [rows]`:** times the FP16 tiles' IQ1_M / IQ2_XXS / IQ2_XS sets, with an output hash. - **`hip_prefill_fused_bench [tokens] [reps] [gu] [down] [ds4]`:** the bench from #634, plus a DeepSeek mode. **Measured.** Radeon 8060S (Ryzen AI MAX+ 395, 128 GB with 108 GB GTT, ROCm 7.15). The GSQ-RCO IQ2_XXS GGUF of DeepSeek-V4.1-Flash-1017 (IQ1_M / IQ2_XXS / IQ2_XS experts; 11,705 of 15,744 in VRAM, the rest streamed from the SSD), 512K context, v1.1.36. `./maya.sh --bench` with the same binary and the switch off / on, two runs each, alternating: | | off (FP16 tiles) | on (fused int8) | | --- | --- | --- | | prefill, 2K tokens | 234 / 234 tok/s | **257 / 257** (+10%) | | prefill, 8K tokens | 432 / 429 tok/s | **466 / 471** (+9%) | | decode | 25.5 / 27.6 | 27.0 / 27.9 (no decode path sets the scope; run-to-run noise) | - **Experts' GPU time, ~9.5K-token prompt** (`DS4_PROF`): 8.95 → 7.35 s. The rest of the expert stage is the streamed experts' arrival, which the GPU's pace sets at ~1.4 GB/s from the SSD. - **Perplexity** (`maya-ds4 --ppl`, 8 sequences from Maya's docs, 7,699 tokens): 8.4907 off (identical on two runs) vs 8.4937 on (+0.035%). Per sequence the difference is ±1% in both directions. - **Per expert row:** - fused at DeepSeek's shape, 9.5K tokens: 3.8–4.0 µs - FP16 tiles (`--bench-set`, 128 rows per expert): 4.9–5.5 µs - **Checks:** `hip_prefill_fused_parity` PASS (196 runs, the split passes bit for bit), `ds4_gguf_test` ALL OK, `tools/check_hip_compat.py` passes. - **Not measured:** gfx1100, RDNA4, Windows, other DeepSeek quants (Maya-S / XS use other formats, and those keep the existing path unless covered), and NVIDIA (the path is HIP only and NVIDIA is unchanged). **With #634.** - **The conflict:** #634 sets 3 blocks per multiprocessor for every pair on gfx1151, measured on GLM's shape. At DeepSeek's shape, 3 slows IQ1_M: 223 → 281 ms at 9.5K tokens, and prompts 497 → 477 tok/s. - **Here:** DeepSeek's shape keeps today's factors, with a comment at the grid sizing. - **Rebase rule:** whichever PR merges second should apply #634's factor only to GLM's shape. - **Shared bench file:** both PRs add `tests/hip/prefill_fused_bench.cpp`; this version is #634's plus the `ds4` mode. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:27:49 +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#646
No description provided.