Quantized conv1d cannot execute on arm cpu

Xingyu_Yan: <p>I’m tring to running quantized NN inference on DPU.So I choose Nvidia Bluefield-2 as my hardware platform, which takes armv8 A72 as embedded CPU. Then installed latest Pytorch2.0.1 from pip. I wrote demo code and got errors like,</p>
<p>codes:</p>
<pre><code class="lang-python">import torch
layer = torch.nn.quantized.Conv1d(in_channels=1, out_channels=32, kernel_size=3)
x = torch.rand(1,1,748)
qx = torch.quantize_per_tensor(input, scale=1.0, zero_point=0,dtype=torch.quint8)
layer(qx)
</code></pre>
<p>errors:</p>
<pre><code class="lang-auto">Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/home/ubuntu/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/torch/ao/nn/quantized/modules/conv.py", line 369, in forward
    return ops.quantized.conv1d(input, self._packed_params, self.scale, self.zero_point)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/torch/_ops.py", line 502, in __call__
    return self._op(*args, **kwargs or {})
RuntimeError: could not create a primitive descriptor for a reorder primitive
</code></pre>
<p>I don’t really understand what is primitive descriptor and reorder primitive.And what may be the reason about this error?</p>

jcaip: <p>Hi  <a class="mention" href="/u/xingyu_yan">@Xingyu_Yan</a>, what hardware are you using to run this code?Is it your target specific architecture or just a general computer?</p>

HDCharles: <aside class="quote no-group" data-username="Xingyu_Yan" data-post="1" data-topic="179693">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/xingyu_yan/48/59064_2.png" class="avatar"> Xingyu_Yan:</div>
<blockquote>
<p>I’m tring to running quantized NN inference on DPU.So I choose Nvidia Bluefield-2 as my hardware platform, which takes armv8 A72 as embedded CPU. Then installed latest Pytorch2.0.1 from pip. I wrote demo code and got errors like,</p>
</blockquote>
</aside>
<p>not sure, it should be noted the error is occuring somewhere in the dispatch system of pytorch rather than specifically in the quantization code which makes it harder to debug. Assuming this works well with a normal fp32 model, I would try testing with a quantized linear, rather than a quantized conv but otherwise, I’ve not seen much about DPUs + quantization, will check with the rest of the team but its entirely possible this type of thing simply isn’t supported at the moment and you may be better off looking for  guidance somewhere with more DPU experience.</p>

Xingyu_Yan: <p>Thanks for replying!<br>
This is my hardware <a href="https://resources.nvidia.com/en-us-accelerated-networking-resource-library/bluefield-2-dpu-datasheet?lx=LbHvpR&amp;topic=networking-cloud" rel="noopener nofollow ugc">NVIDIA BlueField-2 DPU Datasheet</a>. It’s a DPU (network interface card with a powerful processor in my understanding) with embedded Armv8 core(AArch64 architecture). So I can run my code just like what I usually do on nomarl CPU.</p>
<p>More information about os running on it.Got this from execuating <code>cat /proc/version</code>,</p>
<pre><code class="lang-auto">Linux version 5.4.0-1049-bluefield (buildd@bos02-arm64-055) (gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1))
</code></pre>

Xingyu_Yan: <p>Thanks for replying!<br>
I’ve tried running normal fp32 model and  <code>torch.nn.quantized.Linear</code> on DPU and all things goes well.So I only quantize all linear layers in my model in the end.<br>
I agree with your guess.Maybe Pytorch just doesn’t support this type of processor now.<br>
By the way, what should I do if I really want to figure out the reason? Read source code of dispatch systems(if it’s open source) and get information about my proccesor?</p>

HDCharles: <p>The dispatch system is notoriously difficult to learn just by reading the code. The goto resource is <a href="http://blog.ezyang.com/2019/05/pytorch-internals/" rel="noopener nofollow ugc">http://blog.ezyang.com/2019/05/pytorch-internals/</a> but it specifically mentions not convering distributed so idk. To actually fix this I’d suspect you’d need to raise an issue in github or otherwise find someone with dpu experience. Sorry I couldn’t be more helpful.</p>

HDCharles: <p>the other thing to try is conv2d, I know in some weird corners of the dispatch logic that quantized conv1d reshapes things and then just calls conv2d instead, so there’s a possibility that its looking for a quantized conv1d kernel and not finding it, but it’d work where a kernel exists  (like quantized linear).</p>

Xingyu_Yan: <p>Thank you for your helpful suggestion. I have tried using <code>conv2d</code> but encountered the same error as with <code>conv1d</code>. I will continue to learn from the resources you have provided and may raise an issue on Github in a few weeks’ time.</p>
<p>Once again, thank you for all your help.</p>