Skip to content

Commit

Permalink
check min<=max in ChooseQuantizationParams
Browse files Browse the repository at this point in the history
Summary: pytorch#1590

Differential Revision: D43383474

fbshipit-source-id: ff27b44b589f8dbde54f3a2c830d7d489f7a5138
  • Loading branch information
jspark1105 authored and facebook-github-bot committed Feb 24, 2023
1 parent 7f791ed commit 9ee9edc
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 9ee9edc

Please sign in to comment.