[PR #353] [CLOSED] DeepSeek: hipBLASLt solution table for dense prompt GEMMs (AMD, opt-in) #482

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

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/353
Author: @boxwrench
Created: 10/21/2026
Status: ❌ Closed

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


📝 Commits (1)

  • 68ae860 DeepSeek: hipBLASLt solution table for dense prompt GEMMs (AMD, opt-in)

📊 Changes

4 files changed (+264 additions, -0 deletions)

View changed files

📝 CMakeLists.txt (+5 -0)
📝 README.md (+5 -0)
📝 docs/SETTINGS.md (+17 -0)
📝 src/ds4/ds4_model.cu (+237 -0)

📄 Description

DeepSeek: hipBLASLt solution table for dense prompt GEMMs (AMD, opt-in)

What it does

DeepSeek-V4.1-Flash's prompt path reconstructs its dense weights to FP16 and multiplies them with the vendor BLAS
(cublasGemmEx; hipBLAS on AMD). On a HIP build with hipBLASLt, MAYA_DS4_DENSE_LT=1 now asks hipBLASLt for up to
eight heuristic candidates, times each candidate on the real shape and stride the engine is about to use, and keeps
the fastest in a process-local table. Later calls with the same (device, N, K, rows, ldx, ldy, pointer alignment)
reuse it.

The switch is off by default and opt-in. Unset or any value other than 1 keeps the existing call. The gfx1151
numbers below are large enough to consider an architecture-scoped default later, but this PR keeps opt-in: one
machine/ROCm build on this branch and the first-use cost are not enough to change an existing user's path. It only applies
to prompt dense GEMMs with beta == 0 and at least 32 rows; decode shapes and the routed experts are untouched. The
table is built on first use and is included in that prompt's time (a few seconds on a long prompt). The NVIDIA path is
unchanged: the HIP-specific code and the call sites are inside #if defined(STRATA_USE_HIP) && defined(STRATA_HIPBLASLT_AVAILABLE),
and the CUDA build preprocesses ds4_model.cu to the same output as before this change. AMD builds without hipBLASLt
also keep the old path.

The CMake change links roc::hipblaslt and defines STRATA_HIPBLASLT_AVAILABLE=1 for maya-ds4 only when the
hipBLASLt package was found, so a HIP build on a machine without it still configures and builds.

The handle and workspace are per (device, stream), and calls that share them are serialized on the host and
submitted to that stream, so one state is never used by two devices or streams at once. Every setup and timing call
(descriptor, layout, preference, heuristic query, events, allocation, matmul) is checked; a failed candidate is not
published, a failed setup/timing is not cached, and the call returns to the existing BLAS call with one log line. A
forced hipBLASLt failure test (every hipblasLtMatmul returning an error) completed the 8K arm with exit 0, the
fallback line, and the same 128 token IDs.

Hardware

  • Strix Halo (Ryzen AI Max+ 395, Radeon 8060S, 128 GB), gfx1151, Linux.
  • ROCm 7.2.2, hipBLASLt as shipped with it, clang 22.
  • DeepSeek-V4.1-Flash-1017 Maya-S Q8 dense pack (IQ2/IQ3 experts), 40 layers on one GPU, 12,288 MiB reserve.
  • Greedy (temperature 0), --dspark none, prompt skip on (v1.1.20 default), 128 output tokens. The engine was
    driven with raw token IDs, so the server's chat template and its thinking-off switch do not apply; no thinking
    markers were injected.

Before / after

One process per arm, the switch's first-use table included in every "on" number. The same-config A/A floor is two
"off" runs.

context off on gain A/A floor
2,048-token prefill 20.134 s (101.72 tok/s) 18.014 s (113.69 tok/s) +11.8 % 1.03 %
8,192-token prefill 49.336 s (166.06 tok/s) 44.065 s (185.94 tok/s) +12.0 % 1.64 %
32,768-token prefill 160.011 s (204.80 tok/s) 140.460 s (233.29 tok/s) +13.9 % 1.39 %

The two off runs and the on run at 2K are 20.030 / 20.237 and 18.014 s; at 8K the recheck's two off and two on runs are
49.739 / 48.932 and 44.684 / 43.446 s; at 32K 158.901 / 161.121 and 140.460 s. Each "off" time in the table is the mean
of the two off runs; throughput is the mean of their reported rates, and each 8K "on" time is the mean of its two runs.
The 8K gain is 7.3x its 1.64 % off/off floor (the two 8K on runs span 2.8 %). The 2K and 32K rows are the earlier
measurement on the same branch before the ownership/error-handling fix; the 8K row was re-run on the fixed build.
Median clocks over the timed prompt windows moved by at most 3.6 % between arms (below the 5 % comparison threshold),
and the minimum MemAvailable was 19.88 GiB at 32K (21.39 GiB at 2K, 20.81 GiB at 8K), above the 16 GiB guard.

The engine's prompt stage split moves where the change should: at 8K, attention (which includes the dense
projections) falls 21.2 / 21.2 s -> 15.5 / 14.8 s, while routed experts stay within 3 % (22.8 / 22.2 -> 22.5 / 22.0 s)
and routing + shared moves up 4.9 / 4.8 -> 6.2 / 6.1 s. At 32K, attention falls 72.9 / 74.1 -> 49.5 s, experts 67.6 / 68.5 -> 68.1 s, and
routing + shared 16.2 / 16.5 -> 19.7 s. These stage totals are consistent with the intended reduction in dense GEMM time.

Output identity

128-token greedy identity, comparing the printed token IDs of the off and on runs:

  • 8K: 128/128 identical, across two off and two on runs after the fix, and the forced-failure fallback run.
  • 32K: 128/128 identical, including the off/off A/A pair.
  • 2K: not resolvable. The two off runs already differ at 82 of 128 printed positions (first at token 46), so the
    engine's 2K free-running decode is not deterministic between processes on this box. The on run differs from the
    first off run at 76 positions, inside that run-to-run spread; this is not evidence for or against the switch.

The switch can change the last bits of a GEMM (a different candidate's summation order), so the last-bit difference
is expected; the 8K and 32K greedy sequences do not change. This is a greedy identity check, not a task-suite or KL
certificate; see "What was not measured".

How to reproduce

Build (Linux, ROCm with hipBLASLt):

cmake -S . -B build -DSTRATA_ENABLE_HIP=ON -DSTRATA_PREFILL_MMQ=ON -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_HIP_ARCHITECTURES=gfx1151
cmake --build build --target maya-ds4 -j

Run one arm (the prompt IDs are the ones used here; --ids takes a comma-joined list):

MAYA_DS4_DENSE_LT=1 build/maya-ds4 --pack <pack>/maya-ds4 --gpus 0 --max-context 32768 \
  --reserve-mib 12288 --vram-experts 0.92 --dspark none --vision off --mmap-experts auto \
  --expert-profile <profile> --window 32768 --ids <ids> --n 128

Use --max-context 40960 --no-expert-cache and DS4_AHEAD=0 DS4_SPEC_Q=0 for the 32K recipe (the same 12,288 MiB
reserve as above; this Q8 pack used that reserve at every length). The 32K run needs
more IDs than one argument holds on this box, so the measurement used a local --ids-file CLI fixture (the ids-file
hunk of our bench fixture, not part of this PR). The switch logic is the same. The final branch reads the aliased
STRATA_DS4_DENSE_LT rather than MAYA_DS4_DENSE_LT directly (rechecked at 8K: 42.872 s vs 43.395 s on the earlier
build). The final source also adds the per-(device, stream) state and the checked setup/timing path; it was rebuilt on
the Strix Halo machine and the 8K row above plus the forced-failure run were made with that build. The stream query is skipped when the
switch is off, and a failed query falls back.

What was not measured

  • Radeon R9700 / gfx1201: not measured on this branch. A separate v1.1.20 experiment (Q4_K dense fixture,
    first-use selection included) measured dense LT 2.1 % slower at 8K and 2.3 % slower at 32K on gfx1201, so
    this switch should stay off there; the gain above is a gfx1151 result.
  • NVIDIA: only a preprocessor check (the CUDA path is byte-for-byte the same in the preprocessed source); no CUDA
    build or GPU run on this branch.
  • Other AMD packs: only the Q8 dense pack was measured on this branch.
  • Steady state: one request per process, so every "on" run pays the first-use selection. A second request in
    the same process can reuse matching entries; its latency was not measured here.
  • Quality/task suite: no KL or task-suite run on this branch. The greedy comparisons above cover only these
    prompts and generations.
  • Multi-GPU, other ROCm/hipBLASLt versions, Windows: not measured.

Upstream notes

  • The setting is documented as MAYA_DS4_DENSE_LT to match the other DeepSeek settings. The code reads
    STRATA_DS4_DENSE_LT and main()'s env_aliases() maps the MAYA_* name onto it, as for the other settings, so
    both spellings work.
  • The table is process-local and per (device, stream), and is not written to any vendor tuning file. It uses a
    32 MiB workspace cap and frees the temporary output scratch after selection; successful state lives for the
    process.
  • docs/SETTINGS.md has the DeepSeek row; the README's Tuning bullet points to it. CHANGELOG.md and VERSION are
    untouched, as the maintainer writes those.

🔄 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/353 **Author:** [@boxwrench](https://github.com/boxwrench) **Created:** 10/21/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/ds4-dense-lt` --- ### 📝 Commits (1) - [`68ae860`](https://github.com/mw00/project-maya/commit/68ae86015c8cf6c4892d663fe11c87aa499c2243) DeepSeek: hipBLASLt solution table for dense prompt GEMMs (AMD, opt-in) ### 📊 Changes **4 files changed** (+264 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+5 -0) 📝 `README.md` (+5 -0) 📝 `docs/SETTINGS.md` (+17 -0) 📝 `src/ds4/ds4_model.cu` (+237 -0) </details> ### 📄 Description # DeepSeek: hipBLASLt solution table for dense prompt GEMMs (AMD, opt-in) ## What it does DeepSeek-V4.1-Flash's prompt path reconstructs its dense weights to FP16 and multiplies them with the vendor BLAS (`cublasGemmEx`; hipBLAS on AMD). On a HIP build with hipBLASLt, `MAYA_DS4_DENSE_LT=1` now asks hipBLASLt for up to eight heuristic candidates, times each candidate on the real shape and stride the engine is about to use, and keeps the fastest in a process-local table. Later calls with the same `(device, N, K, rows, ldx, ldy, pointer alignment)` reuse it. The switch is off by default and opt-in. Unset or any value other than `1` keeps the existing call. The gfx1151 numbers below are large enough to consider an architecture-scoped default later, but this PR keeps opt-in: one machine/ROCm build on this branch and the first-use cost are not enough to change an existing user's path. It only applies to prompt dense GEMMs with `beta == 0` and at least 32 rows; decode shapes and the routed experts are untouched. The table is built on first use and is included in that prompt's time (a few seconds on a long prompt). The NVIDIA path is unchanged: the HIP-specific code and the call sites are inside `#if defined(STRATA_USE_HIP) && defined(STRATA_HIPBLASLT_AVAILABLE)`, and the CUDA build preprocesses `ds4_model.cu` to the same output as before this change. AMD builds without hipBLASLt also keep the old path. The CMake change links `roc::hipblaslt` and defines `STRATA_HIPBLASLT_AVAILABLE=1` for `maya-ds4` only when the hipBLASLt package was found, so a HIP build on a machine without it still configures and builds. The handle and workspace are per `(device, stream)`, and calls that share them are serialized on the host and submitted to that stream, so one state is never used by two devices or streams at once. Every setup and timing call (descriptor, layout, preference, heuristic query, events, allocation, matmul) is checked; a failed candidate is not published, a failed setup/timing is not cached, and the call returns to the existing BLAS call with one log line. A forced hipBLASLt failure test (every `hipblasLtMatmul` returning an error) completed the 8K arm with exit 0, the fallback line, and the same 128 token IDs. ## Hardware - Strix Halo (Ryzen AI Max+ 395, Radeon 8060S, 128 GB), `gfx1151`, Linux. - ROCm 7.2.2, hipBLASLt as shipped with it, clang 22. - DeepSeek-V4.1-Flash-1017 Maya-S Q8 dense pack (IQ2/IQ3 experts), 40 layers on one GPU, 12,288 MiB reserve. - Greedy (`temperature 0`), `--dspark none`, prompt skip on (v1.1.20 default), 128 output tokens. The engine was driven with raw token IDs, so the server's chat template and its thinking-off switch do not apply; no thinking markers were injected. ## Before / after One process per arm, the switch's first-use table included in every "on" number. The same-config A/A floor is two "off" runs. | context | off | on | gain | A/A floor | |---:|---:|---:|---:|---:| | 2,048-token prefill | 20.134 s (101.72 tok/s) | **18.014 s (113.69 tok/s)** | **+11.8 %** | 1.03 % | | 8,192-token prefill | 49.336 s (166.06 tok/s) | **44.065 s (185.94 tok/s)** | **+12.0 %** | 1.64 % | | 32,768-token prefill | 160.011 s (204.80 tok/s) | **140.460 s (233.29 tok/s)** | **+13.9 %** | 1.39 % | The two off runs and the on run at 2K are 20.030 / 20.237 and 18.014 s; at 8K the recheck's two off and two on runs are 49.739 / 48.932 and 44.684 / 43.446 s; at 32K 158.901 / 161.121 and 140.460 s. Each "off" time in the table is the mean of the two off runs; throughput is the mean of their reported rates, and each 8K "on" time is the mean of its two runs. The 8K gain is 7.3x its 1.64 % off/off floor (the two 8K on runs span 2.8 %). The 2K and 32K rows are the earlier measurement on the same branch before the ownership/error-handling fix; the 8K row was re-run on the fixed build. Median clocks over the timed prompt windows moved by at most 3.6 % between arms (below the 5 % comparison threshold), and the minimum MemAvailable was 19.88 GiB at 32K (21.39 GiB at 2K, 20.81 GiB at 8K), above the 16 GiB guard. The engine's prompt stage split moves where the change should: at 8K, attention (which includes the dense projections) falls 21.2 / 21.2 s -> 15.5 / 14.8 s, while routed experts stay within 3 % (22.8 / 22.2 -> 22.5 / 22.0 s) and routing + shared moves up 4.9 / 4.8 -> 6.2 / 6.1 s. At 32K, attention falls 72.9 / 74.1 -> 49.5 s, experts 67.6 / 68.5 -> 68.1 s, and routing + shared 16.2 / 16.5 -> 19.7 s. These stage totals are consistent with the intended reduction in dense GEMM time. ## Output identity 128-token greedy identity, comparing the printed token IDs of the off and on runs: - 8K: **128/128 identical**, across two off and two on runs after the fix, and the forced-failure fallback run. - 32K: **128/128 identical**, including the off/off A/A pair. - 2K: **not resolvable**. The two off runs already differ at 82 of 128 printed positions (first at token 46), so the engine's 2K free-running decode is not deterministic between processes on this box. The on run differs from the first off run at 76 positions, inside that run-to-run spread; this is not evidence for or against the switch. The switch can change the last bits of a GEMM (a different candidate's summation order), so the last-bit difference is expected; the 8K and 32K greedy sequences do not change. This is a greedy identity check, not a task-suite or KL certificate; see "What was not measured". ## How to reproduce Build (Linux, ROCm with hipBLASLt): ```sh cmake -S . -B build -DSTRATA_ENABLE_HIP=ON -DSTRATA_PREFILL_MMQ=ON -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_HIP_ARCHITECTURES=gfx1151 cmake --build build --target maya-ds4 -j ``` Run one arm (the prompt IDs are the ones used here; `--ids` takes a comma-joined list): ```sh MAYA_DS4_DENSE_LT=1 build/maya-ds4 --pack <pack>/maya-ds4 --gpus 0 --max-context 32768 \ --reserve-mib 12288 --vram-experts 0.92 --dspark none --vision off --mmap-experts auto \ --expert-profile <profile> --window 32768 --ids <ids> --n 128 ``` Use `--max-context 40960 --no-expert-cache` and `DS4_AHEAD=0 DS4_SPEC_Q=0` for the 32K recipe (the same 12,288 MiB reserve as above; this Q8 pack used that reserve at every length). The 32K run needs more IDs than one argument holds on this box, so the measurement used a local `--ids-file` CLI fixture (the ids-file hunk of our bench fixture, not part of this PR). The switch logic is the same. The final branch reads the aliased `STRATA_DS4_DENSE_LT` rather than `MAYA_DS4_DENSE_LT` directly (rechecked at 8K: 42.872 s vs 43.395 s on the earlier build). The final source also adds the per-(device, stream) state and the checked setup/timing path; it was rebuilt on the Strix Halo machine and the 8K row above plus the forced-failure run were made with that build. The stream query is skipped when the switch is off, and a failed query falls back. ## What was not measured - **Radeon R9700 / gfx1201**: not measured on this branch. A separate v1.1.20 experiment (Q4_K dense fixture, first-use selection included) measured dense LT **2.1 % slower at 8K and 2.3 % slower at 32K** on gfx1201, so this switch should stay off there; the gain above is a gfx1151 result. - **NVIDIA**: only a preprocessor check (the CUDA path is byte-for-byte the same in the preprocessed source); no CUDA build or GPU run on this branch. - **Other AMD packs**: only the Q8 dense pack was measured on this branch. - **Steady state**: one request per process, so every "on" run pays the first-use selection. A second request in the same process can reuse matching entries; its latency was not measured here. - **Quality/task suite**: no KL or task-suite run on this branch. The greedy comparisons above cover only these prompts and generations. - **Multi-GPU, other ROCm/hipBLASLt versions, Windows**: not measured. ## Upstream notes - The setting is documented as `MAYA_DS4_DENSE_LT` to match the other DeepSeek settings. The code reads `STRATA_DS4_DENSE_LT` and `main()`'s `env_aliases()` maps the `MAYA_*` name onto it, as for the other settings, so both spellings work. - The table is process-local and per `(device, stream)`, and is not written to any vendor tuning file. It uses a 32 MiB workspace cap and frees the temporary output scratch after selection; successful state lives for the process. - `docs/SETTINGS.md` has the DeepSeek row; the README's Tuning bullet points to it. `CHANGELOG.md` and `VERSION` are untouched, as the maintainer writes those. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:25:54 +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#482
No description provided.