Add MXFP4 and NVFP4 quantization support#99
Merged
Conversation
Recognize the OCP MXFP4 and NVIDIA NVFP4 4-bit microscaling float formats across parsing, family grouping, size/VRAM estimation, speed estimation, ranking and the --quant filter. NVFP4 was previously referenced only in the family/benchmark/prequantized-repo regexes but absent from the quantization tables, so NVFP4 repositories were mislabeled as FP16 and their VRAM was overestimated (~2.0 vs 0.5625 bytes/weight). MXFP4 was not recognized anywhere, so --quant MXFP4 returned no candidates and MXFP4 repos were orphaned from their base family. This makes both formats consistent end-to-end. - bytes/weight: MXFP4 0.53125 (E2M1 + E8M0 scale / 32), NVFP4 0.5625 (E2M1 + E4M3 scale / 16) - quality penalty: NVFP4 0.05 (par with Q4_K_M; finer per-16 scale), MXFP4 0.06 (coarser per-32 power-of-two scale) - parsed from model ids and GGUF filenames; family grouping and output labels follow automatically Closes Andyyyy64#27
Owner
|
Merged, thank you. I reproduced the latent bug you found before merging: on main, both nvidia/...-NVFP4 and ...-MXFP4 repos infer as FP16, so VRAM was overestimated about 3.5x, exactly as described. Bytes-per-weight derivations check out, 301 tests pass locally. Nice catch on the half-wired NVFP4 state. |
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.
Closes #27.
What
Adds first-class support for the two 4-bit microscaling float quantization formats that recent local-LLM and hardware paths have started shipping:
Why
NVFP4 was already half-wired: it appeared in the family-normalization, benchmark pre-strip, and prequantized-repo regexes, but was missing from the quantization tables. The net effect was a latent bug — an
…-NVFP4repo fell throughinfer_non_gguf_quant_typeto theFP16default, so it was labeledFP16in the output and its VRAM was overestimated ~3.5× (2.0 vs 0.5625 bytes/weight). MXFP4 was not recognized anywhere, so--quant MXFP4returned no candidates and MXFP4 repos were orphaned from their base family during grouping.This PR makes both formats consistent across every path that already knew about the older quant formats.
Changes
data/quantization.py,engine/quantization.py0.53125(4.25 bits), NVFP40.5625(4.5 bits)data/quantization.py,engine/quantization.py0.05(par with Q4_K_M — finer per-16 E4M3 scale), MXFP40.06(coarser per-32 E8M0 power-of-two scale)engine/performance.py0.56, MXFP40.55(native FP4 tensor-core paths are weight-read-bound)data/quantization.pyengine/quantization.py(^|[-_/])mxfp4($|[-_/])/nvfp4patternsmodels/fetcher.py_extract_quant_typerecognizes*.MXFP4.gguf/*.NVFP4.ggufmodels/grouper.py-mxfp4/-nvfp4suffixesmodels/benchmark.pymxfp4to the suffix alternation (nvfp4 already present)Output labeling needs no change —
display.pyalready derives the label fromeffective_quant_type, which now returns the correct format.Bytes-per-weight derivation
(4·32 + 8) / 32 = 4.25 bits = 0.53125 B/w(4·16 + 8) / 16 = 4.5 bits = 0.5625 B/w(per-tensor FP32 scale amortizes to ~0)Tests
Covers the issue's "Done when" list:
test_infer_mxfp4,test_infer_nvfp4) and from GGUF filenames (test_extract_quant_type_parses_fp4_gguf_filenames)--quant MXFP4returning a candidate on a runnable (Linux+NVIDIA) host and being correctly filtered out on a GGUF-only backend…-MXFP4/…-NVFP4onto the base familyeffective_quant_typecall asdisplay.pyFull suite:
301 passed;ruff check .andruff format --check .clean.