monniert / differentiable-blocksworld

[NeurIPS 2023] Code for "Differentiable Blocks World: Qualitative 3D Decomposition by Rendering Primitives"
https://www.tmonnier.com/DBW
MIT License
197 stars 10 forks source link

Cpu and Cuda device mismatch error #2

Closed louhz closed 1 year ago

louhz commented 1 year ago

So in the line 422 in dbw.py I notice that you define a val_blocks which is on cpu and the self.get_opacities() is on the gpu so there will be a error raised My personal solution is to revise the line 422 from val_blocks = torch.linspace(0, 1, self.n_blocks + 1)[1:] to val_blocks = torch.linspace(0, 1, self.n_blocks + 1)[1:].to(self.bkg.device)

and line 429 from values = torch.cat([torch.zeros(NFE) , val_blocks.repeat_interleave(self.BNF)])

to values = torch.cat([torch.zeros(NFE).to(self.bkg.device) , val_blocks.repeat_interleave(self.BNF)])

and the problem is solved

i am not sure whether this is a common issue or just happened on my device so just remark it here.

monniert commented 1 year ago

Hi louhz, what is your pytorch version? I have never encountered the issue so it may be linked with a new pytorch behavior related to indexing

Anyway I will fix it tomorrow, thanks for the feedback and solution!

louhz commented 1 year ago

Hi louhz, what is your pytorch version? I have never encountered the issue so it may be linked with a new pytorch behavior related to indexing

Anyway I will fix it tomorrow, thanks for the feedback and solution!

I am using pytorch1.13+cuda 11.7,which is the environment i used for nerfstudio 0.3.1

monniert commented 1 year ago

Got it thanks, it is indeed a new feature implemented in pytorch 1.13 as explained below (screenshot from this release note)

screenshot