I did a very simple test about DSP quantization model.
1. this is my simple pytorch model:
class Net(nn.Module):
def __init__(self, show=False):
super(Net, self).__init__()
self.relu = nn.ReLU()
self.avg_pool = nn.AdaptiveAvgPool2d(1)
OUTPUT_DIM = 40
self.fc1 = nn.Linear(10, OUTPUT_DIM, bias=False)
nn.init.constant_(self.fc1.weight, 1.)
self.conv0 = nn.Conv2d(3,10,1,1,padding=0,bias=True)
def forward(self, x): # (1,3,20,20)
x = self.conv0(x)
x = self.relu(x)
x = self.avg_pool(x)
x = torch.flatten(x, 1)
x = x * x
x = self.fc1(x)
return x
2. And i use AIMET to export quant model
dummy_input = torch.rand((1,3,20,20))
quantsim.export("./aimet_quat/", "tmp", dummy_input, onnx_params)
3. Convert onnx to DLC
./snpe-onnx-to-dlc --input_network tmp.onnx --output_path tmp.dlc --quantization_overrides tmp.encodings
./snpe-dlc-quantize --input_dlc tmp.dlc --input_list tmp_file.txt --output_dlc tmp_quat_aimet.dlc --override_params
4.Run the model on DSP
./snpe-net-run --container /sdcard/tmp_quat_aimet.dlc --input_list /sdcard/tmp_file_android.txt --use_dsp --debug
5.Result
FP32 pytorch model:
tensor([[0.2879, 0.2879, 0.2879, 0.2879, 0.2879, 0.2879, 0.2879, 0.2879, 0.2879,
0.2879, 0.2879, 0.2879, 0.2879, 0.2879, 0.2879, 0.2879, 0.2879, 0.2879,
0.2879, 0.2879, 0.2879, 0.2879, 0.2879, 0.2879, 0.2879, 0.2879, 0.2879,
0.2879, 0.2879, 0.2879, 0.2879, 0.2879, 0.2879, 0.2879, 0.2879, 0.2879,
0.2879, 0.2879, 0.2879, 0.2879]], grad_fn=<AddmmBackward>)
DSP:
logits.raw
(40,)
[0.28776518 0.28776518 0.28776518 0.28776518 0.28776518 0.28776518
0.28776518 0.28776518 0.28776518 0.28776518 0.28776518 0.28776518
0.28776518 0.28776518 0.28776518 0.28776518 0.28776518 0.28776518
0.28776518 0.28776518 0.28776518 0.28776518 0.28776518 0.28776518
0.28776518 0.28776518 0.28776518 0.28776518 0.28776518 0.28776518
0.28776518 0.28776518 0. 0. 0. 0.
0. 0. 0. 0. ]
I checked the results of each layer on the DSP and found that the problem was in the Linear layer.
Only the first 32 were correct, which made me very confused
This problem is very bad. I'm not sure if I did something wrong. I hope I can get advice as soon as possible
Dear customer,
Which SNPE version and SOC you tested? We will release an SNPE UI tools for those model accuracy issues later.
BR.
Wei
Hi
SNPE version: snpe-1.61.0.3358
Soc: SnapDragon 855
I also tested the SnapDragon 835, and the error still exists