nemo_automodel.components.models.deepseek_v3.rope_utils
nemo_automodel.components.models.deepseek_v3.rope_utils
Module Contents
Functions
API
Applies rotary positional embeddings to the input tensor.
Parameters:
Input tensor with positional embeddings to be applied.
Precomputed complex exponential values for positional embeddings.
Returns: torch.Tensor
torch.Tensor: Tensor with rotary embeddings applied.
Apply half-split (rotate_half) rotary embeddings using the complex freqs_cis table.
The DeepSeek-V3.2 DSA indexer rotates its rope slice with the non-interleaved layout
(pair dim j with j + d/2), unlike the main MLA attention which pairs adjacent
dims (apply_rotary_emb). freqs_cis is the same complex table used by the MLA
(exp(i * theta_j * pos) for j in [0, d/2)); its real/imag parts are the cos/sin
for frequency j, so the rotation angles match the interleaved path exactly.
Compute the rotation in FP32, as in the official DeepSeek implementation and
vLLM’s CUDA indexer RoPE, then cast the result back to the input dtype.
Parameters:
Rope slice, [B, S, H, d] / [B, S, d] (bshd) or [T, H, d] / [T, d] (thd).
Complex RoPE table with trailing dim d/2 ([B, S, d/2] or [T, d/2]).
"bshd" or "thd".
Returns: torch.Tensor
Rotated tensor with the same shape and dtype as x.
Precomputes frequency-based complex exponential values for rotary positional embeddings.
Parameters:
Dimensionality of the rotary positional embeddings.
Maximum sequence length.
Original sequence length.
Fast beta value for the exponential computation.
Slow beta value for the exponential computation.
Base value for the exponential computation.
Factor value for the exponential computation.
Returns: torch.Tensor
torch.Tensor: Precomputed complex exponential values for positional embeddings.