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 mmseg with NPU backend. #2768

Merged
merged 1 commit into from
Mar 23, 2023
Merged

[Feature] Support mmseg with NPU backend. #2768

merged 1 commit into from
Mar 23, 2023

Conversation

luomaoling
Copy link

@luomaoling luomaoling commented Mar 17, 2023

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

Added ascending device support in mmseg.

Modification

The main modification points are as follows:
We added an NPU device in the DDP scenario and DP scenario when using the NPU.

BC-breaking (Optional)

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

Use cases (Optional)

We tested fcn_unet_s5-d16_4x4_512x1024_160k_cityscapes.py .

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 MMDet3D.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@CLAassistant
Copy link

CLAassistant commented Mar 17, 2023

CLA assistant check
All committers have signed the CLA.

@luomaoling luomaoling changed the title [Feature] Support mmcls with NPU backend. [Feature] Support mmseg with NPU backend. Mar 17, 2023
@xiexinch
Copy link
Collaborator

Hi @luomaoling,
Thanks for your contribution! Please sign the CLA.

@codecov
Copy link

codecov bot commented Mar 22, 2023

Codecov Report

Patch coverage: 13.63% and project coverage change: -0.17 ⚠️

Comparison is base (d6079bc) 88.36% compared to head (39a4d97) 88.20%.

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

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2768      +/-   ##
==========================================
- Coverage   88.36%   88.20%   -0.17%     
==========================================
  Files         149      149              
  Lines        9109     9128      +19     
  Branches     1523     1527       +4     
==========================================
+ Hits         8049     8051       +2     
- Misses        810      826      +16     
- Partials      250      251       +1     
Flag Coverage Δ
unittests 88.20% <13.63%> (-0.17%) ⬇️

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

Impacted Files Coverage Δ
mmseg/apis/train.py 18.39% <0.00%> (-1.13%) ⬇️
mmseg/utils/util_distribution.py 37.77% <18.75%> (-10.61%) ⬇️

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.

@@ -33,6 +33,14 @@ def build_dp(model, device='cuda', dim=0, *args, **kwargs):
dp_factory['mlu'] = MLUDataParallel
model = model.mlu()

if device == 'npu':
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might add the elif statement to the code above

Copy link
Author

Choose a reason for hiding this comment

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

I've revised it, thanks

@@ -53,7 +61,8 @@ def build_ddp(model, device='cuda', *args, **kwargs):
.. [1] https://pytorch.org/docs/stable/generated/torch.nn.parallel.
DistributedDataParallel.html
"""
assert device in ['cuda', 'mlu'], 'Only available for cuda or mlu devices.'
assert device in ['cuda', 'mlu', 'npu'], 'Only available for cuda '\
'or mlu devices.'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might add npu to the error msg.

Copy link
Author

Choose a reason for hiding this comment

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

I've revised it, thanks

@@ -63,6 +72,14 @@ def build_ddp(model, device='cuda', *args, **kwargs):
ddp_factory['mlu'] = MLUDistributedDataParallel
model = model.mlu()

if device == 'npu':
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might use elif statement.

Copy link
Author

Choose a reason for hiding this comment

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

I've revised it, thanks

tools/test.py Outdated
Comment on lines 265 to 267
optimiter_config = dict(type='Fp16OptimizerHook', loss_scale='dynamic')
cfg.optimizer_config = optimiter_config if \
not cfg.optimizer_config else cfg.optimizer_config
Copy link
Collaborator

Choose a reason for hiding this comment

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

when model testing, there is no runner and no hooks

Copy link
Author

Choose a reason for hiding this comment

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

I've revised it, thanks!

@MeowZheng MeowZheng merged commit ae78cb9 into open-mmlab:master Mar 23, 2023
shireen1512 added a commit to shireen1512/mmsegmentation that referenced this pull request Apr 7, 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.

None yet

5 participants