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_q_proj
def rope_q_proj[dtype: DType, freq_dtype: DType, rank: Int, width: SIMDLength, output_dtype: DType, //, *, interleaved: Bool, has_nope_prefix: Bool = False, rope_dim: Int = Int(0), alignment: Int = Int((get_alignof SIMD[dtype, width], _current_target()))](q_proj: TileTensor[dtype, Storage=q_proj.Storage, address_space=q_proj.address_space, linear_idx_type=q_proj.linear_idx_type], output: TileTensor[output_dtype, Storage=output.Storage, address_space=output.address_space, linear_idx_type=output.linear_idx_type], idx: IndexList[rank], freq_val: SIMD[freq_dtype, width], head_size: Int)
Applies RoPE to a query projection tile and stores the result.
Loads the query projection values at the given coordinate, applies the
rotary position embedding via rope_value, and writes the transformed
result to the output tile. Supports both interleaved and split (real and
imaginary stored separately) layouts, and optionally leaves a nope prefix
region unrotated.
Parameters:
- βdtype (
DType): Element type of theq_projtile tensor (inferred). - βfreq_dtype (
DType): Element type of thefreq_valfrequency coefficients (inferred). - βrank (
Int): Rank of the index list and tile tensors (inferred). - βwidth (
SIMDLength): Number of elements per SIMD vector (inferred). - βoutput_dtype (
DType): Element type of theoutputtile tensor (inferred). - βinterleaved (
Bool): Whether the RoPE weights use interleaved real and imaginary layout. - βhas_nope_prefix (
Bool): Whether a leading prefix of the head dimension is left unrotated (defaults toFalse). - βrope_dim (
Int): Number of trailing head dimensions that undergo RoPE whenhas_nope_prefixis set (defaults to 0). - βalignment (
Int): Memory alignment in bytes for tile loads and stores (defaults to the natural alignment ofSIMD[dtype, width]).
Args:
- βq_proj (
TileTensor[dtype, Storage=q_proj.Storage, address_space=q_proj.address_space, linear_idx_type=q_proj.linear_idx_type]): The query projection tile tensor to read from. - βoutput (
TileTensor[output_dtype, Storage=output.Storage, address_space=output.address_space, linear_idx_type=output.linear_idx_type]): The mutable output tile tensor to write the rotated result. - βidx (
IndexList[rank]): The index list identifying the load and store coordinate. - βfreq_val (
SIMD[freq_dtype, width]): The RoPE frequency coefficients for this position. - βhead_size (
Int): The size of each attention head dimension.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!