pytorch - 如何将两个 PyTorch 量化张量矩阵相乘?

标签 pytorch matrix-multiplication quantization

我是张量量化的新手,并尝试做一些简单的事情

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/

相关文章:

c - C 中最快的抖动/半色调库

pytorch - torch.where 中的标量类型?

python - pytorch:计算向量函数的向量雅可比积

tensorflow - 对如何在 Web 应用程序中使用一些基本的机器学习感到好奇

c++ - 如何在 C++ 中将两个 10x10 数组相乘?

python - ValueError : No 'serving_default' in the SavedModel's SignatureDefs. 可能的值为 'name_of_my_model'

parallel-processing - torch.nn.DataParallel 如何改变输出大小?

c++ - Eigen 库中的稀疏稀疏积 A^T*A 优化

c++ - Eigen C++ 断言失败

tensorflow - 为什么量化后TF-lite的精度不正确