MCPcopy Create free account
hub / github.com/OpenSparseLLMs/Linear-MoE / rotate_half

Function rotate_half

linear_moe/model/common_modules/rotary.py:13–19  ·  view source on GitHub ↗
(x, interleaved=False)

Source from the content-addressed store, hash-verified

11
12
13def rotate_half(x, interleaved=False):
14 if not interleaved:
15 x1, x2 = x.chunk(2, dim=-1)
16 return torch.cat((-x2, x1), dim=-1)
17 else:
18 x1, x2 = x[..., ::2], x[..., 1::2]
19 return rearrange(torch.stack((-x2, x1), dim=-1), "... d two -> ... (d two)", two=2)
20
21
22def apply_rotary_emb_torch(x, cos, sin, interleaved=False):

Callers 1

apply_rotary_emb_torchFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected