Closed wanghaoshuang closed 5 months ago
import paddle import numpy as np from paddle.nn.quant.format import LinearQuanter data = paddle.to_tensor(np.random.randn(2)).astype(paddle.float32) int8_quanter = LinearQuanter(scales= 1.0, bit_length=8) int16_quanter = LinearQuanter(scales= 1.0, bit_length=16) quanted_data = int8_quanter(data) print(quanted_data) print(quanted_data.astype(paddle.int8)) quanted_data = int16_quanter(data) print(quanted_data) print(quanted_data.astype(paddle.int16))