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

[Fix] Fix the device mismatch error when torch version<1.11 #2308

Merged
merged 1 commit into from
Feb 28, 2023

Conversation

Ginray
Copy link
Contributor

@Ginray Ginray commented Feb 27, 2023

Motivation

When the torch version<1.11, an error will be reported when executing the centerpoint model:
The error message is:
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!

This happens at centerpoint_head.py line542, due to center_int is saved on cuda, but feature_map_size is saved on the CPU.

if not (0 <= center_int[0] < feature_map_size[0]
        and 0 <= center_int[1] < feature_map_size[1]):
    continue

A more intuitive example:

>>> import torch
>>> torch.__version__
'1.8.0'
>>> a = torch.tensor([1])
>>> b = torch.tensor([2]).to('cuda')
>>> a<b
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!

Modification

Make center_int and feature_map_size saved on the same device to avoid errors in the lower version of the torch.

BC-breaking (Optional)

Not involved

Use cases (Optional)

Not involved

@Ginray Ginray force-pushed the centerpoint-bugfix branch from 3d0d78a to d5b207b Compare February 27, 2023 09:34
@Ginray Ginray changed the base branch from dev to dev-1.x February 27, 2023 09:34
@Ginray Ginray force-pushed the centerpoint-bugfix branch from d5b207b to 52f9205 Compare February 27, 2023 11:44
@sunjiahao1999 sunjiahao1999 self-requested a review February 28, 2023 06:26
@codecov
Copy link

codecov bot commented Feb 28, 2023

Codecov Report

Base: 46.37% // Head: 46.96% // Increases project coverage by +0.59% 🎉

Coverage data is based on head (7f11980) compared to base (d84e081).
Patch coverage: 66.37% of modified lines in pull request are covered.

❗ Current head 7f11980 differs from pull request most recent head 52f9205. Consider uploading reports for the commit 52f9205 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           dev-1.x    #2308      +/-   ##
===========================================
+ Coverage    46.37%   46.96%   +0.59%     
===========================================
  Files          259      262       +3     
  Lines        21390    21964     +574     
  Branches      3379     3460      +81     
===========================================
+ Hits          9919    10315     +396     
- Misses       10827    10987     +160     
- Partials       644      662      +18     
Flag Coverage Δ
unittests 46.96% <66.37%> (+0.59%) ⬆️

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

Impacted Files Coverage Δ
mmdet3d/datasets/transforms/__init__.py 100.00% <ø> (ø)
mmdet3d/evaluation/__init__.py 100.00% <ø> (ø)
mmdet3d/models/dense_heads/centerpoint_head.py 21.77% <0.00%> (ø)
mmdet3d/models/dense_heads/fcaf3d_head.py 16.23% <ø> (ø)
mmdet3d/models/detectors/mink_single_stage.py 43.58% <ø> (ø)
mmdet3d/testing/data_utils.py 70.83% <ø> (ø)
mmdet3d/models/voxel_encoders/voxel_encoder.py 38.46% <6.94%> (-12.08%) ⬇️
...t3d/models/data_preprocessors/data_preprocessor.py 39.10% <17.24%> (-5.05%) ⬇️
mmdet3d/datasets/transforms/formating.py 58.03% <33.33%> (+1.78%) ⬆️
mmdet3d/models/data_preprocessors/voxelize.py 33.92% <33.92%> (ø)
... and 28 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.

@ZwwWayne ZwwWayne merged commit 6250b2c into open-mmlab:dev-1.x Feb 28, 2023
xizaoqu pushed a commit to xizaoqu/mmdetection3d that referenced this pull request Mar 15, 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.

3 participants