Repository navigation
refactor(mlx): remove the invented FP8 Metal kernels and loader - #5245
Merged
Merged
Conversation
Follow-up to #5242. Delete gptqmodel/nn_modules/qlinear/mlx_fp8.py (MlxFP8Linear, MlxFP8PackedLinear, and the gptqmodel_fp8_packed_matmul Metal kernels), the FP8MlxQuantLinear holder, and the MLX FP8 loader branches. FP8 remains load-only on the Torch backend; the MLX loader now rejects FORMAT.FP8 with a clear ValueError.
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.
Summary
Follow-up to #5242 (merged). #5242 removed the invented
gptqmodel_fp8export, but the MLX FP8 decode runtime it fed still shipped: two custom Metal kernels and a loader that decoded checkpoint bytes on the GPU. This PR deletes that runtime too, so FP8 is load-only on the Torch backend and the MLX backend refuses it explicitly. Net:-329/+47lines across code, tests and docs.What Changed
gptqmodel/nn_modules/qlinear/mlx_fp8.py(303 lines):MlxFP8Linear,MlxFP8PackedLinear, and thegptqmodel_fp8_packed_matmul_{fp16,bf16,fp32}/..._r16_n{16,32}Metal kernels.FP8MlxQuantLinearfromgptqmodel/nn_modules/qlinear/mlx.py:969and itsTorchFP8Linearimport.gptqmodel/utils/mlx.py: droppedTorchFP8Linearfrom the packed-transfer set, removed thefp8_native/fp8_packedbranches andFORMAT.FP8from the supported-format lists, and added a fail-fast guard at_build_mlx_model_from_checkpoint(gptqmodel/utils/mlx.py:528) that raisesValueErrornaming the removed kernels and directing the load to Torch.tests/test_mlx_fp8_native.py,tests/test_mlx_fp8_packed.py,tests/benchmark_mlx_qwen38_fp8_{native,packed,prefill_tile,processor}.py.docs/fp8-load-only.md,docs/mlx-runtime.md,docs/support-matrix.md,docs/kernel-compile-matrix.md,docs/generation-compile-policy.md,docs/fusion-kernel-inventory.md,docs/benchmarks/fusion-kernel-inventory.json,docs/fusion-device-validation.md.tests/test_mlx_fp8_removed.py: no MLX FP8 kernel or holder remains, the MLX loader rejectsFORMAT.FP8, and Torch still selectsTorchFP8Linear.Behaviour changes:
GPTQModel.load(..., backend="mlx")with an FP8 checkpoint now fails instead of decoding on Metal. ExplicitBACKEND.MLXfails in kernel selection (Unsupported backend: BACKEND.MLX for METHOD.FP8 with format FORMAT.FP8); the MLX conversion entry point raises the explicit removalValueError._auto_select_mlx_backend(gptqmodel/models/loader.py:312) catches the selectionValueErrorand returns AUTO, which resolves toTorchFP8Linear.FineGrainedFP8, DeepSeek/Qwen block scales, ModelOpt, MXFP8, NVFP8) is unchanged on the Torch backend.Tests
Executed on Linux/aarch64, CPU only, torch 2.11.0+cu130 (repo safety gate bypassed with
GPTQ_BYPASS_SAFETY_CHECKS=1); no Apple Silicon and no CUDA here, so MLX/CUDA nodes are skipped, not passed.Skipped and unverified: every MLX runtime node (
mlx.coreis not installed), all CUDA FP8 kernel nodes, and the Metal kernel numerics that this PR deletes. The removal itself is covered by CPU tests; no native MLX evidence is claimed.Model Support / Module Plan
Not applicable: no
MODEL_MAP, definition or module-plan change.AWQ onboarding safety
Not applicable: no model/alias, AWQ grouping, search, replay or fold change.
Logic Flow Documentation
The change removes a dispatch branch and a fail-open Metal path, so the flows are repeated in
docs/fp8-load-only.md(new flow) anddocs/mlx-runtime.md(conversion path).Old flow (before this PR):
flowchart TD A["GPTQModel.load(backend='mlx')"] --> B["select_quant_linear(MLX, FORMAT.FP8)"] B --> C["FP8MlxQuantLinear"] C --> D{"native_compatible?"} D -- "yes" --> E["MlxFP8Linear<br/>gptqmodel_fp8_packed_matmul kernels"] D -- "no" --> F["MlxFP8PackedLinear<br/>decode codebook on Metal"] E --> G["MPS output"] F --> GNew flow (shipped):
flowchart TD A["GPTQModel.load(backend='mlx')"] --> B{"FORMAT.FP8?"} B -- "yes" --> C["ValueError: Metal kernels removed<br/>load FP8 with the Torch backend"] B -- "no" --> D["existing MLX holders<br/>GPTQ/AWQ/Paro/QQQ/GGUF/BNB/EXL3/MACaQ/NF12"] A2["GPTQModel.load(backend='auto')"] --> E["_auto_select_mlx_backend"] E --> F{"select_quant_linear(MLX, FORMAT.FP8)"} F -- "ValueError" --> G["stay on AUTO"] G --> H["TorchFP8Linear"] classDef failure fill:#f8d7da,stroke:#b42318,color:#111; classDef ok fill:#d1e7dd,stroke:#0f5132,color:#111; class C failure class H okBefore/after:
FP8MlxQuantLinearatgptqmodel/nn_modules/qlinear/mlx.py:969gptqmodel/nn_modules/qlinear/mlx_fp8.py:48-190,:118-190fp8_native/fp8_packedatgptqmodel/utils/mlx.py:202-203FORMAT.FP8rejected atgptqmodel/utils/mlx.py:528FORMAT.FP8in the list atgptqmodel/utils/mlx.py:574TorchFP8LinearReview Requirements
I or an AI agent (such as Codex or Claude) have:
Kernel Accuracy Requirements
tests/test_fp8.py,tests/kernels/test_fp8_kernel.py) were re-run; GPU-gated nodes skipped as listed above.Notes
SUPPORTS_COMPILE = False), so no measured path is lost; the compile-policy row is removed rather than re-declared.docs/benchmarks/fusion-kernel-inventory.jsonis the committed snapshot: the deleted class rows and the 57 -> 56 counts are removed, without re-running the CUDA/ROCm benchmark here.ValueError.