Skip to content

[BUG] Follow-up on #4069/#4084: hf_repack_layer zero points off by one for GPTQ v1, hf_pack_layer(post_init=True) saves v2 words as gptq, Phi-tiny-MoE AWQ still crashes (out_features % group_size) #4095

Closed

Description

@Qubitium

Regression and completeness review of the quantization-side fix PRs (#4069, #4071, #4080, #4081, #4084, #4086) on main @ a15e6bf, RTX 4090. A/B checks compare against ad0525c, the base before all of these PRs.

1. hf_repack_layer makes every GPTQ v1 zero point one step low (in-memory and loaded models) (high for integrators, silent)

utils/packing.py:797-824 (_copy_packed_state) does the following:

Qwen2.5-0.5B-Instruct-gptq-4bit loaded with GPTQ_TORCH, down_proj repacked:
  -> TritonV2Linear rel_err 0.30        -> MarlinLinear rel_err 0.0   (Marlin ignores qzeros for sym)
Llama-3.2-1B RTN4 sym, offload_to_disk=False, in-memory TorchLinear -> TritonV2Linear: rel_err 0.44-0.61; target zeros == source - 1

On ad0525c, the loaded-checkpoint case was already broken (#4061). The in-memory case happened to work only because the source was itself wrong (#4063). At HEAD both are broken. tests/test_hf_packing_api.py::test_hf_repack_layer_between_compatible_kernels only uses GPTQ_V2, so no conversion happens.

Fix: copy the raw named_buffers() instead of state_dict(), or set target._checkpoint_format_on_disk = source._checkpoint_format_on_disk before load_state_dict (so _load_from_state_dict converts) and drop the relabel.

2. hf_pack_layer(checkpoint_format="gptq", post_init=True) / hf_post_init restore v2 words without setting the checkpoint marker, so state_dict() / save_pretrained write v2 words labelled gptq (medium; a sibling path #4069 missed)

#4069 moved pack_module to "keep live v2 + mark _checkpoint_format_on_disk=GPTQ, convert a copy on serialize". hf_pack_layer (utils/packing.py:675-715) still converts the live buffer to v1. Then post_init / _restore_gptq_runtime_qzeros (:248) converts it back to v2 without setting the marker, so the serialization conversion never runs:

post_init=False: state_dict qzero fields [7,6,7,6]  (correct v1)
post_init=True:  qzero_format=2, ckpt_marker=None, state_dict fields [8,7,8,7] (v2 under a v1 label)
  -> reload as v1 checkpoint: rel_err 0.269

The documented HF lifecycle in docs/hf_packing_api.md (pack → post_init → save_pretrained) therefore produces checkpoints whose zero points are one step high on reload. The behaviour is the same on ad0525c. Fix: have hf_pack_layer mirror pack_module (keep v2 and set the marker), or set _checkpoint_format_on_disk = FORMAT.GPTQ wherever the v1 words are restored to v2.

3. #4084's AWQ group retune is incomplete: Phi-tiny-MoE (the model from #4073 item 3) still crashes under default AWQ (medium)

_ensure_group_size_divisibility / _largest_supported_group_divisor (looper/awq_processor.py:513-600) only check in_features % group_size. They do retune the 512 expert down_proj modules from 128 to 64. But AwqGEMMLinear._validate (qlinear/gemm_awq.py:209-229) also requires out_features % group_size == 0, and the expert gate_proj/up_proj have out_features = 448:

AWQConfig(bits=4, group_size=128), Phi-tiny-MoE-instruct bf16:
NotImplementedError: AWQ GEMM requires a group size divisible by 32 and out_features divisible by that group size: got out_features=448, group_size=128
  (awq_processor.py:3469 pack_module -> utils/model.py:806 create_quant_module)

Fix: check each candidate group size against the kernel's full validate(in_features, out_features, group_size) (64 works here). Add an out_features=448 case to tests/test_awq_dynamic_group_size.py.

Plausible, not verified end to end

Checked, no defect found

🤖 Generated with Claude Code

Activity

  1. added
    bug
    on Nov 15, 2026
  2. Qubitium commented on Nov 15, 2026

    @Qubitium
    CollaboratorAuthor

    All three items are now on main:

    Verification worth recording, because the first item was the subtle one: _restore_gptq_runtime_qzeros() only reaches its new FORMAT.GPTQ assignment when the live words are v1 (qzero_format() != 1 returns early), so a v2-on-disk layer is never mislabelled. Probed across inline/split post_init and repack from v1 and v2 sources — all five paths agree between state_dict() words and live words. _copy_packed_state now copies named_parameters()/named_buffers() instead of state_dict(), which is a strict superset and avoids the v1 checkpoint conversion entirely.

    For item 3, _kernel_group_size_supported now asks the resolved kernel's own validate(in_features, out_features, group_size), and -1 is used only when per-channel itself validates — otherwise the configured size is left alone, so the non-quantized router:! is not rewritten. End-to-end Phi-tiny-MoE (bf16, AWQ g128): 1664 modules packed, 448×4096 and 4096×448 both retuned to g64, attention projections kept g128.

    Both fixes are covered by regression tests that fail on the parent commit, on CUDA and ROCm.

    Closing as resolved.

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