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 registering partial functions and more #595

Merged
merged 6 commits into from
Apr 10, 2023

Conversation

C1rN09
Copy link
Collaborator

@C1rN09 C1rN09 commented Oct 11, 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

This PR is converted to DRAFT because I think this may break the design of Registry and may mess up some concept. I will re-examine the necessity and rationality of this change.

Support registering partial functions in MMEngine, solve #594

This feature might be required by FSDP for auto_wrap_policies

Modification

modify Registry to accept all Callable, including classes, functions, partial functions and more

BC-breaking (Optional)

No

Use cases (Optional)

import functools
from mmengine.registry import Registry
FUNCS = Registry('funcs')
@FUNCS.register_module('resnet')
def build_resnet(layers=50, activation='relu'):
    pass
build_resnet18 = functools.partial(build_resnet, layers=18)
FUNCS.register_module('resnet18', False, build_resnet18)
model = FUNCS.build(dict(type='resnet18', activation='silu'))

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 test to ensure the correctness.
  3. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMCls.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@C1rN09 C1rN09 linked an issue Oct 11, 2022 that may be closed by this pull request
C1rN09 and others added 2 commits October 11, 2022 22:29
Co-authored-by: Mashiro <57566630+HAOCHENYE@users.noreply.github.com>
Co-authored-by: Mashiro <57566630+HAOCHENYE@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Oct 11, 2022

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (2df5bc1) 78.10% compared to head (6a3ee9c) 78.11%.

❗ Current head 6a3ee9c differs from pull request most recent head aae512e. Consider uploading reports for the commit aae512e to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #595   +/-   ##
=======================================
  Coverage   78.10%   78.11%           
=======================================
  Files         126      126           
  Lines        9039     9042    +3     
  Branches     1800     1800           
=======================================
+ Hits         7060     7063    +3     
  Misses       1666     1666           
  Partials      313      313           
Flag Coverage Δ
unittests 78.11% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
mmengine/registry/build_functions.py 80.61% <100.00%> (+0.40%) ⬆️
mmengine/registry/registry.py 95.45% <100.00%> (+0.02%) ⬆️

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 in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

zhouzaida
zhouzaida previously approved these changes Oct 12, 2022
@zhouzaida zhouzaida added this to the 0.3.0 milestone Oct 12, 2022
@C1rN09 C1rN09 marked this pull request as draft October 12, 2022 06:57
@HAOCHENYE HAOCHENYE modified the milestones: 0.3.0, 0.4.0 Oct 27, 2022
@HAOCHENYE HAOCHENYE closed this Jan 12, 2023
@zhouzaida zhouzaida reopened this Apr 4, 2023
@zhouzaida zhouzaida marked this pull request as ready for review April 4, 2023 06:46
mzr1996
mzr1996 previously approved these changes Apr 4, 2023
@HAOCHENYE HAOCHENYE dismissed stale reviews from mzr1996 and zhouzaida via aae512e April 6, 2023 07:15
@HAOCHENYE HAOCHENYE force-pushed the enable_register_partial_function branch from aae512e to 0f652bd Compare April 6, 2023 07:44
@HAOCHENYE HAOCHENYE force-pushed the enable_register_partial_function branch from a78b95d to 9998486 Compare April 10, 2023 11:20
@zhouzaida zhouzaida changed the title [Feat] support registering partial functions and more [Feature] support registering partial functions and more Apr 10, 2023
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.

Function registry cannot register patrial function.
4 participants