Skip to content

Eval bug: Qwen3.5-27B CUDA illegal memory access regression in prompt cache (single GPU, agentic tool-call pattern) #21383

Description

@cutlerbenjamin1-cmd

Name and Version

Last known working: 149b2493c (March 19, 2026)
First observed broken: f49e91787 (April 3, 2026, current master)

Both built from source with identical configuration.

Operating systems

Windows 11 (10.0.26200)

GGML backends

CUDA

Hardware

  • GPU: NVIDIA GeForce RTX 3090 (24 GB VRAM, compute capability 8.6) — single GPU
  • CPU: AMD Ryzen 9 5900XT (16c/32t)
  • RAM: 32 GB
  • CUDA: 12.8
  • Compiler: MSVC 19.44.35222.0

Models

mradermacher/Huihui-Qwen3.5-27B-abliterated-GGUF (i1-Q4_K_M)

Architecture: qwen35 (hybrid attention + Mamba2/Gated Delta Net, 64 layers, full_attention_interval=4)

Problem description & steps to reproduce

Summary

Qwen3.5-27B crashes with CUDA error: an illegal memory access was encountered when used with agentic frameworks that send large, dynamically-changing prompts with tool call/result patterns. The crash occurs in the prompt cache save path after a successful response. This is a regression — commit 149b2493c (March 19) is stable; current master crashes.

Trigger pattern (agentic tool calls)

This specifically reproduces with frameworks like Claude Code CLI that use the OpenAI-compatible /v1/messages endpoint with:

  1. Large prompts (~29K tokens) containing full system prompts, tool schemas, conversation history, and dynamic context injections
  2. Rapidly changing prefixes — each turn injects new <system-reminder> blocks, tool call results, and context that shifts the early prompt tokens
  3. Multi-turn tool-call loops — model generates tool call JSON → tool executes → new prompt with result appended → repeat

The crash does not reproduce with simple chat interfaces (e.g., OpenWebUI) using the same model and server configuration, because those send smaller prompts with stable prefixes.

Steps to reproduce

  1. Start llama-server with Qwen3.5-27B:
llama-server -m Qwen3.5-27B.Q4_K_M.gguf -c 120064 -ngl 99 --flash-attn --port 8090 -np 1
  1. Send a first small request (~233 tokens) — succeeds fine, prompt cache checkpoint saved.

  2. Send a second large request (~29K tokens, typical of an agentic framework with tool definitions) — processes successfully, returns HTTP 200, then:

CUDA error: an illegal memory access was encountered
  current device: 0, in function ggml_backend_cuda_synchronize at ggml/src/ggml-cuda/ggml-cuda.cu:2924
  cudaStreamSynchronize(cuda_ctx->stream())

The crash occurs after the response is sent (during prompt cache save/update), not during inference.

Observed behavior from logs

srv  log_server_r: done request: POST /v1/messages 127.0.0.1 200
reasoning-budget: deactivated (natural end)
CUDA error: an illegal memory access was encountered
  current device: 0, in function ggml_backend_cuda_synchronize at ggml/src/ggml-cuda/ggml-cuda.cu:2924

Key log entries showing the hybrid model's prompt cache behavior:

  • cache_reuse is not supported by this context (hybrid model limitation)
  • forcing full prompt re-processing due to lack of cache data
  • Multiple checkpoints created during processing (created context checkpoint 1-5 of 32)
  • Fused Gated Delta Net enabled (autoregressive + chunked)

Workaround

Adding --cache-ram 0 prevents the checkpoint save crash, but a second crash still occurs during subsequent tool-call turns (likely in memory_seq_rm partial truncation fallback for the recurrent state). Rolling back to 149b2493c resolves both crashes.

Bisection

Commit Date Status
149b2493c March 19 ✅ Stable with agentic tool calls
f49e91787 April 3 ❌ Crashes on prompt cache save

Not yet narrowed further. The 93+ commits between these contain several prompt cache and checkpoint changes (#20087, #19924, #19877, #19849, #20955).

Key differences from existing reports

Aspect This issue #20176 #21140 #20225
Backend CUDA HIP/ROCm HIP/ROCm HIP
GPUs Single Single Multi (2x) Single
Trigger Agentic tool calls (~29K dynamic prompts) Multi-turn chat Sequential agents Multi-turn chat
Crash point Post-response prompt cache save Checkpoint load Checkpoint restore No crash (perf)

First Bad Commit

Not yet bisected to a single commit. Regression window: 149b2493c..f49e91787

Relevant log output

Full server log (working first request, crashing second request)
ggml_cuda_init: found 1 CUDA devices (Total VRAM: 24575 MiB):
  Device 0: NVIDIA GeForce RTX 3090, compute capability 8.6, VMM: yes, VRAM: 24575 MiB
system_info: n_threads = 16 (n_threads_batch = 16) / 32 | CUDA : ARCHS = 860 | USE_GRAPHS = 1

srv    load_model: prompt cache is enabled, size limit: 8192 MiB

# First request (233 tokens) - OK
slot update_slots: id  0 | task 0 | processing task
slot update_slots: id  0 | task 0 | prompt processing done, n_tokens = 233
srv  log_server_r: done request: POST /v1/messages 127.0.0.1 200
prompt eval time = 689.16 ms / 233 tokens (338.09 tokens per second)
eval time = 3760.64 ms / 144 tokens (38.29 tokens per second)

# Second request (29306 tokens) - processes OK then crashes
slot update_slots: id  0 | task 2 | new prompt, n_ctx_slot = 120064, n_keep = 4096, task.n_tokens = 29306
slot update_slots: id  0 | task 2 | forcing full prompt re-processing due to lack of cache data
slot update_slots: id  0 | task 2 | created context checkpoint 1 of 32 (pos_min = 8191)
slot update_slots: id  0 | task 2 | created context checkpoint 2 of 32 (pos_min = 16383)
slot update_slots: id  0 | task 2 | created context checkpoint 3 of 32 (pos_min = 24575)
slot update_slots: id  0 | task 2 | created context checkpoint 4 of 32 (pos_min = 28789)
slot update_slots: id  0 | task 2 | prompt processing done, n_tokens = 29306
slot update_slots: id  0 | task 2 | created context checkpoint 5 of 32 (pos_min = 29301)
srv  log_server_r: done request: POST /v1/messages 127.0.0.1 200
reasoning-budget: deactivated (natural end)

CUDA error: an illegal memory access was encountered
  current device: 0, in function ggml_backend_cuda_synchronize at ggml/src/ggml-cuda/ggml-cuda.cu:2924
  cudaStreamSynchronize(cuda_ctx->stream())

Build configuration

cmake -B build     -DGGML_CUDA=ON     -DCMAKE_CUDA_ARCHITECTURES="86"     -DGGML_NATIVE=ON     -DGGML_LTO=ON     -DGGML_CUDA_FA_ALL_QUANTS=ON     -DLLAMA_CURL=OFF     -DCMAKE_BUILD_TYPE=Release     -G "Ninja"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions