Skip to content

[BUG] GPTQ/QQQ OOM CPU fallbacks (#4400 item 3/4, 5fbd636): block-pass retry restarts from an already error-propagated W (silently worse quantization, +12–35% proxy loss); static_groups=True fallback crashes with device mismatch #4464

Closed

Description

@Qubitium

Severity: medium. Confirmed at 489aed6 on an RTX 4090.

1. The block-pass CPU retry reuses a W that was already modified in place (new bug from 5fbd636)

gptqmodel/quantization/gptq.py:2586-2862:

  • W[:, i2:] -= Err1.matmul(Hinv[i1:i2, i2:]) (line 2847) modifies W in place on every block.
  • On a CUDA OOM, the retry at 2588-2604 only does W = W.to(cpu) and find_params(W) on that already-modified W.
  • So when the OOM hits after block 0, the earlier blocks' errors are propagated a second time. Before this commit, the OOM simply aborted the run.

Repro:

  • A 256×1024 fp32 Linear with a dense correlated H, QuantizeConfig(bits=4, group_size=128, sym=True).
  • Monkeypatch torch.Tensor.matmul to raise torch.OutOfMemoryError on the Nth CUDA (256,128)@… call.
  • Compare the proxy loss (W−Q)ᵀH(W−Q) with a clean CPU run. Clean CPU and clean CUDA agree to about 4e-8.
OOM at block proxy loss elements different from the clean run
none 0.027921 –
1 0.027921 0
2 0.031271 (+12%) 76% (max 0.041)
4 0.037767 (+35%) 76% (max 0.041)

The quantized module is silently worse, with no warning that its result is degraded. tests/test_gptq_post_inverse_fallback_4400.py only fails the first zeros_like and uses a diagonal H, so it cannot catch this. Fix direction: keep a host snapshot of W from before the block pass and restore it on retry.

2. The CPU fallback crashes with static_groups=True

  • GPTQ (gptq.py:2478-2568, all three Hessian-inverse fallbacks): W and H move to CPU, but the groups[*].scale/zero quantizers stay on CUDA. Only the block-pass retry (2593-2600) moves them. This fails the same way at def6e61.
  • QQQ (qqq.py:846-853): the new fallback copies the same pattern (incomplete fix from 5fbd636).

Repro: GPTQ or QQQ on a 64×256 Linear, QuantizeConfig(bits=4, group_size=64, static_groups=True, sym=True), with torch.linalg.cholesky patched to raise torch.OutOfMemoryError (or CUSOLVER_STATUS_ALLOC_FAILED) once on CUDA.

  • Actual: RuntimeError: Expected all tensors to be on the same device, cuda:0 and cpu, for GPTQ with and without desc_act, and for QQQ.
  • Expected: the run finishes on CPU and matches a CPU run. With static_groups=False it does, with max diff 0.

Found during an AI-assisted review (Claude Code, round 13) of 489aed6; repros were run at that commit (A/B against def6e61 where noted) 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

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