mr2.nn.AxialRoPE

class mr2.nn.AxialRoPE[source]

Bases: Module

Axial Rotary Position Embedding.

Applies rotary position embeddings along each axis independently.

__init__(embed_fraction: float = 1.0)[source]

Initialize AxialRoPE.

Parameters:

embed_fraction (float, default: 1.0) – Fraction of channels used for embedding

forward(*tensors: Tensor) → tuple[Tensor, ...][source]

Apply rotary embeddings to input tensors.

Parameters:

*tensors (Tensor) – Tensors to apply rotary embeddings to. Shape must be (batch, heads, *spatial_dims, channels).

static apply_rotary_emb(x: Tensor, theta: Tensor) → Tensor[source]

Add rotary embedding to the input tensor.

Parameters:
  • x (Tensor) – Input tensor to modify

  • theta (Tensor) – Rotation angles