MCPcopy
hub / github.com/THUDM/LongWriter / rotate_half

Function rotate_half

train/patch/modeling_llama.py:198–202  ·  view source on GitHub ↗

Rotates half the hidden dims of the input.

(x)

Source from the content-addressed store, hash-verified

196
197
198def rotate_half(x):
199 """Rotates half the hidden dims of the input."""
200 x1 = x[..., : x.shape[-1] // 2]
201 x2 = x[..., x.shape[-1] // 2 :]
202 return torch.cat((-x2, x1), dim=-1)
203
204
205def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):

Callers 1

apply_rotary_pos_embFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected