Skip to content

fix(export): load MLX exports on CPU so GEMV checkpoints export on GPU hosts (#4809) - #4828

Merged
Qubitium merged 1 commit into
mainfrom
fix/issue-4809-mlx-export-cpu
Nov 17, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/issue-4809-mlx-export-cpu

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4809.

Problem

GPTQModel.export(..., "mlx") loads the checkpoint with a per-method backend and no device. For AWQ it picks
BACKEND.AWQ_TORCH, which resolves FORMAT.GEMV / GEMV_FAST / LLM_AWQ to the CPU-only portable readers
(AwqGEMVTorchLinear, AwqGEMVFastTorchLinear, added for #4554/#4736). Default device selection picks the
accelerator whenever one is visible, so the documented export died before any conversion:

ValueError: <class 'gptqmodel.nn_modules.qlinear.gemv_awq.AwqGEMVTorchLinear'> does not support device: cuda:0
ValueError: <class 'gptqmodel.nn_modules.qlinear.gemv_fast_awq.AwqGEMVFastTorchLinear'> does not support device: cuda:0

The same checkpoint exported correctly with CUDA_VISIBLE_DEVICES="", and the converter already allows those
formats - so the failure depended only on which device was visible, on the very hosts that produce the checkpoints.

Fix

The MLX path only reads packed tensors on the host, so export(..., "mlx") now loads with device="cpu".

Paro is the one exception: its export backend is BACKEND.PARO_CUDA, so forcing CPU there would replace a working
export with a device error. It keeps the default device selection.

Tests (tests/test_mlx_export_device_4809.py)

The real GPTQModel.export entry point is driven with the loader, the MLX writer and the converter stubbed, and the
load kwargs are asserted:

  • AWQ gemv, gemv_fast, llm-awq, gemm -> backend=AWQ_TORCH, device="cpu";
  • gptq, fp8, nf12, macaq, gguf, bitsandbytes -> device="cpu";
  • paro -> backend=PARO_CUDA and no device kwarg (unchanged behaviour).

Red on unmodified main (e33acc804): 10 of 11 fail; the Paro case passes on both, as intended.

Green on this branch: 11 passed. ruff check clean.

…U hosts (#4809)

`GPTQModel.export(..., "mlx")` loads the checkpoint with a per-method backend
and no device. For AWQ it picks `BACKEND.AWQ_TORCH`, which resolves
`FORMAT.GEMV` / `GEMV_FAST` / `LLM_AWQ` to the CPU-only portable readers
(`AwqGEMVTorchLinear`, `AwqGEMVFastTorchLinear`, #4554/#4736). Default device
selection picks the accelerator whenever one is visible, so the documented
export failed before the conversion started:

    ValueError: <class '...AwqGEMVTorchLinear'> does not support device: cuda:0

The same checkpoint exported correctly with no visible GPU, and the converter
already supports those formats.

The MLX path only reads packed host tensors, so the export now loads with
`device="cpu"`. Paro is the one exception: its export backend is CUDA-only, so
it keeps the default device selection rather than turning a working export into
a CPU device error.

Tests: new `tests/test_mlx_export_device_4809.py` drives the real export entry
point with the loader, the MLX writer and the converter stubbed, and asserts
the load kwargs for every method: AWQ (all four formats) and the other
host-side exporters must ask for CPU, Paro must not.

Red on unmodified main (e33acc8): 10 of 11 fail. Green here: 11 passed.
@Qubitium
Qubitium merged commit 6fa1bba into main Nov 17, 2026
9 checks passed
@Qubitium
Qubitium deleted the fix/issue-4809-mlx-export-cpu branch November 17, 2026 16:14
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