MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / fake_quant_tensor

Function fake_quant_tensor

imperative/python/megengine/quantization/utils.py:170–186  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

168
169
170def 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
189def fake_quant_bias(bias: Tensor, inp: Tensor, w_qat: Tensor) -> Tensor:

Callers 6

runFunction · 0.90
testerFunction · 0.90
funcFunction · 0.90
fake_quant_forwardMethod · 0.85
fake_quant_biasFunction · 0.85
fake_quant_forwardMethod · 0.85

Calls 2

TensorClass · 0.50
applyFunction · 0.50

Tested by 3

runFunction · 0.72
testerFunction · 0.72
funcFunction · 0.72