IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).

Mojo function

rope_value

def rope_value[dtype: DType, freq_dtype: DType, width: SIMDLength](val: SIMD[dtype, width], freq: SIMD[freq_dtype, width]) -> SIMD[dtype, width]

Applies a rotary position embedding transformation to a SIMD vector.

Deinterleaves the input into real and imaginary parts, multiplies them as complex numbers against the frequency coefficients, and reinterleaves the result back into the original dtype.

Parameters:

  • ​dtype (DType): Element type of the input and output SIMD vector (inferred).
  • ​freq_dtype (DType): Element type of the frequency coefficients (inferred).
  • ​width (SIMDLength): Number of elements in the SIMD vector (inferred).

Args:

  • ​val (SIMD[dtype, width]): The input SIMD vector with interleaved real and imaginary parts.
  • ​freq (SIMD[freq_dtype, width]): The frequency coefficients with interleaved real and imaginary parts.

Returns:

SIMD[dtype, width]: The RoPE-transformed SIMD vector in the original dtype.

Was this page helpful?