llama.cpp icon indicating copy to clipboard operation
llama.cpp copied to clipboard

Eval bug: CUDA: ADD_ID fails with more than 65535 tokens (invalid configuration argument)

Open fox5611 opened this issue 2 weeks ago • 3 comments

Name and Version

master 3549c274d

Operating systems

Linux

GGML backends

HIP, CUDA

Hardware

AMD Radeon RX 9060 XT (gfx1200), ROCm 7.1.1

Models

N/A, reproduced with test-backend-ops

Problem description & steps to reproduce

ADD_ID fails to launch when the token count exceeds 65535. No model is required.

Add one case to the add_id section of tests/test-backend-ops.cpp:

test_cases.emplace_back(new test_add_id(GGML_TYPE_F32, GGML_TYPE_F32, 32, 4, 2, 70000));

Then run:

./build/bin/test-backend-ops -o ADD_ID

Cause: add-id.cu:50 builds the grid as dim3 blocks(ne01, ne02), where ne02 is the token count, and gridDim.y is capped at 65535.

Scope: this is not hardware-specific. The same cap applies on NVIDIA, and add-id.cu builds for both backends. The existing ADD_ID cases top out at n_token=129, so nothing has ever exercised this. add-id.cu is the only grid in ggml-cuda that takes y or z from a tensor dimension with no clamp, assert, or dispatch bound.

Precedent: the clamp-plus-stride pattern already exists in convert.cu (#19999), pad.cu (#30147) and getrows.cu (#25103, #15882).

I have a fix written and verified: the 70000-token case passes and the existing 37 cases still pass. Should this shape be supported, or should ADD_ID assert instead? If supporting it is right, I will open a PR.

First Bad Commit

Not a regression. add-id.cu has three commits total: fd1234cb4 (llama : add gpt-oss (#15091)) which introduced the file, a MUSA build-warning fix, and my local fix. The unclamped grid has been there since ADD_ID was added in #15091.

Relevant log output

ggml_cuda_compute_forward: ADD_ID failed
ROCm error: invalid configuration argument
  current device: 0, in function ggml_cuda_compute_forward at ggml/src/ggml-cuda/ggml-cuda.cu:3065

fox5611 avatar Nov 17 '26 00:11 fox5611

Reproduces on NVIDIA. RTX 5070, cc 12.0, driver 595.99.02, CUDA 13.1.115, Ubuntu 26.04.1, llama.cpp 8d60873df built Release with GGML_CUDA=ON and arch 120.

I added the same n_token=70000 case to tests/test-backend-ops.cpp. Every standard ADD_ID case passes; only the above-65535 one fails:

ggml_cuda_compute_forward: ADD_ID failed CUDA error: invalid argument current device: 0, in function ggml_cuda_compute_forward at /home/rohan-thacker/ai/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu:3172 /home/rohan-thacker/ai/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu:119: CUDA error

The error code differs from gfx1200, which reported "invalid configuration argument". The NVIDIA backtrace runs through ggml_backend_cuda_graph_compute, so the two backends may be surfacing the bad launch configuration at different points.

So this is not AMD-specific or hardware-specific: the 65535 cap on blockIdx.y is architectural, and the CUDA backend hits it on current-generation NVIDIA hardware too.

I have a fix written and tested that matches the four existing clamp-plus-stride-loop precedents in the tree. Does a maintainer want a PR?

fox5611 avatar Nov 24 '26 18:11 fox5611

NH Applied — ADD_ID GPU Boundary Test Report

Issue: https://github.com/ggml-org/llama.cpp/issues/32444

Test date: 24 November 2026

AI disclosure: AI assistance was used in developing the isolated test harness, technical investigation and preparation of this report. The numerical results are derived from actual physical GPU execution, deterministic CPU reference comparisons and SHA-256-verified evidence.

1. Test environment

Parameter | Identification -- | -- GPU | AMD Radeon 8060S Architecture | gfx1151 Operating system | Windows HIP runtime version | 71260602 Loaded runtime | C:\Windows\System32\amdhip64_7.dll Reported maximum grid Y | 65536

40/40 experimental controls passed, including four expected baseline launch rejections. Test process exit code: 0.

The original HIP module kernel returned launch status 1 at 65537 and 70000 tokens for both column widths.

In all four rejected cases, the destination remained completely unchanged.

The original native kernel successfully executed those same dimensions and produced numerically exact results.

The modified kernel produced exact results across all tested dimensions using both launch paths.

4. Technical findings

The measurements establish a launch-path-dependent difference on the tested Windows gfx1151 environment.

The capped grid and token-axis stride candidate eliminated the observed module launch failures within the tested matrix.

Native and module code objects were compiled separately; therefore, these results do not establish the launch API alone as the cause of the different behaviour.

5. Evidence identification

Upstream source: ggml/src/ggml-cuda/add-id.cu

Git blob:
8d9cf692b4b55f53e062558e317f424756c190ca

SHA-256 evidence identifiers:

Original source:
f696adbcf54d0fda380fc56009c0d68009cacdbc0d226d1c27f999f3881b4840

Modified candidate:
c399341376cca07e07840b1c12e3c8b8d4089aaf176c78b0f361f0e94e08dc96

Test reproducer:
643a59aa5d1da7a15bdf86f2f685c0277defb985d181efae1ebbd08e61071d21

GPU execution log:
1c13f2bf5a20bd26bfcee97ab3b082332da8065d6f97f85b8bae9bf1049c88b9

Test receipt:
0ad40822de89603d2a84c15bb7bcb473bc50308b03b00de955332dfbb5613607

6. Limitations

These were isolated, source-extracted GPU experiments conducted in the NH Applied development laboratory.

The packaged Doctor executable was not used for this original investigation. Full integrated llama.cpp backend testing was not performed.

The reporter's gfx1200 and NVIDIA hardware configurations were not reproduced locally.

The candidate is experimentally qualified within the stated test scope, not an upstream-qualified repair.


Nigel Hutchinson | NH Applied

Website: https://nhapplied.co.uk

Email: [email protected]

# NH Applied — ADD_ID GPU Boundary Test Report

Issue: https://github.com/ggml-org/llama.cpp/issues/32444

Test date: 24 November 2026

AI disclosure: AI assistance was used in developing the isolated test harness, technical investigation and preparation of this report. The numerical results are derived from actual physical GPU execution, deterministic CPU reference comparisons and SHA-256-verified evidence.

1. Test environment

Parameter Identification
GPU AMD Radeon 8060S
Architecture gfx1151
Operating system Windows
HIP runtime version 71260602
Loaded runtime C:\Windows\System32\amdhip64_7.dll
Reported maximum grid Y 65536

2. Test methodology

Source-extracted original ADD_ID kernels were compared against a modified candidate implementing a grid cap of 65535 and a token-axis stride loop.

Test parameters:

  • Token counts: 129, 65535, 65536, 65537 and 70000.
  • Column widths: 32 and 769.
  • Two selected experts from four available experts.
  • Padded source and index strides.
  • Exact independent CPU reference comparison.
  • Destination sentinel verification following rejected launches.

Both native and HIP module launch paths were tested.

3. Results

Launch path Original kernel Modified kernel
Native 10/10 exact 10/10 exact
HIP module 6/10 exact, 4 rejected 10/10 exact

40/40 experimental controls passed, including four expected baseline launch rejections. Test process exit code: 0.

The original HIP module kernel returned launch status 1 at 65537 and 70000 tokens for both column widths.

In all four rejected cases, the destination remained completely unchanged.

The original native kernel successfully executed those same dimensions and produced numerically exact results.

The modified kernel produced exact results across all tested dimensions using both launch paths.

4. Technical findings

The measurements establish a launch-path-dependent difference on the tested Windows gfx1151 environment.

The capped grid and token-axis stride candidate eliminated the observed module launch failures within the tested matrix.

Native and module code objects were compiled separately; therefore, these results do not establish the launch API alone as the cause of the different behaviour.

5. Evidence identification

Upstream source: ggml/src/ggml-cuda/add-id.cu

Git blob: 8d9cf692b4b55f53e062558e317f424756c190ca

SHA-256 evidence identifiers:

Original source: f696adbcf54d0fda380fc56009c0d68009cacdbc0d226d1c27f999f3881b4840

Modified candidate: c399341376cca07e07840b1c12e3c8b8d4089aaf176c78b0f361f0e94e08dc96

Test reproducer: 643a59aa5d1da7a15bdf86f2f685c0277defb985d181efae1ebbd08e61071d21

GPU execution log: 1c13f2bf5a20bd26bfcee97ab3b082332da8065d6f97f85b8bae9bf1049c88b9

Test receipt: 0ad40822de89603d2a84c15bb7bcb473bc50308b03b00de955332dfbb5613607

6. Limitations

These were isolated, source-extracted GPU experiments conducted in the NH Applied development laboratory.

Full integrated llama.cpp backend testing was not performed.

The reporter's gfx1200 and NVIDIA hardware configurations were not reproduced locally.

The candidate is experimentally qualified within the stated test scope, not an upstream-qualified repair.


Nigel Hutchinson | NH Applied

Website: https://nhapplied.co.uk/

Email: [email protected]

nigelhutch avatar Nov 24 '26 23:11 nigelhutch

Thank you, that makes this three architectures now: gfx1200, gfx1151, and an RTX 5070.

The 65537 result is very useful. My case used 70000, which only showed the failure is somewhere above the limit, 65537 pins it to immediately above 65536.

We also landed on the same fix shape, cap the grid at 65535 and add a stride loop over the token axis, which is what the four existing precedents in the tree already do.

fox5611 avatar Nov 25 '26 03:11 fox5611