Forums - Why the total inference time of a model with Sigmoid activation layers is more than that of a model with Relu activation layers?

4 posts / 0 new
Last post
Why the total inference time of a model with Sigmoid activation layers is more than that of a model with Relu activation layers?
lvarikuppala
Join Date: 3 Feb 22
Posts: 3
Posted: Wed, 2023-12-20 02:18

I have created an ONNX model with 7 layers which includes 2 convolution layers, 2 sigmoid layers, 2 max pool layers, and a softmax layer. I processed this model using the qnn-onnx-converter, resulting in .cpp and .bin files. Subsequently, I utilized the qnn-model-lib-generator to generate a shared library (lib*.so).

After the successful generation of the model shared library, I employed the qnn_bench.py script from the QNN SDK to conduct detailed layer-wise profiling on a QRB5165 target on DSP Runtime. The command used for this profiling is:

python3 qnn_bench.py -c model_sigmoid.json -t aarch64-ubuntu-gcc7.5 --dsp_type v66 -l detailed -v ADA7D246

Here are the layer wise computational times and total inference time acheived in the csv file for the model with Sigmoid activation Layers:

Inference time with Sigmoid                                               avg(us)

Total Inference Time [Conv_0:OpId_0(us)]                       392           
Total Inference Time [Sigmoid_1:OpId_1(us)]                   300
Total Inference Time [MaxPool_2:OpId_2(us)]                  234
Total Inference Time [Conv_3:OpId_3(us)]                        188
Total Inference Time [Sigmoid_4:OpId_4(us)]                   84
Total Inference Time [MaxPool_5:OpId_5(us)]                  40
Total Inference Time [_12_nchw:OpId_6(us)]                    338
Total Inference Time [Gemm_7:OpId_7(us)]                     795
Total Inference Time [Softmax_8:OpId_8(us)]                   26
Total Inference Time [NetRun]                                           5461

Then I replaced all the Sigmoid activation layers with ReLu activation layers and again conducted layer-wise profiling. 

Here are the layer wise computational times and total inference time acheived in the csv file for the model with ReLu activation layers:

Inference time with ReLu                                                     avg(us)

Total Inference Time [Conv_0:OpId_0(us)]                       328
Total Inference Time [MaxPool_2:OpId_1(us)]                 213
Total Inference Time [Conv_3:OpId_2(us)]                      188
Total Inference Time [MaxPool_5:OpId_3(us)]                 68
Total Inference Time [_12_nchw:OpId_4us)]                    340
Total Inference Time [Gemm_7:OpId_5(us)]                    801
Total Inference Time [Softmax_8:OpId_6(us)]                  31
Total Inference Time [NetRun]                                          4914

I observed that the model with Sigmoid layers has expensive performance compared to model with ReLu layers.

I would like to understand why the Sigmoids are so expensive and if there is anything we can do about it. We can stick to only using networks that only use ReLu activations ofcourse, but that might hurt our resulting image quality.

Thanks,
Lavanya Varikuppala

  • Up0
  • Down0
khrahul
Join Date: 24 Sep 19
Posts: 1
Posted: Wed, 2024-01-03 21:09

Dear Lavanya,

ReLU performance is better than Sigmoid due to below reasons:

1. ReLUs layers are computationally simple. The forward and backward pass in ReLU are simple "if" statements. Sigmoid layers are computationally expensive because it require computing an exponent.

2. ReLU layer converges quickly so it takes less time compare to Sigmoid functions.

Thanks,

Rahul

  • Up0
  • Down0
lvarikuppala
Join Date: 3 Feb 22
Posts: 3
Posted: Mon, 2024-01-08 02:03

Thanks Rahul.

Please let me know if there is anything that we can do with sigmoid to get better performance than relu.

Regards,

Lavanya Varikuppala


 

  • Up0
  • Down0
aithap
Join Date: 25 Apr 24
Posts: 1
Posted: Fri, 2024-04-26 15:12

Which toolchain target did you use in the `qnn-model-lib-generator` command

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.