mmdeploy icon indicating copy to clipboard operation
mmdeploy copied to clipboard

Rewrite Conv2dAdaptiveOps for conversion of EfficientNet (static shape)

Open SsTtOoNnEe opened this issue 3 years ago • 1 comments

Motivation

Rewrite Conv2dAdaptiveOps for conversion of EfficientNet (static shape). In the PyTorch version of 1.10 (or below), the conversion of EfficientNet can not be fully completed because of different ONNX parsing behaviours against the higher PyTorch versions (>=1.10). In detail, the operator of Conv2dAdaptivePadding in MMCV (which is used in EfficientNet) conducts padding shape computation before the convolution, which introduces complex and redundant nodes in the ONNX graph. By using NVIDIA Polygraphy tools, the output ONNX graph can be simplified to allow for the following conversion procedure. Alternatively, in order to maintain the robustness of MMDeploy, the Conv2dAdaptivePadding operator can be rewritten given different configurations (eg, dynamic and static shapes).

Modification

For the static model conversion task, we extracted the padding computation from the Cov2dAdaptivePadding operator to encapsulate it into a separate torch.autograd.Fcuntion class. After the modification, the ONNX graph exported from the adaptive convolution will not include the computation of padding, thus making it static.

Test results

PyTorch version Top1-Accuracy Top5-Accuracy
1.12.2 75.64 92.38
1.8.0 (Rewritten) 75.12 92.24

SsTtOoNnEe avatar Sep 14 '22 06:09 SsTtOoNnEe

Thanks for the contribution! Could you provide the deploy config you used to convert efficientnet?

grimoire avatar Sep 15 '22 02:09 grimoire

Please resolve the lint error. You can use pre-commit to check if there is lint issues before committing like below,

python3 -m pip install pre-commit
cd /the/root/path/of/mmdeploy
pre-commit install
pre-commit run --all-files

lvhan028 avatar Sep 21 '22 07:09 lvhan028

@SsTtOoNnEe may add unit test for this rewriting.

RunningLeon avatar Sep 21 '22 11:09 RunningLeon

@RunningLeon I have modified the PR according to your comments. Please kindly review it.

SsTtOoNnEe avatar Sep 28 '22 04:09 SsTtOoNnEe

@SsTtOoNnEe Hi, could you fix the conflicts?

RunningLeon avatar Oct 11 '22 08:10 RunningLeon

@SsTtOoNnEe Pls. fix lint error.

RunningLeon avatar Oct 11 '22 11:10 RunningLeon

@grimoire any comment on this PR?

RunningLeon avatar Oct 12 '22 11:10 RunningLeon

Hi @SsTtOoNnEe !First of all, we want to express our gratitude for your significant PR in the MMDeploy project. Your contribution is highly appreciated, and we are grateful for your efforts in helping improve this open-source project during your personal time. We believe that many developers will benefit from your PR.

We would also like to invite you to join our Special Interest Group (SIG) private channel on Discord, where you can share your experiences, ideas, and build connections with like-minded peers. To join the SIG channel, simply message moderator— OpenMMLab on Discord or briefly share your open-source contributions in the #introductions channel and we will assist you. Look forward to seeing you there! Join us :https://discord.gg/UjgXkPWNqA

If you have WeChat account,welcome to join our community on WeChat. You can add our assistant :openmmlabwx. Please add "mmsig + Github ID" as a remark when adding friends:) Thank you again for your contribution❤

OpenMMLab-Assistant005 avatar Apr 04 '23 09:04 OpenMMLab-Assistant005