Skip to content

fix(export): fail closed on unknown formats and keep dense exports loadable (#4386) - #4418

Merged
Qubitium merged 1 commit into
mainfrom
fix/export-contract
Nov 16, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/export-contract

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

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 returned None.

b. trust_remote_code was dropped. auto.py called GPTQModel.load(model_id_or_path, backend=backend) without forwarding it, so a remote-code checkpoint failed with ValueError: ... contains custom code which must be executed.

c. The dense hf export kept quantization metadata. It copied quantize_config.json, quant_config.json and quant_log.csv, so GPTQModel.load(export_dir) took the quantize-config branch and failed with Missing required quantized weights ... .qweight.

d. BaseQModel.to() did raise f"..." — a plain string, which raises TypeError: exceptions must derive from BaseException instead of the intended message.

Fix

  • models/auto.py: normalize and validate format (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. Forward trust_remote_code into GPTQModel.load.
  • utils/model_dequant.py: dense output skips quantize_config.json, quant_config.json, quant_log.csv via a named constant. The source checkpoint and the quantized/save paths are untouched (copy_aux_files itself is unchanged).
  • models/base.py: raise NotImplementedError with the intended message.

Tests

New tests/test_export_contract_4386.py (12 tests, CPU, no downloads):

  • unknown formats (gguf, safetensors, HF2, mlx2, "") raise ValueError;

  • uppercase HF/Hf take 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 .to raises NotImplementedError.

  • pre-fix: 10 failed, 2 passed (the 2 passing are the lowercase-hf control and the unchanged copy_aux_files helper);

  • 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 check on all changed files → clean.

Residual risk

  • MLX export is verified only at the kwarg-forwarding boundary; mlx_lm is not installed here, so no end-to-end MLX conversion ran.
  • The dense-export exclusion is filename-based for the three files named in the issue; other quant sidecars (e.g. hf_quant_config.json) are still copied if present.
  • copy_aux_files stays permissive for callers that do not add names to skip, so the quantized/save paths keep their metadata as required.
  • tests/test_model_dequant_fp8.py has 1 failure from a missing optional bitsandbytes, unrelated and pre-existing.

…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.
@Qubitium
Qubitium merged commit c010e15 into main Nov 16, 2026
10 of 12 checks passed
@Qubitium
Qubitium deleted the fix/export-contract branch November 16, 2026 13:47
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