Skip to content

feat(module): let resident 4-bit parameters use MXFP4 as well as NVFP4 - #5

Open
NolanHo wants to merge 1 commit into
mainfrom
feat/mxfp4-resident-param
Open

NolanHo wants to merge 1 commit into
mainfrom
feat/mxfp4-resident-param

Conversation

@NolanHo

@NolanHo NolanHo commented Nov 19, 2026

Copy link
Copy Markdown

Makes MXFP4 available to the resident 4-bit parameter path, which until now silently ignored it.

The defect

TransformerEngineBaseModule gated residency on the literal string:

if getattr(self, "primary_weights_in_fp4", None) == "nvfp4":

A caller asking for mxfp4 fell through the whole branch — no error, no log, no residency. The
weights stayed bf16 and were quantized per GEMM instead of being stored 4-bit, so the memory
saving simply never appeared.

The same branch also constructed NVFP4Quantizer() with no scale dtype, so even the accepted
nvfp4 value could only ever produce NVFP4 (E4M3, 16-element blocks).

The change

The format now selects the scale, and both 4-bit formats are accepted:

requested scale dtype block
mxfp4 kFloat8E8M0 32
nvfp4 kFloat8E4M3 16

Measured

Full model load, same host and checkpoint, three configurations:

expert parameter format device memory
bf16 (4-bit off) 158,282 MiB
nvfp4 97,520 MiB
mxfp4 before this change 153,820 MiB (identical to bf16 — the silent no-op)
mxfp4 with this change 92,480 MiB

The 5,040 MiB below nvfp4 is the half-width scale grid (2304/32 = 72 scale columns against
2304/16 = 144), so the direction of the difference corroborates that the format really changed
rather than just that nothing raised.

Quantization checked directly on a (2304, 2560) bf16 tensor:
_columnwise_data (2560, 1152) uint8, _columnwise_scale_inv (2560, 72) uint8.

Note on the removed comment

The branch carried a comment saying an E8M0 block-32 tensor has no parameter-capable type here,
citing detach failures. That was true of the reference implementation
(custom_recipes.reference_nvfp4.NVFP4TensorRef), not of the production quantizer, whose
NVFP4Tensor carries detach, requires_grad_, numel and data. The replacement comment
records the measurement instead.

The residency branch compared the requested format to the literal "nvfp4" and then constructed a
default NVFP4Quantizer, so asking for mxfp4 was a silent no-op: no error, no residency, weights
stayed bf16 and were quantized per GEMM instead of stored 4-bit. Measured on a full model load:
mxfp4 without this change settles at 153,820 MiB (identical to the bf16-expert configuration),
with it 92,480 MiB -- below the 97,520 MiB of nvfp4, the direction the half-width scale grid
implies.

The branch also passed no scale dtype, so even the nvfp4 path could only ever be NVFP4. It now
selects E8M0 for mxfp4 and keeps E4M3 otherwise.

The comment claiming an E8M0 block-32 tensor cannot be a parameter described the reference
implementation, whose NVFP4TensorRef lacks detach and requires_grad_; the production quantizer
returns an NVFP4Tensor that carries both.

This branch has not been deployed

No deployments
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