Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.
6403 Discussions

Slower inference with INT8 precision for quantized model(NNCF)

Abramov__Alexey
Beginner
2,130 Views

I've recently started working on speeding up inference of models and used NNCF for INT8 quantization and creating OpenVINO compatible ONNX model. After performing quantization with default parameters and converting model PyTorch->ONNX->OpenVINO, I've compared original and quantized models with benchmark_app and got following results:

Original model:

[Step 1/11] Parsing and validating input arguments
[ INFO ] Parsing input parameters
[Step 2/11] Loading Inference Engine
[ INFO ] InferenceEngine:
API version ............ 2.1
Build .................. 42025
Description ....... API
[ INFO ] Device info:
CPU
MKLDNNPlugin version ......... 2.1
Build ........... 42025

[Step 3/11] Setting device configuration
[Step 4/11] Reading the Intermediate Representation network
[ INFO ] Loading network files
[ INFO ] Read network took 26.46 ms
[Step 5/11] Resizing network to match image sizes and given batch
[ INFO ] Network batch size was changed to: 1
[Step 6/11] Configuring input of the model
[Step 7/11] Loading the model to the device
[ INFO ] Load network took 251.08 ms
[Step 8/11] Setting optimal runtime parameters
[Step 9/11] Creating infer requests and filling input blobs with images
[ INFO ] Network input 'input.1' precision FP32, dimensions (NCHW): 1 1 64 160
[ WARNING ] No input files were given: all inputs will be filled with random values!
[ INFO ] Infer Request 0 filling
[ INFO ] Fill input 'input.1' with random values (some binary data is expected)
[Step 10/11] Measuring performance (Start inference syncronously, limits: 5000 iterations)
Progress: [....................] 100% done

[Step 11/11] Dumping statistics report
Count: 5000 iterations
Duration: 16567.77 ms
Latency: 3.23 ms
Throughput: 309.86 FPS

Quantized model:

[Step 1/11] Parsing and validating input arguments
[ INFO ] Parsing input parameters
[Step 2/11] Loading Inference Engine
[ INFO ] InferenceEngine:
API version ............ 2.1
Build .................. 42025
Description ....... API
[ INFO ] Device info:
CPU
MKLDNNPlugin version ......... 2.1
Build ........... 42025

[Step 3/11] Setting device configuration
[Step 4/11] Reading the Intermediate Representation network
[ INFO ] Loading network files
[ INFO ] Read network took 61.69 ms
[Step 5/11] Resizing network to match image sizes and given batch
[ INFO ] Network batch size was changed to: 1
[Step 6/11] Configuring input of the model
[Step 7/11] Loading the model to the device
[ INFO ] Load network took 814.75 ms
[Step 8/11] Setting optimal runtime parameters
[Step 9/11] Creating infer requests and filling input blobs with images
[ INFO ] Network input 'result.1' precision FP32, dimensions (NCHW): 1 1 64 160
[ WARNING ] No input files were given: all inputs will be filled with random values!
[ INFO ] Infer Request 0 filling
[ INFO ] Fill input 'result.1' with random values (some binary data is expected)
[Step 10/11] Measuring performance (Start inference syncronously, limits: 5000 iterations)
Progress: [....................] 100% done

[Step 11/11] Dumping statistics report
Count: 5000 iterations
Duration: 28721.67 ms
Latency: 5.58 ms
Throughput: 179.06 FPS

Both measurements were performed with following options: -d CPU -api async -niter 5000 -nireq 1 -b 1 -progress -nstreams 1 -nthreads 1. Both IR's were created with FP32.

Why quantized model runs slower than original and how can I improve it? Thanks in advance for any advice!

Both IR's *.xml are attached below.

Upd: Forgot to mention CPU:

Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 8
On-line CPU(s) list: 0-7
Thread(s) per core: 2
Core(s) per socket: 4
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 142
Model name: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
Stepping: 10
CPU MHz: 798.323
CPU max MHz: 3400.0000
CPU min MHz: 400.0000
BogoMIPS: 3600.00
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 6144K
NUMA node0 CPU(s): 0-7
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d

0 Kudos
1 Solution
Max_L_Intel
Moderator
2,087 Views

Hi @Abramov__Alexey 

What compression algorithm have you used?
As I see, benchmark app still shows FP32 precision for your quanatized model. It is not INT8.

[Step 9/11] Creating infer requests and filling input blobs with images
[ INFO ] Network input 'result.1' precision FP32, dimensions (NCHW): 1 1 64 160
[ WARNING ] No input files were given: all inputs will be filled with random values!


Can you please test NNCF Image Classification Sample with MobileNet v2 model similar to your one? For that case for INT8 quantization you should use mobilenet_v2_imagenet_int8.json configuration file.

Thanks.

 

View solution in original post

0 Kudos
4 Replies
Max_L_Intel
Moderator
2,109 Views

Hi @Abramov__Alexey 

We are not able to test your models, since weights files (.bin) are not provided. Can you please attach them as well?

Did you configure NNCF according to NNCF usage instructions? And have you taken one of listed NNCF validated topologies for your custom models? Or is it some different one?

Thanks.
Best regards, Max.

0 Kudos
Abramov__Alexey
Beginner
2,100 Views

Hi, thanks for reply!

I've checked both links that you provided:

1. In NNCF Usage guide I skipped only optional step 3 in Modify the training pipeline - if I understand correctly, this should affect only model accuracy, but not inference time;

2. Used model contains backbone from MobileNetV2 and 2 heads with following layers: ReLU, AdaptiveAvgPool2d, Linear, Conv2d and view/shape operations.

Also, attached weights for both models and used configuration file.

0 Kudos
Max_L_Intel
Moderator
2,088 Views

Hi @Abramov__Alexey 

What compression algorithm have you used?
As I see, benchmark app still shows FP32 precision for your quanatized model. It is not INT8.

[Step 9/11] Creating infer requests and filling input blobs with images
[ INFO ] Network input 'result.1' precision FP32, dimensions (NCHW): 1 1 64 160
[ WARNING ] No input files were given: all inputs will be filled with random values!


Can you please test NNCF Image Classification Sample with MobileNet v2 model similar to your one? For that case for INT8 quantization you should use mobilenet_v2_imagenet_int8.json configuration file.

Thanks.

 

0 Kudos
Max_L_Intel
Moderator
2,058 Views

We haven't heard back from you, so we are closing this case.
If you need any additional information from Intel, please submit a new question as this thread is no longer being monitored.

0 Kudos
Reply