Skip to content

Fix #26558: Eval bug: llama-server hard crash (cublasSgemm INVALID_VALUE) with --spec-type draft-mtp under KV-cache saturation - #27368

Closed
ZisIsNotZis wants to merge 2 commits into
ggml-org:masterfrom
ZisIsNotZis:draft_mtp_crash
Closed

ZisIsNotZis wants to merge 2 commits into
ggml-org:masterfrom
ZisIsNotZis:draft_mtp_crash

Conversation

@ZisIsNotZis

Copy link
Copy Markdown

Overview

This PR fixes #26558. The bug was in CUDA graph cache eviction. Cached graphs are launched asynchronously, but stale graph executables were destroyed without waiting for all CUDA streams to finish. MTP graph churn could then leave in-flight work using destroyed graph state, causing the later cublasSgemm_v2 error.

The patch:

  1. Detects stale graph entries.
  2. Skips eviction during graph capture.
  3. Synchronizes all active CUDA streams.
  4. Destroys stale graph objects only after synchronization.

Additional information

Minimal stress snippet:

  import concurrent.futures
  import json
  import urllib.request

  url = "http://127.0.0.1:18081/completion"
  payload = json.dumps({
      "prompt": "Explain CUDA graph lifetime safety. " * 200,
      "n_predict": 64,
      "temperature": 0,
  }).encode()

  def request(_):
      req = urllib.request.Request(
          url, data=payload,
          headers={"Content-Type": "application/json"})
      with urllib.request.urlopen(req, timeout=300) as response:
          return response.status

  with concurrent.futures.ThreadPoolExecutor(max_workers=10) as pool:
      results = list(pool.map(request, range(1000)))

  print("completed:", len(results))
  print("non-200:", sum(status != 200 for status in results))

Run the server with:

  build/bin/llama-server \
    -m "$HOME/hf/Qwen3.5-0.8B-UD-Q4_K_XL.gguf" \
    --spec-type draft-mtp --temp 0 \
    -c 8192 -np 4 --kv-unified \
    --host 127.0.0.1 --port 18081 --no-webui

A passing result is that the process remains alive and the server log contains no CUDA, cuBLAS, abort, or segmentation-fault errors. HTTP errors due to KV-cache exhaustion are not the CUDA crash.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: Yes, I used GPT to nail down root cause and fix it. Need professionals to review this. But I feel this issue/PR is important because this MTP crash problem has not been fixed for so long, during which a lot of issues has been opened and essentially closed due to lack of activity.

@ZisIsNotZis
ZisIsNotZis requested a review from a team as a code owner August 19, 2026 08:22
@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning CUDA Related to the CUDA backend labels Aug 19, 2026
@ORippler

ORippler commented Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator

Cached graphs are launched asynchronously, but stale graph executables were destroyed without waiting for all CUDA streams to finish. MTP graph churn could then leave in-flight work using destroyed graph state, causing the later cublasSgemm_v2 error.

I agree we should guard against destroying in-flight graphs, but the current time-out of 10s means we would be working at 0.1 t/s (or enqueue the work 10s in advance) - both of which seem unlikely. Note that behavior is to graciously clean-up after execution has finished in CUDA.

  1. Are you on older CUBLAS versions? If so, you might be affected by ggml-cuda: provide static workspace for cuBLAS handles #26574
  2. Is there a (somewhat) stable repro on either:
    • DGX Spark
    • RTX Pro GPUs

Those are systems I have easy access to, and could use for investigation

@ZisIsNotZis

Copy link
Copy Markdown
Author

@ORippler Thanks for the reply! That makes sense, a better method is probably to track each graph's lifecycle instead of blindly syncing, but I think this would require changing a lot of code? Currently the patch does not continuously reduce token throughput, but it can add latency and reduce throughput at eviction points by waiting for all outstanding work on the device’s created streams.robably going to decrease speed, maybe not that extreme at 0.1t/s.

For cublas, I'm on 13.6.0.2-1.

I don't have higher level hardware, and I think it's probably more difficult to reproduce on higher level cards because if CUDA graph finishes within 10s, nothing happens. Maybe downclocking GPU or simply stress the GPU first somehow, then stress test llama-server so that it don't get enough compute?

@ORippler

Copy link
Copy Markdown
Collaborator

#26558 (comment) No longer repros.

@ORippler ORippler closed this Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CUDA Related to the CUDA backend ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Eval bug: llama-server hard crash (cublasSgemm INVALID_VALUE) with --spec-type draft-mtp under KV-cache saturation

2 participants