Skip to content

Eval bug: qwen4exp (Qwen3.8-Flash-Next) aborts with CUDA invalid argument at the native 262144 depth on GB10 (sm_121) #27871

Closed as not planned

Description

@adamlawi

Name and Version

$ llama-cli --version
version: 0.3.0-dev (build 1, commit d077b4c)
built with GNU 13.3.0 for Linux aarch64

Also reproduced on the pre-merge PR #27742 branch at 035e2273.

Operating systems

Linux

GGML backends

CUDA

Hardware

NVIDIA DGX Spark (GB10, compute capability 12.1 / sm_121), aarch64, 121 GiB unified memory, Ubuntu 24.04.4.
CUDA toolkit 13.0 (nvcc 13.0.88), driver 580.173.02 — toolkit matches driver (this matters for this arch; see the toolkit/driver reports in #27742).

Models

unsloth/Qwen3.8-Flash-Next-GGUF — UD-IQ1_S (67.55 GiB) and UD-IQ3_XXS (76.32 GiB). Both reproduce identically.

Problem description & steps to reproduce

qwen4exp aborts at kernel launch when the KV depth reaches the model's native context_length of 262144. No YaRN, no context extension, no --override-kv.

llama-bench -m Qwen3.8-Flash-Next-UD-IQ1_S-00001-of-00003.gguf \
  -ngl 999 -fa 1 -lm none -r 1 -v -p 512 -n 128 -d 0,32768,131072,262144

Depths 0, 32768 and 131072 complete normally; the 262144 point aborts:

depth pp512 (t/s) tg128 (t/s)
0 788.09 37.12
32768 549.96 23.98
131072 259.65 11.18
262144 abort abort

A prior report of the same failure exists inside PR #27742 (by @hyungraekim-bagelcode, on an ASUS Ascent GX10 — also GB10/sm_121), reached via YaRN-extended context. That thread is now closed and locked, so filing here: the abort also occurs at the native boundary with no rope scaling, and it is present in master after the merge.

First Bad Commit

Not bisected. Present both at PR #27742 035e2273 and at master d077b4c21466 (post-merge), so it is not a regression introduced by the merge.

Relevant log output

CUDA error: invalid argument
  current device: 0, in function ggml_cuda_kernel_launch at ggml/src/ggml-cuda/common.cuh:1668
  cudaLaunchKernelEx(&pdl_cfg.cfg, kernel, std::forward<Args>(args)... )
ggml/src/ggml-cuda/ggml-cuda.cu:107: CUDA error

Backtrace (default build):

#3  ggml_cuda_error(...)
#4  rms_norm_mul_f32_cuda(...)
#5  ggml_cuda_op_rms_norm_fused(ggml_backend_cuda_context&, ggml_tensor*, ggml_tensor*)
#6  ggml_cuda_try_fuse(ggml_backend_cuda_context*, ggml_cgraph*, int)
#7  ggml_backend_cuda_graph_compute(ggml_backend*, ggml_cgraph*)
#8  ggml_backend_sched_graph_compute_async()
#9  llama_context::graph_compute(ggml_cgraph*, bool)

What was ruled out

  • Not OOM. A 2-second memory sampler ran throughout every attempt; minimum available unified memory was 20, 25, 29 and 34 GiB across four runs. No out of memory, no failed cudaMalloc in any log.
  • Not the fusion path. With GGML_CUDA_DISABLE_FUSION=1 the abort persists, and the backtrace changes to the unfused path — same error, same depth:
    #4  rms_norm_f32_cuda(...)
    #5  ggml_cuda_op_rms_norm(ggml_backend_cuda_context&, ggml_tensor*)
    #6  ggml_backend_cuda_graph_compute(ggml_backend*, ggml_cgraph*)      <- no try_fuse frame
    
  • Not PDL. With GGML_CUDA_PDL=0 the abort persists and moves to the classic launch path — common.cuh:1674, statement cudaGetLastError(), same invalid argument. So both launch mechanisms reject the same configuration, which points at the launch configuration itself rather than at cudaLaunchKernelEx.
  • Not quantization. Identical on UD-IQ1_S and UD-IQ3_XXS.

Possible cause (not verified)

rms_norm_f32_cuda (ggml/src/ggml-cuda/norm.cu) builds its grid as:

const dim3 blocks_num(nrows, nchannels, nsamples);

grid.y and grid.z are limited to 65535 on CUDA (only grid.x is 2³¹−1), and an over-limit dimension is exactly what makes a launch fail with invalid argument on both launch APIs. That would also explain why the failure is a hard step rather than a gradual degradation.

Scope of this report: I did not instrument the build, so I do not have the actual nrows/nchannels/nsamples at the failing launch, and I did not bisect the exact threshold between 131072 and 262144. The grid-dimension explanation above is a hypothesis consistent with the evidence, not something I verified.

Activity

  1. dragosbas commented on Aug 28, 2026

    @dragosbas

    Your hypothesis is correct, and I can confirm it with a threshold measurement from the two-stream side of the same bug. Full analysis in #27835 (comment 5454764836); short version here since your report is the n_stream == 1 case.

    The offending tensor is built at src/models/qwen4exp.cpp:552:

    pooled = ggml_reshape_3d(ctx0, pooled, idx_dim, 1, n_blocks*n_stream);
    pooled = build_norm(pooled, model.layers[il].index_k_norm, nullptr, LLM_NORM_RMS, il);

    n_blocks*n_stream lands in ne[2], which norm.cu:353 (and :307 for the unfused path, which is why your GGML_CUDA_DISABLE_FUSION=1 test still aborted) maps onto gridDim.y, capped at 65535.

    With n_blocks = ceil(n_kv / r) and r = 4 from qwen4exp.attention.compress_ratios, a single stream overflows at n_kv >= 262144 exactly — which is the boundary you and the reporter in #27742 both hit at the native context depth. n_stream is per-ubatch (llama_memory_hybrid_idx_context::get_n_stream() returns sinfo.s1 - sinfo.s0 + 1), so with two concurrent slots the same limit arrives at n_kv > 131068.

    I reproduced that two-stream threshold on 2x RTX 3090 and got the control for free inside one run: two slots sharing a ubatch at n_kv = 116 803 completed normally, the same pair at n_kv = 138 982 aborted 170 ms later. ceil(116803/4)*2 = 58 402 versus ceil(138982/4)*2 = 69 492.

    The two-line fix in #27835 (normalize before the reshape, so the large count goes to gridDim.x) removes your case as well, since it never puts n_blocks on the limited axis. Validated here: 6/6 concurrent requests served with the deep slot decoding at n_kv = 144 701.

  2. pentar69 commented on Aug 30, 2026

    @pentar69

    Independent reproduction on sm_86 (1× RTX 3090, CUDA 12.8.1, driver 595.84), master at 62acc89c — different arch and toolkit from both existing reports, single stream (-np 1).

    UD-IQ4_XS, -ngl 999 --n-cpu-moe 48 -ub 1024 -fa on -ctk q8_0 -ctv q8_0, YaRN ×2 + --override-kv qwen4exp.context_length=int:524288 (512K slot allocates at 20.7 GiB). A ~320K-token prefill aborts deterministically (two runs, 1698 s / 1707 s) on the ubatch crossing exactly 262144 — last print_timing line is n_tokens = 261120:

    ggml-cuda.cu:107: CUDA error
    E CUDA error: invalid configuration argument
    E   current device: 0, in function ggml_cuda_kernel_launch at ggml/src/ggml-cuda/common.cuh:1676
    E   cudaGetLastError()
    ...
    ggml_cuda_op_rms_norm_fused(ggml_backend_cuda_context&, ggml_tensor*, ggml_tensor*)
    ggml_backend_sched_graph_compute_async
    

    Supporting the n_blocks threshold analysis above: raising context_length via --override-kv does not move the crash point — it still fires at 262144, so the trigger is the size threshold, not n_ctx_train logic. Full server log available on request.

  3. anhyeuviolet commented on Sep 1, 2026

    @anhyeuviolet

    I hit the same crash on a different Blackwell part and instrumented the launch, so here are the actual grid numbers.

    Hardware: 2x RTX PRO Blackwell (5000 48GB + 4500 32GB), cc 12.0, driver 580
    open, CUDA 13.0.1, Ubuntu 22.04. Model is Qwen3.8-Flash-Next UD-Q2_K_XL,
    -c 1048576 --parallel 4 (262144 per slot), --cache-type-k/v q8_0.

    Confirming your PDL finding: GGML_CUDA_PDL=0 does not help here either. It only moves the abort from common.cuh:1668 (the cudaLaunchKernelEx path) to common.cuh:1674 (the plain <<<>>> path). Same function, same message, so the launch configuration itself is what gets rejected.

    The numbers. I patched norm.cu to print the grid right before the launch whenever a dimension is over the limit. Two crashes, both in
    rms_norm_mul_f32_cuda:

    grid=(x=1, y= 88320, z=1)  ncols=128     <- context around 129k tokens
    grid=(x=1, y=110336, z=1)  ncols=128     <- context around 220k tokens
    

    The print and the abort land in the same log second and the same PID, so this is the launch that fails. Your grid-dimension hypothesis is correct: y is the one over 65535, z is fine, and x is sitting at 1 while it could go to 2^31-1.

    Two things worth noting:

    • y grows with context length, it is not a fixed function of the configured n_ctx. That is why the crash is not immediate — it needs enough context to push nchannels past 65535. On our box that works out to roughly 80-95k tokens, and a user independently reported the failure at ~30% of a 262k window, which matches.
    • Lowering -ub does not avoid it. I tried -ub 256 and y still reached 110336, so the channel count does not track the micro-batch size.

    Reproducer. One slot prefilling a very long prompt while other slots send short requests. Single-slot runs are fine — I pushed 160912 tokens through one slot with no trouble. That lines up with #27911, where -np 1 is unaffected.

    A fix that works for us. The kernels take nchannels from gridDim.y and the channel index from blockIdx.y, so the channel dimension can be split into chunks of at most 65535 as long as the kernel can still compute the global channel index. Pointer arithmetic alone is not enough — it breaks the dst offset (which multiplies by nchannels) and the fastmodulo broadcast indices for mul/add.

    What I did instead, in norm_f32, rms_norm_f32 and l2_norm_f32, was add two trailing parameters:

    const int ch_base = 0, const int nch_all = 0
    ...
    const int nchannels = nch_all ? nch_all : (int) gridDim.y;
    const int channel   = ch_base + (int) blockIdx.y;

    and wrap each of the four host helpers in a loop over channel chunks, passing ch0 and the true nchannels. When nothing is over the limit there is exactly one chunk with ch_base = 0, so the existing path is unchanged.

    Results on our box:

    • test-backend-ops -o RMS_NORM 51/51, plus NORM and L2_NORM passing.
    • The concurrent reproducer that used to abort within 90 seconds now completes 4/4 requests, 220914 tokens, zero restarts.
    • Prefill throughput went from ~745 to ~796 tok/s, so the chunking is not costing anything measurable at these sizes.
    • A needle test with three markers planted at the start, middle and end of a ~200k-token prompt comes back with all three, so the split is not corrupting channel indices.

    I am not opening a PR since this is a workaround shaped around our own build, but happy to share the diff or test a proper patch on this hardware if that helps.

  4. github-actions commented on Oct 16, 2026

    @github-actions
    Contributor

    This issue was closed because it has been inactive for 14 days since being marked as stale.

  5. adamlawi commented on Oct 16, 2026

    @adamlawi
    Author

    For the record, since this was closed as stale: the bug is fixed in master by #27941 (36b101543, merged 2026-09-01). build_qsa_top_k in src/models/qwen4exp.cpp now applies build_norm before ggml_reshape_3d, so the block count goes to ne1 instead of gridDim.y. That is the change @dragosbas described above.

    On our side, a prefill on a CUDA build after the fix went past the threshold (264192 tokens) without the abort. That run was on a different CUDA host, not the GB10 from the original report, and I haven't re-run it on sm_121.

    The "not planned" label is only the stale bot. This was fixed (completed), but I don't have permission to change the close reason.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions