Skip to content

[BUG] rotation="hadamard" is accepted by AWQ/FP8/BnB/GGUF/QQQ/... configs: quantize completes with a silently broken model (FP8 nll 21.05 -> 30.20, AWQ 21.59 -> 30.68) and the checkpoint cannot be reloaded #4666

Closed

Description

@Qubitium

Found on main @ 12c1273, CPU (x86-64), transformers 5.22.1.

What is wrong

rotation is a base-class field (gptqmodel/quantization/config.py:4921), so every config accepts it: AWQConfig, FP8Config, BitsAndBytesConfig, GGUFConfig, QQQConfig, VPTQConfig, ParoConfig, EXL3Config, and RTNConfig(format="gemm"). No config rejects it. Only GPTQ-layout kernels can run a rotated model, though:

  1. Load time. from_quantized refuses rotation for anything except GPTQ/GPTQ_V2 checkpoints (gptqmodel/models/loader.py:3005-3008): `rotation` is only supported for GPTQ/GPTQ_V2 checkpoints.
  2. Inference. The online Hadamard that _setup_rotation_online_had attaches to mlp.down_proj (loader.py:1279) is applied only by kernels that call _apply_rotation_to_input: torch.py:464, tritonv2.py:170, nf12.py:458 and the W4A kernels. TorchFP8Linear, the AWQ kernels, BitsAndBytes and the others ignore online_full_had.
  3. Quantize time. BaseQModel.quantize() rotates and fuses the model in place (gptqmodel/models/base.py:2387-2425) before the backend check at base.py:2427. That check maps BACKEND.AUTO to GPTQ_TORCH whatever the method is, so it passes for AWQ and FP8.

As a result, a non-GPTQ method with rotation="hadamard" runs the whole quantization and produces a silently broken in-session model. The saved checkpoint then cannot be loaded. With an explicit non-GPTQ backend (for example backend=BACKEND.AWQ_TORCH), quantize() raises only after the weights have been rotated and the norms fused in place, so the loaded model cannot be reused.

Repro

Llama-3.2-1B-Instruct truncated to 2 decoder layers, CPU, bf16, 16 C4 rows. The script quantizes, scores in memory, saves and reloads. NLL is on 256 wikitext tokens; absolute values are high because only 2 of 16 layers are kept, so compare within the table.

from gptqmodel import GPTQModel
from gptqmodel.quantization import AWQConfig, FP8Config, RTNConfig
cfg = FP8Config(rotation="hadamard")          # or AWQConfig(bits=4, group_size=128, rotation="hadamard")
m = GPTQModel.load(model_2_layers, cfg, dtype=torch.bfloat16, device="cpu")
m.quantize(calib, batch_size=4)               # completes
print(nll(m))                                 # in-session
m.save(out)
GPTQModel.load(out, device="cpu")             # raises
config in-session nll reload
dense base 20.98 n/a
RTNConfig(bits=8, rotation="hadamard") (GPTQ layout, works) 20.98 20.98
FP8Config() 21.05 21.05
FP8Config(rotation="hadamard") 30.20 NotImplementedError: rotation is only supported for GPTQ/GPTQ_V2 checkpoints, got FORMAT.FP8
AWQConfig(bits=4, group_size=128) 21.59 21.59
AWQConfig(bits=4, group_size=128, rotation="hadamard") 30.68 NotImplementedError: ... got FORMAT.GEMM

Construction accepts every one of these (ACCEPT AWQConfig(rotation='hadamard') -> model_rotation='hadamard', and likewise for RTN, FP8, BnB, GGUF, NF12, QQQ, VPTQ, Paro and EXL3). The only signal is a warning that disk offload is being disabled.

Suggested fix

Reject rotation in __post_init__ (or in _validate_quantize_config_factory_kwargs) for every method or format whose runtime kernels do not apply the online Hadamard. Today that means everything except GPTQ/GPTQ_V2 layouts (GPTQ, RTN with GPTQ format, and NF12 if intended). Also move the backend/method check in quantize() ahead of fuse_layer_norms/rotate_model, so a refusal leaves the model untouched. The model-type gate from #4208 (validate_rotation_model_support) already says "No weights were modified".

Tests that should have caught it

tests/qcfg covers rotation only for GPTQ. There is no test that AWQConfig(rotation=...) or FP8Config(rotation=...) is rejected, or that it round-trips quantize, save and load.

Severity

Medium. An accepted option silently corrupts the in-session model (+9 nll here), costs a full quantization run, and produces a checkpoint that cannot be loaded.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Taking this. I'll make rotation a format/method-gated field so every config whose runtime kernels do not apply the online Hadamard rejects it at construction, and move the quantize-time refusal ahead of fuse_layer_norms/rotate_model so a rejected run leaves the model untouched. Regression: a per-method rejection test plus the quantize-order test.

  2. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Claimed by an AI agent. Will reproduce on CPU, fix, add a focused regression test, and open a PR.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions