We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent be73dbb commit 021552fCopy full SHA for 021552f
invokeai/backend/flux/math.py
@@ -24,12 +24,12 @@ def rope(pos: Tensor, dim: int, theta: int) -> Tensor:
24
out = torch.einsum("...n,d->...nd", pos, omega)
25
out = torch.stack([torch.cos(out), -torch.sin(out), torch.sin(out), torch.cos(out)], dim=-1)
26
out = rearrange(out, "b n d (i j) -> b n d i j", i=2, j=2)
27
- return out.float()
+ return out.to(dtype=pos.dtype, device=pos.device)
28
29
30
def apply_rope(xq: Tensor, xk: Tensor, freqs_cis: Tensor) -> tuple[Tensor, Tensor]:
31
xq_ = xq.view(*xq.shape[:-1], -1, 1, 2)
32
xk_ = xk.view(*xk.shape[:-1], -1, 1, 2)
33
xq_out = freqs_cis[..., 0] * xq_[..., 0] + freqs_cis[..., 1] * xq_[..., 1]
34
xk_out = freqs_cis[..., 0] * xk_[..., 0] + freqs_cis[..., 1] * xk_[..., 1]
35
- return xq_out.view(*xq.shape).type_as(xq), xk_out.view(*xk.shape).type_as(xk)
+ return xq_out.view(*xq.shape), xk_out.view(*xk.shape)
0 commit comments