Skip to content

refactor(mlx): remove the invented FP8 Metal kernels and loader - #5245

Merged
Qubitium merged 1 commit into
mainfrom
feat/remove-mlx-fp8-kernels
Nov 18, 2026
Merged

Qubitium merged 1 commit into
mainfrom
feat/remove-mlx-fp8-kernels

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #5242 (merged). #5242 removed the invented gptqmodel_fp8 export, 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/+47 lines across code, tests and docs.

What Changed

  • Deleted gptqmodel/nn_modules/qlinear/mlx_fp8.py (303 lines): MlxFP8Linear, MlxFP8PackedLinear, and the gptqmodel_fp8_packed_matmul_{fp16,bf16,fp32} / ..._r16_n{16,32} Metal kernels.
  • Removed FP8MlxQuantLinear from gptqmodel/nn_modules/qlinear/mlx.py:969 and its TorchFP8Linear import.
  • gptqmodel/utils/mlx.py: dropped TorchFP8Linear from the packed-transfer set, removed the fp8_native / fp8_packed branches and FORMAT.FP8 from the supported-format lists, and added a fail-fast guard at _build_mlx_model_from_checkpoint (gptqmodel/utils/mlx.py:528) that raises ValueError naming the removed kernels and directing the load to Torch.
  • Deleted the MLX FP8 tests and benchmarks: tests/test_mlx_fp8_native.py, tests/test_mlx_fp8_packed.py, tests/benchmark_mlx_qwen38_fp8_{native,packed,prefill_tile,processor}.py.
  • Updated the kernel/compile/fusion inventories and their committed snapshot: 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.
  • Added tests/test_mlx_fp8_removed.py: no MLX FP8 kernel or holder remains, the MLX loader rejects FORMAT.FP8, and Torch still selects TorchFP8Linear.

Behaviour changes:

  • GPTQModel.load(..., backend="mlx") with an FP8 checkpoint now fails instead of decoding on Metal. Explicit BACKEND.MLX fails in kernel selection (Unsupported backend: BACKEND.MLX for METHOD.FP8 with format FORMAT.FP8); the MLX conversion entry point raises the explicit removal ValueError.
  • AUTO no longer selects MLX for FP8: _auto_select_mlx_backend (gptqmodel/models/loader.py:312) catches the selection ValueError and returns AUTO, which resolves to TorchFP8Linear.
  • Production FP8 (transformers FineGrainedFP8, DeepSeek/Qwen block scales, ModelOpt, MXFP8, NVFP8) is unchanged on the Torch backend.
  • Out of scope: no replacement MLX FP8 kernel is proposed. MXFP8/NVFP8 stay Torch-only.

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.

cd tests
PYTHONPATH=$PWD/.. GPTQ_BYPASS_SAFETY_CHECKS=1 CUDA_VISIBLE_DEVICES="" \
  python -m pytest test_mlx_fp8_removed.py -q -rs
# 4 passed

PYTHONPATH=$PWD/.. GPTQ_BYPASS_SAFETY_CHECKS=1 CUDA_VISIBLE_DEVICES="" \
  python -m pytest test_mlx_dense_methods.py test_mlx_method_selection.py \
  test_generation_compile_policy_4669.py test_rocm_kernel_contracts.py \
  kernels/test_kernel_compile_levels_nontorch.py -q -rs
# 475 passed, 21 skipped (mlx/ttnn/torch_xla/CUDA absent)

PYTHONPATH=$PWD/.. GPTQ_BYPASS_SAFETY_CHECKS=1 CUDA_VISIBLE_DEVICES="" \
  python -m pytest test_fp8.py kernels/test_fp8_kernel.py \
  test_fp8_dequant_inplace.py test_rocm_fp8_gating.py test_mlx_fp8_removed.py -q -rs
# 76 passed, 54 skipped (NVIDIA/CUDA FP8 nodes need a GPU)

PYTHONPATH=$PWD/.. GPTQ_BYPASS_SAFETY_CHECKS=1 CUDA_VISIBLE_DEVICES="" \
  python -m pytest test_docs_contract_refs.py -q -rs
# 33 passed

uvx [email protected] check gptqmodel docs/eora tests setup.py
# All checks passed!

Skipped and unverified: every MLX runtime node (mlx.core is 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) and docs/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 --> G
Loading

New 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 ok
Loading

Before/after:

Mechanism Before After
MLX FP8 holder FP8MlxQuantLinear at gptqmodel/nn_modules/qlinear/mlx.py:969 deleted
MLX FP8 kernels gptqmodel/nn_modules/qlinear/mlx_fp8.py:48-190, :118-190 deleted with the file
MLX FP8 loader fp8_native / fp8_packed at gptqmodel/utils/mlx.py:202-203 deleted; FORMAT.FP8 rejected at gptqmodel/utils/mlx.py:528
MLX supported formats FORMAT.FP8 in the list at gptqmodel/utils/mlx.py:574 removed
Torch FP8 TorchFP8Linear unchanged

Review Requirements

I or an AI agent (such as Codex or Claude) have:

  • Reviewed this PR.
  • Checked that the code matches existing project structure, APIs, and conventions.
  • Avoided unnecessary monkeypatching and used the project's normal extension points where possible.
  • Minimized and compacted the impacted code surface.
  • Considered and eliminated potential regressions.

Kernel Accuracy Requirements

  • Not applicable to a remaining kernel: this PR deletes kernels and changes no arithmetic. Production FP8 Torch decode tests (tests/test_fp8.py, tests/kernels/test_fp8_kernel.py) were re-run; GPU-gated nodes skipped as listed above.
  • Fusion support is untouched; the inventory snapshot drops the deleted class and its count (57 -> 56).
  • The kernel inventory lists the removed class as absent; no new unqualified format is admitted.

Notes

  • The Metal FP8 kernels were never traced or timed (SUPPORTS_COMPILE = False), so no measured path is lost; the compile-policy row is removed rather than re-declared.
  • docs/benchmarks/fusion-kernel-inventory.json is the committed snapshot: the deleted class rows and the 57 -> 56 counts are removed, without re-running the CUDA/ROCm benchmark here.
  • MLX hardware was unavailable, so no native Apple Silicon run backs this PR; reviewers on M-series should confirm that an FP8 checkpoint now raises the documented ValueError.

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.
@Qubitium
Qubitium marked this pull request as ready for review November 18, 2026 13:45
@Qubitium
Qubitium merged commit 0275eb4 into main Nov 18, 2026
6 checks passed
@Qubitium
Qubitium deleted the feat/remove-mlx-fp8-kernels branch November 18, 2026 13:48
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