[Fix] Replace hardcoded .cuda() with device-aware .to() in MinkUNet voxelization#3140
Open
Mr-Neutr0n wants to merge 1 commit intoopen-mmlab:mainfrom
Open
Conversation
…oxelization In Det3DDataPreprocessor.voxelize(), the minkunet branch converts numpy arrays back to tensors using torch.from_numpy(...).cuda(), which hardcodes the CUDA device. This causes failures when running on CPU-only environments or when the input data resides on a specific device (e.g., cuda:1). Replace .cuda() with .to(res.device) to correctly place tensors on the same device as the input point cloud.
|
|
Author
|
I have read the CLA Document and I hereby sign the CLA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
In
Det3DDataPreprocessor.voxelize(), theminkunetvoxelization branch converts numpy arrays back to tensors usingtorch.from_numpy(...).cuda(). This hardcodes the CUDA device assumption, which causes:cuda:0regardless of which device the input data resides on (e.g.,cuda:1), leading to device mismatch errors during subsequent operationsModification
Replace
.cuda()with.to(res.device)for bothpoint2voxel_mapandindstensors, whereresis the input point cloud tensor already on the correct device. This is consistent with how device handling is done elsewhere in the same file (e.g., using.new_tensor()andF.pad()which inherit the device from existing tensors).Before:
After:
BC-breaking (No)
This is a backward-compatible fix. On CUDA environments,
res.devicewill becuda:X(matching the previous behavior when oncuda:0), and it additionally supports CPU and multi-GPU scenarios correctly.