Repository navigation
fix(export): fail closed on unknown formats and keep dense exports loadable (#4386) - #4418
Merged
Merged
Conversation
…adable (#4386) - Reject export formats other than hf/mlx (case-insensitive) before any config read or model load instead of silently writing only a tokenizer. - Forward trust_remote_code to GPTQModel.load in the mlx export path. - Exclude quantize_config.json, quant_config.json and quant_log.csv from dense hf output so reloads do not route through from_quantized. - Raise NotImplementedError instead of a plain string in BaseQModel.to(). Adds CPU regression tests covering all four findings.
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.
Fixes #4386.
Problem
Four confirmed defects in the export path:
a. Unknown format strings silently "succeed."
GPTQModel.export(ckpt, out, "HF")/ a typo /"gguf"loaded the whole quantized model, matched no branch, wrote only the tokenizer, and returnedNone.b.
trust_remote_codewas dropped.auto.pycalledGPTQModel.load(model_id_or_path, backend=backend)without forwarding it, so a remote-code checkpoint failed withValueError: ... contains custom code which must be executed.c. The dense
hfexport kept quantization metadata. It copiedquantize_config.json,quant_config.jsonandquant_log.csv, soGPTQModel.load(export_dir)took the quantize-config branch and failed withMissing required quantized weights ... .qweight.d.
BaseQModel.to()didraise f"..."— a plain string, which raisesTypeError: exceptions must derive from BaseExceptioninstead of the intended message.Fix
models/auto.py: normalize and validateformat(hf/mlx, case-insensitive, whitespace-trimmed) before trust-remote-code resolution, config read, snapshot download, or model load — an unknown format no longer pays a full load. Forwardtrust_remote_codeintoGPTQModel.load.utils/model_dequant.py: dense output skipsquantize_config.json,quant_config.json,quant_log.csvvia a named constant. The source checkpoint and the quantized/save paths are untouched (copy_aux_filesitself is unchanged).models/base.py: raiseNotImplementedErrorwith the intended message.Tests
New
tests/test_export_contract_4386.py(12 tests, CPU, no downloads):unknown formats (
gguf,safetensors,HF2,mlx2,"") raiseValueError;uppercase
HF/Hftake the dense path;export(..., "mlx", trust_remote_code=True)forwards the kwarg;dense export drops the three quant metadata files while keeping them in the source;
BaseQModel.to()without a wrapped.toraisesNotImplementedError.pre-fix: 10 failed, 2 passed (the 2 passing are the lowercase-
hfcontrol and the unchangedcopy_aux_fileshelper);post-fix:
tests/test_export_contract_4386.py tests/test_export.py→ 15 passed, 1 skipped.tests/test_trust_remote_code_isolation.py→ 5 passed.ruff checkon all changed files → clean.Residual risk
mlx_lmis not installed here, so no end-to-end MLX conversion ran.hf_quant_config.json) are still copied if present.copy_aux_filesstays permissive for callers that do not add names toskip, so the quantized/save paths keep their metadata as required.tests/test_model_dequant_fp8.pyhas 1 failure from a missing optionalbitsandbytes, unrelated and pre-existing.