MCPcopy Create free account
hub / github.com/UVA-Computer-Vision-Lab/FrameINO / apply_1d_rope

Function apply_1d_rope

architecture/embeddings.py:1270–1275  ·  view source on GitHub ↗
(tokens, pos, cos, sin)

Source from the content-addressed store, hash-verified

1268def 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)

Callers 1

apply_rotary_emb_allegroFunction · 0.85

Calls 1

toMethod · 0.45

Tested by

no test coverage detected