Skip to content

Commit

Permalink
Convert tensor to dtype before moving to device instead of after
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzhaoze authored Jan 26, 2025
1 parent f94437a commit 0a79016
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tianshou/data/utils/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ def to_torch(
x.dtype.type,
np.bool_ | np.number,
): # most often case
x = torch.from_numpy(x).to(device)
x = torch.from_numpy(x)
if dtype is not None:
x = x.type(dtype)
return x
return x.to(device)
if isinstance(x, torch.Tensor): # second often case
if dtype is not None:
x = x.type(dtype)
Expand Down

0 comments on commit 0a79016

Please sign in to comment.