Repository navigation
fix(export): load MLX exports on CPU so GEMV checkpoints export on GPU hosts (#4809) - #4828
Merged
Merged
Conversation
…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.
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.
Fixes #4809.
Problem
GPTQModel.export(..., "mlx")loads the checkpoint with a per-method backend and no device. For AWQ it picksBACKEND.AWQ_TORCH, which resolvesFORMAT.GEMV/GEMV_FAST/LLM_AWQto the CPU-only portable readers(
AwqGEMVTorchLinear,AwqGEMVFastTorchLinear, added for #4554/#4736). Default device selection picks theaccelerator whenever one is visible, so the documented export died before any conversion:
The same checkpoint exported correctly with
CUDA_VISIBLE_DEVICES="", and the converter already allows thoseformats - 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 withdevice="cpu".Paro is the one exception: its export backend is
BACKEND.PARO_CUDA, so forcing CPU there would replace a workingexport with a device error. It keeps the default device selection.
Tests (
tests/test_mlx_export_device_4809.py)The real
GPTQModel.exportentry point is driven with the loader, the MLX writer and the converter stubbed, and theload kwargs are asserted:
gemv,gemv_fast,llm-awq,gemm->backend=AWQ_TORCH,device="cpu";gptq,fp8,nf12,macaq,gguf,bitsandbytes->device="cpu";paro->backend=PARO_CUDAand nodevicekwarg (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 checkclean.