Skip to content

refactor(api): remove the deprecated GPTQModel.export() API - #4831

Merged
Qubitium merged 2 commits into
mainfrom
remove-export-api
Nov 17, 2026
Merged

Qubitium merged 2 commits into
mainfrom
remove-export-api

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Hard-removes the deprecated GPTQModel.export() API. The static wrapper only guessed a backend from quantization_config and forwarded to one of two checkpoint-level operations, so it duplicated dispatch and could hand a checkpoint to a decoder that does not understand its layout. Net diff: +210 / -315 across 12 files. No deprecation warning, shim, or alias remains.

What Changed

  • Deleted GPTQModel.export() from gptqmodel/models/auto.py (95 lines).
  • Dense output: call gptqmodel.utils.model_dequant.dequantize_model() directly (use gptqmodel.utils.hub.snapshot_download() first for repo ids).
  • MLX output: call GPTQModel.load() + gptqmodel.utils.mlx.convert_gptq_to_mlx_weights(..., stock_compatible=True), then mlx_lm.utils.save_model / save_config.
  • Tests: added tests/test_export_api_removed.py; moved surviving dequantization coverage to tests/test_model_dequant_dense.py and tests/test_dequantize_model_dtype_4455.py; dropped export-contract tests; preserved copy_aux_files and BaseQModel.to regressions in dedicated tests.
  • Docs: removed API references from docs/checkpoint-interop.md, docs/mlx-runtime.md, docs/macaq.md, docs/README.md; documented the removal and replacements; linked from README.md.
  • Follow-up out of scope: no replacement convenience wrapper is planned; callers own the destination API.

Tests

  • Unit tests executed and passed; skips are listed below.
  • Added new fast unit tests (tests/test_export_api_removed.py).
python -m pytest \
  tests/test_model_dequant_dense.py \
  tests/test_dequantize_model_dtype_4455.py \
  tests/test_base_qmodel_to.py \
  tests/test_export_api_removed.py \
  tests/test_model_dequant_dynamic_bits.py -q -p no:randomly
# 21 passed, 1 skipped in 1.35s

Skips: local /monster/data/model/AWQ-Llama-3.2-1B-g128-gemm checkpoint is absent on this host.

Red evidence on the parent commit (origin/main @ 22f124d) with the new test file copied in:

python -m pytest tests/test_export_api_removed.py -q -p no:randomly
# 2 failed
# test_export_is_not_part_of_the_public_api -> assert "export" not in GPTQModel.__dict__
# test_export_call_raises_attribute_error -> API exists and reaches model_dequant

Static checks:

ruff check gptqmodel/models/auto.py tests/test_model_dequant_dense.py \
  tests/test_dequantize_model_dtype_4455.py tests/test_base_qmodel_to.py \
  tests/test_export_api_removed.py tests/test_mlx_packing.py
# All checks passed!

Collection baseline: pytest tests -k "export or dequant" --collect-only reports the same 35 environment-only errors on both origin/main and this branch (missing triton, peft); no new collection failures.

Model Support / Module Plan

Not applicable: no MODEL_MAP, definition, module-plan, or fusion change.

Model test node IDs and results: not applicable.

AWQ onboarding safety

Not applicable: no model onboarding, AWQ grouping, search, replay, or fold change.

AWQ evidence and per-variant policy: not applicable.

Logic Flow Documentation

  • This change removes a public entry point, so the required diagrams and docs page are included.
  • New-flow Mermaid diagram describes the shipped code using real symbol names.
  • The removed mechanism is shown and tabulated with file:line evidence.
  • Failure and ambiguity paths are marked visually.
  • docs/checkpoint-interop.md repeats the diagrams, is titled for the mechanism, and is linked from README.md.

Diagram summary: the removed wrapper guessed a backend and forwarded to dequantize_model() or convert_gptq_to_mlx_weights(). The replacement flow has the caller choose the destination and call that API directly.

Review Requirements

  • Reviewed this PR.
  • Checked that the code matches existing project structure, APIs, and conventions.
  • Avoided unnecessary monkeypatching; used the existing public utilities.
  • Minimized and compacted the impacted code surface.
  • Considered and eliminated potential regressions (dequantization coverage preserved).

Kernel Accuracy Requirements

  • Not applicable: no kernel, fusion, or quantization-math change.

Notes


1. The problem

GPTQModel.export(model, target, format) was a static wrapper that validated format, guessed a runtime backend from quantization_config, then routed to one of two checkpoint-level operations. It owned no checkpoint logic; it only duplicated dispatch.

Old flow (removed)

flowchart TD
    A["GPTQModel.export(model, target, format)"] --> B{"format"}
    B -- hf --> C["snapshot_download when not local"]
    C --> D["dequantize_model()"]
    B -- mlx --> E["guess backend from quant_method"]
    E --> F["GPTQModel.load()"]
    F --> G["convert_gptq_to_mlx_weights<br/>stock_compatible=True"]
    B -- other --> X["ValueError"]
    style X fill:#f8d7da,stroke:#b02a37
Loading

Mechanisms removed

Mechanism Where it lived (origin/main @ 22f124d) Replacement
export() entry point + format validation gptqmodel/models/auto.py:1247-1253 None; callers pick the destination API
format="hf" snapshot resolve + dequantize gptqmodel/models/auto.py:1257-1277 dequantize_model() (call snapshot_download() first for repo ids)
Backend guessing from quant_method gptqmodel/models/auto.py:1279-1306 GPTQModel.load(..., backend=...) chosen by the caller
format="mlx" load + convert + save gptqmodel/models/auto.py:1315-1340 convert_gptq_to_mlx_weights(..., stock_compatible=True) + mlx_lm.utils.save_model / save_config

2. The new flow

flowchart TD
    S["caller"] --> Q{"destination"}
    Q -- "dense Transformers" --> R["snapshot_download for repo ids"]
    R --> T["dequantize_model(source, target)"]
    T --> U["dense safetensors + config<br/>without quantization_config"]
    Q -- "MLX-LM" --> V["GPTQModel.load(source, backend=...)"]
    V --> W["convert_gptq_to_mlx_weights<br/>stock_compatible=True"]
    W --> Y["mlx_lm.utils.save_model / save_config"]
    style U fill:#d9f2d9,stroke:#2e7d32
    style Y fill:#d9f2d9,stroke:#2e7d32
Loading

3. Failure and ambiguity contract

Situation Before After
GPTQModel.export(...) Ran a full model load / dequantize AttributeError
Unknown format ValueError after argument parsing AttributeError; no format argument exists
Unsupported checkpoint layout for dense output Could route through a wrong decoder and write garbage (#4786) dequantize_model() raises from detect_format()
MLX custom-runtime output Wrapper raised after conversion Caller inspects the converted config, as documented

4. Change inventory

Area File Purpose
API gptqmodel/models/auto.py Delete GPTQModel.export
Tests tests/test_export_api_removed.py Pin absence of attribute and call path
Tests tests/test_model_dequant_dense.py (renamed from test_export.py) Call dequantize_model(); keep metadata-drop and copy_aux_files coverage
Tests tests/test_dequantize_model_dtype_4455.py (renamed from test_export_dtype_4455.py) Keep dtype regression on dequantize_model()
Tests tests/test_base_qmodel_to.py Preserve the BaseQModel.to regression from the deleted contract file
Tests tests/test_export_contract_4386.py Deleted; export-contract tests no longer apply
Tests tests/test_mlx_packing.py Comment points at conversion, not the removed API
Docs docs/checkpoint-interop.md Dense-dequantization section + removal/replacement diagrams
Docs docs/mlx-runtime.md, docs/macaq.md, docs/README.md, README.md Remove API references; link the replacement docs

Rebase note (merge-conflict resolution)

Rebased onto main @ 5b58307 after #4824/#4828/#4809 landed, which touched the wrapper being removed:

Post-rebase validation: python -m pytest tests/test_model_dequant_dense.py tests/test_dequantize_model_dtype_4455.py tests/test_base_qmodel_to.py tests/test_export_api_removed.py tests/test_model_dequant_dynamic_bits.py -q -p no:randomly -> 29 passed, 1 skipped; ruff check clean.

GPTQModel.export() was a static convenience wrapper that guessed a
runtime backend from quantization_config and then routed to one of two
checkpoint-level operations. Both destinations have their own explicit
entry points, so the wrapper only duplicated dispatch.

Hard remove it: no deprecation warning, shim, or alias.

- Dense Transformers checkpoints: call
  gptqmodel.utils.model_dequant.dequantize_model() directly.
- MLX-LM checkpoints: call GPTQModel.load() and
  gptqmodel.utils.mlx.convert_gptq_to_mlx_weights(..., stock_compatible=True).

Tests:
- test_export_api_removed.py pins the absence of the attribute and call.
- Move the surviving dequantization coverage to
  test_model_dequant_dense.py and test_dequantize_model_dtype_4455.py,
  calling dequantize_model() directly.
- Drop the export-contract tests; keep the copy_aux_files and
  BaseQModel.to regressions in dedicated tests.

Docs:
- Remove GPTQModel.export references from checkpoint interop, MLX, and
  MACaQ pages.
- Document the removal, before/after flow, and replacements in
  docs/checkpoint-interop.md; link the page from README.md.
Rebase follow-up for the removal of GPTQModel.export():

- docs/export-hf-format-detection.md now documents dequantize_model()
  directly instead of the removed wrapper.
- Delete tests/test_mlx_export_device_4809.py: it exercised the CPU-load
  behaviour of the removed wrapper through a mocked export() call, so
  there is no surviving API for it to test.
@Qubitium
Qubitium merged commit 966ea73 into main Nov 17, 2026
9 checks passed
@Qubitium
Qubitium deleted the remove-export-api branch November 17, 2026 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant