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

[Enhancement] Support LayerScale #2451

Merged
merged 16 commits into from
Dec 11, 2022
Merged

Conversation

okotaku
Copy link
Contributor

@okotaku okotaku commented Nov 24, 2022

Motivation

Support LayerScale from mmcls.
https://github.com/open-mmlab/mmclassification/blob/dev-1.x/mmcls/models/utils/layer_scale.py

Support LayerScale in FFN.
https://github.com/open-mmlab/mmclassification/blob/dev-1.x/mmcls/models/backbones/deit3.py#L18
It is also used in other backbones such as ViT-Adapter.

Related PR

open-mmlab/mmpretrain#1209
open-mmlab/mmdetection#9354

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.

@codecov
Copy link

codecov bot commented Nov 24, 2022

Codecov Report

Base: 66.62% // Head: 66.69% // Increases project coverage by +0.07% 🎉

Coverage data is based on head (51ffb60) compared to base (104aaa8).
Patch coverage: 100.00% of modified lines in pull request are covered.

❗ Current head 51ffb60 differs from pull request most recent head ec1a7cb. Consider uploading reports for the commit ec1a7cb to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##              2.x    #2451      +/-   ##
==========================================
+ Coverage   66.62%   66.69%   +0.07%     
==========================================
  Files         120      120              
  Lines        7799     7816      +17     
  Branches     1067     1072       +5     
==========================================
+ Hits         5196     5213      +17     
  Misses       2436     2436              
  Partials      167      167              
Flag Coverage Δ
unittests 66.69% <100.00%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
mmcv/cnn/bricks/__init__.py 100.00% <100.00%> (ø)
mmcv/cnn/bricks/scale.py 100.00% <100.00%> (ø)
mmcv/cnn/bricks/transformer.py 84.28% <100.00%> (+0.15%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Co-authored-by: Zaida Zhou <58739961+zhouzaida@users.noreply.github.com>
okotaku and others added 2 commits November 25, 2022 16:12
Co-authored-by: Zaida Zhou <58739961+zhouzaida@users.noreply.github.com>
@HAOCHENYE
Copy link
Collaborator

Hi! thanks for your contribution!
It seems

class Scale(nn.Module):

is similar to LayerScale, could implement LayerScale there?

mmcv/cnn/bricks/transformer.py Outdated Show resolved Hide resolved
mmcv/cnn/bricks/scale.py Outdated Show resolved Hide resolved
mmcv/cnn/bricks/scale.py Outdated Show resolved Hide resolved
mmcv/cnn/bricks/scale.py Outdated Show resolved Hide resolved
@HAOCHENYE
Copy link
Collaborator

Hi ! CI seems failed now and we need to fix it 😸

@okotaku
Copy link
Contributor Author

okotaku commented Dec 9, 2022

@HAOCHENYE I have fixed test.

@HAOCHENYE
Copy link
Collaborator

LGTM 👍 ! My last comment: Please also update LayerScale in https://github.com/open-mmlab/mmcv/blob/2.x/docs/en/api/cnn.rst and https://github.com/open-mmlab/mmcv/blob/2.x/docs/zh_cn/api/cnn.rst.

@okotaku
Copy link
Contributor Author

okotaku commented Dec 9, 2022

Thank you for your reviews!

Copy link
Collaborator

@HAOCHENYE HAOCHENYE left a comment

Choose a reason for hiding this comment

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

Approved!!!
image

@zhouzaida zhouzaida merged commit d510b8b into open-mmlab:2.x Dec 11, 2022
tyomj pushed a commit to tyomj/mmcv that referenced this pull request May 8, 2023
* add layer scale

* add layer scale

* add layer scale

* Update mmcv/cnn/bricks/transformer.py

Co-authored-by: Zaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update mmcv/cnn/bricks/transformer.py

Co-authored-by: Zaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* add layer scale

* move LayerScale

* add layer_scale_init_value

* add typehint

* fix for tensor with any dim

* fix layer scale rule

* fix layer scale rule

* fix test

* add docs

Co-authored-by: Zaida Zhou <58739961+zhouzaida@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants