Skip to content

[BUG] GGUF CUDA: per-device locks still abort the process when layers on 2 GPUs run concurrently (incomplete fix of #4314) #4378

Closed

Description

@Qubitium

Severity: medium (process abort). Status: confirmed statistically on 2× RTX 4090 at def6e61, with PYTHON_GIL=0 and llama-cpp-python 0.3.36 (ggml-cuda). Kind: incomplete fix of #4314 (e47fe06).

Where

  • gptqmodel/nn_modules/qlinear/gguf_cpp.py: _GGMLBridge.cuda_backend_lock (~484) is keyed per device.
  • GGUFCudaKernel.forward (~1387) takes that lock.
  • So forwards on cuda:0 and cuda:1 can be inside ggml-cuda at the same time.

Repro

Take the #4314 repro script and change it so that:

  • layer i lives on cuda:{i%2}, and its input is on the same device;
  • 4 threads × 200 forwards run, i.e. 2 threads per device;
  • 2 GPUs are visible.

Actual:

  • 5 of 20 runs abort with rc 134: CUDA error: an internal operation failed ... ggml_cuda_mul_mat_cublas_impl ... cublasGemmEx, on device 1.
  • With cuda_backend_lock monkeypatched to a single process-wide RLock, 0 of 20 runs abort.

Expected: no aborts, and outputs equal to the serial run. ggml-cuda state appears to be shared across devices (cuBLAS handles, pools), so a process-wide lock or a proven per-device-safe design is needed.

Now fixed:

  • One GPU, same-layer and distinct-layer runs: 0 mismatches.
  • Moving a layer between devices works.
  • One thread per GPU: 0 of 12 runs abort.
  • Single-thread latency is unchanged (~57 µs per call).

Found during an AI-assisted review (Claude Code, round 12) of def6e61; repros were run at that commit (A/B against 842d666 where noted) on RTX 4090/5090 (CUDA 13) and/or Radeon AI PRO R9700 (ROCm) unless marked static/suspected.

Activity

  1. added
    bug
    on Nov 16, 2026
  2. Qubitium commented on Nov 16, 2026

    @Qubitium
    CollaboratorAuthor

    Claimed. This issue is now owned by a dedicated worker; a fix PR referencing it will follow. Please avoid duplicating work on it in the meantime.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions