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

[Feature] Support registry auto import modules. #643

Merged
merged 14 commits into from
Dec 23, 2022

Conversation

RangiLyu
Copy link
Member

@RangiLyu RangiLyu commented Oct 26, 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

Support auto-import modules from pre-defined locations.
Use lazy import during building to avoid registering useless modules at the beginning.

Modification

Modify the get method.

Use case

in mmdet/registry.py

DATASETS = Registry('dataset', parent=MMENGINE_DATASETS, locations=['mmdet.datasets'])
DATA_SAMPLERS = Registry('data sampler', parent=MMENGINE_DATA_SAMPLERS, locations=['mmdet.datasets.samplers'])
TRANSFORMS = Registry('transform', parent=MMENGINE_TRANSFORMS, locations=['mmdet.datasets.transforms'])

and then the regsiter_all_modules is no longer needed

More details at open-mmlab/mmdetection#9143.

BC-Breaking

None

Verified in MMDetection, MMClassification, MMYOLO, and MMSelfsup.

@zhouzaida zhouzaida changed the base branch from dev to main November 9, 2022 06:42
@RangiLyu RangiLyu marked this pull request as ready for review November 14, 2022 05:47
@RangiLyu RangiLyu changed the title [Draft][Feature] Support registry auto import modules. [Feature] Support registry auto import modules. Nov 14, 2022
@codecov
Copy link

codecov bot commented Nov 15, 2022

Codecov Report

Base: 78.66% // Head: 78.83% // Increases project coverage by +0.16% 🎉

Coverage data is based on head (ddf60d1) compared to base (fe26c65).
Patch coverage: 49.48% of modified lines in pull request are covered.

❗ Current head ddf60d1 differs from pull request most recent head 45a7774. Consider uploading reports for the commit 45a7774 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #643      +/-   ##
==========================================
+ Coverage   78.66%   78.83%   +0.16%     
==========================================
  Files         128      128              
  Lines        9348     9399      +51     
  Branches     1848     1862      +14     
==========================================
+ Hits         7354     7410      +56     
+ Misses       1679     1673       -6     
- Partials      315      316       +1     
Flag Coverage Δ
unittests 78.83% <49.48%> (+0.16%) ⬆️

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

Impacted Files Coverage Δ
mmengine/optim/optimizer/zero_optimizer.py 52.17% <0.00%> (-4.97%) ⬇️
mmengine/registry/build_functions.py 80.20% <ø> (ø)
mmengine/registry/default_scope.py 100.00% <ø> (ø)
mmengine/runner/runner.py 84.96% <ø> (-0.19%) ⬇️
mmengine/visualization/vis_backend.py 84.49% <ø> (ø)
mmengine/visualization/visualizer.py 93.19% <ø> (ø)
mmengine/runner/checkpoint.py 52.07% <11.11%> (+8.11%) ⬆️
mmengine/model/weight_init.py 35.63% <33.33%> (+0.12%) ⬆️
mmengine/registry/registry.py 89.44% <41.93%> (-3.15%) ⬇️
mmengine/optim/optimizer/optimizer_wrapper.py 62.06% <71.42%> (-0.44%) ⬇️
... and 6 more

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.

@RangiLyu RangiLyu requested a review from HAOCHENYE November 15, 2022 10:56
@RangiLyu RangiLyu requested a review from HAOCHENYE November 18, 2022 06:24
Comment on lines +103 to +104
never_created = DefaultScope.get_current_instance(
) is None or not DefaultScope.check_instance_created(scope)
Copy link
Collaborator

Choose a reason for hiding this comment

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

check_instance_created only checks the instance name rather than the scope name.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is exactly used to check the instance with the name of scope here.

@RangiLyu RangiLyu requested a review from HAOCHENYE November 21, 2022 02:37
@RangiLyu RangiLyu requested a review from HAOCHENYE November 28, 2022 03:05
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

HAOCHENYE
HAOCHENYE previously approved these changes Nov 29, 2022
@zhouzaida
Copy link
Collaborator

It would be better to add this usage to docs/zh_cn/tutorials/registry.md and docs/en/tutorials/registry.md

HAOCHENYE
HAOCHENYE previously approved these changes Dec 20, 2022
zhouzaida
zhouzaida previously approved these changes Dec 21, 2022
@HAOCHENYE HAOCHENYE added this to the 0.4.0 milestone Dec 21, 2022
@HAOCHENYE HAOCHENYE added the ready ready to merge label Dec 21, 2022
@zhouzaida zhouzaida merged commit e83ac94 into open-mmlab:main Dec 23, 2022
MeowZheng pushed a commit to open-mmlab/mmsegmentation that referenced this pull request Feb 23, 2023
## Motivation

The registry now supports auto-import modules from the given location.

register_all_modules before running is no longer needed. The modules
will be lazy-imported during building.

- [x] This PR can be merged after
open-mmlab/mmengine#643. The MMEngine version
should be updated.

Ref: open-mmlab/mmdetection#9143
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants