- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am looking for help with the NNCF training-time compression on a U-net model. I have a U-net model trained in PyTorch, and then I tried to use NNCF to do filter pruning in training, so that we can speedup the model inference.
During the NNCF training, it shows the "current pruning level" to slowly increase to reach the target value of 0.30, but the FLOPS reduction is always 0. It also shows "WARNING:nncf:Binary masks are identity matrix, please check your config." during the training which seems suspicious if NNCF is doing anything.
Finally, I converted the model to OpenVINO and compare the pruned model vs the original unpruned model (both in OV), and there seem to be no speed improvement, while the output accuracy has reduced.
Could you provide any suggestion on what may be the problem here? Really appreciated.
==========================
Current pruning level: 0.00
Target pruning level: 0.30
FLOPs reduction due to pruning: 0.00
Epoch 1/10, Train Batch 1/325, Loss: 0.04538079723715782
--
Current pruning level: 0.00
Target pruning level: 0.30
FLOPs reduction due to pruning: 0.00
Epoch 2/10, Train Batch 1/325, Loss: 0.045010462403297424
--
Current pruning level: 0.00
Target pruning level: 0.30
FLOPs reduction due to pruning: 0.00
Epoch 3/10, Train Batch 1/325, Loss: 0.0421537347137928
--
Current pruning level: 0.10
Target pruning level: 0.30
FLOPs reduction due to pruning: 0.00
Epoch 4/10, Train Batch 1/325, Loss: 0.045686956495046616
--
Current pruning level: 0.15
Target pruning level: 0.30
FLOPs reduction due to pruning: 0.00
Epoch 5/10, Train Batch 1/325, Loss: 0.045078352093696594
--
Current pruning level: 0.21
Target pruning level: 0.30
FLOPs reduction due to pruning: 0.00
Epoch 6/10, Train Batch 1/325, Loss: 0.05612863600254059
--
Current pruning level: 0.25
Target pruning level: 0.30
FLOPs reduction due to pruning: 0.00
Epoch 7/10, Train Batch 1/325, Loss: 0.0534798726439476
--
Current pruning level: 0.30
Target pruning level: 0.30
FLOPs reduction due to pruning: 0.00
Epoch 8/10, Train Batch 1/325, Loss: 0.05307655408978462
--
Current pruning level: 0.30
Target pruning level: 0.30
FLOPs reduction due to pruning: 0.00
Epoch 9/10, Train Batch 1/325, Loss: 0.05456303432583809
--
Current pruning level: 0.30
Target pruning level: 0.30
FLOPs reduction due to pruning: 0.00
Epoch 10/10, Train Batch 1/325, Loss: 0.05304049700498581
============================
Code snippet of the NNCF training:
============================
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Lfan,
Thank you for reaching out.
If possible, can you share the steps you used to compress the model? Also, please share the OpenVINO version and the inference results before and after pruning.
Regards,
Zul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Zul,
My OpenVINO version is: 2024.1.0. NNCF version is 2.16.0.
Here is the NNCF compression steps I took (the code snippet was also included in the first post):
Starting with a U-net model already trained.
NNCF Configuration:
- An NNCF configuration dictionary is created, specifying:
- Input shapes for model tracing.
- Compression algorithm "filter_pruning" with parameters like pruning target, schedule, and number of steps.
- An NNCF configuration dictionary is created, specifying:
Initialization DataLoader to prepare data for NNCF.
Register Initialization Args:
- The initialization data is registered with the NNCF configuration using register_default_init_args.
Create Compressed Model:
- The model is wrapped with NNCF using create_compressed_model, which returns the compressed model (nncf_model) and compression_ctrl.
Training with Pruning:
- Ran 10 epochs, for each epoch:
- The pruning scheduler is updated compression_ctrl.scheduler.epoch_step .
- The model is trained on batches of data, computing losses and updating weights.
- Pruning statistics (e.g., current pruning level, FLOPs reduction) are printed.
- Ran 10 epochs, for each epoch:
Model Conversion to OpenVINO:
- After training, the pruned model is converted to OpenVINO format using ov.convert_model.
- A pruning transformation is applied to the OpenVINO model.
- The converted model is saved as .xml and .bin files for deployment.
I am happy to share all relevant scripts if needed.
Looking at the pruning statistics (also in the previous post), it seems to indicate that there were no actual FLOPs reduction happened during the pruning (0.0).
I then tested the inference time on the original model as well as the pruned model on 100 inputs, the mean value is very similar between the two models:
Inference time OpenVINO 99 0.0089114286
Inference time OpenVINO Pruned 99 0.0088372314
I also tested the pruned model on the large dataset (>1000 images) and it showed no change in runtime.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Lfan,
That would be great if you could share all the necessary files. I'll check on my side and help refer this issue to the development team.
Regards,
Zul

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page