我是张量量化的新手,并尝试做一些简单的事情
import torch
x = torch.rand(10, 3)
y = torch.rand(10, 3)
x@y.T
使用在 CPU 上运行的 PyTorch 量化张量。我因此尝试scale, zero_point = 1e-4, 2
dtype = torch.qint32
qx = torch.quantize_per_tensor(x, scale, zero_point, dtype)
qy = torch.quantize_per_tensor(y, scale, zero_point, dtype)
qx@qy.T # I tried...
..并得到了错误RuntimeError: Could not run 'aten::mm' with arguments from the 'QuantizedCPUTensorId' backend. 'aten::mm' is only available for these backends: [CUDATensorId, SparseCPUTensorId, VariableTensorId, CPUTensorId, SparseCUDATensorId].
是不支持矩阵乘法,还是我做错了什么?
最佳答案
为量化矩阵实现矩阵乘法并不简单。因此,“常规”矩阵乘法( @
)不支持它(正如您的错误消息所暗示的那样)。
您应该查看量化操作,例如 torch.nn.quantized.functional.linear
:
torch.nn.quantized.functional.linear(qx[None,...], qy.T)
关于pytorch - 如何将两个 PyTorch 量化张量矩阵相乘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60325913/