Skip to content

MACaQ: rotation-free W4A16 mode, identity fast paths, stock MLX export - #4163

Merged
Qubitium merged 4 commits into
mainfrom
feat/macaq-rotation-free-w4a16
Nov 16, 2026
Merged

Qubitium merged 4 commits into
mainfrom
feat/macaq-rotation-free-w4a16

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • MacaqConfig(rotation="none") (default rotation="hadamard"): rotation-free MXFP4 that trades accuracy for faster inference. The Hessian-weighted exponent screen and greedy flip refinement still run, but in the original weight frame. Also settable per module via dynamic. Checkpoints with the legacy rotation: null load as "hadamard".
  • Plain mxfp4 format: MacaqLinear builds its transforms from the quant config — BH only for rotation="hadamard", pre_scale only for pre_mode="balance". With rotation="none" + pre_mode="none" a layer stores just W_packed, W_scales (+ bias), so the checkpoint format is FORMAT.MXFP4 ("mxfp4") instead of mxfp4_macaq. The format is derived from the settings across the base config and every dynamic override. Both formats save method: "macaq", which is how the resolver tells a MACaQ mxfp4 checkpoint from GGUF's mxfp4 subtype; a bare format: "mxfp4" still resolves to GGUF (verified unchanged).
  • rotation field isolation: MACaQ redefines the inherited rotation field, which elsewhere drives model-wide rotation (rotate_model, fused norms, online Hadamard at load, disabling disk offload). Generic code now reads it through resolve_model_rotation() / BaseQuantizeConfig.model_rotation, which MacaqConfig overrides to None. Behavior for other methods is unchanged.
  • Transform-free runtime: plain layers run a plain MXFP4 dequantize-matmul (W4A16) on Torch, Triton and MLX, bit-identical to applying identity transforms. Triton W4A4 rotates by an in-memory identity to keep the fused kernel.
  • Stock MLX export: GPTQModel.export(format="mlx") previously raised for every MACaQ checkpoint. Plain W4A16 layers now become a stock QuantizedLinear(mode="mxfp4", group_size=32, bits=4) with our packed bytes passed through unchanged, loadable by stock mlx_lm. Rotated layers still use the native MACaQ MLX module.
  • Zero-sample fallback: experts with no calibration data now use the min-MSE exponent screen (identity metric) instead of the OCP exponent, which clips block amax when its mantissa exceeds 1.5. Never worse, still data-independent.
  • Docs: rotation-free usage, runtime skipping, MLX export, and a note on MLX's activation exponent rule (ceil vs. OCP floor; MSE after Hadamard is no worse, so CUDA is unchanged).

Results — Llama-3.2-1B-Instruct, W4A16, Wikitext-2 PPL

Variant PPL vs BF16
BF16 19.39 —
MXFP4 RTN, no rotation 23.68 +22.1%
MACaQ rotation-free (hadamard=False) 21.27 +9.7%
MACaQ default (rotation + pre-scale) 20.46 +5.5%

The rotation-free mode closes 56% of the RTN→BF16 gap at zero runtime cost; the default is unchanged.

Tests

  • End-to-end on Llama-3.2-1B-Instruct (quantize → save → GPTQModel.load): plain saves format: mxfp4 with only W_packed/W_scales per layer, reloads 112/112 plain layers with bit-identical logits; default saves mxfp4_macaq with BH/pre_scale and also reloads bit-identically.
  • tests/test_macaq.py + tests/test_checkpoint_interop_4053.py + tests/test_required_qweight.py: 159 passed, 1 skipped (RTX 4090), including bit-exact Torch/Triton checks that skipping identity transforms changes nothing.
  • tests/test_mlx_macaq.py: the 5 non-Metal tests pass on CPU MLX, including a save/reload round trip through stock mlx_lm. The 9 Metal-only tests were not run — needs a Mac.
  • Pre-existing failures, identical on main: tests/test_fallback.py (24, GPTQ smoothing) and the other MLX converter tests on CPU MLX (same failing set on both).
  • Rotation/loader suites (test_rotation_persistence, test_auto_dtype_cast, test_checkpoint_model_types, test_hf_gptqmodel_load_bridge): 95 passed, 1 skipped. test_mlx_method_selection on CPU MLX: same 13 failures as before this change.
  • Config/serialization/GGUF suites: pass apart from 3 failures that are identical on the previous commit (test_dynamic::test_skip_module, 2 in test_hf_config_compat).
  • ruff clean.

🤖 Generated with Claude Code

Qubitium and others added 4 commits November 16, 2026 02:42
- MacaqConfig(block_hadamard=False) keeps the Hessian-weighted exponent
  screen and flip refinement but quantizes in the original weight frame.
  An identity BH is stored, so the checkpoint layout is unchanged and
  older loaders still run it correctly. Supported in `dynamic` too.
- MacaqLinear detects an identity BH and a unit pre_scale and skips them
  at runtime (bit-exact) on Torch, Triton W4A16 and MLX. Triton W4A4
  keeps the fused kernel.
- W4A16 layers with identity BH and unit pre_scale now export to a stock
  MLX QuantizedLinear(mode="mxfp4") with the packed bytes passed through
  unchanged; rotated layers keep the native MACaQ MLX path.
- Zero-sample fallback now runs the min-MSE exponent screen with an
  identity metric instead of the clipping OCP exponent.
- Docs: rotation-free usage and PPL table, MLX activation exponent rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…de-off

`hadamard` defaults to True. Comments and docs now state that
`hadamard=False` trades accuracy for faster inference.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
MacaqConfig now redefines the inherited `rotation` field as its own
per-layer transform: "hadamard" (default) or "none", which trades
accuracy for faster inference. Legacy `rotation: null` loads as
"hadamard".

The inherited field also drives model-wide rotation (rotate_model, fused
norms, online Hadamard at load, disabling disk offload). Generic code now
reads it through `resolve_model_rotation()` / `model_rotation`, which
MacaqConfig overrides to None, so MACaQ never triggers that path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…quant cfg

MacaqLinear now builds its activation transforms from the quant config
instead of detecting identity tensors: `BH` is registered only for
rotation="hadamard" and `pre_scale` only for pre_mode="balance". With
both off a layer stores just W_packed, W_scales and an optional bias.

That layout carries nothing MACaQ-specific, so it gets its own format:
FORMAT.MXFP4 ("mxfp4"). MacaqConfig derives the format from rotation and
pre_mode across the base settings and every dynamic override; anything
that keeps a transform stays mxfp4_macaq. Both formats save
method="macaq", which the config resolver uses to tell a MACaQ mxfp4
checkpoint from GGUF's mxfp4 subtype (a bare format="mxfp4" stays GGUF).

Triton W4A4 rotates by an in-memory identity for rotation="none" so it
keeps the fused rotate+quantize kernel. MLX stock export keys off the
same config-driven state.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Qubitium
Qubitium merged commit 9dad249 into main Nov 16, 2026
9 checks passed
@Qubitium
Qubitium deleted the feat/macaq-rotation-free-w4a16 branch November 16, 2026 03:24
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