Hi Muppet!



 Muppet:

rewards = torch.as_tensor(rewards).to(self.device).float()

vs
rewards = torch.as_tensor(rewards).float().to(self.device)



Speaking as a non-expert, I would think that
rewards = torch.as_tensor (rewards, dtype = torch.float, device = torch.device('cuda'))

would be the way to go.  I believe that pytorch will “no-op” any
unneeded casts.
Note, if rewards starts out as, for example, a numpy double array
(and self.device is the gpu), I think converting to float first, and
then moving it to the gpu would win, because bandwidth to the gpu
is a bottleneck, and moving the float would only involve half as
much data as moving the double.


does PyTorch know it’s already float and will not do the cast? Or does that result in a significant overhead that should be avoided?


I’m pretty sure that pytorch knows enough to skip redundant casts.
(May the experts correct me if I’m wrong.)
Best.
K. Frank