Skip to navigation

nemo_automodel.components.models.ergo.rope

View as MarkdownOpen in Claude

Source-equivalent CPU RoPE tables with a model-owned device cache.

The arithmetic contract is documented in layers.py’s release provenance. DeepSeek’s shared helpers allow default-device construction and fused rotation; Ergo requires CPU FP32 table construction and its existing complex rotation.

Module Contents

Classes

NameDescription
ErgoRotaryFrequenciesShare one derived table across attention layers, outside checkpoint state.

API

class nemo_automodel.components.models.ergo.rope.ErgoRotaryFrequencies(
)

Bases: Module

Share one derived table across attention layers, outside checkpoint state.

These caches deliberately are not buffers: Module.to(dtype) would cast complex buffers to real values, and to_empty would destroy their contents. The CPU master remains complex64; module transforms invalidate only the device copy. Construction is lazy so meta initialization allocates no frequency table.

_cpu_frequencies
Tensor | None = None
_device_frequencies
Tensor | None = None
head_dim
= config.head_dim
max_positions
= config.max_position_embeddings
theta
= config.rope_theta
nemo_automodel.components.models.ergo.rope.ErgoRotaryFrequencies._apply(
fn: collections.abc.Callable[[torch.Tensor], torch.Tensor],
recurse: bool = True
) -> typing.Self
nemo_automodel.components.models.ergo.rope.ErgoRotaryFrequencies.forward(
positions: torch.Tensor
) -> torch.Tensor

Select CPU-rounded complex64 frequencies on the positions’ device.

Parameters:

positions
torch.Tensor

Integer IDs [batch, sequence] or packed [tokens], in [0, max_position_embeddings). Resets and repeated IDs are valid.

Returns: torch.Tensor

Complex64 frequencies [batch, sequence, head_dim / 2] or