Skip to content

Eval bug: dsv4 CUDA race — illegal memory access with REAP-pruned DeepSeek-V4-Flash (144 experts) on GB10/sm_121; works with CUDA_LAUNCH_BLOCKING=1 #26588

Closed as duplicate

Description

@ioseobcn

Name and Version

version: b10269 (1c3c967), built from master (2026-08-04) with -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=121

Operating systems

Linux (DGX Spark / GB10, aarch64, kernel 6.17.0-1029-nvidia, driver 580.173.02, CUDA 13.1)

Which llama.cpp modules do you know to be affected?

llama-cli, llama-server (CUDA backend, DeepSeek V4 / dsv4 path)

Problem description & steps to reproduce

Running a REAP expert-pruned DeepSeek-V4-Flash (144 routed experts instead of 256; checkpoint 0xSero/DeepSeek-V4-Flash-162B, converted with current convert_hf_to_gguf.py) crashes with CUDA error: an illegal memory access was encountered (ggml/src/ggml-cuda/ggml-cuda.cu:106) at the first generated token. Model load always completes fine.

Key finding: with CUDA_LAUNCH_BLOCKING=1 the model generates correctly (coherent output, 16.1 t/s decode on GB10), which points to a race condition in the async dsv4 CUDA path rather than a miscomputing kernel.

Isolation matrix (each ~7 min load cycle on this machine):

Config Result
KV f16 / q8_0 (both) ❌ same crash
GGML_CUDA_DISABLE_GRAPHS=1 ❌
GGML_CUDA_DISABLE_FUSION=1 ❌
experts as native MXFP4 / requantized Q4_K_M ❌ both
CUDA_LAUNCH_BLOCKING=1 ✅ generates correctly
CPU backend ✅ loads clean (no CUDA)

Also checked:

  • ffn_gate_tid2eid routing tables are consistent (indices 0–143, i32, matching deepseek4.expert_count=144).
  • topk-moe fusion is correctly skipped for n_expert=144 (non-power-of-2 guard in ggml_cuda_should_use_topk_moe), so the fused topk path is not the culprit.
  • Unpruned V4-Flash (256 experts) has been reported working on DGX Spark by others with recent master, so the async bug seems related to the non-standard expert count (144) — possibly mul_mat_id or the lightning-indexer path interacting across streams.

Repro:

./build-v4/bin/llama-cli -m v4-flash-162b-Q4_K_M.gguf -ngl 99 -c 4096 -st -n 20 -p "Hola"
# crashes at first token; prefix CUDA_LAUNCH_BLOCKING=1 and it generates fine

(Unrelated checkpoint note, in case someone else converts this model: the 0xSero source checkpoint ships one corrupted embedding row — token 47503, values ~1e26 — which makes llama-quantize fail validation with "found inf value"; grafting the row from the official deepseek-ai/DeepSeek-V4-Flash shard fixes it. The crash reported here happens with or without that fix.)

First Bad Commit

No response

Relevant log output

/home/.../llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu:106: CUDA error
E CUDA error: an illegal memory access was encountered
(backtrace points into generate_completion; crash timing is at first decode step)

Activity

  1. sama6486 commented on Aug 4, 2026

    @sama6486
  2. ioseobcn commented on Aug 4, 2026

    @ioseobcn
    Author

    Additional data points:

    • The community fork cdome94/llama.cpp-deepseek-v4-flash (CUDA-fix branch over antirez's tree) crashes identically in async mode — three codebases now (master b10269, antirez fork, cdome94 fork), same failure.
    • Timing refinement: model load and warmup always complete fine (warmup does prefill-style forward passes). The crash is precisely at the first decode token (batch size 1). The batch=1 path goes through the MoE vector kernels (mmvq-style / fused MoE vec) which prefill never exercises — so the race is likely in the batch-1 MoE mul_mat_id path with the non-standard expert count (144), not in the batched path.
    • CUDA_LAUNCH_BLOCKING=1 remains a full workaround (correct generation, 16.1 t/s decode on GB10).
  3. ioseobcn commented on Aug 4, 2026

    @ioseobcn
    Author

    Pinpointed. A longer multi-turn run (llama-cli, CUDA_LAUNCH_BLOCKING=1, -c 16384) finally crashed with the failing function identified:

    E CUDA error: an illegal memory access was encountered
    E   current device: 0, in function ggml_cuda_mul_mat_q at ggml/src/ggml-cuda/mmq.cu:239
    E   cudaGetLastError()
    

    So this is the MMQ path (ggml_cuda_mul_mat_q), which both MXFP4 and Q4_K experts go through — consistent with the crash being independent of the expert quant format. Shape-dependence (prompt length / batch size) would also explain why short prompts sometimes survive and why CUDA_LAUNCH_BLOCKING=1 looked like a workaround at first (it isn't reliable — it merely changes timing).

    Possibly relevant context: n_expert=144 (REAP-pruned), so mul_mat_id feeds MMQ with a non-standard expert count; GB10/sm_121, CUDA 13.1, gcc 13.3. Now testing GGML_CUDA_FORCE_CUBLAS=1 as a workaround and will report back.

  4. ioseobcn commented on Aug 4, 2026

    @ioseobcn
    Author

    Ruled out local miscompilation: did a from-scratch rebuild of all ggml-cuda objects (-j2, zero compiler warnings/ICEs this time — the original build had had a gcc ICE on mmq.cu that made me suspicious) and the crash reproduces identically with the clean binaries (ggml_cuda_mul_mat_q, first decode / long-prompt prefill).

    Also note GGML_CUDA_FORCE_CUBLAS=1 does NOT avoid it — the MoE mul_mat_id path still goes through MMQ (launch_mul_mat_q at mmq.cuh:1401, cudaFuncSetAttribute), so for MoE models there is no runtime flag to dodge this kernel.

    Next: testing the official .devops/spark.Dockerfile build (NGC toolchain) to discriminate upstream bug vs host CUDA toolchain (13.1, gcc 13.3, driver 580.173.02).

  5. ioseobcn commented on Aug 4, 2026

    @ioseobcn
    Author

    Toolchain ruled out too: built the same commit (b10269) inside an NGC container (CUDA 13.0.1, gcc 14, .devops/cuda.Dockerfile with CUDA_DOCKER_ARCH=121) — crashes identically (ggml-cuda.cu:106, illegal memory access) on the first long-prompt request in server mode.

    Summary of the full elimination matrix: 2 toolchains × 3 codebases × clean rebuild × {MXFP4, Q4_K_M} × {KV f16/q8} × {graphs on/off, fusion on/off, FORCE_CUBLAS} — all crash in ggml_cuda_mul_mat_q; CPU backend loads fine. This is a genuine bug in the MMQ path for this model shape (DeepSeek-V4-Flash REAP-pruned to n_expert=144) on sm_121. Happy to test patches — this machine reproduces it deterministically with long prompts.

  6. fairydreaming commented on Aug 4, 2026

    @fairydreaming
    Contributor

    @ioseobcn hint: check tid2eid array for duplicated expert indices.

  7. ioseobcn commented on Aug 4, 2026

    @ioseobcn
    Author

    ROOT CAUSE FOUND AND FIXED (data-side). Not a race condition after all — apologies for the earlier framing.

    The pruned checkpoint's static routing tables (blk.{0,1,2}.ffn_gate_tid2eid.weight, token→6-experts) contained duplicate expert ids within a single token's list (~3k tokens per layer, e.g. token 38 → [121, 121, 62, 31, 65, 5]) — an artifact of the third-party 256→144 REAP remap. When a batch contains one of those tokens, the MoE ids path (ggml_cuda_launch_mm_ids_helper → quantize_scatter_mmq_q8_1_cuda, which assumes unique experts per token slot) produces a colliding inverse map → illegal memory access in ggml_cuda_mul_mat_q.

    This explains every symptom: prompt-content dependence (crash only when a duplicated token is present — short "Hola" survived, long Spanish prompts didn't), independence from quant format/toolchain/codebase, and why CUDA_LAUNCH_BLOCKING merely shifted timing.

    After deduplicating the tables in the GGUF (replacing duplicate slots with distinct experts), the model runs clean in fully async mode on GB10: prefill 62-150 t/s, decode 15.5 t/s, all long prompts pass.

    Suggested upstream hardening: mm_ids_helper (or a load-time check for arches with static routing tables) could validate/deduplicate ids defensively — a malformed table shouldn't surface as an illegal memory access. Happy to open a PR if there's interest in either the validation or a graceful-degradation approach.

  8. underlines commented on Aug 5, 2026

    @underlines

    Reproduced this on a different card and quant, might be useful signal.

    -- disclosure: claude slop follows (but i verified manually) --

    Model: heath0xFF/DeepSeek-V4-Flash-0731-REAP-K216-GGUF (216/256 routed experts retained, i.e. also non-power-of-2, built from the unsloth/DeepSeek-V4-Flash-0731-GGUF UD-IQ3_XXS quant + a REAP expert map applied post-quantization).

    Hardware: NVIDIA RTX PRO 6000 Blackwell Workstation Edition (discrete, not GB10), driver 595.71.05, compute capability 12.0 (sm_120), CUDA via Docker (ghcr.io/mostlygeek/llama-swap:unified-cuda, image pulled 2026-08-04, llama-server binary dated 2026-08-04 09:14 UTC — first build we had with deepseek4 arch support).

    Command: llama-server -ngl 999 -np 1 --split-mode none --main-gpu 0 --flash-attn on -c 131072 -b 1024 -ub 512 --cache-type-k q8_0 --cache-type-v q8_0 --jinja (mmap enabled, host RAM-constrained so --no-mmap wasn't used).

    Result: Model loads fine (full CUDA offload, ~85GB VRAM), crashes on the first decoded token every time. dmesg/journalctl -k shows:

    NVRM: Xid (PCI:0000:01:00): 31, pid=..., name=llama-server, channel 0x00000003, intr 00000000. MMU Fault: ENGINE GRAPHICS GPC1 GPCCLIENT_T1_12 faulted @ 0x22_e8606000. Fault is of type FAULT_PDE ACCESS_TYPE_VIRT_WRITE
    

    Reproduced twice with identical fault address both times (0x22_e8606000):

    • Without CUDA_LAUNCH_BLOCKING=1: crash ~98s in (first decode step)
    • With CUDA_LAUNCH_BLOCKING=1: crash ~85s in, same fault address/type

    So on this hardware/quant combo, CUDA_LAUNCH_BLOCKING=1 did not work around the crash, unlike the original GB10 report. The identical repeatable fault address across two independent runs (rather than varying, as you'd expect from a pure timing-dependent race) makes me wonder if there's also a deterministic out-of-bounds/indexing component here, possibly specific to certain non-standard expert counts or this particular REAP conversion path, on top of (or instead of) the async race — happy to help narrow it down further if useful (e.g. CUDA_LAUNCH_BLOCKING + compute-sanitizer, or testing the unpruned 256-expert quant for comparison).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions