pypto.dequantize#
产品支持情况#
产品 |
是否支持 |
|---|---|
Ascend 950PR/Ascend 950DT |
√ |
Atlas A3 训练系列产品/Atlas A3 推理系列产品 |
√ |
Atlas A2 训练系列产品/Atlas A2 推理系列产品 |
√ |
功能说明#
将量化后的低精度数据转换为高精度格式, 并应用缩放(scale)和偏移(zero_points)参数,当前支持
输入DT_INT8/DT_INT16的Tensor反量化为DT_FP32的Tensor $\( \text{dst} = ([float]\text{input} + \text{zero\_points}) * \text{scale} \)$
函数原型#
dequantize(input: Tensor, scale: Tensor, otype: DataType, axis: int, zero_points: Tensor) -> Tensor
参数说明#
参数名 |
输入/输出 |
说明 |
|---|---|---|
input |
输入 |
源操作数。 |
scale |
输入 |
缩放因子。 |
otype |
输入 |
返回值的数值类型 |
axis |
输入 |
指定反量化压缩的轴 |
zero_points |
输入 |
可选的非对称量化的偏移因子 |
返回值说明#
返回输出Tensor,Tensor的数据类型由otype指定,Shape与input相同。
调用示例#
TileShape设置示例#
说明:调用该operation接口前,应通过set_vec_tile_shapes设置TileShape。
TileShape维度应和输出一致。
示例1:输入input shape为[m, n],输出为[m, n], TileShape设置为[m1, n1], 则m1, n1分别用于切分m, n轴。
pypto.set_vec_tile_shapes(4, 16)
接口调用示例#
x = pypto.tensor([3, 4], pypto.DT_INT8)
scale = pypto.tensor([3, 1], pypto.DT_FP32)
zero_points = pypto.tensor([3, 1], pypto.DT_FP32)
# fp32 -> int8 对称反量化
y1 = pypto.dequantize(x, scale, pypto.DT_FP32, -1, None)
# fp32 -> uint8 非对称反量化
y2 = pypto.dequantize(x, scale, pypto.DT_FP32, -1, zero_points)
结果示例如下:
Input x:[[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]]
Input scale:[1.0, 1.0, 1.0]
Input zero_points:[-2.0, -2.0, -2.0]
Output y1:[[1.0, 2.0, 3.0, 4.0], [1.0, 2.0, 3.0, 4.0], [1.0, 2.0, 3.0, 4.0]]
Output y2:[[-1.0, 0.0, 1.0, 2.0], [-1.0, 0.0, 1.0, 2.0], [-1.0, 0.0, 1.0, 2.0]]