(tokens, pos, cos, sin)
| 1268 | def apply_rotary_emb_allegro(x: torch.Tensor, freqs_cis, positions): |
| 1269 | # TODO(aryan): rewrite |
| 1270 | def apply_1d_rope(tokens, pos, cos, sin): |
| 1271 | cos = F.embedding(pos, cos)[:, None, :, :] |
| 1272 | sin = F.embedding(pos, sin)[:, None, :, :] |
| 1273 | x1, x2 = tokens[..., : tokens.shape[-1] // 2], tokens[..., tokens.shape[-1] // 2 :] |
| 1274 | tokens_rotated = torch.cat((-x2, x1), dim=-1) |
| 1275 | return (tokens.float() * cos + tokens_rotated.float() * sin).to(tokens.dtype) |
| 1276 | |
| 1277 | (t_cos, t_sin), (h_cos, h_sin), (w_cos, w_sin) = freqs_cis |
| 1278 | t, h, w = x.chunk(3, dim=-1) |
no test coverage detected