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] Add DMCP and fix the deploy pipeline of NAS algorithms #406

Merged
merged 69 commits into from
Mar 2, 2023

Conversation

Lxtccc
Copy link
Contributor

@Lxtccc Lxtccc commented Dec 22, 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

Please describe the motivation of this PR and the goal you want to achieve through this PR.

Modification

Please briefly describe what modification is made in this PR.

BC-breaking (Optional)

Does the modification introduce changes that break the backward compatibility of the downstream repositories?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.

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:

  • Pre-commit or other linting tools are used to fix the potential lint issues.
  • Bug fixes are fully covered by unit tests, the case that causes the bug should be added in the unit tests.
  • The modification is covered by complete unit tests. If not, please add more unit tests to ensure the correctness.
  • The documentation has been modified accordingly, like docstring or example tutorials.

After PR:

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

# To static ops for loaded pruned network.
self._deploy()

def _deploy(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

_deploy is not needed here.

ForwardResults = Union[LossResults, TensorResults, PredictResults]

@MODELS.register_module()
class DMCP(ItePruneAlgorithm):
Copy link
Contributor

Choose a reason for hiding this comment

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

inherit from ItePruneAlgorithm for ?

def __init__(self,
channel_unit_cfg: Union[dict, Type[ChannelUnitType]] = dict(
type='DMCPChannelUnit', units={}),
parse_cfg=dict(
Copy link
Contributor

Choose a reason for hiding this comment

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

update parse_cfg to ChannelAnalyzer, according to:

else:
raise NotImplementedError

def calc_current_flops(self, model):
Copy link
Contributor

Choose a reason for hiding this comment

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

move to Algorithm.

@@ -172,7 +171,8 @@ def params_units_convert(num_params, units='M', precision=3):
>>> params_units_convert(3e-9)
'3e-09'
"""

if getattr(num_params, 'requires_grad', None):
Copy link
Contributor

Choose a reason for hiding this comment

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

If you want to get num_params without units, just pass the argument units with the None.

@sunnyxiaohu sunnyxiaohu self-requested a review December 23, 2022 06:42
class DynamicSyncBatchNorm(nn.SyncBatchNorm, DynamicBatchNormMixin):
"""DynamicOp for sync bn."""
@MODELS.register_module()
class DMCPBatchNorm2d(DynamicBatchNorm2d):
Copy link
Contributor

Choose a reason for hiding this comment

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

fix dynamic_norm.py


self.modify_supernet_forward(arch_train)

def _prune_by_arch(self, mode, group_id):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

docstr

group_arch_param = self._build_arch_param(arch_message[1])
self.arch_params[str(group_id)] = group_arch_param

for m in module[0].output_related:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

modify name:m->unit

min_ratio: float = 0.5) -> None:
super().__init__(num_channels, choice_mode, divisor, min_value,
min_ratio)
self._traceable_choice = tracable_choice()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

traceable

@sunnyxiaohu sunnyxiaohu self-requested a review December 28, 2022 07:24
@codecov
Copy link

codecov bot commented Jan 11, 2023

Codecov Report

Patch coverage: 75.92% and project coverage change: +0.35 🎉

Comparison is base (60469c0) 79.14% compared to head (7d57599) 79.49%.

Additional details and impacted files
@@             Coverage Diff             @@
##           dev-1.x     #406      +/-   ##
===========================================
+ Coverage    79.14%   79.49%   +0.35%     
===========================================
  Files          276      279       +3     
  Lines        13597    14027     +430     
  Branches      2084     2155      +71     
===========================================
+ Hits         10761    11151     +390     
- Misses        2395     2416      +21     
- Partials       441      460      +19     
Flag Coverage Δ
unittests 79.49% <75.92%> (+0.35%) ⬆️

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

Impacted Files Coverage Δ
mmrazor/engine/hooks/dump_subnet_hook.py 35.00% <0.00%> (ø)
mmrazor/engine/runner/subnet_val_loop.py 24.00% <0.00%> (ø)
...architectures/backbones/searchable_mobilenet_v3.py 89.11% <ø> (ø)
...dynamic_ops/bricks/dynamic_multi_head_attention.py 69.73% <ø> (ø)
mmrazor/models/mutables/__init__.py 100.00% <ø> (ø)
mmrazor/models/mutators/__init__.py 100.00% <ø> (ø)
mmrazor/models/algorithms/nas/bignas.py 38.28% <10.66%> (+1.05%) ⬆️
.../models/task_modules/predictor/metric_predictor.py 65.62% <16.66%> (-7.32%) ⬇️
...zor/models/architectures/utils/mutable_register.py 75.75% <28.57%> (-14.57%) ⬇️
mmrazor/engine/hooks/dmcp_subnet_hook.py 30.55% <30.55%> (ø)
... and 27 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.

@sunnyxiaohu sunnyxiaohu changed the title [Feature] Add DMCP [Feature] Add DMCP and fix the deploy pipeline of NAS algorithms Mar 2, 2023
@sunnyxiaohu sunnyxiaohu merged commit 0b24276 into open-mmlab:dev-1.x Mar 2, 2023
@vansin
Copy link
Collaborator

vansin commented Mar 8, 2023

@Lxtccc Congratulations on having your first PR merged in OpenMMLab! I am a technical operations staff member of OpenMMLab. My WeChat ID is van-sin ,please add me . I would like to invite you to join the OpenMMLab contributors WeChat group.

@openmmlab-bot
Copy link
Collaborator

Dear Lxtccc,
First of all, we want to express our gratitude for your significant PR in the MMRazor project. Your contribution is highly appreciated, and we are grateful for your efforts in helping improve this open-source project during your personal time. We believe that many developers will benefit from your PR.
We are looking forward to continuing our collaboration with you. OpenMMLab has established a special contributors' organization called MMSIG, which provides contributors with open-source certificates, a recognition system, and exclusive rewards. You can contact us by adding our WeChat(if you have WeChat): openmmlabwx, or join in our discord:https://discord.gg/raweFPmdzG. We sincerely hope you will join us!
Best regards! @Lxtccc

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.

None yet

6 participants