mmdeploy
mmdeploy copied to clipboard
Rewrite Conv2dAdaptiveOps for conversion of EfficientNet (static shape)
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 |
Thanks for the contribution! Could you provide the deploy config you used to convert efficientnet?
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
@SsTtOoNnEe may add unit test for this rewriting.
@RunningLeon I have modified the PR according to your comments. Please kindly review it.
@SsTtOoNnEe Hi, could you fix the conflicts?
@SsTtOoNnEe Pls. fix lint error.
@grimoire any comment on this PR?
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❤