Skip to content

Commit

Permalink
Requires for torch.tensor before casting
Browse files Browse the repository at this point in the history
  • Loading branch information
echarlaix committed Jul 2, 2024
1 parent 82486e5 commit 9268d6b
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 9268d6b

Please sign in to comment.