You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[MEM] MACaQ MXFP4 exponent screen materializes every code/index plane as int64 (values 0..14): screen_block_exponents 4.2 GiB on an 8B down_proj, 2.1 GiB with int32/uint8 (bitwise-identical); 8B layer peak 12.9 -> 10.7 GiB #4820
Found on main @ dba142d, RTX 4090 (CUDA 13.2, torch 2.15).
What is wrong
MACaQ's MXFP4 exponent screen builds every per-weight intermediate as int64, although the values are 0..14:
_e2m1_code_from_scaled (quantization/macaq.py:172-197) builds a 7-deep torch.where tree from Python ints and ends in .long();
mxfp4_rtn_signed_index (:200-238) then builds signed_index with two more int64 torch.wheres.
screen_block_exponents (:241-286) does this for 3 exponent offsets and keeps best_index int64 too. On an 8B down_proj (4096 x 14336), each int64 plane is 448 MiB. The screen alone peaks at about 4.1 GiB above its inputs. The default processor runs a layer's modules concurrently, so this is a large part of MACaQ's 8B layer peak: 12.9 GiB, 3.2x GPTQ's 4.0 GiB on the same layers.
This is separate from #4801, the compiled flip-sweep frame cycle that retains memory after the call. Here the waste is the live working set of the screen itself.
Measured
screen_block_exponents on a random 4096x14336 weight (Llama-3.1-8B down_proj shape), extra peak above inputs:
current (int64 codes/indices) 4195 MiB, 0.25 s, result 679 MiB
int32 signed index, uint8 accumulation of the 7 thresholds 2123 MiB, 0.12 s, result 455 MiB
-> best_index, best_log2 and best_scale are bitwise equal (indices compared after .long())
End to end, Llama-3.1-8B-Instruct truncated to 2 layers, MacaqConfig(), 64 C4 samples. The patch only changes mxfp4_rtn_signed_index, and the screen result is cast back to int64 so nothing downstream changes:
grid[signed_index] accepts int32 indices. Going further, the following would cut the screen to well under 1 GiB at this shape:
keep signed_index int32 (or uint8 with a cast at the gather) through flip_refine_levels;
return scale_element as the broadcast view of [out, groups, 1] instead of a contiguous fp32 [out, in], since it is 4 B/weight per offset.
Test that should have caught it
tests/test_macaq*.py: assert that screen_block_exponents on a 1024x4096 weight stays under about 1.5x of (fp32 weight bytes + int32 index bytes) of extra peak, and that its output is bitwise equal to a reference.
Severity
Medium-low: about 2.2 GiB (18%) of MACaQ's 8B per-layer peak, with no numeric change and a 2x faster screen.
Fixed by #4840 (merged). _e2m1_code_from_scaled now accumulates the four-bit code in uint8, mxfp4_rtn_signed_index widens once to int32, and the screen's index/exponent/scale stay bitwise identical.
Measured on the same host for screen_block_exponents: 4096x14336 extra peak 4195 -> 2011 MiB (-52%), retained result 679 -> 455 MiB; 1024x4096 extra peak 300 -> 144 MiB.
Activity
Qubitium commentedon Nov 17, 2026
Agent claim released:
agent-11788dff99fdfinished this issue.Pull request: #4840
Reproducing the int64 exponent screen; will move the code/index planes to uint8/int32 and prove bitwise-identical output plus a lower peak
perf(macaq): keep the MXFP4 exponent screen off int64 planes (#4820) (#…
Qubitium commentedon Nov 17, 2026
Fixed by #4840 (merged).
_e2m1_code_from_scalednow accumulates the four-bit code in uint8,mxfp4_rtn_signed_indexwidens once to int32, and the screen's index/exponent/scale stay bitwise identical.Measured on the same host for
screen_block_exponents: 4096x14336 extra peak 4195 -> 2011 MiB (-52%), retained result 679 -> 455 MiB; 1024x4096 extra peak 300 -> 144 MiB.