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

RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu) #41

Open
Chris004869 opened this issue Jul 24, 2024 · 5 comments

Comments

@Chris004869
Copy link

Hi,

I encountered an issue when running the following command:
python train.py -s $gs_data_path/m4c_processed -m output/m4c_processed --train_stage 1
The error message is:
RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)
Could someone please help me understand what might be causing this error? My level of expertise is somewhat limited, and I’m not quite sure how to resolve this issue. Any guidance would be greatly appreciated.

Thank you!

@Suanfacayou
Copy link

Hello,

Modify the last line of error code and move all related variables to run on the GPU (using the statement tensor=tensor. to ('cpu '), if unsure, you can move all variables in the last error code to run on the GPU using this statement.)
I forgot the specific question, and if it's convenient, you can upload the entire error message.

Hope to help you.

@Chris004869
Copy link
Author

Hello,

Modify the last line of error code and move all related variables to run on the GPU (using the statement tensor=tensor. to ('cpu '), if unsure, you can move all variables in the last error code to run on the GPU using this statement.) I forgot the specific question, and if it's convenient, you can upload the entire error message.

Hope to help you.

Hello,

Thank you for your help. Here is the complete error message I encountered:
Optimizing output/m4c_processed
Output folder: output/m4c_processed [25/07 06:33:29]
loading smpl data /data_share/gaoyuan/GaussianAvatar/gs_data/data/m4c_processed/train/smpl_parms.pth [25/07 06:33:29]
total pose length 110 [25/07 06:33:29]
Traceback (most recent call last):
File "/data_share/gaoyuan/GaussianAvatar/train.py", line 179, in
train(lp.extract(args), np.extract(args), op.extract(args), args.save_epochs, args.checkpoint_epochs)
File "/data_share/gaoyuan/GaussianAvatar/train.py", line 24, in train
avatarmodel = AvatarModel(model, net, opt, train=True)
File "/data_share/gaoyuan/GaussianAvatar/model/avatar_model.py", line 76, in init
query_points = query_map[valid_idx, :].cuda().contiguous()
RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)
I appreciate your assistance.

@Suanfacayou
Copy link

Hello,

I think just modify the last line of your error message.
Change
“'query_points = query_map[valid_idx, :].cuda().contiguous()'”
to
“‘query_map = torch.from_numpy(np.load(query_map_path)['posmap' + str(self.model_parms.query_posmap_size)]).reshape(-1,3)
query_map = query_map.to('cuda')
query_points = query_map[valid_idx, :].contiguous()’”
You just need to compare your code and add the missing parts.

Hoping This Helps

@suzoosuagr
Copy link

The valid_idx was load as GPU tensor at previous step. At the error point, query_map is a cpu tensor. To fix it. You can modified to

query_points = query_map[valid_idx.cpu(), :].cuda().contiguous()

Good Luck

@nagexiaochengzi
Copy link

Thank you for your excellent work, but I have a new question:
Traceback (most recent call last):
File "/home/jkx/projects/mjz/GaussianAvatar/train.py", line 179, in
train(lp.extract(args), np.extract(args), op.extract(args), args.save_epochs, args.checkpoint_epochs)
File "/home/jkx/projects/mjz/GaussianAvatar/train.py", line 24, in train
avatarmodel = AvatarModel(model, net, opt, train=True)
File "/home/jkx/projects/mjz/GaussianAvatar/model/avatar_model.py", line 90, in init
self.query_lbs = query_lbs[valid_idx, :][None].expand(self.batch_size, -1, -1).cuda().contiguous()
RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)

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

No branches or pull requests

4 participants