Add activation-aware local Hessian scale calibration#1976
Conversation
|
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. |
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1976 +/- ##
==========================================
- Coverage 77.79% 77.78% -0.02%
==========================================
Files 518 518
Lines 58204 58279 +75
==========================================
+ Hits 45279 45331 +52
- Misses 12925 12948 +23
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Signed-off-by: realAsma <akuriparambi@nvidia.com>
fd8f9d9 to
2010ef8
Compare
|
/claude review |
There was a problem hiding this comment.
Claude review passed — no blocking issues found. LGTM
Findings: CRITICAL: 0, IMPORTANT: 0, SUGGESTION: 1
Scope
Full review. 12 files changed (+438/-43); reviewed all modelopt/ source (model_calib.py, calib/mse.py, config.py, kernels/.../nvfp4_fp8_sweep.py), the new recipe YAML, the README, and cross-checked mode.py registration and the test suite. Skipped only the CHANGELOG line and deprioritized test files (spot-checked for signature drift).
Assessment
This is a clean, well-guarded feature extension. Traced the activation-error-coupling math end-to-end and it holds:
- Sign flip
dw = quant(w) - w(wasw - quant(w)): the quadratic term is sign-invariant so the default path is numerically unchanged, while the new linear coupling term2 dw^T (P W0)gets the correct sign. Applied consistently in the Triton kernel, the referencelocal_hessian_error, and docstrings. - Coupling accumulation
H = Xq^T Xq / B,P = Xq^T (Xq - X) / B, and thenbd,cnd->cnbeinsum forP·W0all match the block-wise expansion of the output MSE. The dropped scale-independent constant (hence possibly-negative objective) is documented, andargmin/best_loss=infcomparisons handle negative losses correctly. - Kernel plumbing (flat
coupling_biaslayout,HAS_COUPLINGconstexpr, CUDA/numel validation) is consistent withx_flat; the non-coupling branch reusesx_flatas a harmless placeholder. - Fallback logic for disabled/absent input quantizers and
pre_quant_scale/rotation correctly reverts to the Hessian-only pre-hook with a rank-0 warning; the fused-MoE post-hook mirrors the dense post-hook. - Backward compatibility:
activation_error_couplingdefaultsFalse; internal renames (hessian->metric,hessian_for->metric_for) are private and all call sites/tests updated. Config flows cleanly viamodel_dump(). Post-calibration cleanup clears_couplingalongside_hessian, so no state leaks across runs.
Risk level: low. The one suggestion is a docstring accuracy nit on _LocalHessianAccumulator (still says H = sum X^T X, which is only exact on the default path). Non-blocking.
Signed-off-by: realAsma <akuriparambi@nvidia.com>
|
/claude review |
There was a problem hiding this comment.
Claude re-review — commit 1b30839 ("Use quantized activations for local Hessian capture")
Findings: CRITICAL: 0, IMPORTANT: 1, SUGGESTION: 0
Scope: Re-review of the follow-up commit on top of the previously-approved 2010ef8. Traced the delta end-to-end across model_calib.py, calib/mse.py, nvfp4_fp8_sweep.py (Triton kernel), config.py, the new preset YAML, and the test suite.
Assessment — the activation-error-coupling math is correct and well-tested:
- accumulate builds H = SUM X_q^T X_q and P = SUM X_q^T (X_q - X); the einsum for PW0 and the 2dW^T(PW0) term match the block-wise expansion of ||X_qW_q - X*W_0||^2. test_activation_error_coupling_objective_matches_output_mse verifies this against the true output MSE, including the deliberately-negative objective.
- The Triton kernel and reference local_hessian_error are mutually consistent: dw = quant(w)-w, flat coupling_bias layout matches x_flat, HAS_COUPLING gating, CUDA/numel validation, and best_loss=inf/argmin all handle negative losses correctly.
- Hook rework (input-quantizer register_forward_hook capturing X_q plus raw args[0]) is sound; is_quantized_linear guarantees input_quantizer exists, so the new continue never drops a real linear.
- Disabled/absent quantizer and pre_quant_scale/rotation fallback reverts to the Hessian-only path with a rank-0 warning; cleanup clears _coupling alongside _hessian.
Most impactful finding — [IMPORTANT Compatibility]: This commit changes the default (activation_error_coupling=False) Hessian from SUM X^T X to SUM X_q^T X_q whenever the input quantizer is enabled — which the released nvfp4_local_hessian recipe does. The existing recipe will yield different weight amaxes in 0.46 even without the new flag, yet the CHANGELOG says the change preserves the existing objective by default. Either document the default-path shift or gate X_q capture behind the new flag. Details inline on CHANGELOG.rst.
Risk level: low-moderate. The feature is clean and correct; the concern is the undocumented behavior shift to an already-shipped recipe.
Signed-off-by: realAsma <akuriparambi@nvidia.com>
Signed-off-by: realAsma <akuriparambi@nvidia.com>
What does this PR do?
Type of change: new feature
Extends
local_hessianweight-scale calibration with an opt-in activation-quantization-aware block-wise output MSE objective.When
act_quant_aware=True, scale search minimizes the exact expanded error for||X_q W_q - X W_0||²using:H = X_qᵀ X_q / BP = X_qᵀ (X_q - X) / BThe default remains
False, preserving the existinglocal_hessianobjective. The reference path and Triton FP8 scale-sweep fast path both support the cross term. Dense and fused-MoE activation capture are covered, with explicit fallback for transformed input quantizers.For both regular and activation-aware
local_hessian, usebatch_size=1andlayerwise=Truefor calibration fidelity and bounded memory.Usage
The new
nvfp4_local_hessian_act_awarerecipe alias enables this configuration directly.Testing
tests/unit/torch/quantization/test_local_hessian.py: 16 passedtests/unit/recipe/test_presets.py: 6 passedBefore your PR is "Ready for review"
CONTRIBUTING.md: N/AAdditional Information
The implementation follows the activation-quantization-aware block-wise output MSE derivation supplied with the feature request.