nemo_automodel.components.models.deepseek_v4.kernels.rope
nemo_automodel.components.models.deepseek_v4.kernels.rope
One-pass DSV4 partial interleaved RoPE with a conjugate backward.
Module Contents
Classes
Functions
API
Bases: Function
Apply the conjugate rotation to the upstream gradient.
Parameters:
Saved frequency tables and rotary dimension.
Tensor of shape [batch, heads, sequence, channels].
Returns: torch.Tensor
Input gradient in the same logical layout, followed by None for
Rotate trailing channels and retain only the frequency tables.
Parameters:
Autograd context.
Tensor of shape [batch, heads, sequence, channels].
FP32 tensor of shape [batch, sequence, rotary_channels].
FP32 tensor with the same shape as cos.
Number of trailing channels to rotate.
Returns: torch.Tensor
Independent tensor with x’s logical shape and dtype.
Run a rotation without materializing a heads-to-tokens transpose.
Parameters:
CUDA tensor of shape [batch, heads, sequence, channels].
CUDA FP32 cosines of shape [batch, sequence, rotary_channels].
CUDA FP32 sines of the same shape as cos.
Even number of trailing channels to rotate.
Whether to negate sine for the backward rotation.
Returns: torch.Tensor
Tensor of shape [batch, heads, sequence, channels] with token-major
Rotate [batch, heads, sequence, channels] into token-major storage.
Parameters:
Input tensor with logical shape [batch, heads, sequence, channels].
Cosines of shape [batch, sequence, rotary_channels], first half unique.
Sines with the same logical layout as cos.
Output storage of shape [batch, sequence, heads, channels].
Number of channel pairs in x.
Fuse partial interleaved RoPE and its conjugate backward.
Parameters:
CUDA FP32/FP16/BF16 tensor of shape [batch, heads, sequence, channels]. The channel count must be even.
CUDA tensor of shape [batch, sequence, rotary_channels]; the first half contains the unique frequencies. Must not require gradients.
CUDA tensor with cos’s shape and the same fixed-frequency contract.
Positive even number of trailing channels, no greater than channels.
Returns: torch.Tensor
Tensor of shape [batch, heads, sequence, channels] in x’s dtype,