You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Entropy calibration mutates the stored NumPy histogram #2654
With HistogramCalibrator(torch_hist=False), computing an entropy threshold changes the collected histogram. _compute_amax_entropy uses calib_hist[:], a NumPy view, then replaces its first bin. Later percentile/MSE queries and subsequent collection therefore operate on modified counts.
Reproduced on main at 6a1068746dd0e746fe4bcb79152b86bdcf58cb41, using CPU tensors.
Reproduction
importnumpyasnpimporttorchfrommodelopt.torch.quantization.calibimportHistogramCalibratorcalibrator=HistogramCalibrator(4, None, False, num_bins=32, torch_hist=False)
calibrator.collect(torch.cat((torch.zeros(100), torch.arange(1, 33).float())))
original=calibrator._calib_hist.copy()
calibrator.compute_amax("entropy", start_bin=16)
np.testing.assert_array_equal(calibrator._calib_hist, original)
# Fails: the first bin changes from 100 samples to 1.
The entropy calculation should use a private copy of the histogram. Its existing first-bin adjustment can remain local to that calculation. The PyTorch histogram backend already avoids modifying persistent counts because compute_amax converts its histogram to a fresh array.
This is separate from #2369, which handles zero-only initial batches in the PyTorch collector. The proposed fix changes only the entropy helper, with a regression covering persistent counts, repeated threshold queries, and continued collection.
Activity
Preserve histogram counts during entropy calibration (#2655)