# transformers 5.24.1 (Apache-2.0), harvested by tools/harvest_corpus.py
=== input

    Applies interleaved Rotary Position Embedding to the query and key tensors.

    DeepSeek lays the rotary dimensions out in interleaved pairs `(x0, x1), (x2, x3), ...`, each rotated by a
    single frequency. We compute that rotation directly on the even/odd slices instead of de-interleaving with a
    `view`/`transpose`/`reshape`; the output is bit-identical to the de-interleaved `rotate_half` formulation while
    avoiding the extra contiguous copy.

    Args:
        q (`torch.Tensor`): The query tensor.
        k (`torch.Tensor`): The key tensor.
        cos (`torch.Tensor`): The cosine part of the rotary embedding.
        sin (`torch.Tensor`): The sine part of the rotary embedding.
        position_ids (`torch.Tensor`):
            The position indices of the tokens corresponding to the query and key tensors. For example, this can be
            used to pass offsetted position ids when working with a KV-cache.
        unsqueeze_dim (`int`, *optional*, defaults to 1):
            The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
            sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
            that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
            k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
            cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
            the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
    Returns:
        `tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
    
=== parse google
short_description: 'Applies interleaved Rotary Position Embedding to the query and key tensors.'
long_description: |
  DeepSeek lays the rotary dimensions out in interleaved pairs `(x0, x1), (x2, x3), ...`, each rotated by a
  single frequency. We compute that rotation directly on the even/odd slices instead of de-interleaving with a
  `view`/`transpose`/`reshape`; the output is bit-identical to the de-interleaved `rotate_half` formulation while
  avoiding the extra contiguous copy.
blank_after_short_description: True
blank_after_long_description: True
style: google
- DocstringParam
  description: 'The query tensor.'
  kind: param
  key: 'param'
  arg_name: 'q'
  type_name: '`torch.Tensor`'
  is_optional: False
- DocstringParam
  description: 'The key tensor.'
  kind: param
  key: 'param'
  arg_name: 'k'
  type_name: '`torch.Tensor`'
  is_optional: False
- DocstringParam
  description: 'The cosine part of the rotary embedding.'
  kind: param
  key: 'param'
  arg_name: 'cos'
  type_name: '`torch.Tensor`'
  is_optional: False
- DocstringParam
  description: 'The sine part of the rotary embedding.'
  kind: param
  key: 'param'
  arg_name: 'sin'
  type_name: '`torch.Tensor`'
  is_optional: False
- DocstringParam
  description: |
    The position indices of the tokens corresponding to the query and key tensors. For example, this can be
    used to pass offsetted position ids when working with a KV-cache.
  kind: param
  key: 'param'
  arg_name: 'position_ids'
  type_name: '`torch.Tensor`'
  is_optional: False
- DocstringParam
  description: |
    The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
    sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
    that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
    k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
    cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
    the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
  kind: param
  key: 'param'
  arg_name: 'unsqueeze_dim'
  type_name: '`int`'
  is_optional: True
  default: '1'
  raw_type_name: '`int`, *optional*, defaults to 1'
- DocstringReturns
  description: '`tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.'
  kind: returns
  key: 'returns'
  is_generator: False
=== detect
google
=== compose google
Applies interleaved Rotary Position Embedding to the query and key tensors.

DeepSeek lays the rotary dimensions out in interleaved pairs `(x0, x1), (x2, x3), ...`, each rotated by a
single frequency. We compute that rotation directly on the even/odd slices instead of de-interleaving with a
`view`/`transpose`/`reshape`; the output is bit-identical to the de-interleaved `rotate_half` formulation while
avoiding the extra contiguous copy.

Args:
    q (`torch.Tensor`): The query tensor.
    k (`torch.Tensor`): The key tensor.
    cos (`torch.Tensor`): The cosine part of the rotary embedding.
    sin (`torch.Tensor`): The sine part of the rotary embedding.
    position_ids (`torch.Tensor`): The position indices of the tokens corresponding to the query and key tensors. For example, this can be
        used to pass offsetted position ids when working with a KV-cache.
    unsqueeze_dim (`int`, *optional*, defaults to 1): The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
        sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
        that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
        k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
        cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
        the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.

Returns:
    `tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
