[GH-ISSUE #447] MAYA_DS4_TP_GGUF_UNEVEN: cublasGemmEx fails on the first long prompt, then illegal memory access (4x RTX 3090, Maya-S) #185

Closed
opened 2026-10-29 21:22:15 +07:00 by bsakaguchi · 4 comments
Owner

Originally created by @mgabor3141 on GitHub (Oct 24, 2026).
Original GitHub issue: https://github.com/mw00/project-maya/issues/447

v1.1.26, DeepSeek-V4.1-Flash Maya-S, 4x RTX 3090 (Gen3, no P2P, driver 615.78.08, CUDA 13.4).

Args: --tp 2 --dspark on --mmap-experts off --cpu-threads 16

Env: MAYA_DS4_TP_GGUF_UNEVEN=1 DS4_FLOW_TP=1 MAYA_DS4_TP_CHECK=1 DS4_REQUIRE_ALL_RAM=1

The TP check passes and decode works. The first prompt that reaches the busy experts' path fails, and every request after it fails the same way:

ds4: CUDA1 busy experts (64 rows or more) as FP16 GEMMs, 1024 rows a piece (40 MB)
ds4: CUDA0 busy experts (64 rows or more) as FP16 GEMMs, 1024 rows a piece (47 MB)
ds4: the busy experts' path: cublasGemmEx (gate / up) failed
ds4: cudaStreamSynchronize(s): an illegal memory access was encountered
NVRM: Xid (PCI:0000:0b:00): 31, pid=371902, name=maya-ds4 ... MMU Fault ... FAULT_PDE ACCESS_TYPE_VIRT_WRITE

CUDA1 is the group's part 1. We have not tried it without DS4_FLOW_TP. Without the TP setting, the same box runs fine.

Placement. Only CUDA0 and CUDA1 form a group, and CUDA1 is left with 8.5 GB free:

ds4: CUDA0 layers [0, 42] (tensor parallel 2, part 0): ... experts 17.73 GB (2278 of 7680 in VRAM), 578 MiB free
ds4: CUDA1 layers [0, 18] (tensor parallel 2, part 1): ... experts 10.45 GB (1894 of 7296 in VRAM), 8546 MiB free
ds4: CUDA2 layers [19, 29]: ... 590 MiB free
ds4: CUDA3 layers [30, 39] + head: ... 590 MiB free

That puts 863 more experts on the CPU lane than without the setting (10,042 vs 9,179), and free RAM drops from ~13 GB to 5.2 GB. Is this the intended placement?

Decode before the failure (tok/s, 5 runs each):

layer split TP
Prose 41.5 39.1
Code 51.0 41.5

On prose the CPU-lane share is the same (~8%), so we take the ~6% loss to be the all-reduce through host memory. On code the extra CPU-lane experts add to it (10-12.5% vs 7-8%).

Happy to rerun with other settings or a debug build.

Originally created by @mgabor3141 on GitHub (Oct 24, 2026). Original GitHub issue: https://github.com/mw00/project-maya/issues/447 v1.1.26, DeepSeek-V4.1-Flash Maya-S, 4x RTX 3090 (Gen3, no P2P, driver 615.78.08, CUDA 13.4). Args: `--tp 2 --dspark on --mmap-experts off --cpu-threads 16` Env: `MAYA_DS4_TP_GGUF_UNEVEN=1 DS4_FLOW_TP=1 MAYA_DS4_TP_CHECK=1 DS4_REQUIRE_ALL_RAM=1` The TP check passes and decode works. The first prompt that reaches the busy experts' path fails, and every request after it fails the same way: ``` ds4: CUDA1 busy experts (64 rows or more) as FP16 GEMMs, 1024 rows a piece (40 MB) ds4: CUDA0 busy experts (64 rows or more) as FP16 GEMMs, 1024 rows a piece (47 MB) ds4: the busy experts' path: cublasGemmEx (gate / up) failed ds4: cudaStreamSynchronize(s): an illegal memory access was encountered ``` ``` NVRM: Xid (PCI:0000:0b:00): 31, pid=371902, name=maya-ds4 ... MMU Fault ... FAULT_PDE ACCESS_TYPE_VIRT_WRITE ``` CUDA1 is the group's part 1. We have not tried it without `DS4_FLOW_TP`. Without the TP setting, the same box runs fine. **Placement.** Only CUDA0 and CUDA1 form a group, and CUDA1 is left with 8.5 GB free: ``` ds4: CUDA0 layers [0, 42] (tensor parallel 2, part 0): ... experts 17.73 GB (2278 of 7680 in VRAM), 578 MiB free ds4: CUDA1 layers [0, 18] (tensor parallel 2, part 1): ... experts 10.45 GB (1894 of 7296 in VRAM), 8546 MiB free ds4: CUDA2 layers [19, 29]: ... 590 MiB free ds4: CUDA3 layers [30, 39] + head: ... 590 MiB free ``` That puts 863 more experts on the CPU lane than without the setting (10,042 vs 9,179), and free RAM drops from ~13 GB to 5.2 GB. Is this the intended placement? **Decode before the failure** (tok/s, 5 runs each): | | layer split | TP | |---|---|---| | Prose | 41.5 | 39.1 | | Code | 51.0 | 41.5 | On prose the CPU-lane share is the same (~8%), so we take the ~6% loss to be the all-reduce through host memory. On code the extra CPU-lane experts add to it (10-12.5% vs 7-8%). Happy to rerun with other settings or a debug build.
Author
Owner

@pepuscz commented on GitHub (Oct 24, 2026):

This looks like the same overrun as #439, which #446 fixes.

DS4_FAT_ROWS sizes its FP16 buffers at first use, from whichever layer reaches the busy-experts path first. With MAYA_DS4_TP_GGUF_UNEVEN the members' FFN widths alternate between layers (1280 / 1024 on Maya-S), so a wider layer later writes past them: the cublasGemmEx failure, then the illegal access. #446 sizes the buffers for the widest FFN a device's layers give it. Until it is merged, DS4_FAT_ROWS=0 should avoid the crash, at the busy experts' old speed.

On the placement: a tensor parallel group holds the same experts on both members (each its share of every expert's rows), so the group's VRAM experts are capped by the member with less room. Here CUDA0 also carries the DSpark blocks and layers 40-42, so it fills first, and CUDA1's 8.5 GB stays unused by experts. #412 (DS4_DRAFT_DEV, open) lets the blocks sit on other devices, which should give the group back that room. We have not measured that on a 3090 box, though.

<!-- gh-comment-id:6383761598 --> @pepuscz commented on GitHub (Oct 24, 2026): This looks like the same overrun as #439, which #446 fixes. DS4_FAT_ROWS sizes its FP16 buffers at first use, from whichever layer reaches the busy-experts path first. With MAYA_DS4_TP_GGUF_UNEVEN the members' FFN widths alternate between layers (1280 / 1024 on Maya-S), so a wider layer later writes past them: the cublasGemmEx failure, then the illegal access. #446 sizes the buffers for the widest FFN a device's layers give it. Until it is merged, DS4_FAT_ROWS=0 should avoid the crash, at the busy experts' old speed. On the placement: a tensor parallel group holds the same experts on both members (each its share of every expert's rows), so the group's VRAM experts are capped by the member with less room. Here CUDA0 also carries the DSpark blocks and layers 40-42, so it fills first, and CUDA1's 8.5 GB stays unused by experts. #412 (DS4_DRAFT_DEV, open) lets the blocks sit on other devices, which should give the group back that room. We have not measured that on a 3090 box, though.
Author
Owner

@mw00 commented on GitHub (Oct 24, 2026):

v1.1.27 includes #446, which fixes a buffer overrun in the same path under MAYA_DS4_TP_GGUF_UNEVEN (#439). It very likely fixes this too - could you try your 4x RTX 3090 setup on v1.1.27 and tell us? Until then, DS4_FAT_ROWS=0 avoids that path.

<!-- gh-comment-id:6388598526 --> @mw00 commented on GitHub (Oct 24, 2026): v1.1.27 includes #446, which fixes a buffer overrun in the same path under `MAYA_DS4_TP_GGUF_UNEVEN` (#439). It very likely fixes this too - could you try your 4x RTX 3090 setup on v1.1.27 and tell us? Until then, `DS4_FAT_ROWS=0` avoids that path.
Author
Owner

@mgabor3141 commented on GitHub (Oct 24, 2026):

Thanks, that explained both. I retested on v1.1.26 + #446 + #412, 4x RTX 3090 (Gen3, no NVLink):

Why only one pair formed. Groups are built from neighbouring GPUs with exactly equal total memory. The GPU the firmware uses for POST reserves 402 MiB, its three twins 400 MiB, so that GPU never matched its neighbour and GPUs 2 and 3 each ran alone. Comparing totals within 1% instead of exactly gives two pairs: GPUs 0+1 on layers 0-18 and 2+3 on layers 19-39.

#446 fixes the crash on CUDA. No failures over ~40 requests, including 11K and 101K prompts.

#412 with DS4_DRAFT_DEV=1,1,0 moves two drafter blocks to the lead's partner. That frees room on the lead for experts. With both pairs and #412, 9,556 experts are on the CPU lane, against 10,042 in my first run (one pair, no #412) and 9,179 with the layer split. I did not run two pairs without #412, so I cannot split that gain between the two changes.

P2P. A two-member group's all-reduce goes through host memory: each member writes its partial to pinned host memory, and the other reads it back, so every row crosses PCIe twice. I added an opt-in DS4_TP_P2P=1: each member writes its partial straight into an inbox in the other's VRAM and waits on a flag there, so the row crosses PCIe once and is read locally. The sum is the same two FP32 adds as ar_sum_kernel. It needs a driver with peer access (we used the aikitoria P2P patch), and the inboxes take 321 MiB of VRAM per member. Without peer access it logs that and keeps the host path.

All three on the same driver, speeds from the engine's timings, fresh prompts each time (C source code):

tok/s layer split TP TP + P2P
Decode, prose 33.4 34.5 35.0
Decode, code 37.9 35.8 34.3
Prompt, 11K tokens 637 420 486
Prompt, 101K tokens 1,240 652 797

Decode is the same in all three within noise. On prompts, P2P makes TP 16-22% faster, which shows the all-reduce is a real part of TP's cost. But TP with P2P is still 24-36% slower than the layer split, so most of the gap lies elsewhere. We stay on the layer split.

Happy to send PRs for the 1% match and for DS4_TP_P2P if either is wanted.

<!-- gh-comment-id:6388835636 --> @mgabor3141 commented on GitHub (Oct 24, 2026): Thanks, that explained both. I retested on v1.1.26 + #446 + #412, 4x RTX 3090 (Gen3, no NVLink): **Why only one pair formed.** Groups are built from neighbouring GPUs with exactly equal `total` memory. The GPU the firmware uses for POST reserves 402 MiB, its three twins 400 MiB, so that GPU never matched its neighbour and GPUs 2 and 3 each ran alone. Comparing totals within 1% instead of exactly gives two pairs: GPUs 0+1 on layers 0-18 and 2+3 on layers 19-39. **#446** fixes the crash on CUDA. No failures over ~40 requests, including 11K and 101K prompts. **#412** with `DS4_DRAFT_DEV=1,1,0` moves two drafter blocks to the lead's partner. That frees room on the lead for experts. With both pairs and #412, 9,556 experts are on the CPU lane, against 10,042 in my first run (one pair, no #412) and 9,179 with the layer split. I did not run two pairs without #412, so I cannot split that gain between the two changes. **P2P.** A two-member group's all-reduce goes through host memory: each member writes its partial to pinned host memory, and the other reads it back, so every row crosses PCIe twice. I added an opt-in `DS4_TP_P2P=1`: each member writes its partial straight into an inbox in the other's VRAM and waits on a flag there, so the row crosses PCIe once and is read locally. The sum is the same two FP32 adds as `ar_sum_kernel`. It needs a driver with peer access (we used the aikitoria P2P patch), and the inboxes take 321 MiB of VRAM per member. Without peer access it logs that and keeps the host path. All three on the same driver, speeds from the engine's timings, fresh prompts each time (C source code): | tok/s | layer split | TP | TP + P2P | |---|---|---|---| | Decode, prose | 33.4 | 34.5 | 35.0 | | Decode, code | 37.9 | 35.8 | 34.3 | | Prompt, 11K tokens | 637 | 420 | 486 | | Prompt, 101K tokens | 1,240 | 652 | 797 | Decode is the same in all three within noise. On prompts, P2P makes TP 16-22% faster, which shows the all-reduce is a real part of TP's cost. But TP with P2P is still 24-36% slower than the layer split, so most of the gap lies elsewhere. We stay on the layer split. Happy to send PRs for the 1% match and for `DS4_TP_P2P` if either is wanted.
Author
Owner

@mw00 commented on GitHub (Oct 27, 2026):

Closing: the crash was the busy-experts buffer overrun fixed by #446 (commit f46e395c, in v1.1.27), and your retest confirmed it. Thanks for the 1%-equal grouping finding and the DS4_TP_P2P numbers - noted.

<!-- gh-comment-id:6448811415 --> @mw00 commented on GitHub (Oct 27, 2026): Closing: the crash was the busy-experts buffer overrun fixed by #446 (commit f46e395c, in v1.1.27), and your retest confirmed it. Thanks for the 1%-equal grouping finding and the `DS4_TP_P2P` numbers - noted.
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#185
No description provided.