Skip to content

Commit

Permalink
fix depthwise conv quantize compute weight scale>1 algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
vera121 committed Dec 24, 2021
1 parent d2dfb1d commit 7e78f94
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/caffe/util/math_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,11 @@ void MultiplyByQuantizedMultiplierVR(const int n, Dtype* x, const int mul, const
}
} else if (round_mode == 2) {
for(int i = 0; i < n; ++i) {
x[i] = tfl_RoundingDivideByPOT(tfl_SaturatingRoundingDoublingHighMul((int)x[i], mul), shf);
// ref see https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/kernels/internal/common.h#L251
int left_shift = shift > 0 ? shift : 0;
int right_shift = shift > 0 ? 0 : -shift;
x[i] = tfl_RoundingDivideByPOT(tfl_SaturatingRoundingDoublingHighMul(int(x[i]) *
(1 << left_shift), mul), right_shift);
}
}
}
Expand Down

0 comments on commit 7e78f94

Please sign in to comment.