[PR #408] [MERGED] ds4: MAYA_DS4_TP_GGUF_UNEVEN - tensor parallel 2 on Maya's quants (whole blocks, as even as they go), with DS4_FLOW_TP on its groups #517

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

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/408
Author: @pepuscz
Created: 10/23/2026
Status: ✅ Merged
Merged: 10/23/2026
Merged by: @mw00

Base: main ← Head: pr/ds4-tp-uneven


📝 Commits (2)

  • 6c3f554 ds4: MAYA_DS4_TP_GGUF_UNEVEN - tensor parallel 2 on Maya's quants, the experts split in whole blocks as even as they go
  • bfcc751 ds4: DS4_FLOW_TP on MAYA_DS4_TP_GGUF_UNEVEN's groups - each member streams its own part, the down gathered on the device

📊 Changes

5 files changed (+759 additions, -80 deletions)

View changed files

📝 docs/SETTINGS.md (+19 -0)
📝 src/ds4/ds4_kernels.cu (+14 -0)
📝 src/ds4/ds4_kernels.cuh (+2 -0)
📝 src/ds4/ds4_model.cu (+632 -80)
➕ tools/test_ds4_tp_uneven.py (+92 -0)

📄 Description

What. A GGUF's experts split between a tensor-parallel group's GPUs only in whole blocks of their type. Maya's quants
use 256-value blocks (n_ff 2304 = 9 blocks), so --tp 2 (or 4, 8) falls back to 1: "tensor parallel 2 -> 1", each
GPU its own layers. With MAYA_DS4_TP_GGUF_UNEVEN=1 a member takes whole blocks as even as they go, 5 + 4 for two
GPUs, the odd block going round the members layer by layer, as EXL3's split128 does.

  • splitb: split128's rule for any block size; split128 is splitb in 128s, unchanged.
  • Each member loads, streams, swaps and checks its own range and layout (the GGUF converters, load_experts_mx,
    swap_in_mx, DS4_CHECK_SWAPS); chunk_dims sizes for the widest member.
  • The shared expert is split at the member's own range (mat_bf16 takes an explicit one); the load is refused if it is
    not as wide as the routed experts.
  • Placement: #344's per-member room proposes as before; then each member's exact expert bytes are fitted to its own
    room from the same snapshot, a slot fewer at a time (trim_to_fit), else the load is refused.
  • With DS4_FLOW_TP=1 the members take the prompt flow too: each reads its own gate / up rows (#377's staging, with the
    member's range), and an uneven member's down is copied whole into a device scratch and gathered (gather_cols) - a
    2D copy of its rows cost 34.5-35.3 ms a call against 0.65-0.73 ms on an RX 7900 XTX. Off the flow, a group's prompt
    chunks stream every slot-less expert through the group's windows, which on a disk-streaming box is much slower
    (3,981 tokens: 431.6 s against 37.8 s on the flow, on our earlier build).
  • MAYA_DS4_TP_CHECK=1 (at load, before any request), for each expert format and rotation: one token through every
    member's parts as decode runs them, summed on the host and compared with the whole (the CPU lane's sums, the shared
    expert with the GPU's int8 rounding), and, with the flow, one expert through the flow's copy into a guarded buffer,
    byte for byte. More than 1e-3 of the largest output, a value that is not finite, a CUDA error or no end fails the
    start.

Changes. src/ds4/ds4_model.cu, src/ds4/ds4_kernels.cu/.cuh (gather_cols), docs/SETTINGS.md, and
tools/test_ds4_tp_uneven.py (compiles the engine's splitb / split128, CPU only). Unset, every path is as before.
The engine reads STRATA_DS4_TP_GGUF_UNEVEN / STRATA_DS4_TP_CHECK (and DS4_*), as for the other MAYA_DS4_*
settings.

Verified. The load (MAYA_DS4_TP_GGUF_UNEVEN=1 MAYA_DS4_TP_CHECK=1 DS4_FLOW_TP=1, --tp 2):

ds4: tensor parallel 2: the experts' n_ff 2304 in 256-value blocks, 1280 to 1024 a member (the odd blocks going round the members layer by layer) (DS4_TP_GGUF_UNEVEN)
ds4: CUDA1: 3 expert slots fewer, its own parts' bytes (16.77 GB) in its room (16.77 GB) (DS4_TP_GGUF_UNEVEN)
ds4: TP check: IQ2_XXS/IQ2_XXS/IQ3_XXS (layer 4, member 0 takes 1280 of 2304): 2 members' parts summed against the whole - routed (3 experts) 2.08e-07 of the largest, shared 1.39e-07
ds4: TP check: the flow's copies passed (8 of the formats', rotations' and members' copies) (DS4_FLOW_TP)
ds4: TP check passed (4 expert formats and rotations, all the split layers have) (DS4_TP_CHECK)

The four parts-against-the-whole checks came to 1.0e-07 - 2.1e-07 of the largest output (routed) and 0.9e-07 -
1.6e-07 (shared). Perplexity, --ppl over 23 sequences / 47,081 tokens: main's --tp 2 (its fallback to 1)
7.2526, with the setting 7.2519 (0.01% apart).

Speed, tok/s - one 2,048-token prompt and 512 greedy tokens, a cold and a warm pass a load, two loads a side (load 1,
load 2):

--tp 2 prefill, cold prefill, warm decode, cold decode, warm
main (falls back to 1) 43.5, 43.4 69.9, 69.3 22.5, 22.2 22.8, 25.9
MAYA_DS4_TP_GGUF_UNEVEN=1, DS4_FLOW_TP=1 42.0, 42.1 67.4, 67.6 23.3, 23.3 27.3, 27.1

Decode +4% cold and +12% warm (means), prefill 3% slower. About a fifth of the experts fit in VRAM either way (3,166
of 15,360 split by layers, 3,014 in two parts), so both are mostly the CPU lane and the disk; the gain is both GPUs
on every layer. The greedy streams part at the second token, a near tie: main's own two loads split there too (and at
199), its cold and warm passes differ, and with the setting both loads' streams are identical.

Test setup. Measured on v1.1.23 + main's commits after it (#382, #380, #379, #377, #370, #369, #381, #368; main at
c9683e3) + this branch. Rebased onto v1.1.24 (25deec5) without conflicts; the change's lines are the same, and main's
engine change since (df7e8b9) is Windows-only. HIP build (ROCm 7.2.4, gfx1100;gfx1151), 2x RX 7900 XTX (gfx1100), the
engine CLI. Model: DeepSeek-V4.1-Flash-1017 Maya-S (the IQ2_XXS / IQ2_S experts with IQ3_XXS / IQ3_S down, the pack's
four shards; not the newer Maya-XS, which this did not test).
Same binary both ways: --tp 2 as main runs it (its fallback to 1) against --tp 2 with MAYA_DS4_TP_GGUF_UNEVEN=1
MAYA_DS4_TP_CHECK=1 DS4_FLOW_TP=1; --dspark none, 128K context, the same expert profile, an empty
MAYA_DS4_LT_STORE each run. Perplexity as #344 measured it: --ppl over 23 sequences of 2048 tokens (this repo's
docs and DS4 sources). Speed on a 2,048-token prompt: a 16K one on main's fallback (its CPU lane, 16 threads, on
8,192-token chunks) took this box's CPU to its 95 °C limit. This is a correctness check and one same-binary speed
comparison, not a quality or DSpark qualification.

🤖 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/mw00/project-maya/pull/408 **Author:** [@pepuscz](https://github.com/pepuscz) **Created:** 10/23/2026 **Status:** ✅ Merged **Merged:** 10/23/2026 **Merged by:** [@mw00](https://github.com/mw00) **Base:** `main` ← **Head:** `pr/ds4-tp-uneven` --- ### 📝 Commits (2) - [`6c3f554`](https://github.com/mw00/project-maya/commit/6c3f554696b4162641db6e682797c8e303a19d3a) ds4: MAYA_DS4_TP_GGUF_UNEVEN - tensor parallel 2 on Maya's quants, the experts split in whole blocks as even as they go - [`bfcc751`](https://github.com/mw00/project-maya/commit/bfcc751b14d903b95ff22ba21d2e00cf759c4a47) ds4: DS4_FLOW_TP on MAYA_DS4_TP_GGUF_UNEVEN's groups - each member streams its own part, the down gathered on the device ### 📊 Changes **5 files changed** (+759 additions, -80 deletions) <details> <summary>View changed files</summary> 📝 `docs/SETTINGS.md` (+19 -0) 📝 `src/ds4/ds4_kernels.cu` (+14 -0) 📝 `src/ds4/ds4_kernels.cuh` (+2 -0) 📝 `src/ds4/ds4_model.cu` (+632 -80) ➕ `tools/test_ds4_tp_uneven.py` (+92 -0) </details> ### 📄 Description **What.** A GGUF's experts split between a tensor-parallel group's GPUs only in whole blocks of their type. Maya's quants use 256-value blocks (n_ff 2304 = 9 blocks), so `--tp 2` (or 4, 8) falls back to 1: "tensor parallel 2 -> 1", each GPU its own layers. With `MAYA_DS4_TP_GGUF_UNEVEN=1` a member takes whole blocks as even as they go, 5 + 4 for two GPUs, the odd block going round the members layer by layer, as EXL3's split128 does. - `splitb`: split128's rule for any block size; split128 is splitb in 128s, unchanged. - Each member loads, streams, swaps and checks its own range and layout (the GGUF converters, `load_experts_mx`, `swap_in_mx`, `DS4_CHECK_SWAPS`); `chunk_dims` sizes for the widest member. - The shared expert is split at the member's own range (`mat_bf16` takes an explicit one); the load is refused if it is not as wide as the routed experts. - Placement: #344's per-member room proposes as before; then each member's exact expert bytes are fitted to its own room from the same snapshot, a slot fewer at a time (`trim_to_fit`), else the load is refused. - With `DS4_FLOW_TP=1` the members take the prompt flow too: each reads its own gate / up rows (#377's staging, with the member's range), and an uneven member's down is copied whole into a device scratch and gathered (`gather_cols`) - a 2D copy of its rows cost 34.5-35.3 ms a call against 0.65-0.73 ms on an RX 7900 XTX. Off the flow, a group's prompt chunks stream every slot-less expert through the group's windows, which on a disk-streaming box is much slower (3,981 tokens: 431.6 s against 37.8 s on the flow, on our earlier build). - `MAYA_DS4_TP_CHECK=1` (at load, before any request), for each expert format and rotation: one token through every member's parts as decode runs them, summed on the host and compared with the whole (the CPU lane's sums, the shared expert with the GPU's int8 rounding), and, with the flow, one expert through the flow's copy into a guarded buffer, byte for byte. More than 1e-3 of the largest output, a value that is not finite, a CUDA error or no end fails the start. **Changes.** `src/ds4/ds4_model.cu`, `src/ds4/ds4_kernels.cu/.cuh` (`gather_cols`), `docs/SETTINGS.md`, and `tools/test_ds4_tp_uneven.py` (compiles the engine's `splitb` / `split128`, CPU only). Unset, every path is as before. The engine reads `STRATA_DS4_TP_GGUF_UNEVEN` / `STRATA_DS4_TP_CHECK` (and `DS4_*`), as for the other `MAYA_DS4_*` settings. **Verified.** The load (`MAYA_DS4_TP_GGUF_UNEVEN=1 MAYA_DS4_TP_CHECK=1 DS4_FLOW_TP=1`, `--tp 2`): ``` ds4: tensor parallel 2: the experts' n_ff 2304 in 256-value blocks, 1280 to 1024 a member (the odd blocks going round the members layer by layer) (DS4_TP_GGUF_UNEVEN) ds4: CUDA1: 3 expert slots fewer, its own parts' bytes (16.77 GB) in its room (16.77 GB) (DS4_TP_GGUF_UNEVEN) ds4: TP check: IQ2_XXS/IQ2_XXS/IQ3_XXS (layer 4, member 0 takes 1280 of 2304): 2 members' parts summed against the whole - routed (3 experts) 2.08e-07 of the largest, shared 1.39e-07 ds4: TP check: the flow's copies passed (8 of the formats', rotations' and members' copies) (DS4_FLOW_TP) ds4: TP check passed (4 expert formats and rotations, all the split layers have) (DS4_TP_CHECK) ``` The four parts-against-the-whole checks came to 1.0e-07 - 2.1e-07 of the largest output (routed) and 0.9e-07 - 1.6e-07 (shared). Perplexity, `--ppl` over 23 sequences / 47,081 tokens: main's `--tp 2` (its fallback to 1) 7.2526, with the setting 7.2519 (0.01% apart). Speed, tok/s - one 2,048-token prompt and 512 greedy tokens, a cold and a warm pass a load, two loads a side (load 1, load 2): | `--tp 2` | prefill, cold | prefill, warm | decode, cold | decode, warm | |---|---|---|---|---| | main (falls back to 1) | 43.5, 43.4 | 69.9, 69.3 | 22.5, 22.2 | 22.8, 25.9 | | `MAYA_DS4_TP_GGUF_UNEVEN=1`, `DS4_FLOW_TP=1` | 42.0, 42.1 | 67.4, 67.6 | 23.3, 23.3 | 27.3, 27.1 | Decode +4% cold and +12% warm (means), prefill 3% slower. About a fifth of the experts fit in VRAM either way (3,166 of 15,360 split by layers, 3,014 in two parts), so both are mostly the CPU lane and the disk; the gain is both GPUs on every layer. The greedy streams part at the second token, a near tie: main's own two loads split there too (and at 199), its cold and warm passes differ, and with the setting both loads' streams are identical. **Test setup.** Measured on v1.1.23 + main's commits after it (#382, #380, #379, #377, #370, #369, #381, #368; main at c9683e3) + this branch. Rebased onto v1.1.24 (25deec5) without conflicts; the change's lines are the same, and main's engine change since (df7e8b9) is Windows-only. HIP build (ROCm 7.2.4, `gfx1100;gfx1151`), 2x RX 7900 XTX (gfx1100), the engine CLI. Model: DeepSeek-V4.1-Flash-1017 **Maya-S** (the IQ2_XXS / IQ2_S experts with IQ3_XXS / IQ3_S down, the pack's four shards; not the newer Maya-XS, which this did not test). Same binary both ways: `--tp 2` as main runs it (its fallback to 1) against `--tp 2` with `MAYA_DS4_TP_GGUF_UNEVEN=1` `MAYA_DS4_TP_CHECK=1` `DS4_FLOW_TP=1`; `--dspark none`, 128K context, the same expert profile, an empty `MAYA_DS4_LT_STORE` each run. Perplexity as #344 measured it: `--ppl` over 23 sequences of 2048 tokens (this repo's docs and DS4 sources). Speed on a 2,048-token prompt: a 16K one on main's fallback (its CPU lane, 16 threads, on 8,192-token chunks) took this box's CPU to its 95 °C limit. This is a correctness check and one same-binary speed comparison, not a quality or DSpark qualification. 🤖 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>
bsakaguchi 2026-10-29 21:26:17 +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#517
No description provided.