Skip to content

[Fix] Replace hardcoded .cuda() with device-aware .to() in MinkUNet voxelization#3140

Open
Mr-Neutr0n wants to merge 1 commit intoopen-mmlab:mainfrom
Mr-Neutr0n:fix/hardcoded-cuda-device-in-voxelization
Open

[Fix] Replace hardcoded .cuda() with device-aware .to() in MinkUNet voxelization#3140
Mr-Neutr0n wants to merge 1 commit intoopen-mmlab:mainfrom
Mr-Neutr0n:fix/hardcoded-cuda-device-in-voxelization

Conversation

@Mr-Neutr0n
Copy link

Motivation

In Det3DDataPreprocessor.voxelize(), the minkunet voxelization branch converts numpy arrays back to tensors using torch.from_numpy(...).cuda(). This hardcodes the CUDA device assumption, which causes:

  1. RuntimeError on CPU-only environments — users without a GPU cannot use MinkUNet-based models at all
  2. Incorrect device placement in multi-GPU setups — tensors always land on cuda:0 regardless of which device the input data resides on (e.g., cuda:1), leading to device mismatch errors during subsequent operations

Modification

Replace .cuda() with .to(res.device) for both point2voxel_map and inds tensors, where res is 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() and F.pad() which inherit the device from existing tensors).

Before:

point2voxel_map = torch.from_numpy(point2voxel_map).cuda()
...
inds = torch.from_numpy(inds).cuda()

After:

point2voxel_map = torch.from_numpy(point2voxel_map).to(res.device)
...
inds = torch.from_numpy(inds).to(res.device)

BC-breaking (No)

This is a backward-compatible fix. On CUDA environments, res.device will be cuda:X (matching the previous behavior when on cuda:0), and it additionally supports CPU and multi-GPU scenarios correctly.

…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.
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@Mr-Neutr0n
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

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.

2 participants