Skip to content

[BUG] A GPU excluded via device= still gets a CUDA context and linalg warmup allocations from the global DeviceThreadPool (follow-up to #4233) #4320

Closed

Description

@Qubitium

Severity: low. Status: confirmed on 2× RTX 4090. Kind: incomplete fix of #4233 (5149b1a).

Where

gptqmodel/__init__.py:420-438: _build_device_thread_pool creates cuda:per workers that run run_torch_linalg_warmup on every visible device. The compute_device_filter from the #4233 fix is not applied to this pool.

Repro

With CUDA_VISIBLE_DEVICES=0,1:

from gptqmodel import GPTQModel, GPTQConfig
m = GPTQModel.load("Qwen/Qwen2.5-0.5B-Instruct", GPTQConfig(bits=4), device=("cuda:1",))
m.quantize(calib)

Actual:

  • nvidia-smi shows about 524 MiB used by this process on GPU 0.
  • PyTorch's peak allocation on cuda:0 is 6 MiB, with 22 MiB reserved.
  • The allocation traces all point to utils/linalg_warmup.py (_run_qr 49 MB, _run_cholesky_and_eigh, _run_svd), reached through threadx._run_warmup.

Expected: no context or allocation on a GPU the user excluded.

What is fixed: the original OOM. With GPU 0 capped (set_per_process_memory_fraction(1e-9, 0)) the run now completes, so the pre_quantize staging itself is correct.


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.

Activity

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

    @Qubitium
    CollaboratorAuthor

    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.

  3. self-assigned this
    on Nov 16, 2026
  4. Qubitium commented on Nov 16, 2026

    @Qubitium
    CollaboratorAuthor

    Round-12 follow-up at def6e61 (from code reading; not run on 2 GPUs): 8b139ab skips warmup only when device= is a tuple or list.

    • models/auto.py:777-789 calls _explicit_requested_devices, which returns None for anything else (loader.py:467).
    • So device="cuda:1" (a string) still warms up, and creates a context on, every visible GPU. A user-set quantize_config.compute_device_filter does too.
    • The pool is a process-wide singleton built once, so a later load with a different device selection cannot change the warmup set either.
  5. Qubitium commented on Nov 16, 2026

    @Qubitium
    CollaboratorAuthor

    Another round-12 check at def6e61 (2× RTX 4090, CUDA_VISIBLE_DEVICES=0,1), using GPTQModel.load("Qwen/Qwen2.5-0.5B-Instruct", QuantizeConfig(bits=4, group_size=128), device=("cuda:1",)) followed by quantize(calib):

    • After load, only GPU1 is in use. That part is fixed.
    • After quantize, the process still holds 386 MiB on GPU0, down from 524 MiB before the fix. The context is created during layer-0 calibration.
    • I have not pinned down the call that creates it. It is not torch.cuda.memory_stats(0); I tested that, and it does not create a context.
    • With device="cuda:1" passed as a plain string (see the previous comment), every device is still warmed up, which puts about 1.07 GiB on GPU0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions