【问题标题】:How can I matrix-multiply two PyTorch quantized Tensors?如何对两个 PyTorch 量化张量进行矩阵相乘?
【发布时间】:2020-06-05 03:09:24
【问题描述】:

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

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: 无法使用来自 'QuantizedCPUTensorId' 后端。 'aten::mm' 仅适用于这些 后端:[CUDATensorId,SparseCPUTensorId,VariableTensorId, CPUTensorId, SparseCUDATensorId].

只是不支持矩阵乘法,还是我做错了什么?

【问题讨论】:

    标签: pytorch matrix-multiplication quantization


    【解决方案1】:

    为量化矩阵实现矩阵乘法并不简单。因此,“常规”矩阵乘法 (@) 不支持它(如您的错误消息所示)。

    您应该查看量化操作,例如,torch.nn.quantized.functional.linear

    torch.nn.quantized.functional.linear(qx[None,...], qy.T)
    

    【讨论】:

      猜你喜欢
      • 2018-05-04
      • 2019-04-21
      • 1970-01-01
      • 2019-09-22
      • 2011-09-28
      • 1970-01-01
      • 2020-10-14
      • 1970-01-01
      • 2021-03-05
      相关资源
      最近更新 更多