Repository navigation
fix(macaq): int64 row offsets, device-bound Triton launches, sm_120 K tiles (#4090) - #4099
Merged
Merged
Conversation
… tiles (#4090) - widen the row index to int64 in the activation quantizer, fused rotate+quantize, and weight dequantizer kernels; rows*K can exceed 2^31 - enter the operand's device for every MACaQ Triton launch and only latch _triton_disabled for permanent failures, not transient OOMs - keep BLOCK_K >= 64 and rely on the existing K-tail masks so sm_120's native MXFP4 dot_scaled compiles - honor the configured fallback threshold with data-independent MXFP4 RTN (identity H, no D1) when an expert receives no calibration tokens - apply a one-element exp_offsets entry on the RTN path - translate dynamic={pattern: False} into a `-:` exclusion - register refusing HF quantizers for macaq, paroquant, qqq, nf12 and tt-blockfloat so transformers cannot silently random-initialize them
This was referenced Nov 15, 2026
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 #4090
TL;DR
Seven MACaQ MXFP4 W4A4 defects: 32-bit row offsets in three Triton kernels,
transformers silently random-initializing MACaQ (and ParoQuant/QQQ/NF12/
TT-blockfloat) checkpoints, MACaQ launches ignoring the operand's device
(permanent Torch fallback), the
sm_120BLOCK_K=32compile failure, theunread MoE
fallback, one-elementexp_offsets, anddynamic={pattern: False}.Core MACaQ math is unchanged.
Root cause and fix
1 (high) — int32 row offsets overflow once
rows*K >= 2^31gptqmodel/utils/macaq_triton.py:_quant_mxfp4_kernel,_rot_scale_quant_kerneland
_dequant_w4_to_bf16_kernelusedrow = tl.program_id(0)(i32) and computedrow * stride_xr/row * stride_pr/row * (K // 2)in i32. The dense GEMMalready widened
offs_m(:200). One large prefill through a widedown_proj(
K=18944overflows at 113,359 tokens) wrapped the row address, read the wrongrow on CUDA, and faulted the HIP context on ROCm.
Fix:
row = tl.program_id(0).to(tl.int64)in all three kernels(
gptqmodel/utils/macaq_triton.py:143,178,258).2 (medium) — HF loads MACaQ checkpoints as random dense weights
config.jsoncarriesquant_method: "macaq". Transformers 5.22'sAutoHfQuantizer.supports_quant_methodonly warnsUnknown quantization typeand sets
pre_quantized=False, sofrom_pretrainedreturns a plain model whosepacked tensors were randomly initialized. Only
gptqmodel_ggufhad a refusingquantizer (
gptqmodel/__init__.py:131-156).Fix: one table,
REFUSED_HF_QUANT_METHODSingptqmodel/_quant_methods.py:21,registers
GPTQModelRefusingHfQuantizer/GPTQModelRefusingQuantizationConfig(
gptqmodel/utils/hf_refusing_quantizer.py) formacaq,paroquant,qqq,nf12,tt-blockfloat. GGUF keeps its dedicated quantizer. The table is thesingle extension point for the sibling #4091 item 5 fix.
Before (origin/main, tiny packed checkpoint re-labelled
macaq):After:
3 (medium) — Triton launches ignored the tensor's GPU; modules latched to Torch
quantize_mxfp4,rot_scale_quantize_mxfp4,dequant_w4_to_bf16andmxfp4_w4a4_linearlaunched into the current context. A layer oncuda:1while
cuda:0was current raisedValueError: Pointer argument cannot be accessed from Triton, andMacaqLinear.forwardset_triton_disabled=Truepermanently (
gptqmodel/nn_modules/qlinear/macaq.py:279-287).Fix: every launch is wrapped in
_launch_device(<operand>.device)(
gptqmodel/utils/macaq_triton.py:56, same guard as GGUF/W4A), and the catch-allnow latches only permanent failures:
_triton_failure_is_transient(
gptqmodel/nn_modules/qlinear/macaq.py:41,297) keeps Triton enabled after atransient OOM.
flowchart TD A["MacaqLinear.forward"] --> B{"_can_use_triton"} B -->|no| T["_forward_torch"] B -->|yes| C["with torch.cuda.device(x.device)<br/>Triton launch"] C -->|ok| O["output"] C -->|OOM or 'out of memory'| T2["_forward_torch<br/>Triton stays enabled"] C -->|compile or pointer error| L["_triton_disabled = True<br/>_forward_torch"] classDef error fill:#fdd,stroke:#c00,color:#000; class L error;Measured cliff the latch protected, decode shape
M=1, N=896, K=4864(300 iterations, CUDA events):
4 (medium) — sm_120
BLOCK_K=32fails to compile_pick_tilesfell back toblock_k=32when no candidate dividedK(
gptqmodel/utils/macaq_triton.py:370). Onsm_120,tl.dot_scaledlowers tothe native
mma.sync...kind::mxf4nvf4.block_scaleinstruction, which requires aK tile of at least 64 →
RuntimeError: PassManager::run failed, then thecatch-all disabled Triton.
Fix:
_pick_tileskeeps the largest measured tile and the public entry pointshrinks it only down to 64 (
:440-443). The existingkb_mask/ks_masktailsmake a non-divisor tile correct; no divisor requirement remains.
test_triton_dense_kernel_masks_k_tailnow also coversK=96/288/160.The sm_120 compile path itself was not re-verified here (no sm_120 card is
available; the RTX 5090 is off-limits). Correctness of the 64-wide tile with the
K tails was verified against the fp64-derived Torch oracle on
sm_89andgfx1201.5 (medium) — MoE expert with no calibration tokens crashed;
fallbacknever readMacaqProcessor.preprocesssettask.fallback(
gptqmodel/looper/macaq_processor.py:114), butMacaq.quantizealways raisedValueError: ... no usable calibration signal(gptqmodel/quantization/macaq.py:706).Fix (
gptqmodel/quantization/macaq.py:715-760): consultshould_use_fallback(self.fallback, nsamples, expected_nsamples). When itmatches, or the Hessian is unusable but a fallback threshold is configured, run
data-independent MXFP4 RTN with an identity metric, no D1, no exponent screen and
no flips; record
fallback=Truein the result stats. Without a configuredthreshold the original actionable
ValueErrorremains.flowchart TD E["Macaq.add_batch<br/>capture Hessian"] --> U{"finite and nonzero<br/>diagonal?"} U -->|no| F{"fallback threshold<br/>matches observed tokens?"} U -->|yes| G{"observed tokens below<br/>fallback threshold?"} F -->|no| X["ValueError<br/>no usable calibration signal"] F -->|yes| R["MXFP4 RTN<br/>identity H, no D1"] G -->|yes| R G -->|no| Q["calibrated MACaQ<br/>D1 + screen + flip"] classDef error fill:#fdd,stroke:#c00,color:#000; class X error;6 (low) — one non-zero
exp_offsetsentry was ignoredmacaq_quantize_weightonly screenedlen(exp_offsets) > 1, so(-1,)and(2,)fell through tomxfp4_rtn_signed_index(..., offset=0)(
gptqmodel/quantization/macaq.py:533). Fix: pass the single offset(
:540).7 (low) —
dynamic={pattern: False}crashedMacaqConfigThe documented exclusion form (
docs/macaq.md:319) was accepted byMacaqConfig.__post_init__but the shared normalizer calls.items()on theFalsepayload (gptqmodel/quantization/config.py:4571/4719). Fix: translateFalseto the base-:patternrule with an empty override before sharednormalization (
gptqmodel/quantization/config.py:6244-6256).Before / after
packed[-1]all zero bytes (wrong row); source check failsLOADEDplainLinearx8, noqweight, random weightsValueErrornamingGPTQModel.load/vLLM[]; transient OOM sets_triton_disabled=True_pick_tiles(1,96)[2] == 32,(8,160) == 32>= 64ValueError: no usable calibration signalfallback=True,pre_scale=None, bytes equal independent RTN oracle(-1,)/(2,)produce offset-0 packed bytesAttributeError: 'bool' object has no attribute 'items'dynamic_get(...) is False, round-trips as-:.*down_projTests
New regressions in
tests/test_macaq.py; the ParoQuant registration guard intests/test_paroquant.pywas updated (it previously asserted the name wasunknown, which is exactly the silent-load path).
The fail-before numbers above were produced in a clean
git worktreeoforigin/main@718256fd7with the same test file:16 failed, 3 passedfor the new regressions. The two-device cross-device testis skipped in both runs.
Hardware: RTX 4090 (
sm_89, Torch 2.16.0.dev+cu130, Triton 3.9) and Radeon AIPRO R9700 (
gfx1201, Torch 2.16.0.dev+rocm10.1).Limitations
CUDA device and one HIP device (
HIP_VISIBLE_DEVICES=3). CUDA/HIP rejectduplicate UUID/index entries (
device_count() == 0), the RTX 5090 isoff-limits, and the other 4090s belong to parallel workers. The committed
test_macaq_module_on_non_current_gpu_stays_on_tritonruns thecuda:0vscuda:1output/disabled-module comparison whenever two devices arevisible; it is the skipped test here. The launch-guard regression fails before
and passes after, and the decode cliff is quantified above.
above).
macaq,paroquant,qqq,nf12,tt-blockfloat(plusthe existing GGUF refusal).
exl3and the barebitsandbytesname are alsoabsent from transformers' mapping but are outside this issue's enumerated set.
Docs
docs/macaq.mdgains the runtime/edge-case contracts, the updated calibrationfallback flow, the launch/latch diagram, the
BLOCK_K >= 64contract, thedynamic=Falsetranslation, and the transformers refusal table. It is alreadylinked from
README.md(MACaQlinks todocs/macaq.md).