[PR #377] [MERGED] ds4: flow - a TP member stages its own gate/up rows from a RAM copy #500

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

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/377
Author: @NenadSteric
Created: 10/22/2026
Status: ✅ Merged
Merged: 10/22/2026
Merged by: @mw00

Base: main ← Head: pr/ds4-flow-tp-ram-copy


📝 Commits (1)

  • 2b728d5 ds4: flow - a TP member stages its own rows from a RAM copy

📊 Changes

1 file changed (+14 additions, -5 deletions)

View changed files

📝 src/ds4/ds4_model.cu (+14 -5)

📄 Description

Problem

With a tensor-parallel group, the flow on (DS4_FLOW_TP=1) and the CPU lane's experts copied into RAM (--mmap-experts off), every member after the first computes its streamed experts with the first member's gate/up rows. The output stays plausible, so nothing looks broken - but the logits are wrong (KLD 0.32 against the non-flow path, top-1 agreement 85%).

On main this needs a GGUF that can form a TP group (TP 2 with 32-value expert blocks; Maya's own 256-value quants cannot), so few setups reach it today. It matters once the flow is used with TP - which is worth doing, see Why it matters below.

Cause

A member reads only its share of each gate/up matrix. The file path applies the member's row offset when it reads (mx_read_off), so the staging slot starts at the member's rows. The copy path stages the whole matrix, and the DMA then takes mx_read_len bytes from the start of the slot - the first member's rows. Example with TP 2 (n_ff 2304, 1152 rows a member), member 1:

flowchart LR
  subgraph main["main, RAM copy (--mmap-experts off)"]
    direction TB
    A1["RAM copy of the gate<br/>rows 0 - 2303"] -->|"stage the whole matrix"| B1["staging slot<br/>rows 0 - 2303"]
    B1 -->|"DMA 1152 rows<br/>from the slot start"| C1["member 1 computes with<br/>rows 0 - 1151 ✗<br/>(member 0's)"]
  end
  subgraph fixed["file path, and RAM copy with this PR"]
    direction TB
    A2["gate rows 0 - 2303"] -->|"read rows 1152 - 2303<br/>(mx_read_off / mx_read_len)"| B2["staging slot<br/>rows 1152 - 2303"]
    B2 -->|"DMA 1152 rows<br/>from the slot start"| C2["member 1 computes with<br/>rows 1152 - 2303 ✓"]
  end
  main ~~~ fixed

The down matrix is staged whole on both paths and cut by the 2D copy, so it is right either way. Member 0's rows start at 0, which is why one member in the group is always right.

Fix

The copy path now stages the same rows the file path reads (mx_read_off / mx_read_len), taking each NUMA part's share of that range when NH > 1, and the item counts the jobs it queued. A member's copy jobs only get smaller; jobs[6] still bounds them (at most NH a matrix).

Why it matters: the flow makes TP prompt reading much faster

Without the flow, a TP group's chunked prompt path streams every CPU-lane expert of every layer for each chunk - on our machine about 60 GB, ~5 s per prompt, however short. The flow streams only the experts a chunk routes to. With this fix the flow is correct, and on 6x RTX 3090 / 256 GB RAM, DeepSeek V4.1 Flash 1017 Maya-S, TP 3 (a v1.1.20 build with this fix, the TP patches listed under Next and a P2P all-reduce of ours) it reads prompts much faster:

workload (replayed prompts, no decode) non-flow flow, fixed
agent coding session: 28 follow-up prompts, 128 - 3K tokens, at 30K - 150K context 160 s, 228 tok/s 95 s (-40%), 382 tok/s
code-comprehension session: 39 prompts, 1.3K - 13K tokens, at 30K - 160K context 375 s, 343 tok/s 269 s (-28%), 479 tok/s

On v1.1.22 (same TP patches, plus the CPU-lane patch from Next) the agent-session replay takes 95 s with v1.1.22's copy-engine all-reduce and 98 s with DS4_AR_DMA=0: the gain comes from the flow, not from the all-reduce.

In full agent coding sessions (flow plus a small CPU-lane patch for prompts under 512 tokens) prompt reading went from 174 - 205 to 403 - 408 tok/s and a session's wall time from 23 - 25 to 11.5 - 14 minutes, with decode unchanged (90 - 94 tok/s).

Validation

Engine CLI logits of 1,024 fixed tokens on v1.1.22, compared with the non-flow chunked path (DS4_CHUNK=256). Maya-S cannot form a TP group on main (TP 2 halves n_ff 2304 into rows that are not whole 256-value blocks; TP 3 does not divide the 64 heads), so this used main + a local uneven-head-split patch (not part of this PR) with even FFN shares, TP 3 over 6 GPUs:

KLD mean top-1 agreement
main, flow on 0.323 84.7%
this PR, flow on 0.0083 97.0%
reference noise: non-flow path, chunk size changed only 0.0095 97.1%
non-flow path, main vs this PR bit-identical

CI-equivalent: HIP name mapping passes; server tests 342 OK (10 skipped); tools tests 383 OK (28 skipped).

Not tested: HIP at runtime; NH = 2 (one NUMA node here - the part arithmetic is checked by reading only); a TP group on main without the head-split patch.

Next

Further PRs will follow, each opt-in with unchanged defaults:

  • TP for GGUF packs whose heads do not split evenly - lets Maya-S / Maya-XS form TP groups (3 GPUs a group), which is where this fix starts to matter.
  • Uneven FFN shares per group member - so a member that also holds the drafter takes a smaller share and the others fill their VRAM.
  • CPU lane for short chunked prompts - prompts under ~512 tokens compute their CPU-lane rows on the CPU instead of streaming.
  • An issue on --mmap-experts auto for GGUFs: it reads in place even when RAM holds every CPU-lane expert; copying them was +34% decode here.

🤖 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/377 **Author:** [@NenadSteric](https://github.com/NenadSteric) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@mw00](https://github.com/mw00) **Base:** `main` ← **Head:** `pr/ds4-flow-tp-ram-copy` --- ### 📝 Commits (1) - [`2b728d5`](https://github.com/mw00/project-maya/commit/2b728d504297ac95f78483bd9eabd1da9c42ddcd) ds4: flow - a TP member stages its own rows from a RAM copy ### 📊 Changes **1 file changed** (+14 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `src/ds4/ds4_model.cu` (+14 -5) </details> ### 📄 Description ### Problem With a tensor-parallel group, the flow on (`DS4_FLOW_TP=1`) and the CPU lane's experts copied into RAM (`--mmap-experts off`), every member after the first computes its streamed experts with **the first member's gate/up rows**. The output stays plausible, so nothing looks broken - but the logits are wrong (KLD 0.32 against the non-flow path, top-1 agreement 85%). On main this needs a GGUF that can form a TP group (TP 2 with 32-value expert blocks; Maya's own 256-value quants cannot), so few setups reach it today. It matters once the flow is used with TP - which is worth doing, see *Why it matters* below. ### Cause A member reads only its share of each gate/up matrix. The file path applies the member's row offset when it reads (`mx_read_off`), so the staging slot starts at the member's rows. The copy path stages the whole matrix, and the DMA then takes `mx_read_len` bytes from the start of the slot - the first member's rows. Example with TP 2 (n_ff 2304, 1152 rows a member), member 1: ```mermaid flowchart LR subgraph main["main, RAM copy (--mmap-experts off)"] direction TB A1["RAM copy of the gate<br/>rows 0 - 2303"] -->|"stage the whole matrix"| B1["staging slot<br/>rows 0 - 2303"] B1 -->|"DMA 1152 rows<br/>from the slot start"| C1["member 1 computes with<br/>rows 0 - 1151 ✗<br/>(member 0's)"] end subgraph fixed["file path, and RAM copy with this PR"] direction TB A2["gate rows 0 - 2303"] -->|"read rows 1152 - 2303<br/>(mx_read_off / mx_read_len)"| B2["staging slot<br/>rows 1152 - 2303"] B2 -->|"DMA 1152 rows<br/>from the slot start"| C2["member 1 computes with<br/>rows 1152 - 2303 ✓"] end main ~~~ fixed ``` The down matrix is staged whole on both paths and cut by the 2D copy, so it is right either way. Member 0's rows start at 0, which is why one member in the group is always right. ### Fix The copy path now stages the same rows the file path reads (`mx_read_off` / `mx_read_len`), taking each NUMA part's share of that range when NH > 1, and the item counts the jobs it queued. A member's copy jobs only get smaller; `jobs[6]` still bounds them (at most NH a matrix). ### Why it matters: the flow makes TP prompt reading much faster Without the flow, a TP group's chunked prompt path streams every CPU-lane expert of every layer for each chunk - on our machine about 60 GB, ~5 s per prompt, however short. The flow streams only the experts a chunk routes to. With this fix the flow is correct, and on **6x RTX 3090 / 256 GB RAM, DeepSeek V4.1 Flash 1017 Maya-S, TP 3** (a v1.1.20 build with this fix, the TP patches listed under *Next* and a P2P all-reduce of ours) it reads prompts much faster: | workload (replayed prompts, no decode) | non-flow | flow, fixed | |---|---|---| | agent coding session: 28 follow-up prompts, 128 - 3K tokens, at 30K - 150K context | 160 s, 228 tok/s | **95 s (-40%), 382 tok/s** | | code-comprehension session: 39 prompts, 1.3K - 13K tokens, at 30K - 160K context | 375 s, 343 tok/s | **269 s (-28%), 479 tok/s** | On v1.1.22 (same TP patches, plus the CPU-lane patch from *Next*) the agent-session replay takes 95 s with v1.1.22's copy-engine all-reduce and 98 s with `DS4_AR_DMA=0`: the gain comes from the flow, not from the all-reduce. In full agent coding sessions (flow plus a small CPU-lane patch for prompts under 512 tokens) prompt reading went from 174 - 205 to 403 - 408 tok/s and a session's wall time from 23 - 25 to 11.5 - 14 minutes, with decode unchanged (90 - 94 tok/s). ### Validation Engine CLI logits of 1,024 fixed tokens on v1.1.22, compared with the non-flow chunked path (`DS4_CHUNK=256`). Maya-S cannot form a TP group on main (TP 2 halves n_ff 2304 into rows that are not whole 256-value blocks; TP 3 does not divide the 64 heads), so this used main + a local uneven-head-split patch (not part of this PR) with even FFN shares, TP 3 over 6 GPUs: | | KLD mean | top-1 agreement | |---|---|---| | main, flow on | 0.323 | 84.7% | | this PR, flow on | 0.0083 | 97.0% | | reference noise: non-flow path, chunk size changed only | 0.0095 | 97.1% | | non-flow path, main vs this PR | bit-identical | | CI-equivalent: HIP name mapping passes; server tests 342 OK (10 skipped); tools tests 383 OK (28 skipped). Not tested: HIP at runtime; NH = 2 (one NUMA node here - the part arithmetic is checked by reading only); a TP group on main without the head-split patch. ### Next Further PRs will follow, each opt-in with unchanged defaults: - **TP for GGUF packs whose heads do not split evenly** - lets Maya-S / Maya-XS form TP groups (3 GPUs a group), which is where this fix starts to matter. - **Uneven FFN shares per group member** - so a member that also holds the drafter takes a smaller share and the others fill their VRAM. - **CPU lane for short chunked prompts** - prompts under ~512 tokens compute their CPU-lane rows on the CPU instead of streaming. - An issue on `--mmap-experts auto` for GGUFs: it reads in place even when RAM holds every CPU-lane expert; copying them was +34% decode here. 🤖 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:06 +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#500
No description provided.