Skip to content

[BUG] CUDA OOM during desc_act / act_group_aware Hessian permutation permutes W twice → scrambled weights #4168

Closed

Description

@Qubitium

Severity: high — silent corruption; only a WARN is logged
Version: 7.11.0 @ 6c3421c

Summary

In GPTQ.quantize() the permutation block does W = W[:, perm] and then self.H = self.H[perm][:, perm] inside one try. The H permutation is the step likely to OOM: it needs two cols×cols temporaries, while W is only rows×cols.

When it OOMs, W has already been permuted. The except branch then runs W = W.to(cpu)[:, perm], permuting it a second time while H is permuted once. The rest of GPTQ runs with W and H on mismatched column orders.

  • quantization/gptq.py:2297-2310 (desc_act)
  • the same pattern in the act_group_aware branch just below (~2313-2330)

Reproduce (real CUDA OOM)

import torch
from gptqmodel.quantization.config import QuantizeConfig
from gptqmodel.quantization.gptq import GPTQ
cols, rows, dev = 4096, 64, "cuda:0"
torch.manual_seed(0)
W = torch.randn(rows, cols) * 0.02
X = torch.randn(4096, cols) * (torch.rand(cols) * 3 + 0.1)
Href = 2 * X.double().T @ X.double() / X.shape[0]
def run(oom):
    torch.cuda.empty_cache()
    lin = torch.nn.Linear(cols, rows, bias=False, device=dev); lin.weight.data.copy_(W)
    g = GPTQ(lin, qcfg=QuantizeConfig(bits=4, group_size=128, desc_act=True)); g.quantizer.configure(perchannel=True)
    g.add_batch(X.to(dev).unsqueeze(0), None); g.finalize_hessian(torch.device(dev))
    if oom:
        torch.cuda.synchronize(); torch.cuda.empty_cache()
        torch.cuda.set_per_process_memory_fraction(
            (torch.cuda.memory_reserved(0) + 40 * 2**20) / torch.cuda.get_device_properties(0).total_memory, 0)
    try: Q = g.quantize()[0].float().cpu()
    finally: torch.cuda.set_per_process_memory_fraction(1.0, 0)
    D = (W - Q).double(); return torch.einsum("ij,jk,ik->", D, Href, D).item() / rows
print(run(False), run(True))

Proxy loss tr(ΔW·H·ΔWᵀ):

Mode Normal OOM fallback
desc_act 0.0553 21.66
act_group_aware 0.0759 21.70

This is likely in practice on wide down_proj layers (e.g. 14336 columns, about 820 MB fp32 H) on a busy GPU.

Suggested fix

Permute into temporaries and assign only after both succeed, or re-permute from an unpermuted copy of W on the CPU path:

W_p = W[:, perm]; H_p = self.H[perm][:, perm]
W, self.H = W_p, H_p

Found during an AI-assisted review (Claude Code) of 6c3421c; repros were run on RTX 4090/5090 (CUDA 13) and 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

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