Skip to content

fix(awq,requantize): pick the AWQ packer by width and rehome packed payloads - #6143

Merged
Qubitium merged 2 commits into
mainfrom
fix/6135-6132-awq-requantize
Nov 27, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/6135-6132-awq-requantize

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

Fixes #6135
Fixes #6132

#6135 — AWQ GEMM AUTO pack backend ignored the global width

awq_gemm_pack_backend() returned BACKEND.AWQ_GEMM for every CUDA run, so the model-wide
select_quant_linear(..., pack=True) gate validated AwqGEMMLinear (4-bit only) for
AWQConfig(bits=8) / AWQConfig(bits=3) and raised before calibration. The function now takes
the global width and returns AWQ_TORCH for non-4-bit GEMM; AWQ_GEMM is unchanged for 4-bit
CUDA, and the ROCm/CPU/weight-only paths still return AWQ_TORCH.

#6132 — requantize() placement snapshot saw the CPU qzeros_format marker

_snapshot_module_placement() / _embedding_endpoint_state() used get_device(module), which
returns the first buffer. Every BaseQuantLinear registers the CPU-created persistent
qzeros_format marker first, so a CUDA-resident TritonV2Linear was recorded as CPU and the
post-run rehome left its packed payload on CPU (Expected a cuda device, but got: cpu). The
snapshot and rehome now use the real checkpoint payload device (first parameter, else first
non-marker buffer).

For the layer-wise dispatch case, StageInputsCapture now materializes a module on its resident
accelerate hook's execution device instead of forcing CPU, so the hook no longer moves inputs to
one device while the weight sits on another. Offload hooks are left untouched.

What Changed

  • gptqmodel/utils/backend.py: awq_gemm_pack_backend(..., bits) selects AWQ_TORCH for 2/3/8-bit GEMM.
  • gptqmodel/models/base.py: pass runtime_bits to the pack-backend resolver; add
    _module_payload_device() and use it for the requantize placement snapshot/rehome.
  • gptqmodel/looper/stage_inputs_capture.py: honor resident accelerate dispatch hook execution
    devices when materializing capture layers and base modules.
  • Tests: extended tests/test_awq_cuda_contract.py and
    tests/test_requant_embed_endpoint_5116.py.

Tests

All commands run with CUDA_VISIBLE_DEVICES=1 and
PYTHONPATH=<clone>:<clone>/tests from <clone>/tests:

/root/venv/bin/python -m pytest test_awq_cuda_contract.py -q -rs
# 12 passed, 2 skipped (both need 2 visible GPUs)

/root/venv/bin/python -m pytest test_awq_dynamic_bits_gate_5408.py -q -rs
# 7 passed

/root/venv/bin/python -m pytest test_awq_gemm.py -q -rs
# 1 passed in 150.15s (4-bit AUTO still selects AwqGEMMLinear)

/root/venv/bin/python -m pytest test_requant_embed_endpoint_5116.py -q -rs
# 10 passed

/root/venv/bin/python -m pytest test_requant_embed_lm_head.py -q -rs
# 26 passed

/root/venv/bin/python -m pytest test_requant_embed_lm_head_e2e.py -q -rs
# 1 passed in 39.02s

/root/venv/bin/python -m pytest test_norm_requant.py -q -rs
# 17 passed, 2 failed — same 2 failures at base 43b999585
# (test_requantize_dispatches_norm_without_embedding_target,
#  test_norm_validates_arguments: AttributeError 'quantize_config' in requantize())

/root/venv/bin/ruff check gptqmodel gptqmodel/models/ports/native/auto/__init__.py \
  gptqmodel/models/ports/native/auto/_registry.py docs/eora tests setup.py
# All checks passed!

Red evidence at base 43b999585

  • test_awq_cuda_contract.py::test_awq_gemm_non_4bit_global_width_quantizes_with_default_backend[8]
    fails with:
    ValueError: <class 'gptqmodel.nn_modules.qlinear.gemm_awq.AwqGEMMLinear'> only supports [4] bits: actual bits = 8
  • test_requantize_default_loaded_checkpoint_runs_in_session[output] fails at the payload-device
    assertion after requantize(): every q_proj buffer is still CPU.
    The same script's in-session generate() raised
    ValueError: Expected a cuda device, but got: cpu.
  • test_requantize_keeps_a_resident_dispatch_hook_module_in_place fails with
    RuntimeError: Expected all tensors to be on the same device, but got index is on cuda:0, different from other tensors on cpu.

Green at 27c5a3e0f

  • Both new AWQ tests pass; bits=8/3 pack with AwqTorchLinear, and the existing 4-bit AWQ GEMM
    end-to-end test still loads AwqGEMMLinear and generates.
  • Both default-load requantize variants (OUTPUT, BOTH) rehome every q_proj buffer to CUDA,
    generate in-session, save, reload, and generate again.
  • The resident-hook capture case stays on its execution device and generates in-session.

Skips / limits

  • The two 2-GPU tests in test_awq_cuda_contract.py were skipped: this worker only has one
    visible GPU assigned. The 2-GPU requantize variant was therefore not run end to end; the
    hook path is covered by the single-GPU resident-hook regression above.
  • test_norm_requant.py's two failures are pre-existing at 43b999585 (verified in a clean
    worktree) and unrelated to this diff.

@Qubitium
Qubitium marked this pull request as ready for review November 27, 2026 11:07
@Qubitium
Qubitium merged commit aac58e2 into main Nov 27, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/6135-6132-awq-requantize branch November 27, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant