nemo_automodel.components.models.gpt_oss.rope_utils
nemo_automodel.components.models.gpt_oss.rope_utils
Module Contents
Classes
Functions
Data
API
Bases: Module
See YaRN paper: https://arxiv.org/abs/2309.00071
Uses rotary_dim instead of head_dim to support partial rotary embeddings.
Rotate query/key together, sharing their dtype-rounded tables.
Parameters:
Tensor of shape […, query_heads, head_dim], with arbitrary leading dimensions and strides.
Tensor of shape […, key_heads, head_dim], sharing the leading
dimensions of q and accepting arbitrary strides.
Tensor of shape […, rotary_dim], with leading dimensions
broadcastable to q and k. The last dimension concatenates
cosine and sine tables; rotary_dim is even and at most
head_dim.
Returns: torch.Tensor
Independently allocated rotated query and key tensors, preserving
Apply rotary embeddings to input tensor.
If cos/sin have fewer dimensions than x (due to partial_rotary_factor < 1.0), only the first rotary_dim dimensions of x are rotated, and the rest are passed through.
Parameters:
Input tensor (…, head_dim)
Cosine tensor (…, rotary_dim // 2)
Sine tensor (…, rotary_dim // 2)
Apply rotary embeddings to query and key tensors.
Parameters:
Query tensor of shape [batch, sequence, query_heads, head_dim] for BSHD or [tokens, query_heads, head_dim] for packed THD. Leading dimensions contain the local context-parallel shard, if used.
Key tensor with the same layout as q, with key_heads in
place of query_heads. Arbitrary strides are supported.
For non-fused RoPE, tensor of shape [batch, sequence,
rotary_dim] or [tokens, rotary_dim], containing concatenated
cosine/sine tables with concentration applied. Leading dimensions
broadcast to the local tokens in q and k. For TE fused
RoPE, tensor of shape [sequence, 1, 1, rotary_dim] containing
duplicated angles for the global sequence. rotary_dim is even
and at most head_dim.
QKV format (“bshd” or “thd”).
If True, use TE fused rope. If False, use non-fused rope.
Optional tensor of shape [num_sequences + 1] containing cumulative sequence lengths for variable-length TE fused RoPE.
Optional scale applied after TE fused RoPE.
Context parallelism size.
Context parallelism rank.
Returns: torch.Tensor
Tuple of rotated query and key tensors, preserving their respective