Skip to content

Commit

Permalink
check min<=max in ChooseQuantizationParams (#95529)
Browse files Browse the repository at this point in the history
Summary:
X-link: pytorch/pytorch#95529

Pull Request resolved: pytorch#1612

pytorch#1590

Reviewed By: summerdengfb

Differential Revision: D43383474

fbshipit-source-id: 7b61eda2e80e5ca9c34cfe6b26f85adfd20ddc6e
  • Loading branch information
jspark1105 authored and facebook-github-bot committed Feb 26, 2023
1 parent be11e98 commit e0ced99
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/QuantUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ TensorQuantizationParams ChooseQuantizationParams(
int32_t qmax,
bool preserve_sparsity,
bool force_scale_power_of_two) {
if (min > max) {
throw std::runtime_error(
"In ChooseQuantizationParams, min should be less than or equal to max");
}

if (min < 0 && max > 0 && preserve_sparsity) {
int symmetric_qmin = -((qmax - qmin) / 2 + 1);
int symmetric_qmax = (qmax - qmin) / 2;
Expand Down

0 comments on commit e0ced99

Please sign in to comment.