Skip to content

Commit

Permalink
Fix support for bf16 in to_numpy
Browse files Browse the repository at this point in the history
  • Loading branch information
BloodAxe committed Oct 14, 2024
1 parent 5b65fa1 commit fcae22a
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pytorch_toolbelt/utils/torch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ def to_numpy(x: Union[torch.Tensor, np.ndarray, Any, None]) -> Union[np.ndarray,
"""
if x is None:
return None
elif torch.is_tensor(x) and x.dtype == torch.bfloat16:
return x.data.float().cpu().numpy()
elif torch.is_tensor(x):
return x.data.cpu().numpy()
elif isinstance(x, np.ndarray):
Expand Down

0 comments on commit fcae22a

Please sign in to comment.