pub struct QMul {
pub input_a_zero_point: i8,
pub input_b_zero_point: i8,
pub requantizer: Requantizer,
}Expand description
Elementwise multiplication of two int8 tensors with their own zero points
(C++ QMul, TFLite MUL): squeeze-and-excite gating in MobileNet-V3 and
EfficientNet. out = requantize((a - zp_a) * (b - zp_b)), where the
requantizer encodes scale_a * scale_b / scale_out
(calibration::build_mul_requantizer).
use tinymind::int8::{QMul, Requantizer};
// Scales 1/4, 1/4 and 1/16: the product of the real values, in quarters
// times quarters, is exact on the output grid (ratio 1, shift -1 then 1/2).
let mul = QMul {
input_a_zero_point: 0,
input_b_zero_point: 2,
requantizer: Requantizer { multiplier: 1 << 30, shift: -1, zero_point: 0, qmin: -128, qmax: 127 },
};
let a = [[4i8, -8], [3, 0]];
let b = [[6i8, 4], [2, 9]];
let mut y = [[0i8; 2]; 2];
mul.forward(&a, &b, &mut y);
assert_eq!(y, [[16, -16], [0, 0]]);Fields§
§input_a_zero_point: i8Zero point of the first input.
input_b_zero_point: i8Zero point of the second input.
requantizer: RequantizerRescales each product to the output: scale_a * scale_b / scale_out,
the output zero point and the saturation range.
Implementations§
Trait Implementations§
impl Copy for QMul
impl Eq for QMul
impl StructuralPartialEq for QMul
Auto Trait Implementations§
impl Freeze for QMul
impl RefUnwindSafe for QMul
impl Send for QMul
impl Sync for QMul
impl Unpin for QMul
impl UnsafeUnpin for QMul
impl UnwindSafe for QMul
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more