Skip to content

feat(codebase/cls): support vision_transformer #403

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

Merged
merged 12 commits into from
Apr 26, 2022

Conversation

tpoisonooo
Copy link
Collaborator

@tpoisonooo tpoisonooo commented Apr 25, 2022

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

Motivation

Deploy mmcls ViT with ncnn.

Modification

  • Add function write to vision_transformer.py
    • MultiHeadAttention
    • GeLU
    • LayerNorm
  • onnx2ncnn.cpp
    • add a simple shape inference for fuse_conv_reshape
    • remove MultiHeadAttention qkv weight transpose
    • support convert GeLU opr
  • Others
    • shape.cpp code cleanup
    • get_node_attr_from_input function to template
    • add vision_transformer testcase

BC-breaking (Optional)

Use cases (Optional)

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

Checklist

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit tests to ensure the correctness.
  3. If the modification has a dependency on downstream projects of a newer version, this PR should be tested with all supported versions of downstream projects.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@tpoisonooo
Copy link
Collaborator Author

tpoisonooo commented Apr 25, 2022

Many thansk to your review @grimoire

  • resnet50 crash has been fixed because of an index out of range
  • update denpendency, mmcv >= 1.4.2 & mmcls >= 0.21.0

@tpoisonooo tpoisonooo changed the title [WIP] feat(codebase/cls): support vision_transformer feat(codebase/cls): support vision_transformer Apr 25, 2022
Copy link
Collaborator

@hanrui1sensetime hanrui1sensetime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will these changes in onnx2ncnn.cpp be synced to ncnn repo or not?

@tpoisonooo
Copy link
Collaborator Author

Will these changes in onnx2ncnn.cpp be synced to ncnn repo or not?

This week only a little part of onnx2ncnn.cpp would merge to ncnn, check Tencent/ncnn#3730.

Copy link
Member

@grimoire grimoire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@hanrui1sensetime hanrui1sensetime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@lvhan028 lvhan028 merged commit 2c2d1e5 into open-mmlab:dev-v0.5.0 Apr 26, 2022
lvhan028 pushed a commit to lvhan028/mmdeploy that referenced this pull request Jun 3, 2022
* feat(codebase/cls): support vision_transformer

* style(onnx2ncnn): format cpp code, upgrade mmcls version

* fix(CI): upgrade mmcv to 1.4.2

* fix(onnx2ncnn): offset out of range during fuse conv reshape

* docs(vision_transformer.py): update VisionTransformer desc

* docs(onnx2ncnn.cpp): add more comment

* feat(onnx2ncnn.cpp): revert fuse weight

* docs(onnx2ncnn.cpp): add more comment

* test(vision_transformer): add test case

* refactor(vision_transformer.py): use symbol rewrite layer_norm

* refactor(vision_transformer): fix review

* fix(attention): add missing files
lvhan028 pushed a commit to lvhan028/mmdeploy that referenced this pull request Jun 3, 2022
* feat(codebase/cls): support vision_transformer

* style(onnx2ncnn): format cpp code, upgrade mmcls version

* fix(CI): upgrade mmcv to 1.4.2

* fix(onnx2ncnn): offset out of range during fuse conv reshape

* docs(vision_transformer.py): update VisionTransformer desc

* docs(onnx2ncnn.cpp): add more comment

* feat(onnx2ncnn.cpp): revert fuse weight

* docs(onnx2ncnn.cpp): add more comment

* test(vision_transformer): add test case

* refactor(vision_transformer.py): use symbol rewrite layer_norm

* refactor(vision_transformer): fix review

* fix(attention): add missing files
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