[PR #5146] [Engine] DFlash2: opt-in Q4_0 GEMM variant table for gfx103x (STRATA_DF2_Q4_RDNA2=1) #5325

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5146
Author: @Vop3p
Created: 11/3/2026
Status: 🔄 Open

Base: main ← Head: df2-rdna2-q4-table


📝 Commits (1)

  • 3e15a40 dflash2: STRATA_DF2_Q4_RDNA2=1 (opt-in, gfx103x): the Q4_0 GEMM variant by rows from dflash2_gemm_bench on 2x RX 6900 XT (21 / 38 / 20, 20-21% less GEMM time a round, bitwise the same)

📊 Changes

1 file changed (+11 additions, -0 deletions)

View changed files

📝 src/kernels/cuda/dflash2.cu (+11 -0)

📄 Description

Problem and result

df2_q4_auto picks variant 17 (tuned on sm_120) for every card except gfx12. On RDNA2 (gfx1030, RX 6900 XT) 17 is not the fastest variant for most of the drafter's matrices. dflash2_gemm_bench 50 q4 finds bitwise-identical variants that cut the round's Q4_0 GEMM time by about 20%:

matrix (rows) variant 17 table variant
gate+up (15360) 90.0 us 63.1 us 21
qkv (6144) 48.3 31.7 21
down (2560) 51.2 45.9 38
o (2560) 38.3 32.4 38
fc (2560) 76.7 77.0 38
kv (2048) 19.7 12.2 20
akp (640) 11.8 6.3 20
sel (256) 11.7 5.9 20
sum 347.7 274.5 (-21.1%)

That is card 0 of the PR build. Card 1 (a different board, same chip) gives 346.9 -> 278.1 us (-19.8%). All 304 variant/matrix entries are bitwise on both cards.

With STRATA_DF2_Q4_RDNA2=1, the table picks by rows: >= 6144 -> 21, >= 2560 -> 38, else 20. Without the variable, nothing changes: the lambda returns false and the function still returns 17. CUDA, gfx12 and every other HIP target are unaffected; the block sits inside the existing #if defined(STRATA_USE_HIP) and checks gcnArchName for gfx103.

End to end, the gain is small. On one RX 6900 XT running the whole model (DFlash2 alone, --spec 6 --draft-conf 0.5), the draft step per window fell from 6.17 / 6.16 ms to 5.86 / 5.87 ms (-4.9%), in two interleaved pairs off/on/on/off. That is about 0.3 ms of a ~46 ms window, so the expected decode gain is ~0.7%. Measured tok/ms moved +1.7%, but most of that came from tokens per window differing between sampled runs, and the table cannot change acceptance (its results are bitwise the same), so I do not claim it.

A data point that may be more useful than the patch: DFlash2 runs on gfx1030 (no upstream report so far), passes the standard protocol's 12/12 sanity checks, and on one card it beats the MTP drafter. Over the whole standard-protocol run (engine STRATA_DECODE_TIMING, all decode tokens weighted):

  • DFlash2, 6 arms (conf 0.5/0.65/0.8 × 2): 0.0488-0.0496 tok/ms
  • MTP, 4 arms (spec 3/0.7 and 4/0.5 × 2): 0.0465-0.0480 tok/ms
  • conf 0.5 is best: +4.4% over MTP spec 4/0.5. DFlash2 accepts more per window (2.27 vs 2.13 tokens) and leaves 2.7% more expert slots (4,846 vs 4,718).

The standard protocol's own n=3 decode medians swing ±6-12% between rounds (sampling + thinking), so they cannot resolve a 3-5% difference; the tok/ms ranges above do not overlap. This roughly matches the 3-6% in drafting.py for ~4,700 slots. On a two-card layer split the same drafter loses (-10 to -14% tok/ms against MTP + pipelined windows), because DFlash2 turns --pipeline-windows off; that is as documented, and the table does not change it.

none (opt-in, per-architecture, bitwise-identical kernel choice, like the gfx12 line above it)

Approach

The patch adds one opt-in branch next to the existing gfx12 branch in df2_q4_auto. It is opt-in rather than a gfx103x default for two reasons: it was measured on one chip only (two boards of the RX 6900 XT), and the end-to-end effect is below 1%. If you would rather make it the gfx103x default, the env check can go away; the result is bitwise the same either way.

Validation

Environment: 2x RX 6900 XT (gfx1030, 80 CUs, 16 GB, PCIe 4.0 x8 each, cards at 245 W / -81 mV), Ryzen 5 5600X, 128 GB DDR4-3200, Ubuntu 26.04, kernel 7.0.0-42, ROCm 10.0 (/opt/rocm/core-10.0 clang, runtime /opt/rocm/lib).

Passed:

  • Build: this branch (main ffa80d73 + one commit), -DSTRATA_ENABLE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=gfx1030 -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_PREFILL_MMQ=ON -DSTRATA_Q6K_EXPERTS=ON -DGGML_HIP_GRAPHS=ON -DGGML_HIP_NO_VMM=ON -DSTRATA_BUILD_TESTS=ON: builds clean, including the targets dflash2_parity, dflash2_q4_parity and dflash2_gemm_bench.
  • dflash2_q4_parity, run on both cards with STRATA_DF2_Q4_RDNA2 set to 0 and to 1: exit 0 all four times, 160 "ok" lines, 0 failures.
  • dflash2_gemm_bench 50 q4 on both cards: the table above; 0 non-bitwise entries out of 304 per card.
  • notes/tools/kernel_resources.sh (our script, which reads the code object) on the three selected variants: VGPR <= 96, 0 spills, 0 LDS.
  • ctest -j 1 (193 tests): 189 pass or skip, 4 fail. ple_parity, conversation_copy_streams_test and isa_guard_check fail the same way on our v0.2.10 tree without this change. hip_prefill_mmq_parity dies with SIGFPE (exit 136) on this build, and it also dies with this commit's dflash2.cu swapped back to main's and that target rebuilt, so this change does not cause it. Our production tree builds with STRATA_GGML_DIR set to a llama.cpp fb5d45967 checkout and passes there; this branch uses the default ggml. I have not looked further.
  • Whole model, one card: the same patch on our v0.2.10 production tree (prod tree + this commit, IQ3_S), strata.py bench run --track custom --optional-concurrency. Runs: four arms in one window (off/on/on/off), plus the five-arm × 2 drafter comparison above. Every arm 12/12, 0 stalls.

Failed:

  • none caused by this change (see the ctest line above for the four failures that are already there)

Not run:

  • 10+ cold-start interleaved pairs: we have 2 off/on pairs for the table (4 arms) and 2 rounds per drafter setting. That is enough for the draft-step time, which has a tight spread (5.83-5.87 on, 6.16-6.17 off), but not for decode tok/s at the sub-1% level.
  • Other gfx103x chips (gfx1031/1032/1034/1035/1036), and a second independent machine.
  • CUDA / SYCL / Metal builds: the change is inside #if defined(STRATA_USE_HIP), so no code reaches them, but I did not build them.
  • Greedy byte-identity runs end to end. The kernels are bitwise identical in the bench, so the engine should not change any text; that was not checked on the whole model.

Limits

Measured on one chip only. The end-to-end gain is under 1% because the Q4_0 GEMMs are only part of the draft step: a STRATA_DF2_PROFILE=1 run on the two-card setup put them at 1.88 ms a round, with the head at 0.58 ms and attention at 0.40 ms. The rest of the step is unchanged. Remaining work on the drafter for this card, if anyone wants it, is outside the GEMM: the draft head and the attention.


Developed with an AI coding assistant; every number above was measured on the machine described in Validation.

🤖 Generated with Claude Code


🔄 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/5146 **Author:** [@Vop3p](https://github.com/Vop3p) **Created:** 11/3/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `df2-rdna2-q4-table` --- ### 📝 Commits (1) - [`3e15a40`](https://github.com/Niko1221/Strata/commit/3e15a40b89039e82659de069072b81669cc7380d) dflash2: STRATA_DF2_Q4_RDNA2=1 (opt-in, gfx103x): the Q4_0 GEMM variant by rows from dflash2_gemm_bench on 2x RX 6900 XT (21 / 38 / 20, 20-21% less GEMM time a round, bitwise the same) ### 📊 Changes **1 file changed** (+11 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `src/kernels/cuda/dflash2.cu` (+11 -0) </details> ### 📄 Description ## Problem and result `df2_q4_auto` picks variant 17 (tuned on sm_120) for every card except gfx12. On RDNA2 (gfx1030, RX 6900 XT) 17 is not the fastest variant for most of the drafter's matrices. `dflash2_gemm_bench 50 q4` finds bitwise-identical variants that cut the round's Q4_0 GEMM time by about 20%: | matrix (rows) | variant 17 | table | variant | |---|---|---|---| | gate+up (15360) | 90.0 us | 63.1 us | 21 | | qkv (6144) | 48.3 | 31.7 | 21 | | down (2560) | 51.2 | 45.9 | 38 | | o (2560) | 38.3 | 32.4 | 38 | | fc (2560) | 76.7 | 77.0 | 38 | | kv (2048) | 19.7 | 12.2 | 20 | | akp (640) | 11.8 | 6.3 | 20 | | sel (256) | 11.7 | 5.9 | 20 | | **sum** | **347.7** | **274.5 (-21.1%)** | | That is card 0 of the PR build. Card 1 (a different board, same chip) gives 346.9 -> 278.1 us (-19.8%). All 304 variant/matrix entries are `bitwise` on both cards. With `STRATA_DF2_Q4_RDNA2=1`, the table picks by rows: >= 6144 -> 21, >= 2560 -> 38, else 20. Without the variable, nothing changes: the lambda returns false and the function still returns 17. CUDA, gfx12 and every other HIP target are unaffected; the block sits inside the existing `#if defined(STRATA_USE_HIP)` and checks `gcnArchName` for `gfx103`. End to end, the gain is small. On one RX 6900 XT running the whole model (DFlash2 alone, `--spec 6 --draft-conf 0.5`), the draft step per window fell from 6.17 / 6.16 ms to 5.86 / 5.87 ms (-4.9%), in two interleaved pairs off/on/on/off. That is about 0.3 ms of a ~46 ms window, so the expected decode gain is ~0.7%. Measured tok/ms moved +1.7%, but most of that came from tokens per window differing between sampled runs, and the table cannot change acceptance (its results are bitwise the same), so I do not claim it. A data point that may be more useful than the patch: **DFlash2 runs on gfx1030** (no upstream report so far), passes the standard protocol's 12/12 sanity checks, and on one card it beats the MTP drafter. Over the whole standard-protocol run (engine `STRATA_DECODE_TIMING`, all decode tokens weighted): - DFlash2, 6 arms (conf 0.5/0.65/0.8 × 2): 0.0488-0.0496 tok/ms - MTP, 4 arms (spec 3/0.7 and 4/0.5 × 2): 0.0465-0.0480 tok/ms - conf 0.5 is best: +4.4% over MTP spec 4/0.5. DFlash2 accepts more per window (2.27 vs 2.13 tokens) and leaves 2.7% more expert slots (4,846 vs 4,718). The standard protocol's own n=3 decode medians swing ±6-12% between rounds (sampling + thinking), so they cannot resolve a 3-5% difference; the tok/ms ranges above do not overlap. This roughly matches the 3-6% in `drafting.py` for ~4,700 slots. On a two-card layer split the same drafter loses (-10 to -14% tok/ms against MTP + pipelined windows), because DFlash2 turns `--pipeline-windows` off; that is as documented, and the table does not change it. ## Related discussion none (opt-in, per-architecture, bitwise-identical kernel choice, like the gfx12 line above it) ## Approach The patch adds one opt-in branch next to the existing gfx12 branch in `df2_q4_auto`. It is opt-in rather than a gfx103x default for two reasons: it was measured on one chip only (two boards of the RX 6900 XT), and the end-to-end effect is below 1%. If you would rather make it the gfx103x default, the env check can go away; the result is bitwise the same either way. ## Validation Environment: 2x RX 6900 XT (gfx1030, 80 CUs, 16 GB, PCIe 4.0 x8 each, cards at 245 W / -81 mV), Ryzen 5 5600X, 128 GB DDR4-3200, Ubuntu 26.04, kernel 7.0.0-42, ROCm 10.0 (`/opt/rocm/core-10.0` clang, runtime `/opt/rocm/lib`). **Passed:** - Build: this branch (main ffa80d73 + one commit), `-DSTRATA_ENABLE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=gfx1030 -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_PREFILL_MMQ=ON -DSTRATA_Q6K_EXPERTS=ON -DGGML_HIP_GRAPHS=ON -DGGML_HIP_NO_VMM=ON -DSTRATA_BUILD_TESTS=ON`: builds clean, including the targets `dflash2_parity`, `dflash2_q4_parity` and `dflash2_gemm_bench`. - `dflash2_q4_parity`, run on both cards with `STRATA_DF2_Q4_RDNA2` set to 0 and to 1: exit 0 all four times, 160 "ok" lines, 0 failures. - `dflash2_gemm_bench 50 q4` on both cards: the table above; 0 non-bitwise entries out of 304 per card. - `notes/tools/kernel_resources.sh` (our script, which reads the code object) on the three selected variants: VGPR <= 96, 0 spills, 0 LDS. - `ctest -j 1` (193 tests): 189 pass or skip, 4 fail. `ple_parity`, `conversation_copy_streams_test` and `isa_guard_check` fail the same way on our v0.2.10 tree without this change. `hip_prefill_mmq_parity` dies with SIGFPE (exit 136) on this build, and it also dies with this commit's `dflash2.cu` swapped back to main's and that target rebuilt, so this change does not cause it. Our production tree builds with `STRATA_GGML_DIR` set to a llama.cpp fb5d45967 checkout and passes there; this branch uses the default ggml. I have not looked further. - Whole model, one card: the same patch on our v0.2.10 production tree (prod tree + this commit, IQ3_S), `strata.py bench run --track custom --optional-concurrency`. Runs: four arms in one window (off/on/on/off), plus the five-arm × 2 drafter comparison above. Every arm 12/12, 0 stalls. **Failed:** - none caused by this change (see the ctest line above for the four failures that are already there) **Not run:** - 10+ cold-start interleaved pairs: we have 2 off/on pairs for the table (4 arms) and 2 rounds per drafter setting. That is enough for the draft-step time, which has a tight spread (5.83-5.87 on, 6.16-6.17 off), but not for decode tok/s at the sub-1% level. - Other gfx103x chips (gfx1031/1032/1034/1035/1036), and a second independent machine. - CUDA / SYCL / Metal builds: the change is inside `#if defined(STRATA_USE_HIP)`, so no code reaches them, but I did not build them. - Greedy byte-identity runs end to end. The kernels are bitwise identical in the bench, so the engine should not change any text; that was not checked on the whole model. ## Limits Measured on one chip only. The end-to-end gain is under 1% because the Q4_0 GEMMs are only part of the draft step: a `STRATA_DF2_PROFILE=1` run on the two-card setup put them at 1.88 ms a round, with the head at 0.58 ms and attention at 0.40 ms. The rest of the step is unchanged. Remaining work on the drafter for this card, if anyone wants it, is outside the GEMM: the draft head and the attention. --- Developed with an AI coding assistant; every number above was measured on the machine described in Validation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <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#5325
No description provided.