CANN/pypto量化操作API
pypto.quantize【免费下载链接】pyptoPyPTO发音: pai p-t-oParallel Tensor/Tile Operation编程范式。项目地址: https://gitcode.com/cann/pypto产品支持情况产品是否支持Ascend 950PR/Ascend 950DT√Atlas A3 训练系列产品/Atlas A3 推理系列产品√Atlas A2 训练系列产品/Atlas A2 推理系列产品√功能说明将高精度浮点数据转换为低精度格式 当前支持输入DT_FP32的Tensor通过对称量化转换为DT_INT8的Tensor $$ \text{dst} round(\text{input} * \text{scale}) $$输入DT_FP32的Tensor通过非对称量化转换为DT_UINT8的Tensor $$ \text{dst} round(\text{input} * \text{scale} \text{zero_points}) $$函数原型quantize(input: Tensor, scale: Tensor, otype: DataType, axis: int, zero_points: Tensor) - Tensor参数说明参数名输入/输出说明input输入源操作数。支持的类型为Tensor。Tensor支持的数据类型为DT_FP32。不支持空TensorShape仅支持2-4维Shape Size不大于2147483647即INT32_MAX。shape记为 [..., row, col]scale输入缩放因子。支持的类型为Tensor。Tensor数据类型与input一致支持DT_FP32;不支持空TensorShape比input少一维仅支持1-3维Shape Size不大于2147483647即INT32_MAX;axis -1 或 input.shape.size() -1 时 shape [..., row]axis -2 或 input.shape.size() -2 时 shape [..., col]otype输入返回值的数值类型目前支持int8 和 uint8 分别对应对称量化和非对称量化。axis输入指定量化压缩的轴目前支持末尾两轴即 -1/-2 或者input.shape.size() -1/input.shape.size()-2zero_points输入可选的非对称量化的偏移因子支持的类型为Tensor。Tensor数据类型与input一致支持DT_FP32;支持空TensorShape比input少一维仅支持1-3维Shape Size不大于2147483647即INT32_MAX;axis -1 或 input.shape.size() -1 时 shape [..., row]axis -2 或 input.shape.size() -2 时 shape [..., col]返回值说明返回输出TensorTensor的数据类型由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_FP32) scale pypto.tensor([3], pypto.DT_FP32) zero_points pypto.tensor([3], pypto.DT_FP32) # fp32 - int8 对称量化 y1 pypto.quantize(x, scale, pypto.DT_INT8, -1, None) # fp32 - uint8 非对称量化 y2 pypto.quantize(x, scale, pypto.DT_UINT8, -1, zero_points)结果示例如下Input x:[[1.1, -2.2, 3.3, -4.4], [1.1, -2.2, 3.3, -4.4], [1.1, -2.2, 3.3, -4.4]] Input scale:[1.0, 1.0, 1.0] Input zero_points:[-5.0, -5.0, -5.0] Output y1:[[1, -2, 3, -4], [1, -2, 3, -4], [1, -2, 3, -4]] Output y2:[[6, 3, 8, 1], [6, 3, 8, 1], [6, 3, 8, 1]]【免费下载链接】pyptoPyPTO发音: pai p-t-oParallel Tensor/Tile Operation编程范式。项目地址: https://gitcode.com/cann/pypto创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考