Repository navigation
Description
Summary
Plain Transformers loading of a GPTQ checkpoint goes through Optimum's GPTQQuantizer.convert_model(). When quantization_config.block_name_to_quantize is absent, Optimum guesses the decoder container from a short hard-coded list (transformer.h, model.decoder.layers, gpt_neox.layers, model.layers, model.language_model.layers, h, decoder.layers, layers). GPT-QModel knows the exact path from the definition's module_tree, but the writer never puts it in config.json. For any supported model whose decoder lives somewhere else, AutoModel*.from_pretrained(<quantized dir>) raises:
ValueError: Block pattern could not be match. Pass `block_name_to_quantize` argument in `quantize_model`
I confirmed this end to end with SmolVLM2 (model.text_model.layers). If I add "block_name_to_quantize": "model.text_model.layers" to the saved config.json by hand, the same checkpoint loads through plain HF, and the output and PPL match GPTQModel.load.
Other Transformers-native families whose definition prefix is not in Optimum's list hit the same path. I found these statically from module_tree and did not run them: mpt (transformer.blocks), dbrx (transformer.blocks), falcon_mamba (backbone.layers).
Introduced by
Pre-existing. The writer has never emitted block_name_to_quantize. Optimum's in-tree copy that had the parameter was removed in 9c59a1c (#1186), and since then nothing writes it. Still present at HEAD 8ebe255.
Location
gptqmodel/models/writer.py:2567-2579 (HEAD 8ebe255). quantization_config is built from the quantize config, and only modules_in_block_to_quantize is optionally added:
config.quantization_config = _quantization_config_for_model_config(
quantize_config,
runtime_format,
)
explicit_quantized_modules = _gptq_explicit_quantized_modules(
quantize_config, model_for_save
)
if explicit_quantized_modules is not None:
config.quantization_config["modules_in_block_to_quantize"] = (
explicit_quantized_modules
)gptqmodel/models/definitions/smolvlm.py:38-41: module_tree = ["model", "text_model", "layers", "#", ...]
Reproduction (ran on RTX 4090, torch 2.15, transformers 5.23, optimum installed)
from gptqmodel import GPTQModel, GPTQConfig, CalibrationConfig
mid = "HuggingFaceTB/SmolVLM2-256M-Video-Instruct"
m = GPTQModel.load(mid, GPTQConfig(bits=4, group_size=64)) # g64 because hidden=576 (g128 additionally hits #6149)
m.quantize(CalibrationConfig(dataset=image_and_text_conversations, batch_size=1))
m.save("smolvlm2-gptq")
from transformers import AutoModelForImageTextToText
AutoModelForImageTextToText.from_pretrained("smolvlm2-gptq", device_map="cuda:0")Output:
File ".../transformers/quantizers/quantizer_gptq.py", line 94, in _process_model_before_weight_loading
File ".../optimum/gptq/quantizer.py", line 258, in convert_model
File ".../optimum/gptq/utils.py", line 85, in get_block_name_with_pattern
ValueError: Block pattern could not be match. Pass `block_name_to_quantize` argument in `quantize_model`
GPTQModel.load("smolvlm2-gptq") on the same directory works: wikitext2 PPL 30.60 (bf16 26.88), text and image answers are coherent.
After adding "block_name_to_quantize": "model.text_model.layers" to config.json["quantization_config"], the same from_pretrained call loads. HF PPL is 30.59, and the outputs are ' The capital of France is Paris, France. ...' and ' The image captures a breathtaking view of a mountain range, ...' (the image answer is identical to GPTQModel.load).
Expected vs actual
Expected: a GPTQ checkpoint saved by GPT-QModel for a supported, Transformers-native architecture loads with from_pretrained, as it does for models under model.layers / model.language_model.layers (e.g. InternVL3-1B-hf in the same run: HF PPL 23.85 vs native 23.84).
Actual: Optimum cannot locate the decoder blocks and the load fails.
Suggested fix
In the writer, set quantization_config["block_name_to_quantize"] to the definition's layer-container path, i.e. the module_tree prefix before "#" as a dotted runtime name such as model.text_model.layers. Do it at least when that prefix is not one of Optimum's BLOCK_PATTERNS. Transformers' GPTQConfig already carries the field, and Optimum uses it verbatim.
Activity