Repository navigation
fix(export): refuse an hf export whose method has no dense decoder (#4786) - #4824
Merged
Merged
Conversation
…4786) detect_format() guessed from tensor names before it looked at the declared quant_method. Paro carries .qweight without .g_idx and was decoded as AWQ, and MACaQ's format 'mxfp4_macaq' matched the 'mxfp4' substring, so both dropped their rotation, reported success and wrote a dense checkpoint whose weights ran but were garbage (nll 1.5 -> 13). GGUF failed with a misleading AWQ KeyError. A GPT-QModel method owns its packed layout and its format is only a sub-format of it, so the declared method now decides: detect_format() reports the method, and dequantize_model() refuses it with NotImplementedError before it creates the output directory.
13 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GPTQModel.export(path, out, "hf")reported success and wrote a dense checkpoint with wrong weights for Paro and MACaQ checkpoints.detect_format()guessed from tensor names before it looked at the declaredquant_method:method: "paro")awq.qweightwith no.g_idxtheta/pairs/channel_scalesdropped, rotated codes read as plain AWQ: silent garbage (nll 1.49 -> 13.28)method: "macaq")mxfp4mxfp4offormat: "mxfp4_macaq"BH/pre_scaledropped: silent garbage (nll 1.73 -> 12.64)method: "gguf")awqKeyError: Incomplete AWQ buffers ... missing {'qzeros', 'scales'}ValueError: Unable to detect quantization formatThe exported config carries no
quantization_config, so nothing downstream can tell the weights are wrong.A GPT-QModel method owns its packed layout, and its
formatis only a sub-format of that method — a rotation-free MACaQ checkpoint storesformat: "mxfp4"next tomethod: "macaq"(docs/macaq.md). Neither anmxfp4substring nor a.qweight-without-.g_idxsniff can separate those from a real MXFP4/AWQ checkpoint.Fixes #4786.
What Changed
gptqmodel/utils/model_dequant.py_UNDECODABLE_METHODS:paro,macaq,gguf,gptqmodel_gguf,qqq,nf12,vptq,exl3,tt_blockfloat.detect_format()returns the declared method for those, before the MX/FP8 string guesses and before the tensor-name sniffing, so the caller can refuse it instead of guessing a decoder.dequantize_model()raisesNotImplementedErrornaming the method and listing the formats that do have a dense decoder. The check runs beforeoutput_path.mkdir(), so a refused export leaves no half-built directory (it also now runs before the directory is created for any other pre-dispatch failure).docs/export-hf-format-detection.md(new) — Mermaid flow of the new decision order with the fail-closed exit marked, plus the before/after table. Linked fromREADME.md.tests/test_export.py—test_export_hf_refuses_a_method_without_a_dense_decoder, 8 nodes over Paro, MACaQ (mxfp4_macaqand rotation-freemxfp4), GGUF, QQQ, NF12, VPTQ, EXL3.Behaviour change:
export(..., "hf")now refuses these methods instead of writing wrong weights.GPTQModel.load()and the quantized checkpoints are unaffected; there is still no dense decoder for them, so the refusal message points atGPTQModel.load().Tests
ruff check gptqmodel docs/eora tests setup.py(theformat/check.shgate): All checks passed.Red / green evidence
Reverting only the
model_dequant.pyhunk, keeping the new test:[paro-paro]Failed: DID NOT RAISE NotImplementedError[macaq-mxfp4_macaq]DID NOT RAISE[macaq-mxfp4]DID NOT RAISE[gguf-q4_k_m]KeyError: Incomplete AWQ buffers ... missing {'qzeros', 'scales'}[qqq-qqq],[nf12-nf12],[vptq-vptq],[exl3-exl3]KeyErrorRed run:
8 failed. Green run:12 passed. The twoDID NOT RAISEcases are the reported silent-garbage bug: the broken export completes and writes the directory.Logic Flow Documentation
Required and included, because this introduces a fail-closed contract:
docs/export-hf-format-detection.md(linked fromREADME.md) holds the flow diagram, with the two fail-closed nodes (Eclassification,Krefusal) filled red.dequantize_model()->detect_format()-> declared method in_UNDECODABLE_METHODS? ->return method; otherwise the declared MX/FP8 semantics, otherwise tensor-name sniffing; thendequantize_model()raisesNotImplementedErroriffmt in _UNDECODABLE_METHODSbeforeoutput_path.mkdir().file:lineevidence: the olddetect_format()read"mxfp4" in declared(a substring of the joinedmethod format variant quant_algo) and then sniffed.qweightwithout.g_idxas AWQ. The table above records what each method resolved to before and after.G/J) is unstyled.Model Support / Module Plan
Not applicable — no
MODEL_MAPentry, definition or fusion config is touched.Review Requirements
tests/test_export.pyalready covers the other methods' export path; docs page follows thedocs/*.mdMermaid convention).dequantize_model().test_model_dequant_fp8.py), EXL3 still classifies asexl3.Notes
dequantize_model()and not indetect_format():detect_format()stays a pure classifier (tests call it directly), and returning the method name is what lets the caller refuse._UNDECODABLE_METHODSand adding afmt == ...branch.