Skip to content

[Enhance] Use PyTorch HSwish implementation.#1709

Merged
zhouzaida merged 4 commits intoopen-mmlab:masterfrom
RangiLyu:torch_hswish
Feb 12, 2022
Merged

[Enhance] Use PyTorch HSwish implementation.#1709
zhouzaida merged 4 commits intoopen-mmlab:masterfrom
RangiLyu:torch_hswish

Conversation

@RangiLyu
Copy link
Copy Markdown
Member

@RangiLyu RangiLyu commented Feb 10, 2022

Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.

Motivation

Replace naive HSwish with PyTorch official HSwish implementation. In some models, it will improve inference speed by around 30%.

Modification

Use PyTorch official HSwish when torch>=1.7 (Hardswish in PyTorch 1.6 does not support inplace.)

BC-breaking (Optional)

None

Use cases (Optional)

If this PR introduces a new feature, it is better to list some use cases here, and update the documentation.

Checklist

Before PR:

  • I have read and followed the workflow indicated in the CONTRIBUTING.md to create this PR.
  • Pre-commit or linting tools indicated in CONTRIBUTING.md are used to fix the potential lint issues.
  • Bug fixes are covered by unit tests, the case that causes the bug should be added in the unit tests.
  • New functionalities are covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • The documentation has been modified accordingly, including docstring or example tutorials.

After PR:

  • If the modification has potential influence on downstream or other related projects, this PR should be tested with some of those projects, like MMDet or MMCls.
  • CLA has been signed and all committers have signed the CLA in this PR.

@RangiLyu
Copy link
Copy Markdown
Member Author

Hardswish in PyTorch 1.6 does not support inplace.

@RangiLyu
Copy link
Copy Markdown
Member Author

When exporting to ONNX, the OP may change. Waiting MMDeploy to check.

@ZwwWayne
Copy link
Copy Markdown
Collaborator

Hardswish in PyTorch 1.6 does not support inplace.

May leave this comment in the code to indicate the reason why we check for 1.7 rather than 1.6.

@zhouzaida zhouzaida requested a review from grimoire February 10, 2022 16:32
@zhouzaida
Copy link
Copy Markdown
Collaborator

When exporting to ONNX, the OP may change. Waiting MMDeploy to check.

Please @grimoire have a check.

@grimoire
Copy link
Copy Markdown
Member

HardSwish node is only available since op-set version 14. And some backends would unpack it (for example Torch-TensorRT) even when you export it as an independent node. It is ok if the exporter transforms it to other nodes.

@ZwwWayne
Copy link
Copy Markdown
Collaborator

ZwwWayne commented Feb 11, 2022

HardSwish node is only available since op-set version 14. And some backends would unpack it (for example Torch-TensorRT) even when you export it as an independent node. It is ok if the exporter transforms it to other nodes.

So can we merge this PR?

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.

4 participants