产品 |
是否支持 |
|---|---|
Ascend 950PR/Ascend 950DT |
√ |
√ |
|
√ |
|
√ |
|
√ |
|
x |
|
x |
本接口提供对输出矩阵采用向量进行量化或反量化的功能,即对于输入shape为[1, N]的参数向量,N值为Matmul矩阵计算时M/N/K中的N值,对输出矩阵的每一列都采用该向量中对应列的系数进行量化或反量化。量化、反量化的详细内容请参考量化场景。
Matmul反量化场景:在Matmul计算时,左、右矩阵的输入为int8_t或int4b_t类型,输出为half类型;或者左、右矩阵的输入为int8_t类型,输出为int8_t类型。该场景下,输出C矩阵的数据从CO1搬出到Global Memory时,会执行反量化操作,将最终结果反量化为对应的half或int8_t类型。
Matmul量化场景:在Matmul计算时,左、右矩阵的输入为half或bfloat16_t类型,输出为int8_t类型。该场景下,输出C矩阵的数据从CO1搬出到Global Memory时,会执行量化操作,将最终结果量化为int8_t类型。
1 | __aicore__ inline void SetQuantVector(const GlobalTensor<uint64_t>& quantTensor) |
1 | __aicore__ inline void SetQuantVector(const LocalTensor<uint64_t>& quantTensor) |
参数名 |
输入/输出 |
描述 |
|---|---|---|
quantTensor |
输入 |
量化或反量化运算时的参数向量。参数向量的存储位置为GM或L1 Buffer。 |
将float数据类型的量化计算参数scale、offset转换为uint64类型的入参的计算公式如下:
无
完整样例请参考matmul_quant样例。
1 2 3 4 5 6 7 8 9 10 11 12 | REGIST_MATMUL_OBJ(&pipe, GetSysWorkSpacePtr(), mm, &tiling); // quantTensor:量化或反量化运算时的Tensor,支持的存储位置为GM和L1 mm.SetQuantVector(quantTensor); mm.SetTensorA(gm_a); mm.SetTensorB(gm_b); if (tiling.isBias) { matmulObj.SetBias(biasGlobal); } mm.IterateAll(gm_c); mm.End(); |