Skip to content

Commit

Permalink
only ipu cos sin in fp16
Browse files Browse the repository at this point in the history
  • Loading branch information
danjust committed Oct 20, 2023
1 parent dc77144 commit 40437d0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion besskge/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def complex_rotation(v: torch.Tensor, r: torch.Tensor) -> torch.Tensor:
Row-wise rotated tensors.
"""
# Always compute sin and cos in fp16, as faster on IPU
if r.dtype == torch.float32:
if r.dtype == torch.float32 and r.device.type == "ipu":
r_cos = torch.cos(r.to(dtype=torch.float16)).to(dtype=torch.float32)
r_sin = torch.sin(r.to(dtype=torch.float16)).to(dtype=torch.float32)
else:
Expand Down

0 comments on commit 40437d0

Please sign in to comment.