Skip to content

Accumulate activation calibration ranges#2724

Open
kiwigitops wants to merge 1 commit into
apple:mainfrom
kiwigitops:fix-calibration-running-range
Open

Accumulate activation calibration ranges#2724
kiwigitops wants to merge 1 commit into
apple:mainfrom
kiwigitops:fix-calibration-running-range

Conversation

@kiwigitops
Copy link
Copy Markdown

Fixes #2704.

Activation calibration was overwriting each tensor's stored rmin/rmax before comparing the current batch against the previous range. That made the collected range depend on sample order, and a later narrower batch could replace an earlier wider range.

This initializes stats only when a tensor is first seen, then accumulates the running min and max for later batches. The same fix is applied to the experimental calibration/debugger paths that record activation ranges.

Tested:

  • python -m pytest coremltools/test/optimize/test_utils.py::TestUpdateTensorRange coremltools/optimize/coreml/experimental/test_post_training_quantization.py::TestGetActivationStats::test_update_tensor_range_accumulates_running_min_max coremltools/optimize/coreml/experimental/test_post_training_quantization.py::TestGetActivationStats::test_record_intermediate_output_accumulates_running_min_max -q
  • python -m compileall -q coremltools/optimize/_utils.py coremltools/optimize/coreml/experimental/_post_training_quantization.py coremltools/optimize/coreml/experimental/_model_debugger.py coremltools/test/optimize/test_utils.py coremltools/optimize/coreml/experimental/test_post_training_quantization.py
  • git diff --check

Signed-off-by: kiwigitops <kiwisclubco@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(calibration): _update_tensor_range should not pick only last batch min/max

1 participant