[PR #4969] [Engine] dsv41: the chunked prompt pass DMAs a pinned expert copy from every NUMA part #5271

Open
opened 2026-11-07 16:33:57 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4969
Author: @yazun
Created: 11/2/2026
Status: 🔄 Open

Base: main ← Head: fix/dsv41-numa-pinned-dma


📝 Commits (1)

  • 36278a0 [Engine] dsv41: the chunked prompt pass DMAs a pinned expert copy from every NUMA part

📊 Changes

1 file changed (+40 additions, -0 deletions)

View changed files

📝 src/dsv41/ds4_model.cu (+40 -0)

📄 Description

Problem and result

On a machine with two NUMA nodes, DeepSeek V4.1 crashed on the first prompt of 96 tokens or more:

maya-ds4: cudaStreamSynchronize(s): an illegal memory access was encountered

The first report came through the server, with a 20,053-token prompt at a 1M context. It also happens with the
engine alone and a 301-token prompt at an 8K context.

Cause. With two NUMA nodes the engine keeps its RAM copy of the CPU lane's experts in two parts. Part X holds
rows [X n / 2, ..) of each matrix, at cp_lay (ram_to_blob puts them back together). The staging pump and
stream_expert read both parts. But the chunked prompt pass DMAs a pinned copy straight from RAM, and it took
every matrix from part 0 only. So the second half of each gate, up and down matrix came from the wrong bytes.

What that did, in the per-layer dumps (DS4_DUMP_L) of the old binary:

  • Layers 3 to 7 (all IQ2_XXS) gave wrong but finite values.

  • Layer 8, the first with an IQ2_S down, gave NaN.

  • The router of the next layer then read out of bounds. All-NaN scores leave its pick at 0x7fffffff.
    compute-sanitizer (memcheck) reported:

    Invalid __shared__ read of size 4 bytes
        at strata::ds4::<unnamed>::route_kernel(...)+0x1750
        Access to 0xfffffffc is out of bounds
    

When it happens. All three must hold:

  1. The CPU lane's experts are copied into RAM and pinned. This is the default when they fit: the log says
    "copied into RAM (…, 2 NUMA parts)" and "the copied experts pinned … the prompt path DMAs them in place".
  2. The copy is in two parts. That means two NUMA nodes, with ff / 2 and dim / 2 multiples of 128.
  3. The prompt takes the chunked pass (96 tokens or more).

Until now the workaround was DS4_COPY_NUMA=1.

After this change the crash is gone. The two-part run gives the same prompt pass as the one-part run (below).
The one-part path is unchanged.

None needed. This is a focused fix.

  • #4825: on Strix Halo a NaN in the chunked prompt pass also reached route_kernel, from another cause (the Q6_K
    dequant staging). There the maintainer said a router change that stops a NaN from becoming an out-of-bounds read
    is being tested. That change would turn this crash into wrong output. This PR fixes where the NaN comes from on a
    two-node host and leaves the router alone. Strix Halo has one NUMA node, so this bug does not explain the faults
    reported there.
  • #4016 (NUMA bands) changes the same copy layout (ram_part, cp_lay). Its diff does not touch the pinned DMA
    branch in flow_push. If it lands, its band layout would need the same per-part DMA. This PR covers the current
    two-part layout only.

Approach

  • flow_push: in copy mode with NH > 1, a pinned item records its copy's slot (Item::cs). It no longer stores
    three pointers into part 0, because no single pointer can hold a matrix split over two parts.
  • New dma_parts: copies such an item into its ring slot from both parts. It puts the same bytes in the same
    places as the one-part path:
    • Gate and up: the rows this device takes ([a, b); all rows when alone), cut at the part boundary. One copy per
      part that holds some of them.
    • Down: each part's rows. With tensor parallel (nm > 1) it copies the member's blocks of every row, with one
      cudaMemcpy2DAsync per part.
  • The DMA loop counts it as one DMA, as before: the ring_fill event, n_dma and stream_bytes.

Compatibility:

  • With one part, it.cs stays -1 and the old code runs unchanged. One part means one NUMA node,
    DS4_COPY_NUMA=1, experts read from the files, or no pinned copy.
  • On a one-node machine the default path is therefore the old one. I checked this by reading the code: the new
    branch runs only when copy_mode && NH > 1. A run also checked it: the new binary with one part gives the same
    32 tokens as the old binary (below).
  • On a two-node machine the default path changes, because that path is the bug.
  • A two-part item now takes two to four DMA calls per matrix instead of one. Prompt speed was 941.3 vs
    947.7 tok/s (two parts vs one, one run each). I make no speed claim.

Validation

Environment:

Code 36278a0c (this branch) on c62d5e3a (main)
OS AlmaLinux 9.3, kernel 7.0.1
CPU and RAM 2 × AMD EPYC 9354 (2 NUMA nodes, 128 threads), 1 TB RAM
GPU NVIDIA A100 80GB PCIe, driver 595.58.03, CUDA 13.2
Build GCC 12.2.1 (gcc-toolset-12), Release, STRATA_BUILD_DSV41=ON, CMAKE_CUDA_ARCHITECTURES=native (sm_80)
Model DeepSeek-V4.1-Flash IST-DAS 2.25bpw pack. 7,699 CPU-lane experts copied into RAM (74.7 GB, 2 NUMA parts) and pinned

Each run used this command, with the one-part and two-part copies chosen by DS4_COPY_NUMA:

DS4_COPY_NUMA=<1|2> strata-dsv41 --pack <pack> --max-context <8192|1048576> --eos 1 --vision on \
  --dspark auto --dspark-conf 0.65 --ids "0,<300 or 20000 fixed token ids>" --n 32

Passed:

  • Build: cmake --build build-dsv41 --target strata-dsv41 (CUDA, sm_80).

  • The crash is gone. One run each:

    Binary Parts Context Prompt tokens Result Prompt tok/s Decode tok/s
    old (c62d5e3a) 2 8K 301 illegal memory access, exit 1 – –
    new 2 8K 301 ok 103.35 41.49
    new 1 8K 301 ok 104.49 41.64
    new 1 8K 301 ok (repeat) 104.71 41.79
    old (c62d5e3a) 1 8K 301 ok 104.01 41.48
    new 2 1M 20,001 ok 941.30 39.10
    new 1 1M 20,001 ok 947.72 39.00
  • The 32 generated tokens:

    • New with one part = old with one part: identical. The one-part path is unchanged.
    • New with one part, two runs: identical.
    • New with two parts = new with one part, 20,001-token prompt at 1M: identical.
    • New with two parts vs new with one part, 301-token prompt: the first 28 tokens are identical, then they differ.
      See the run-to-run note under Limits.
  • Per-layer prompt residuals (DS4_DUMP_L). New binary, 301-token prompt, 8K context, four runs (two with one
    part, two with two parts):

    • Two parts (run B) vs one part (run A): all 80 prompt records are byte-identical. cmp of the two dump
      files finds no difference, and neither has NaN.
    • Two parts (run A) vs one part (run A): byte-identical through layer 19. That covers layers 3 to 19, where the
      old binary read wrong rows and layer 8 gave NaN. Differences start at layer 20 (4.8e-7 in 31 of 301 rows) and
      grow to 1063 at layer 39.
    • One part (run A) vs one part (run B): the first difference is at layer 11 (2.4e-7 in 9 of 301 rows). It grows
      to 7403 at layer 39.

    So two parts differ from one part no more than two one-part runs differ from each other, and one two-part run
    matches a one-part run byte for byte. Wrong rows would have given NaN at layer 8.

  • python -m pytest tests/terminal/test_dsv41_context.py (it reads ds4_model.cu): 12 passed, 1 skipped.

Failed:

None observed with this change. One existing behaviour is noted under Limits.

Not run:

  • HIP build and run: this machine has no ROCm. The new code uses only cudaMemcpyAsync and cudaMemcpy2DAsync,
    which this file already uses on the same path. Still unverified.
  • Metal build: I have no Mac. metal/CMakeLists.txt compiles ds4_model.cu, and its shim defines both calls. A
    Mac is one node, so its default is one part and the old path. Unverified.
  • SYCL: not built. From reading the CMake files, no SYCL target compiles ds4_model.cu.
  • Windows: not run.
  • Tensor parallel over several GPUs (nm > 1): I have one GPU. The nm > 1 parts of dma_parts never ran (the
    member's gate and up rows cut at the part boundary, and the down's 2D copy per part).
  • DS4_COPY_NUMA=2 on a one-node machine: not run. From reading the code it should reproduce the bug and the fix
    there.
  • More than two NUMA nodes: not run. NH is capped at 2, so it is the same code path.
  • The server (strata launch / serve) with the fixed engine: not run. Only the engine alone.
  • Other packs (2.00bpw, Unsloth, Gyro), and prompts longer than 20,001 tokens: not run.
  • Repeated speed runs: one run each, so there is no speed claim.

Limits

  • Run-to-run differences (existing, cause not found). On this machine the prompt pass is not reproducible bit
    for bit between runs, even with one part:

    • Two one-part runs of the same binary differ from layer 11 or later, and the differences grow through the layers.
    • With --dump-logits (the window path, which this change does not touch), the logits of the old and new
      binaries with one part differ too.

    This is why a two-part and a one-part run can pick different tokens after many identical ones. I did not look
    for the cause. It is outside this change.

  • route_kernel still reads out of bounds when every score is NaN. This PR does not change it (see #4825).

🤖 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/Niko1221/Strata/pull/4969 **Author:** [@yazun](https://github.com/yazun) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/dsv41-numa-pinned-dma` --- ### 📝 Commits (1) - [`36278a0`](https://github.com/Niko1221/Strata/commit/36278a0c228a9bec4b92bf42bd80924c35d34cb3) [Engine] dsv41: the chunked prompt pass DMAs a pinned expert copy from every NUMA part ### 📊 Changes **1 file changed** (+40 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `src/dsv41/ds4_model.cu` (+40 -0) </details> ### 📄 Description ## Problem and result On a machine with two NUMA nodes, DeepSeek V4.1 crashed on the first prompt of 96 tokens or more: ```text maya-ds4: cudaStreamSynchronize(s): an illegal memory access was encountered ``` The first report came through the server, with a 20,053-token prompt at a 1M context. It also happens with the engine alone and a 301-token prompt at an 8K context. **Cause.** With two NUMA nodes the engine keeps its RAM copy of the CPU lane's experts in two parts. Part X holds rows `[X n / 2, ..)` of each matrix, at `cp_lay` (`ram_to_blob` puts them back together). The staging pump and `stream_expert` read both parts. But the chunked prompt pass DMAs a *pinned* copy straight from RAM, and it took every matrix from part 0 only. So the second half of each gate, up and down matrix came from the wrong bytes. What that did, in the per-layer dumps (`DS4_DUMP_L`) of the old binary: - Layers 3 to 7 (all IQ2_XXS) gave wrong but finite values. - Layer 8, the first with an IQ2_S down, gave NaN. - The router of the next layer then read out of bounds. All-NaN scores leave its pick at `0x7fffffff`. compute-sanitizer (memcheck) reported: ```text Invalid __shared__ read of size 4 bytes at strata::ds4::<unnamed>::route_kernel(...)+0x1750 Access to 0xfffffffc is out of bounds ``` **When it happens.** All three must hold: 1. The CPU lane's experts are copied into RAM and pinned. This is the default when they fit: the log says "copied into RAM (…, 2 NUMA parts)" and "the copied experts pinned … the prompt path DMAs them in place". 2. The copy is in two parts. That means two NUMA nodes, with `ff / 2` and `dim / 2` multiples of 128. 3. The prompt takes the chunked pass (96 tokens or more). Until now the workaround was `DS4_COPY_NUMA=1`. **After this change** the crash is gone. The two-part run gives the same prompt pass as the one-part run (below). The one-part path is unchanged. ## Related discussion None needed. This is a focused fix. - #4825: on Strix Halo a NaN in the chunked prompt pass also reached `route_kernel`, from another cause (the Q6_K dequant staging). There the maintainer said a router change that stops a NaN from becoming an out-of-bounds read is being tested. That change would turn this crash into wrong output. This PR fixes where the NaN comes from on a two-node host and leaves the router alone. Strix Halo has one NUMA node, so this bug does not explain the faults reported there. - #4016 (NUMA bands) changes the same copy layout (`ram_part`, `cp_lay`). Its diff does not touch the pinned DMA branch in `flow_push`. If it lands, its band layout would need the same per-part DMA. This PR covers the current two-part layout only. ## Approach - `flow_push`: in copy mode with `NH > 1`, a pinned item records its copy's slot (`Item::cs`). It no longer stores three pointers into part 0, because no single pointer can hold a matrix split over two parts. - New `dma_parts`: copies such an item into its ring slot from both parts. It puts the same bytes in the same places as the one-part path: - Gate and up: the rows this device takes (`[a, b)`; all rows when alone), cut at the part boundary. One copy per part that holds some of them. - Down: each part's rows. With tensor parallel (`nm > 1`) it copies the member's blocks of every row, with one `cudaMemcpy2DAsync` per part. - The DMA loop counts it as one DMA, as before: the `ring_fill` event, `n_dma` and `stream_bytes`. Compatibility: - With one part, `it.cs` stays `-1` and the old code runs unchanged. One part means one NUMA node, `DS4_COPY_NUMA=1`, experts read from the files, or no pinned copy. - On a one-node machine the default path is therefore the old one. I checked this by reading the code: the new branch runs only when `copy_mode && NH > 1`. A run also checked it: the new binary with one part gives the same 32 tokens as the old binary (below). - On a two-node machine the default path changes, because that path is the bug. - A two-part item now takes two to four DMA calls per matrix instead of one. Prompt speed was 941.3 vs 947.7 tok/s (two parts vs one, one run each). I make no speed claim. ## Validation Environment: | | | |---|---| | Code | `36278a0c` (this branch) on `c62d5e3a` (main) | | OS | AlmaLinux 9.3, kernel 7.0.1 | | CPU and RAM | 2 × AMD EPYC 9354 (2 NUMA nodes, 128 threads), 1 TB RAM | | GPU | NVIDIA A100 80GB PCIe, driver 595.58.03, CUDA 13.2 | | Build | GCC 12.2.1 (gcc-toolset-12), Release, `STRATA_BUILD_DSV41=ON`, `CMAKE_CUDA_ARCHITECTURES=native` (sm_80) | | Model | DeepSeek-V4.1-Flash IST-DAS 2.25bpw pack. 7,699 CPU-lane experts copied into RAM (74.7 GB, 2 NUMA parts) and pinned | Each run used this command, with the one-part and two-part copies chosen by `DS4_COPY_NUMA`: ```sh DS4_COPY_NUMA=<1|2> strata-dsv41 --pack <pack> --max-context <8192|1048576> --eos 1 --vision on \ --dspark auto --dspark-conf 0.65 --ids "0,<300 or 20000 fixed token ids>" --n 32 ``` **Passed:** - Build: `cmake --build build-dsv41 --target strata-dsv41` (CUDA, sm_80). - The crash is gone. One run each: | Binary | Parts | Context | Prompt tokens | Result | Prompt tok/s | Decode tok/s | |---|---|---|---|---|---|---| | old (`c62d5e3a`) | 2 | 8K | 301 | illegal memory access, exit 1 | – | – | | new | 2 | 8K | 301 | ok | 103.35 | 41.49 | | new | 1 | 8K | 301 | ok | 104.49 | 41.64 | | new | 1 | 8K | 301 | ok (repeat) | 104.71 | 41.79 | | old (`c62d5e3a`) | 1 | 8K | 301 | ok | 104.01 | 41.48 | | new | 2 | 1M | 20,001 | ok | 941.30 | 39.10 | | new | 1 | 1M | 20,001 | ok | 947.72 | 39.00 | - The 32 generated tokens: - New with one part = old with one part: identical. The one-part path is unchanged. - New with one part, two runs: identical. - New with two parts = new with one part, 20,001-token prompt at 1M: identical. - New with two parts vs new with one part, 301-token prompt: the first 28 tokens are identical, then they differ. See the run-to-run note under Limits. - Per-layer prompt residuals (`DS4_DUMP_L`). New binary, 301-token prompt, 8K context, four runs (two with one part, two with two parts): - Two parts (run B) vs one part (run A): **all 80 prompt records are byte-identical.** `cmp` of the two dump files finds no difference, and neither has NaN. - Two parts (run A) vs one part (run A): byte-identical through layer 19. That covers layers 3 to 19, where the old binary read wrong rows and layer 8 gave NaN. Differences start at layer 20 (4.8e-7 in 31 of 301 rows) and grow to 1063 at layer 39. - One part (run A) vs one part (run B): the first difference is at layer 11 (2.4e-7 in 9 of 301 rows). It grows to 7403 at layer 39. So two parts differ from one part no more than two one-part runs differ from each other, and one two-part run matches a one-part run byte for byte. Wrong rows would have given NaN at layer 8. - `python -m pytest tests/terminal/test_dsv41_context.py` (it reads `ds4_model.cu`): 12 passed, 1 skipped. **Failed:** None observed with this change. One existing behaviour is noted under Limits. **Not run:** - HIP build and run: this machine has no ROCm. The new code uses only `cudaMemcpyAsync` and `cudaMemcpy2DAsync`, which this file already uses on the same path. Still unverified. - Metal build: I have no Mac. `metal/CMakeLists.txt` compiles `ds4_model.cu`, and its shim defines both calls. A Mac is one node, so its default is one part and the old path. Unverified. - SYCL: not built. From reading the CMake files, no SYCL target compiles `ds4_model.cu`. - Windows: not run. - Tensor parallel over several GPUs (`nm > 1`): I have one GPU. The `nm > 1` parts of `dma_parts` never ran (the member's gate and up rows cut at the part boundary, and the down's 2D copy per part). - `DS4_COPY_NUMA=2` on a one-node machine: not run. From reading the code it should reproduce the bug and the fix there. - More than two NUMA nodes: not run. `NH` is capped at 2, so it is the same code path. - The server (`strata launch` / `serve`) with the fixed engine: not run. Only the engine alone. - Other packs (2.00bpw, Unsloth, Gyro), and prompts longer than 20,001 tokens: not run. - Repeated speed runs: one run each, so there is no speed claim. ## Limits - **Run-to-run differences (existing, cause not found).** On this machine the prompt pass is not reproducible bit for bit between runs, even with one part: - Two one-part runs of the same binary differ from layer 11 or later, and the differences grow through the layers. - With `--dump-logits` (the window path, which this change does not touch), the logits of the old and new binaries with one part differ too. This is why a two-part and a one-part run can pick different tokens after many identical ones. I did not look for the cause. It is outside this change. - `route_kernel` still reads out of bounds when every score is NaN. This PR does not change it (see #4825). 🤖 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>
Sign in to join this conversation.
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
Niko1221/Strata#5271
No description provided.