Add WMSE weight scale search calibration - #2283
Draft
realAsma wants to merge 1 commit into
Draft
Conversation
Add `wmse`, an NVFP4 weight-scale-search algorithm that weights the
block-quantization error by a per-input-channel importance
`Imp_i = ||X[:, i]||^2` instead of the full per-cin-block Hessian `X^T X`
used by `local_hessian`. This is the ScaleSweep objective (arXiv 2606.07618,
eqs. 12-13): the same quadratic form with `H` replaced by `diag(Imp)`.
Rather than duplicate the calibration pipeline, extract the shared
accumulate -> metric -> MSE-search body into `_hessian_weighted_calibrate`,
parameterized by the weighting term; `local_hessian_calibrate` and the new
`wmse_calibrate` are thin wrappers over it. The accumulator gains a `diagonal`
flag that accumulates `x.square().sum(-1)` into a `[n_blocks, block_size]`
buffer, and the block loss dispatches on tensor rank so the diagonal case uses
`einsum("cnb,nb->cn")`. The Triton FP8 scale-sweep kernel gains a matching
`DIAGONAL` constexpr specialization, avoiding a 16x memory blowup from
materializing `diag_embed(Imp)` on the hot path.
`local_hessian` is verified bit-identical after the refactor: on Qwen3-1.7B
through the real layerwise NVFP4 path with the FP8 scale sweep enabled, all 784
fingerprinted tensors -- quantizer amax, block scales, and final fake-quantized
weights -- match the pre-refactor library exactly.
Also add the `ABLATE_W4A4_WMSE` / `ABLATE_W4A16_WMSE` eval configs and the
`--calib_dataset` / `--calib_seqlen` plumbing they need, so the ablation is
reproducible against the existing local-Hessian numbers.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: realAsma <akuriparambi@nvidia.com>
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueComment |
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.
What
Adds
wmse, an NVFP4 weight-scale-search calibration algorithm that weights theblock quantization error by a per-input-channel importance
Imp_i = ||X[:, i]||^2, instead of the full per-cin-block HessianX^T Xusedby
local_hessian. This is the ScaleSweep objective (arXiv 2606.07618,eqs. 12-13) — the same quadratic form with
Hreplaced bydiag(Imp).How
Rather than duplicating the calibration pipeline, the shared
accumulate → metric → MSE-search body is extracted into
_hessian_weighted_calibrate, parameterized by the weighting term.local_hessian_calibrateand the newwmse_calibrateare thin wrappers thatdiffer only in a
diagonalflag:diagonalpath accumulatesx.square().sum(-1)into a[n_blocks, block_size]buffer instead of[n_blocks, block_size, block_size].einsum("cnb,nb->cn")for thediagonal case,
einsum("cnb,nbd,cnd->cn")for the full Hessian._fp8_scale_sweep_hessian_kernelgains amatching
DIAGONAL: tl.constexprspecialization that replacestl.dotwith aweighted sum, so the diagonal case does not materialize
diag_embed(Imp)onthe hot path across the 126 candidate scales.
Also adds the
ABLATE_W4A4_WMSE/ABLATE_W4A16_WMSEeval configs and the--calib_dataset/--calib_seqlenplumbing inexamples/llm_evalthat theyneed, so the ablation below is reproducible.
Refactor safety —
local_hessianis bit-identicalThe shared-path refactor touches
local_hessian, so it was verified rather thanassumed. Qwen3-1.7B was calibrated in two separate processes — pre-refactor and
post-refactor — from identical seeded input (matching
input_idsSHA-256),through the real 28-layer layerwise NVFP4 path with the FP8 scale sweep on.
Fingerprint: 784 tensors per run covering quantizer
amax/_amax/_scale/_double_scale/_pre_quant_scale, all non-recursive buffers, and the finalfake-quantized weights, compared by value and by int32 bit pattern.
local_hessian: 784/784 bit-identical.msecontrol: 784/784 bit-identical.local_hessianvs July-msediffers in 588/784tensors, so the fingerprint does detect real objective changes.
Proven for the dense single-GPU path; fused-MoE and multi-rank are covered by
unit tests only.
Ablation
10 cells (5 models x NVFP4 W4A4 / W4A16), calibration matched exactly to the
existing local-Hessian campaign:
nemotron-post-training-v3,--calib_size 512,--calib_seqlen 2048,--calib_batch_size 1, layerwise calibration on, FP8scale sweep on,
WORLD_SIZE=1, one GPU per job, no chat template. Baseline rowsare the stored local-Hessian campaign numbers, not re-runs.
avg acc %is the unweighted mean of mmlu.acc, arc_challenge.acc_norm,arc_easy.acc_norm, boolq.acc, hellaswag.acc_norm, piqa.acc_norm, winogrande.acc.
Deltas are versus
local_hessian.Reading:
local_hessianon accuracy —every cell is within +-0.52 points, 6 of 10 up, 4 of 10 down, mean delta
-0.02 points.
and beats
local_hessianin 8 of 10 (mean -0.05).maxon perplexity in every cell, and on accuracy in 9 of 10.Against
mse, WMSE has lower perplexity in 8 of 10; the two exceptions areboth Qwen3-8B cells, where
mseedges it out.Hessian, at 1/16 the accumulator memory and no matmul in the sweep.
Tests
tests/unit/torch/quantization/test_wmse.py.test_local_hessian.py: no regression (22 tests).test_nvfp4_fp8_sweep_kernel.py: 54 passed, including newDIAGONALspecialization cases.pre-commitclean.🤖 Generated with Claude Code