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

check min<=max in ChooseQuantizationParams #1612

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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