Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable BN adaptation upon compressed model initialization #41

Merged

Conversation

lzrvch
Copy link
Contributor

@lzrvch lzrvch commented Jun 25, 2020

The PR adds a final BatchNorm statistics adaptation step to any compressed model initializer.

This is roughly based on the results of the FNNP paper and with further considerations that BN statistics adaptation acts as a bias & variance correction procedure following model weight perturbations during compression.

Preliminary results for quantization (ImageNet; fixed random seed for all expts; accuracy measured right after initialization):

Model Quantization bitwidths Quantization mode Range initializer Accuracy@1 Accuracy@5
ResNet18 a8w4 asymmetric, per-channel mean min max, 100 batches 49.352 73.822
ResNet18 (BN adapted) a8w4 asymmetric, per-channel mean min max, 100 batches 66.866 87.476
MobilenetV2 a8w4 asymmetric, per-channel mean min max, 100 batches 14.034 29.278
MobilenetV2 (BN adapted) a8w4 asymmetric, per-channel mean min max, 100 batches 65.216 86.304
MobilenetV2 a8w8 symmetric, per-tensor mean min max, 100 batches 69.984 89.356
MobilenetV2 (BN adapted) a8w8 symmetric, per-tensor mean min max, 100 batches 70.842 89.760
ResNet50 a4w4 asymmetric, per-channel mean min max, 100 batches 2.206 5.902
ResNet50 (BN adapted) a4w4 asymmetric, per-channel mean min max, 100 batches 20.428 39.690
ResNet50 a8w4 asymmetric, per-channel mean min max, 100 batches 69.440 89.208
ResNet50 (BN adapted) a8w4 asymmetric, per-channel mean min max, 100 batches 74.866 92.244

NB: the "per-channel" tag above relates to weight quantization, activations are always quantized per-tensor. "(A)symmetric" relates to both weights and activations.

Pruning/sparsity results (ImageNet; fixed random seed for all expts; accuracy measured right after initialization)

Model Pruning algo info Accuracy@1 Accuracy@5
ResNet18 geometric median criterion, pruning target = 30% 0.308 1.110
ResNet18 (BN adapted) geometric median criterion, pruning target = 30% 33.582 59.336
ResNet18 magnitude sparsity, sparsity tagret = 70% 41.196 66.952
ResNet18 (BN adapted) magnitude sparsity, sparsity target = 70% 61.222 84.022

Preliminary results obtained by fully resetting BN statistics after initialization and running inference of 200 batches (256 samples each).

To do's:

  • Add BN adaptation to sparsity & pruning initialization
  • Use large momentum value instead of zeroing BN stats completely
  • Do iterative adaptation BN layer after BN layer - results in BatchNorm adaptation results #46

@lzrvch lzrvch requested a review from a team June 25, 2020 20:56
@openvino-pushbot
Copy link

Can one of the admins verify this patch?

1 similar comment
@openvino-pushbot
Copy link

Can one of the admins verify this patch?

@lzrvch
Copy link
Contributor Author

lzrvch commented Jun 25, 2020

@mkaglins have a look. This initialization procedure can be used for model subjected to filter pruning. We should try to reproduce the results of the FNNP paper saying that accuracy after BN adaptation correlates well with fine-tuned model accuracy (basically using Figure 4 of the paper as reference).

nncf/config_schema.py Outdated Show resolved Hide resolved
@lzrvch
Copy link
Contributor Author

lzrvch commented Jun 29, 2020

@mkaglins could you also please run your fine-tuning experiments with L1/L2 and Geomean filter selection criteria separately? It'd be good to know whether the correlation between metrics depends somehow on the pruning criterion chosen.

@lzrvch lzrvch changed the title WIP: Enable BN adaptation upon compressed model initialization Enable BN adaptation upon compressed model initialization Jul 20, 2020
@lzrvch
Copy link
Contributor Author

lzrvch commented Jul 21, 2020

Jenkins please retry a build

1 similar comment
@vshampor
Copy link
Contributor

Jenkins please retry a build

nncf/initialization.py Outdated Show resolved Hide resolved
@ljaljushkin ljaljushkin self-requested a review July 21, 2020 15:52
@lzrvch
Copy link
Contributor Author

lzrvch commented Jul 22, 2020

@AlexKoff88 @vshampor PR is ready to be merged. BN adaptation is switched off by default for now.

@vshampor vshampor merged commit 62a66f2 into openvinotoolkit:develop Jul 22, 2020
kshpv pushed a commit to kshpv/nncf that referenced this pull request Oct 11, 2022
…olkit#41)

* Add batchnorm statistics adaptation to quantization algo initializer

* Enable BN stats adaptation for filter pruning.

Need to further rename QuantizationRangeInitArgs properly since it's now being used outside the quantization algo scope.

* + BN adaptation for magnitude sparsity

* Extend the config schema to include the *num_bn_adaptation_steps* parameter for algo initializers

* Proper pass of BN adaptation args (dataloader) via BNAdaptationInitArgs struct

* Improved config setting for BN adaptation parameters

* Remove initialzier in config schema for RB sparsity

* Replace resetting of BN stats with a forgetting step via large momentum value.

Appoximately same accuracy with fewer init steps required.

* Fix forgetting momentum value

* Default num of steps = 20 for BN adaptation since it is sufficient empirically

* Move BN adaptation to base algo class

* formatting

* Fix export_model method docstring for filter pruning

* Fix range init call counter test for BN adaptation

* No BN adaptation by default, adjust call counter test

* add BN adaptation docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants