Skip to content

[BUG] FP8 quantize+save with default offload writes source weights as fp8 (PPL 7.6e38); GPTAQ crashes under default auto_nf12; FOEM block-boundary correction is dead code #4037

Closed

Description

@Qubitium

Audit of main @ 8f2efe5, re-checked on ff8443d. GPU: RTX 5090.

Checked against independent fp64 references: correct

GPTQ core. 42 configs (bits 2/3/4/8, gs −1/32/128, sym/asym, desc_act, static_groups), plus mse, dead columns, nsamples=16, tiny damping and bits 5–7.

  • ‖ΔW·X‖² matches to 4 significant digits.
  • g_idx is exact.
  • The reported loss equals reference loss / N.
  • The only code mismatches are float ties in sym configs at −max/scale = −7.5, identical on CPU and CUDA.

Also correct:

Qwen2.5-0.5B-Instruct, held-out c4 PPL (fp16 = 19.93). GPTQ and AWQ beat RTN everywhere:

PPL
RTN sym / asym 26.06 / 24.01
GPTQ default / GAR off / desc_act / asym 22.20 / 22.40 / 22.08 / 21.95
AWQ sym / asym 24.60 / 22.71
GPTAQ (auto_dtype_cast="off") / FOEM 22.00 / 22.72
3-bit GPTQ / RTN 36.1 / 159.5

Three defects follow.

1. FP8 quantize + save with the default offload_to_disk=True writes the original weights as fp8 next to the real weight_scale_inv (critical: silent garbage checkpoint)

TorchFP8Linear stores its packed codes in a buffer named weight, the same name as the source checkpoint tensor. In gptqmodel/models/writer.py:2053-2070, alias_all_from_turtle_if_meta and the meta-materialise helpers run before offloaded tensors are restored. So the offloaded-meta weight is filled from the lazy source checkpoint by name. The log shows "Total direct tensors materialized from lazy checkpoint source: 242", which includes all 168 FP8 linears.

in memory after pack : src absmax 1.2266   packed absmax 448.0   scale_inv max 21716
saved, offload=True  : model.layers.0.self_attn.q_proj.weight  float8_e4m3fn  absmax 1.25   (= source)   scale_inv max 21716
saved, offload=False : model.layers.0.self_attn.q_proj.weight  float8_e4m3fn  absmax 448.0                scale_inv max 21716
end to end (Qwen2.5-0.5B): PPL 7.6e38 with defaults  vs  20.11 with offload_to_disk=False

Fix: don't alias from the turtle source for tensors owned by quantized modules (any module with QUANT_TYPE), or restore offloaded tensors before aliasing. fp4.py also registers a weight buffer, so check it too. Add an FP8 quantize → save → reload test with the default offload.

2. GPTAQ crashes under the default auto_dtype_cast="auto_nf12" (high)

StopIteration at gptqmodel/looper/named_module.py:33 (next(module.parameters())). GPTAQ's native-input capture forward swaps self_attn.q_proj for a parameterless AutoNF12HookedLinear (models/base.py:3915, _maybe_auto_dtype_cast_forward_module). That pass has no quantization task, so the dense source is never restored before GPTAQ builds its NamedModules. With auto_dtype_cast="off", it works (PPL 22.00).

FOEM with alpha > 0 uses the same native path and is probably affected (not run). This likely regressed with the auto-NF12 forward changes (#3853 / #4012). Fix: disable auto-NF12 for the native-capture forward, or restore the source module after it.

3. FOEM block-boundary correction is dead code and off by one (low)

gptqmodel/quantization/foem.py:370-371:

if i+1 < count:
    W[:, i2+1] -= self.qcfg.foem.beta * (W[:, i2+1]-W_raw[:, i2+1])

After the inner loop i == count-1, so this never runs, and the target should be W[:, i2]. The first column of every block skips the β correction, so results depend on blocksize: gs=−1, β=0.2 gives 1646 weights differing between blocksize 128 and 512 (err 0.13201 vs 0.13216). Fix: apply it to W[:, i2] when i2 < columns, or remove it.

Unverified:

  • FOEM nsamples counts requests, not tokens, so its avg_loss isn't comparable with GPTQ/GPTAQ.
  • FOEM (β=0.2) is slightly worse than plain GPTQ here (PPL 22.72 vs 22.40). The formula matches the official implementation, so this may just be how the method behaves.

🤖 Generated with Claude Code

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