Repository navigation
feat(nvfp4): add NVFP4 weight-only quantization with Schur Replay - #6486
Conversation
ZX-ModelCloud
left a comment
There was a problem hiding this comment.
Fixed in 4d8af81. Schur Replay now scores the full conditional curvature from the upper Cholesky factor. NVFP4 scale bytes round-trip through reload, requantization, and dense export, including subnormal scales. Reload preserves the stored bias, deferred packing holds only the packed payload, and direct repacking respects the forward lock.
format/check.sh passed. The CPU suite passed 1,095 tests with three accelerator-only skips. The docs suite reproduced the existing docs/measurement.md example failure. The published benchmark numbers predate the curvature fix.
ZX-ModelCloud
left a comment
There was a problem hiding this comment.
Fixed in 07c8412. Casting a model to FP16 before its first forward could narrow the NVFP4 global scale and bias. Copy-loading a state dict could also narrow the bias or fail for modules constructed in inference mode. The regression now reproduces the exact cancellation result of -1 and preserves the saved values. Bias-free layers also honor meta-device construction.
format/check.sh passed. CPU validation passed 1,105 tests, including quantize/save/reload. Four accelerator-dependent tests were skipped.
0217385 to
c250596
Compare
Add the NVFP4 weight block-scale core from arXiv:2609.36654: - 126-point E4M3 scale grid and round-to-nearest-even E2M1 rounding - proposal/replay/commit selection with old-scale retention - GPTQ NVFP4 solve with a max-scale baseline - unit tests for the grid, rounding, replay/commit consistency and the per-group surrogate guarantee Add scripts/ab_schur_replay_nvfp4.py and docs/schur-replay-ab.md with a small-model W4A16 A/B. On Qwen3-0.6B and Llama-3.2-1B the selector reduces weight reconstruction error by about 25% and improves held-out loss, with no per-layer regressions. This is the gate for the full NVFP4 checkpoint/kernel work; it does not add the checkpoint format or an inference kernel yet.
Quantize dense weights to the NVIDIA/ModelOpt NVFP4 layout (E2M1 codes, one E4M3 scale per 16 input columns, FP32 per-tensor multiplier) with GPTQ's sequential error-feedback solve. Each 16-column group picks its block scale with Schur Replay (arXiv:2609.36654) or the max-scaled baseline, and the old scale is always a candidate, so a group cannot be worse than the baseline in the calibration metric. - METHOD.NVFP4 / FORMAT.NVFP4, NVFP4Config, BACKEND.NVFP4_TORCH, and a ProcessorStep.NVFP4 lifecycle that reuses the GPTQ Hessian capture - NVFP4Task: per-device X^T X capture, shared-input adoption, and a max-scaled RTN fallback for layers without calibration signal - NVFP4Linear: packed storage only, tiled FP32 decode, bias added once after the reduction; declares CPU, NVIDIA CUDA and AMD ROCm - ModelOpt-compatible checkpoint tensors (weight, weight_scale, weight_scale_2) plus a refused-plain-HF entry - desc_act and static groups are rejected: the block scale is bound to 16 consecutive input columns - tests: code-table and kernel oracles, the solver's per-group guarantee, and a save/reload lifecycle; run on CUDA and ROCm
c250596 to
d31d37c
Compare
Summary
Adds
METHOD.NVFP4/FORMAT.NVFP4so GPT-QModel can produce NVIDIA NVFP4weight-only checkpoints instead of only loading them. Weights are E2M1 codes
with one E4M3 block scale per 16 input columns and an FP32 per-tensor
multiplier. The solve is GPTQ's sequential
error-feedback recursion; every 16-column group picks its block scale with
Schur Replay (arXiv:2609.36654) or the
max-scaled baseline.
Net diff across the ten commits: 26 files, +3259 / −5. One new format; no
existing quantization path is rewritten.
No tracking issue; this is a new feature.
What Changed
METHOD.NVFP4,FORMAT.NVFP4,NVFP4Config,BACKEND.NVFP4_TORCH, and aProcessorStep.NVFP4lifecycle that reuses the shared Hessian capture.gptqmodel/quantization/nvfp4.py: clean-room code tables (126-point E4M3grid, round-to-nearest-even E2M1), the Schur-Replay selector, E2M1 packing,
decode, and
NVFP4Task(per-deviceX^T X, shared-input adoption,max-scaled RTN fallback when a layer has no calibration signal).
gptqmodel/nn_modules/qlinear/nvfp4.py:NVFP4Linearkeeps only packedstorage (
weightuint8[out, in/2],weight_scaleuint8[out, in/16],weight_scale_2scalar). The forward decodes output-channel tiles to FP32,adds the bias once after the reduction, and rounds once to the activation
dtype. Declared for CPU, NVIDIA CUDA and AMD ROCm.
gptqmodel/looper/nvfp4_processor.py: capture → solve → pack per layer.weight/weight_scale/weight_scale_2under ModelOpt'stensor names, with the block scales stored as raw E4M3 code bytes rather
than ModelOpt's typed FP8 tensors,
quant_method: nvfp4, and a producermarker in
meta.quantizer.nvfp4is added to the refused-plain-HF list sotransformers fails instead of silently returning random weights.
docs/nvfp4.md(flows below),docs/schur-replay-ab.md,support matrix row, README entry.
Intentionally out of scope: W4A4 activations, a fused dequant-GEMM kernel
(the portable Torch forward is the correctness path), and the paper's
tiered-memory / tensor-parallel infrastructure.
Flow
Old flow: NVFP4 was load-only.
FORMAT.NVFP4: E2M1 nibbles + E4M3 block-16 scales + FP32 multiplierweight/weight_scale/weight_scale_2(raw E4M3 scale bytes)TorchFP4Linear(load-only)NVFP4Linearpacks, runs and re-savesflowchart TD A["QuantizeConfig method=nvfp4"] --> B["_resolve_quantize_config_class"] B --> C["NVFP4Config validates bits=4, group_size=16, desc_act=False"] C --> D["QuantizationRunPlan picks ProcessorStep.NVFP4"] D --> E["NVFP4Processor captures X^T X per device"] E --> F["NVFP4Task.quantize"] F --> G["Damped inverse gives U = chol of inverse H"] G --> H["Per 16-column group: schur_replay_group"] H --> I["Full conditional curvature; score replay candidates, keep the old scale on ties"] I --> J["GPTQ error feedback into the remaining columns"] J --> K["Result: packed bytes, E4M3 codes, global scale"] K --> L["NVFP4Linear.pack"] L --> M["Checkpoint: weight, weight_scale, weight_scale_2"]stateDiagram-v2 [*] --> Dense Dense --> Calibrating: quantize starts Calibrating --> Packed: NVFP4Linear.pack Packed --> Packed: forward decodes tiles in FP32 Packed --> Saved: save writes packed NVFP4 tensors Saved --> Packed: GPTQModel.load rebuilds the kernel Packed --> [*]Failure contracts:
desc_act=Trueandstatic_groupsare rejected (the blockscale is bound to 16 consecutive input columns);
bitsmust be 4,group_size16,
in_featuresdivisible by 16; the LM head is not quantized.Tests
The same NVFP4 subset (solver, kernel, save/reload lifecycle, ROCm
kernel-contract audit) passes on the AMD ROCm runtime with the same count.
New tests pin: the 126-point E4M3 grid, E2M1 round-to-nearest-even at and
around every threshold, pack/unpack bytes, decode == solver reconstruction,
forward vs. an independent dense FP32 oracle in FP16/BF16/FP32, bias added
once after the FP32 reduction, packed-only persistent storage, state-dict
round trip, and a quantize → save → reload lifecycle that compares packed
tensors and logits.
Known unrelated failures:
tests/test_docs_contract_refs.pyreports 7failures and 235 passes on a clean
origin/maincheckout in thisenvironment (
docs/measurement.md::3, the twodocs/weight-loader.mdexamples, and four contract-reference checks). The same 7 fail on this
branch, so none are introduced here.
Measured Impact
Gate: same calibration Hessians and held-out windows for both selectors;
weights evaluated through the dequantized path (W4A16). Current selector,
which scores the full conditional curvature from the upper Cholesky factor,
on Qwen3-0.6B with 64 x 512 calibration and 32 x 512 held-out windows:
maxschur_replayAll 196 layers improved (worst 7.4 %, best 35.3 %, mean 24.7 %), 68.5 % of
row-groups changed scale, the surrogate score dropped 29.7 %, and the solve
took 200 s against 182 s for
max(about 1.1x). Historical rows from theinitial diagonal-curvature selector are kept in
docs/schur-replay-ab.md.The lifecycle test quantizes, saves, reloads and compares the packed tensors
and logits, so the checkpoint round trip is covered by an exact assertion
rather than by a sampled loss.
These numbers are not a reproduction of the paper's 70B/397B results; the
models and calibration sets are small and W4A4 is out of scope.
End-to-end scores
Same protocol as the INT4 comparison in #6063: WikiText-2 test perplexity with
24 x 2048 calibration windows from the train split, 32768 evaluation tokens in
2048-token windows, and every checkpoint saved to disk and reloaded through
GPTQModel.loadbefore scoring. GPTQ usesgroup_size=128; NVFP4 uses itsfixed block of 16. Lower is better.
The dense and GPTQ rows reproduce the values reported in #6063
(14.711 / 18.836 and 13.770 / 14.990), so the harness is directly comparable.
Schur Replay lowers perplexity by 4.3% / 2.3% / 3.4% versus max-scaled NVFP4
and by 12.6% / 5.2% versus GPTQ on the first two models.
ARC-Easy, Qwen2.5-0.5B-Instruct, 400 test questions, fixed prompt:
At 400 samples the 1-sigma binomial noise is about 2.4 points, so the NVFP4
rows are within noise of dense, and the max-versus-Schur gaps (0.8 points on
acc, 4 points onacc_norm) stay inside two sigma; the perplexity gap isthe stronger signal.
Reproduce:
Llama-3.2-1B was scored in bf16 (the checkpoint's training dtype) and its
GPTQ row is omitted because the INT4 baseline for that checkpoint is
pathological in this build (39.2 fp16 / 45.4 bf16 against 13.78 dense); that
path does not involve NVFP4. Schur Replay costs about 1.4-1.8x the max-scaled
solve on the portable Torch path; these are single-process runs that include
calibration, packing and saving, so wall-clock varies with host load and the
ratio is the meaningful part.
Model Support / Module Plan
Not applicable: no new model, alias or definition, and no module-plan change.
The lifecycle reuses the existing per-layer processor framework.
AWQ onboarding safety
Not applicable: no AWQ grouping, search, replay or fold change.
Contracts
buffers are
uint8and never re-cast.the single output cast.
are local to one call.