MCPcopy Create free account
hub / github.com/Pints-AI/1.5-Pints / apply_rope

Function apply_rope

lit_gpt/model.py:469–475  ·  view source on GitHub ↗
(x: torch.Tensor, cos: torch.Tensor, sin: torch.Tensor)

Source from the content-addressed store, hash-verified

467
468
469def apply_rope(x: torch.Tensor, cos: torch.Tensor, sin: torch.Tensor) -> torch.Tensor:
470 head_size = x.size(-1)
471 x1 = x[..., : head_size // 2] # (B, nh, T, hs/2)
472 x2 = x[..., head_size // 2 :] # (B, nh, T, hs/2)
473 rotated = torch.cat((-x2, x1), dim=-1) # (B, nh, T, hs)
474 roped = (x * cos) + (rotated * sin)
475 return roped.type_as(x)

Callers 2

forwardMethod · 0.90
forwardMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected