You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] GGUFCudaKernel (GGUF_CPP_CUDA) forward is not thread-safe: concurrent calls on one layer return wrong outputs; distinct layers on one GPU abort the process #4314
Each layer caches one ggml plan per batch size, with fixed input and output buffers. Every layer on a device shares one ggml CUDA backend.
The CUDA path takes no lock; the CPU path has _cpu_backend_lock.
Same layer from two threads: the threads overwrite each other's plan input and output.
Different layers on one GPU: the threads drive the shared backend's stream, CUDA-graph capture and memory pool at the same time, and ggml aborts.
Also unsynchronized, from static reading (not separately reproduced):_cuda_weight() (fe09ce2) closes every plan and frees the shared weight when the key changes, possibly while another thread is computing with it.
shared: 188 of 800 outputs differ from the serial result (max abs diff 61.8). With the GIL on, 292 differ (max 56.1).
distinct: the process aborts with CUDA error: the operation cannot be performed in the present state in cudaStreamBeginCapture / cudaGraphLaunch. Another run aborted on GGML_ASSERT(ptr == pool_addr + pool_used) (ggml-cuda.cu:674).
Expected: concurrent forwards are bitwise identical to the serial result. That needs a per-device lock around plan build, run and weight swap, or per-thread plans and contexts.
The test used llama-cpp-python 0.3.36 with the ggml-cuda build.
Found during an AI-assisted review (Claude Code, round 11) of 842d666; repros were run at that commit on RTX 4090/5090 (CUDA 13) and/or Radeon AI PRO R9700 (ROCm) unless marked static/suspected.
Taking this. I'll investigate against current main, add a targeted regression test, and open a PR. Will report back here if the claim turns out to be invalid or already fixed.
Activity
Qubitium commentedon Nov 16, 2026
Taking this. I'll investigate against current
main, add a targeted regression test, and open a PR. Will report back here if the claim turns out to be invalid or already fixed.Qubitium commentedon Nov 16, 2026
Fix PR: #4336
fix: serialize GGUF CUDA forward per device (ModelCloud#4314) (ModelC…