Skip to content

Commit

Permalink
Requires for torch.tensor before casting (#31755)
Browse files Browse the repository at this point in the history
  • Loading branch information
echarlaix authored and ArthurZucker committed Jul 11, 2024
1 parent b7ee1e8 commit 0be998b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/transformers/utils/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ def torch_int(x):

import torch

return x.to(torch.int64) if torch.jit.is_tracing() else int(x)
return x.to(torch.int64) if torch.jit.is_tracing() and isinstance(x, torch.Tensor) else int(x)


def torch_float(x):
Expand All @@ -774,7 +774,7 @@ def torch_float(x):

import torch

return x.to(torch.float32) if torch.jit.is_tracing() else int(x)
return x.to(torch.float32) if torch.jit.is_tracing() and isinstance(x, torch.Tensor) else int(x)


def filter_out_non_signature_kwargs(extra: Optional[list] = None):
Expand Down

0 comments on commit 0be998b

Please sign in to comment.