Skip to main content

apply_llama_rope

Function apply_llama_rope 

Source
pub fn apply_llama_rope(
    x: Tensor<4>,
    cos_table: Tensor<2>,
    sin_table: Tensor<2>,
    start_pos: usize,
) -> Tensor<4>
Expand description

Llama-style rotary embedding apply on [b, heads, seq, head_dim] with prebuilt [max_seq, head_dim] cos/sin tables (positions start..).

rotate_half(x) = cat([-x[half:], x[:half]]); out = x*cos + rot*sin. Shared by Chronos, Sundial, Toto (all use this exact form).