vllm.model_executor.layers.rotary_embedding.mrope_vit_setup
¶
Classes:
-
VitMropeSetup–Builds triton_mrope's (3, N, half_rot) cos/sin t/h/w planes.
Functions:
-
vit_mrope_setup–Compatibility wrapper around :class:
VitMropeSetup.
VitMropeSetup
¶
Bases: PluggableLayer
Builds triton_mrope's (3, N, half_rot) cos/sin t/h/w planes.
One fused kernel: positions are computed arithmetically from the grids and the rotation comes from the per-axis inv_freq, so there is no cos/sin cache to size or grow.
Stateless: the caller's inv_freq buffers are passed per call. OOT
platforms replace the whole layer via @VitMropeSetup.register_oot
with a subclass overriding :meth:forward (e.g. to retune the kernel
tiling for their hardware).
Methods:
-
forward–(3, total_N, half_rot_dim) fp32 cos/sin t/h/w planes.
Source code in vllm/model_executor/layers/rotary_embedding/mrope_vit_setup.py
forward(inv_freq_t, inv_freq_h, inv_freq_w, grid_thw, spatial_merge_size)
¶
(3, total_N, half_rot_dim) fp32 cos/sin t/h/w planes.
Parameters:
-
(inv_freq_t¶Tensor) –t-axis inverse frequencies, (t_dim // 2,).
-
(inv_freq_h¶Tensor) –h-axis inverse frequencies, (h_dim // 2,).
-
(inv_freq_w¶Tensor) –w-axis inverse frequencies, (w_dim // 2,).
-
(grid_thw¶list[list[int]]) –per-grid [t, h, w] patch counts (host metadata).
-
(spatial_merge_size¶int) –spatial merge factor of the ViT.
Source code in vllm/model_executor/layers/rotary_embedding/mrope_vit_setup.py
_vit_mrope_setup_kernel(inv_freq_t_ptr, inv_freq_h_ptr, inv_freq_w_ptr, cos_out_ptr, sin_out_ptr, cu_seqlens_ptr, grids_ptr, num_tokens, num_grids, half_t, half_h, half_w, spatial_merge, BLOCK_N, BLOCK_D)
¶
Build triton_mrope's (3, N, half_rot) cos/sin t/h/w planes in one launch: compute each token's (t, h, w) position arithmetically and the rotation in fp32 from the per-axis inv_freq. Only each axis's mrope section columns are written; the rest is left uninitialized (the consumer's per-axis masked loads read only the section columns).
Source code in vllm/model_executor/layers/rotary_embedding/mrope_vit_setup.py
vit_mrope_setup(inv_freq_t, inv_freq_h, inv_freq_w, grid_thw, spatial_merge_size)
¶
Compatibility wrapper around :class:VitMropeSetup.