PINA icon indicating copy to clipboard operation
PINA copied to clipboard

.cpu() method for LabelTensor

Open luAndre00 opened this issue 1 year ago • 2 comments

When I perform some computations with LabelTensor I may obtain another LabelTensor without labels, and I found that, if I use .cpu() it does not work because at some points it needs to take out the labels and it finds none of them. While if I give any name to that LabelTensor, it works with no problems.

Maybe there could be a way of avoiding this error?

luAndre00 avatar Jul 30 '24 22:07 luAndre00

Hi! Can you provide extra context with a snippet of code? I experimented locally and I did not see any issue with labels

>>> from pina import LabelTensor
>>> import torch
>>> 
>>> x_cpu = LabelTensor(torch.rand(3,1), ['x'])
>>> print(x_cpu.labels, x_cpu.device)
['x'] cpu
>>> 
>>> x_gpu = x_cpu.to('mps')  # should be the same with .cuda() if you have torch compiled with cuda 
>>> print(x_gpu.labels, x_gpu.device)
['x'] mps:0
>>> 
>>> x_cpu_back = x_gpu.cpu()
>>> print(x_cpu_back.labels, x_cpu_back.device)
['x'] cpu

dario-coscia avatar Aug 06 '24 10:08 dario-coscia

Hi @luAndre00 ! Do you still face the issue?

dario-coscia avatar Sep 03 '24 14:09 dario-coscia