So I have a big list of cuda tensors containing loss values of each iteration but I can’t even scatter plot it. How can I convert it to a list of cpu tensors or even numpy array without iterating over the indices? Thank You!
Hi,
In this post I have written a code to transfer a list of CPU tensors to GPU which all have the same shape (in your case all have shape of (1, )
).
Bests
Thank you so much @Nikronic .
Just creating a new tensor with torch.tensor() worked. Then simply plotted the scatter plot on torch tensor (with device = cpu).
new_tensor = torch.tensor(list_of_cuda_tensors, device = 'cpu')
But, what if you want to keep it as a list of tensors after the transfer from gpu to cpu
Thanks! This helped me with my code which ran on cpu but running a plot in gpu.
In a context where performance is a concern, you’d be better off stacking the scalar tensors first then moving to cpu: torch.stack(list_of_losses).cpu()
. Otherwise [t.item() for t in list_of_losses]
seems more idiomatic to me if you want the result as a list of floats.