MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / quant_np

Function quant_np

tools/pytorch-quantization/tests/utils.py:119–129  ·  view source on GitHub ↗

Quantize x using numpy.

(x, amax, num_bits=8, fake=False, narrow_range=True)

Source from the content-addressed store, hash-verified

117 raise AssertionError("MSE = %.2e < %.2e" % (mse, tol))
118
119def quant_np(x, amax, num_bits=8, fake=False, narrow_range=True):
120 """Quantize x using numpy."""
121 intmax = 2.0**(num_bits - 1) - 1
122 intmin = -intmax if narrow_range else -intmax - 1
123 scale = intmax / amax
124 x_q = np.round(np.clip(x * scale, intmin, intmax))
125
126 if fake:
127 x_q /= scale
128
129 return x_q

Callers

nothing calls this directly

Calls 1

roundMethod · 0.45

Tested by

no test coverage detected