Skip to content

fix(writer): record GPTQ block_name_to_quantize for HF interop - #6222

Merged
Qubitium merged 1 commit into
mainfrom
fix/6182-issue
Nov 29, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/6182-issue

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

GPT-QModel knew the decoder-block path from each definition's module_tree, but the writer never put it in config.json. Optimum's HF GPTQ loader then guessed from a short hard-coded list; models whose decoder is elsewhere (SmolVLM2's model.text_model.layers, MPT's transformer.blocks) failed with:

ValueError: Block pattern could not be match. Pass `block_name_to_quantize` argument in `quantize_model`

This records quantization_config.block_name_to_quantize from the definition's effective layer-container path. The value is only emitted when the path exists in the materialized model and is unambiguous (a definition may declare multiple layout variants). A loaded checkpoint's existing value wins, so re-saving does not rewrite it. No other emitted keys change.

Tests

Added to the existing checkpoint-compat family (tests/test_checkpoint_compat.py), using a one-layer CPU MPT (transformer.blocks, not in Optimum's BLOCK_PATTERNS):

  • test_gptq_save_records_definition_block_name
  • test_gptq_block_name_loads_through_plain_hf (plain AutoModelForCausalLM.from_pretrained)
  • test_gptq_resave_preserves_existing_block_name

Red evidence

Before the writer change (regression test kept, only gptqmodel/models/writer.py reverted):

cd /root/openai-audit/issue-6182/tests
PYTHONPATH=/root/openai-audit/issue-6182:/root/openai-audit/issue-6182/tests CUDA_VISIBLE_DEVICES= \
  /root/venv/bin/python -m pytest test_checkpoint_compat.py -q -rs -k block_name --tb=line
E   KeyError: 'block_name_to_quantize'
E   ValueError: Block pattern could not be match. Pass `block_name_to_quantize` argument in `quantize_model`
E   KeyError: 'block_name_to_quantize'
3 failed, 22 deselected in 5.24s

Green evidence

After the fix:

cd /root/openai-audit/issue-6182/tests
PYTHONPATH=/root/openai-audit/issue-6182:/root/openai-audit/issue-6182/tests CUDA_VISIBLE_DEVICES= \
  /root/venv/bin/python -m pytest test_checkpoint_compat.py -q -rs -k block_name
# 3 passed, 22 deselected

PYTHONPATH=/root/openai-audit/issue-6182:/root/openai-audit/issue-6182/tests CUDA_VISIBLE_DEVICES= \
  /root/venv/bin/python -m pytest test_checkpoint_compat.py -q -rs
# 22 passed, 3 skipped

PYTHONPATH=/root/openai-audit/issue-6182:/root/openai-audit/issue-6182/tests CUDA_VISIBLE_DEVICES= \
  /root/venv/bin/python -m pytest test_checkpoint_interop_4053.py -q -rs
# 19 passed, 6 skipped

PYTHONPATH=/root/openai-audit/issue-6182:/root/openai-audit/issue-6182/tests CUDA_VISIBLE_DEVICES= \
  /root/venv/bin/python -m pytest test_checkpoint_metadata_contracts.py test_checkpoint_subfolder_resolution.py test_auto_nf12_excluded_layers.py -q -rs
# 36 passed, 15 skipped

Lint:

/root/venv/bin/ruff check gptqmodel/models/writer.py tests/test_checkpoint_compat.py
# All checks passed!

Skips / unverified

  • CPU-only: no GPU tests were run.
  • test_checkpoint_compat.py: 3 skipped because lm_head quantization needs an accelerator.
  • test_checkpoint_interop_4053.py: 6 skipped (Marlin/ExLlamaV2/GPTQ Triton need CUDA).
  • test_auto_nf12_excluded_layers.py: 15 skipped (AUTO_NF12 eligibility needs CUDA/HIP).
  • Did not run the full SmolVLM2 checkpoint from the issue; the same nonstandard-prefix path is covered by the tiny MPT fixture, and the writer helper reads the same module_tree prefix that SmolVLM declares (model.text_model.layers).

Fixes #6182

@Qubitium
Qubitium marked this pull request as ready for review November 29, 2026 02:06
@Qubitium
Qubitium merged commit e94e51d into main Nov 29, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/6182-issue branch November 29, 2026 02:06
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