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

[Refactor] Handle case where device is neither CPU nor CUDA in HamHead #2868

Merged
merged 1 commit into from
Apr 14, 2023

Conversation

KKIEEK
Copy link
Contributor

@KKIEEK KKIEEK commented Apr 7, 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

Traceback (most recent call last):
  File "/Users/kkieek/Workspace/mmsegmentation/tools/train.py", line 104, in <module>
    main()
  File "/Users/kkieek/Workspace/mmsegmentation/tools/train.py", line 100, in main
    runner.train()
  File "/Users/kkieek/Workspace/mmsegmentation/.env/lib/python3.9/site-packages/mmengine/runner/runner.py", line 1686, in train
    model = self.train_loop.run()  # type: ignore
  File "/Users/kkieek/Workspace/mmsegmentation/.env/lib/python3.9/site-packages/mmengine/runner/loops.py", line 264, in run
    self.run_iter(data_batch)
  File "/Users/kkieek/Workspace/mmsegmentation/.env/lib/python3.9/site-packages/mmengine/runner/loops.py", line 287, in run_iter
    outputs = self.runner.model.train_step(
  File "/Users/kkieek/Workspace/mmsegmentation/.env/lib/python3.9/site-packages/mmengine/model/base_model/base_model.py", line 114, in train_step
    losses = self._run_forward(data, mode='loss')  # type: ignore
  File "/Users/kkieek/Workspace/mmsegmentation/.env/lib/python3.9/site-packages/mmengine/model/base_model/base_model.py", line 326, in _run_forward
    results = self(**data, mode=mode)
  File "/Users/kkieek/Workspace/mmsegmentation/.env/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/Users/kkieek/Workspace/mmsegmentation/mmseg/models/segmentors/base.py", line 94, in forward
    return self.loss(inputs, data_samples)
  File "/Users/kkieek/Workspace/mmsegmentation/mmseg/models/segmentors/encoder_decoder.py", line 176, in loss
    loss_decode = self._decode_head_forward_train(x, data_samples)
  File "/Users/kkieek/Workspace/mmsegmentation/mmseg/models/segmentors/encoder_decoder.py", line 137, in _decode_head_forward_train
    loss_decode = self.decode_head.loss(inputs, data_samples,
  File "/Users/kkieek/Workspace/mmsegmentation/mmseg/models/decode_heads/decode_head.py", line 261, in loss
    seg_logits = self.forward(inputs)
  File "/Users/kkieek/Workspace/mmsegmentation/mmseg/models/decode_heads/ham_head.py", line 252, in forward
    x = self.hamburger(x)
  File "/Users/kkieek/Workspace/mmsegmentation/.env/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/Users/kkieek/Workspace/mmsegmentation/mmseg/models/decode_heads/ham_head.py", line 188, in forward
    enjoy = self.ham(enjoy)
  File "/Users/kkieek/Workspace/mmsegmentation/.env/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/Users/kkieek/Workspace/mmsegmentation/mmseg/models/decode_heads/ham_head.py", line 94, in forward
    bases, coef = self.local_inference(x, bases)
  File "/Users/kkieek/Workspace/mmsegmentation/mmseg/models/decode_heads/ham_head.py", line 63, in local_inference
    coef = torch.bmm(x.transpose(1, 2), bases)
RuntimeError: Placeholder storage has not been allocated on MPS device!

Modification

I modified the logic to assign tensor to a specific device.
However, training is not supported in MPS due to GN backward, so this PR only has meaning for inference.

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.

Use cases (Optional)

If this PR introduces a new feature, it is better to list some use cases here, and update the documentation.

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.

@codecov
Copy link

codecov bot commented Apr 7, 2023

Codecov Report

Patch coverage: 62.50% and project coverage change: +0.01 🎉

Comparison is base (892f9e1) 83.66% compared to head (177b63c) 83.67%.

❗ Current head 177b63c differs from pull request most recent head faad3c2. Consider uploading reports for the commit faad3c2 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           dev-1.x    #2868      +/-   ##
===========================================
+ Coverage    83.66%   83.67%   +0.01%     
===========================================
  Files          156      156              
  Lines         9355     9355              
  Branches      1373     1373              
===========================================
+ Hits          7827     7828       +1     
+ Misses        1283     1282       -1     
  Partials       245      245              
Flag Coverage Δ
unittests 83.67% <62.50%> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
mmseg/models/decode_heads/ham_head.py 89.89% <62.50%> (ø)

... and 1 file with indirect coverage changes

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.

@xiexinch xiexinch merged commit ced29fc into open-mmlab:dev-1.x Apr 14, 2023
@KKIEEK KKIEEK deleted the refact/ham_device branch April 15, 2023 14:10
nahidnazifi87 pushed a commit to nahidnazifi87/mmsegmentation_playground that referenced this pull request Apr 5, 2024
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.

3 participants