Preserve zero batches in histogram calibration - #2369
MrCapricornLiu wants to merge 3 commits into
Conversation
Signed-off-by: Chenghao Liu <chliu@stu.pku.edu.cn>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 12 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughHistogram calibration now preserves zero-valued samples from initial batches, establishes a valid range for all-zero input, and expands the range when later batches contain nonzero values. Tests cover collection, reset, percentile calibration, and quantizer output. ChangesHistogram calibration
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The histogram fix preserves zero-prefix counts and supports later nonzero calibration without an established merge-blocking regression. 🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Signed-off-by: Chenghao Liu <chliu@stu.pku.edu.cn>
Signed-off-by: Chenghao Liu <chliu@stu.pku.edu.cn>
What does this PR do?
Type of change: Bug fix
Histogram calibration can fail when its first batch is all zeros and a later batch contains nonzero values. The initial bin edges are all zero, so growing the range divides by a zero bin width and raises
OverflowError.torch.histcalso places zeros in the middle of its automatic range when both bounds are zero.Keep zero-only batches in the first bin, then rebuild the range when the first nonzero batch arrives and carry the previous zero counts into that bin. This preserves the calibrated distribution without imposing a minimum range that would lose resolution for small activations. Ordinary range growth and the NumPy collector are unchanged.
Usage
No API change. Existing histogram-calibrated
TensorQuantizercalls accept initial zero batches.Testing
TensorQuantizer.This covers the default
torch_hist=True, skip_zeros=Falsecollector. Empty input after filtering withskip_zeros=True, nonfinite inputs, distributed calibration and full-model accuracy/performance were not tested or changed.Before your PR is "Ready for review"
Additional Information
The histogram collector is separate from the NVFP4 activation headroom algorithm in #2028.
Summary by CodeRabbit
Bug Fixes
Tests