ncnn Could not run 'quantized::conv2d_prepack' with arguments from the 'CPU' backend.

dzjeubhm  于 4个月前  发布在  其他
关注(0)|答案(3)|浏览(35)

新建了一个纯卷积的量化网络:

class Model(nn.Module):
    def __init__(self):
        super(Model, self).__init__()

        self.quant = nnq.Quantize(dtype=torch.quint8, scale=1, zero_point=0)
        self.dequant = nnq.DeQuantize()

        self.conv_0 = nnq.Conv2d(in_channels=12, out_channels=16, kernel_size=3)
        self.conv_1 = nnq.Conv2d(in_channels=16, out_channels=20, kernel_size=(2,4), stride=(2,1), padding=2, dilation=1)
        self.conv_2 = nnq.Conv2d(in_channels=20, out_channels=24, kernel_size=(1,3), stride=1, padding=(2,4), dilation=1, groups=1, bias=False)

        self.conv_3 = nnq.Conv2d(in_channels=24, out_channels=28, kernel_size=(5,4), stride=1, padding=0, dilation=1, groups=4, bias=True)
        self.conv_4 = nnq.Conv2d(in_channels=28, out_channels=32, kernel_size=3, stride=1, padding=1, dilation=(1,2), groups=2, bias=False, padding_mode='zeros')

        self.conv_5 = nnq.Conv2d(in_channels=32, out_channels=32, kernel_size=2, stride=2, padding=3, dilation=1, groups=32, bias=True, padding_mode='zeros')
        self.conv_6 = nnq.Conv2d(in_channels=32, out_channels=28, kernel_size=2, stride=1, padding=2, dilation=1, groups=1, bias=False, padding_mode='zeros')

    def forward(self, x):
        x = self.quant(x)
        
        x = self.conv_0(x)
        x = self.conv_1(x)
        x = self.conv_2(x)
        x = self.conv_3(x)
        x = self.conv_4(x)
        x = self.conv_5(x)
        x = self.conv_6(x)

        x = self.dequant(x)

        return x

生成pt之后用pnnx转换:

./pnnx test_nn_quantized_Conv2d.pt inputshape=[1,12,64,64]

生成的pnnx模型推理时报错:

NotImplementedError: Could not run 'quantized::conv2d_prepack' with arguments from the 'CPU' backend. This could be because the operator doesn't exist for this backend, or was omitted during the selective/custom build process (if using custom build). If you are a Facebook employee using PyTorch on mobile, please visit https://fburl.com/ptmfixes for possible resolutions. 'quantized::conv2d_prepack' is only available for these backends: [QuantizedCPU, BackendSelect, Python, Named, Conjugate, Negative, ADInplaceOrView, AutogradOther, AutogradCPU, AutogradCUDA, AutogradXLA, AutogradLazy, AutogradXPU, AutogradMLC, Tracer, UNKNOWN_TENSOR_TYPE_ID, Autocast, Batched, VmapMode].

原因是torch.ops.quantized.conv2d_prepack在cpu没有实现,而我已经设置了 torch.backends.quantized.engine = 'qnnpack' ,这个问题应该如何解决呢?

3j86kqsm

3j86kqsm1#

你好, 请问这个问题后来解决了吗?是怎么解决的?

dwthyt8l

dwthyt8l2#

I am getting the same error, with my model parameters and inputs on CPU. Still its saying NotImplementedError: Could not run 'quantized::conv2d_prepack' with arguments from the 'CUDA' backend.
Plz help.

相关问题