Apply fake quantization to the inp tensor. Args: inp: the input tensor which need to be faked. qparams: to get mode, qmin, qmax, scale and zero_point from.
(inp: Tensor, qparams: QParams)
| 168 | |
| 169 | |
| 170 | def fake_quant_tensor(inp: Tensor, qparams: QParams) -> Tensor: |
| 171 | """Apply fake quantization to the inp tensor. |
| 172 | |
| 173 | Args: |
| 174 | inp: the input tensor which need to be faked. |
| 175 | qparams: to get mode, qmin, qmax, scale and zero_point from. |
| 176 | """ |
| 177 | scale = qparams.scale |
| 178 | if qparams.mode == QuantMode.ASYMMERTIC: |
| 179 | zero_point = qparams.zero_point |
| 180 | else: |
| 181 | zero_point = Tensor([0.0], dtype=np.float32) |
| 182 | qmin = qparams.dtype_meta.qmin |
| 183 | qmax = qparams.dtype_meta.qmax |
| 184 | |
| 185 | op = builtin.FakeQuant(qmin=qmin, qmax=qmax) |
| 186 | return apply(op, inp, scale, zero_point)[0] |
| 187 | |
| 188 | |
| 189 | def fake_quant_bias(bias: Tensor, inp: Tensor, w_qat: Tensor) -> Tensor: |