[PR #598] [CLOSED] HIP: optional sparse-row expert combination #618

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

📋 Pull Request Information

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

Base: main ← Head: upstream/hip-sparse-expert-combine


📝 Commits (1)

  • df90078 HIP: add optional sparse-row expert combination

📊 Changes

6 files changed (+220 additions, -4 deletions)

View changed files

📝 CMakeLists.txt (+4 -0)
📝 docs/SETTINGS.md (+19 -0)
📝 src/ds4/ds4_kernels.cu (+41 -2)
📝 src/ds4/ds4_kernels.cuh (+2 -1)
📝 src/ds4/ds4_model.cu (+1 -1)
➕ tests/ds4_sparse_combine_test.cu (+153 -0)

📄 Description

This optional HIP change makes the last step of sparse expert batches much cheaper: instead of starting work for every prompt token, it visits the rows that the batch actually computed. On an R9700, current-base synthetic tests reduced this combination operator's latency by 73–93% when one matching pick touched 1–10% of a 4,096-token prompt. Earlier whole-model tests showed a much smaller 0.42–0.47% lower warm 4K prefill latency, with mixed results on other prompts. Those model numbers are historical, not a new result on this port.

Upstream already avoids reading untouched accumulators (#344 / 68c0f31). This PR adds only the distinct sparse-row dispatch; it does not claim that existing optimization as new.

Enable with MAYA_DS4_SPARSE_COMBINE=1 (default off; STRATA/native aliases supported). The existing sorted row-to-token map is passed to moe_combine. If a batch has fewer rows than prompt tokens, its first matching pick owns each token's output and adds all matching picks in their original FMA order. Duplicate token rows therefore produce one writer. Dense batches and callers without the row map retain the original kernel. CUDA retains its original execution path. There are no extra allocations, transfers, cache slots, or GPU-count assumptions.

Current-base validation (249f9a8, Release HIP, gfx1201):

  • Production maya-ds4 and standalone ds4_sparse_combine_test builds.
  • 96 exact operator checks across two R9700s: flag off/on and null-map fallback; sparse/dense/empty batches, k=1/3/6/8, nonzero row offsets, reordered rows, repeated token IDs, ragged dimensions, signed zero, finite outputs and allocation guards. Small cases also match independent CPU std::fma references.
  • Sixteen synthetic timing shapes; two warmups and 12 alternating measured pairs per shape, eviction buffer outside event intervals. For D=5120, T=4096:
Rows in batch Token-grid baseline Sparse-row option Operator latency reduction
1% tokens, one pick 181.16us 13.44us 92.6%
10% tokens, one pick 197.50us 52.88us 73.2%
10% tokens, three picks 205.32us 87.66us 57.3%
50% tokens, one pick 290.58us 226.76us 22.0%
All tokens, one pick (fallback) 440.28us 440.82us −0.1%
All tokens, six picks (fallback) 1119.11us 1120.55us −0.1%

Small/ragged cases are around launch overhead and show mixed noise. These measurements do not establish whole-model speedups or actual sparse-batch frequency. The historical model check compared 12 full-vocabulary states across three prompts and found exact outputs; frozen residency and no actual drafting limit that evidence. Current-base full-model parity/performance, adaptive-cache behavior and MTP interaction remain follow-up work. Existing serving has not been changed by this PR.

Build/run:

cmake --build build-hip --target ds4_sparse_combine_test maya-ds4 -j4
HIP_VISIBLE_DEVICES=0 ./build-hip/ds4_sparse_combine_test
HIP_VISIBLE_DEVICES=1 ./build-hip/ds4_sparse_combine_test --parity-only

This is the focused current-main port of the remaining sparse-row part of fork experiment #46.


🔄 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/598 **Author:** [@LostVector](https://github.com/LostVector) **Created:** 10/28/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `upstream/hip-sparse-expert-combine` --- ### 📝 Commits (1) - [`df90078`](https://github.com/mw00/project-maya/commit/df900787dba86b55098511153cdd5ca16ba0fcdf) HIP: add optional sparse-row expert combination ### 📊 Changes **6 files changed** (+220 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+4 -0) 📝 `docs/SETTINGS.md` (+19 -0) 📝 `src/ds4/ds4_kernels.cu` (+41 -2) 📝 `src/ds4/ds4_kernels.cuh` (+2 -1) 📝 `src/ds4/ds4_model.cu` (+1 -1) ➕ `tests/ds4_sparse_combine_test.cu` (+153 -0) </details> ### 📄 Description This optional HIP change makes the last step of sparse expert batches much cheaper: instead of starting work for every prompt token, it visits the rows that the batch actually computed. On an R9700, current-base synthetic tests reduced this combination operator's latency by **73–93%** when one matching pick touched 1–10% of a 4,096-token prompt. Earlier whole-model tests showed a much smaller **0.42–0.47% lower warm 4K prefill latency**, with mixed results on other prompts. Those model numbers are historical, not a new result on this port. Upstream already avoids reading untouched accumulators (#344 / 68c0f31). This PR adds only the distinct sparse-row dispatch; it does not claim that existing optimization as new. Enable with `MAYA_DS4_SPARSE_COMBINE=1` (default off; STRATA/native aliases supported). The existing sorted row-to-token map is passed to `moe_combine`. If a batch has fewer rows than prompt tokens, its first matching pick owns each token's output and adds all matching picks in their original FMA order. Duplicate token rows therefore produce one writer. Dense batches and callers without the row map retain the original kernel. CUDA retains its original execution path. There are no extra allocations, transfers, cache slots, or GPU-count assumptions. Current-base validation (249f9a8, Release HIP, gfx1201): - Production `maya-ds4` and standalone `ds4_sparse_combine_test` builds. - 96 exact operator checks across two R9700s: flag off/on and null-map fallback; sparse/dense/empty batches, k=1/3/6/8, nonzero row offsets, reordered rows, repeated token IDs, ragged dimensions, signed zero, finite outputs and allocation guards. Small cases also match independent CPU `std::fma` references. - Sixteen synthetic timing shapes; two warmups and 12 alternating measured pairs per shape, eviction buffer outside event intervals. For D=5120, T=4096: | Rows in batch | Token-grid baseline | Sparse-row option | Operator latency reduction | | --- | ---: | ---: | ---: | | 1% tokens, one pick |181.16us|13.44us|92.6%| | 10% tokens, one pick |197.50us|52.88us|73.2%| | 10% tokens, three picks |205.32us|87.66us|57.3%| | 50% tokens, one pick |290.58us|226.76us|22.0%| | All tokens, one pick (fallback) |440.28us|440.82us|−0.1%| | All tokens, six picks (fallback) |1119.11us|1120.55us|−0.1%| Small/ragged cases are around launch overhead and show mixed noise. These measurements do not establish whole-model speedups or actual sparse-batch frequency. The historical model check compared 12 full-vocabulary states across three prompts and found exact outputs; frozen residency and no actual drafting limit that evidence. Current-base full-model parity/performance, adaptive-cache behavior and MTP interaction remain follow-up work. Existing serving has not been changed by this PR. Build/run: ```sh cmake --build build-hip --target ds4_sparse_combine_test maya-ds4 -j4 HIP_VISIBLE_DEVICES=0 ./build-hip/ds4_sparse_combine_test HIP_VISIBLE_DEVICES=1 ./build-hip/ds4_sparse_combine_test --parity-only ``` This is the focused current-main port of the remaining sparse-row part of [fork experiment #46](https://github.com/LostVector/project-maya/pull/46). --- <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:32 +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#618
No description provided.