Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PyTorch][Fix] Improve numerical stability of HistogramObserver #86522

Closed
wants to merge 1 commit into from

Conversation

yulin0077
Copy link
Contributor

Summary:
As titled, HistogramObserver may fail in a certain scenario.
Specifically, we originally compute hist_bin_width as (self.max_val - self.min_val) / (self.bins * upsample_rate). It's possible that the numerator part is close the the FP32 threshold (1.4e-45) and conducting the division will cause overflow.

Bring some redundent computations to avoid such scenario.

Test Plan: https://pxl.cl/2ggD4 (04490e9)

Differential Revision: D40149594

@pytorch-bot pytorch-bot bot added the release notes: quantization release notes category label Oct 8, 2022
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 8, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

@pytorch-bot
Copy link

pytorch-bot bot commented Oct 8, 2022

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/86522

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures, 7 Pending

As of commit 557876e:
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D40149594

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 10, 2022
…rch#86522)

Summary:
Pull Request resolved: pytorch#86522

As titled, HistogramObserver may fail in a certain scenario.
Specifically, we originally compute `hist_bin_width` as `(self.max_val - self.min_val) / (self.bins * upsample_rate)`. It's possible that the numerator part is close the the FP32 threshold (1.4e-45) and conducting the division will cause overflow.

Bring some redundent computations to avoid such scenario.

Test Plan: https://pxl.cl/2ggD4 (pytorch@04490e9)

Reviewed By: jerryzh168

Differential Revision: D40149594

fbshipit-source-id: e14564cd2c65ab32b2600adf383f1d807af197ac
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D40149594

@facebook-github-bot
Copy link
Contributor

@pytorchbot merge

(Initiating merge automatically since Phabricator Diff has merged)

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@github-actions
Copy link

Hey @yulin0077.
You've committed this PR, but it does not have both a 'release notes: ...' and 'topics: ...' label. Please add one of each to the PR. The 'release notes: ...' label should represent the part of PyTorch that this PR changes (fx, autograd, distributed, etc) and the 'topics: ...' label should represent the kind of PR it is (not user facing, new feature, bug fix, perf improvement, etc). The list of valid labels can be found here for the 'release notes: ...' and here for the 'topics: ...'.
For changes that are 'topic: not user facing' there is no need for a release notes label.

facebook-github-bot pushed a commit that referenced this pull request Oct 11, 2022
Summary:
Pull Request resolved: #86522

As titled, HistogramObserver may fail in a certain scenario.
Specifically, we originally compute `hist_bin_width` as `(self.max_val - self.min_val) / (self.bins * upsample_rate)`. It's possible that the numerator part is close the the FP32 threshold (1.4e-45) and conducting the division will cause overflow.

Bring some redundent computations to avoid such scenario.

Test Plan: https://pxl.cl/2ggD4 (4fc0d53)

Reviewed By: jerryzh168

Differential Revision: D40149594

fbshipit-source-id: 49ed9980d7a641c14dda5a103e76c0c16f29c665
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/trunk Trigger trunk jobs on your pull request fb-exported Merged release notes: quantization release notes category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants