Repository navigation
MACaQ: rotation-free W4A16 mode, identity fast paths, stock MLX export - #4163
Merged
Merged
Conversation
- 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]>
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
MacaqConfig(rotation="none")(defaultrotation="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 viadynamic. Checkpoints with the legacyrotation: nullload as"hadamard".mxfp4format:MacaqLinearbuilds its transforms from the quant config —BHonly forrotation="hadamard",pre_scaleonly forpre_mode="balance". Withrotation="none"+pre_mode="none"a layer stores justW_packed,W_scales(+bias), so the checkpoint format isFORMAT.MXFP4("mxfp4") instead ofmxfp4_macaq. The format is derived from the settings across the base config and everydynamicoverride. Both formats savemethod: "macaq", which is how the resolver tells a MACaQmxfp4checkpoint from GGUF'smxfp4subtype; a bareformat: "mxfp4"still resolves to GGUF (verified unchanged).rotationfield isolation: MACaQ redefines the inheritedrotationfield, which elsewhere drives model-wide rotation (rotate_model, fused norms, online Hadamard at load, disabling disk offload). Generic code now reads it throughresolve_model_rotation()/BaseQuantizeConfig.model_rotation, whichMacaqConfigoverrides toNone. Behavior for other methods is unchanged.GPTQModel.export(format="mlx")previously raised for every MACaQ checkpoint. Plain W4A16 layers now become a stockQuantizedLinear(mode="mxfp4", group_size=32, bits=4)with our packed bytes passed through unchanged, loadable by stockmlx_lm. Rotated layers still use the native MACaQ MLX module.Results — Llama-3.2-1B-Instruct, W4A16, Wikitext-2 PPL
hadamard=False)The rotation-free mode closes 56% of the RTN→BF16 gap at zero runtime cost; the default is unchanged.
Tests
GPTQModel.load): plain savesformat: mxfp4with onlyW_packed/W_scalesper layer, reloads 112/112 plain layers with bit-identical logits; default savesmxfp4_macaqwithBH/pre_scaleand 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 stockmlx_lm. The 9 Metal-only tests were not run — needs a Mac.main:tests/test_fallback.py(24, GPTQ smoothing) and the other MLX converter tests on CPU MLX (same failing set on both).test_rotation_persistence,test_auto_dtype_cast,test_checkpoint_model_types,test_hf_gptqmodel_load_bridge): 95 passed, 1 skipped.test_mlx_method_selectionon CPU MLX: same 13 failures as before this change.test_dynamic::test_skip_module, 2 intest_hf_config_compat).ruffclean.🤖 Generated with Claude Code