Skip to content

[BUG][multi-GPU] Closed #3826 partly reproduces: pre_quantize stages every layer on device 0 when only cuda:1 is allowed, and OOMs if GPU 0 is full #4233

Closed

Description

@Qubitium

Severity: medium. A whole decoder layer lands on a GPU the user excluded; if that GPU is busy, quantization crashes. Not ROCm-specific.
Version: 7.11.0 @ 9dad249

Summary

  • models/base.py:3947-3957 (pre_quantize(), called from looper/stage_layer.py:~716) calls move_to(module, device=self.quantize_config.device). Its META branch calls shell_module_materialize(..., device=self.quantize_config.device).
  • quantize_config.device holds only the index-less family (DEVICE.CUDA / DEVICE.ROCM). as_torch_device turns that into "cuda", i.e. the current device, cuda:0.
  • compute_device_filter, which the loader builds from device=("cuda:1",) (models/loader.py:~1919-1929), is never consulted here.

docs/multi_gpu_quantization.md:59,105 documents device=("cuda:1",) as "Both use only cuda:1". #3826 named this exact pre_quantize staging in its trigger; only the forward-executor part was fixed.

Reproduce (2 GPUs)

import torch
from transformers import AutoTokenizer
from gptqmodel import GPTQModel
from gptqmodel.quantization import AWQConfig, FORMAT
MODEL = "Qwen/Qwen2.5-0.5B-Instruct"
torch.cuda.set_per_process_memory_fraction(1e-9, 0)   # simulate a busy/full GPU 0
tok = AutoTokenizer.from_pretrained(MODEL)
calib = [tok("The quick brown fox jumps over the lazy dog. " * 8 + str(i)) for i in range(32)]
m = GPTQModel.load(MODEL, AWQConfig(bits=4, group_size=128, format=FORMAT.GEMM), device=("cuda:1",))
m.quantize(calib, batch_size=4)
# torch.OutOfMemoryError: ... GPU 0 ...   (base.py pre_quantize -> move_to -> safe_module_to)

Without the memory-fraction line, torch.cuda.max_memory_allocated(0) is about 35 MiB (one decoder layer), and MemDiag shows cuda:0 reserved=0.04GiB for every layer, even though only cuda:1 was allowed.

Expected

No allocation on an excluded GPU: stage layers on the filtered or primary quantization device.

Related: #3826 (closed), #3577.


Found during an AI-assisted review (Claude Code) of 9dad249; repros were run on RTX 4090/5090 (CUDA 13) and/or Radeon AI PRO R9700 (ROCm) unless marked static/suspected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions