vllm_omni.diffusion.layers.rope ¶
RotaryEmbedding ¶
Bases: CustomOp
rotary positional embedding. interleaved: if True, rotate pairs of even and odd dimensions (GPT-J style) instead of 1st half and 2nd half (GPT-NeoX style).
RotaryEmbeddingS2VGrid ¶
Bases: Module
Grid-based RoPE for S2V motioner/init attention.
Applies complex-valued rotary embeddings using 3D grid sampling (frame, height, width). Used by SimpleSelfAttention, SwinSelfAttention, CausalSelfAttention in motioner blocks.
apply_precomputed staticmethod ¶
Apply precomputed position frequencies to input tensor.
RotaryEmbeddingWan ¶
Bases: RotaryEmbedding
rotary positional embedding for Wan. interleaved: if True, rotate pairs of even and odd dimensions (GPT-J style) instead of 1st half and 2nd half (GPT-NeoX style).
RotaryEmbeddingWanS2V ¶
Bases: RotaryEmbeddingWan
Apply RoPE using precomputed complex freqs for Wan S2V main transformer.
Converts complex freqs (from WanS2VRotaryPosEmbed) to cos/sin and delegates to RotaryEmbeddingWan for platform-optimized application (float32 kernel). Under TP, freqs has 1 head — broadcasts automatically via cos/sin.
WanS2VRotaryPosEmbed ¶
Bases: Module
Precompute complex-valued RoPE embeddings for S2V multi-grid positions.
Owns the base frequency buffer and provides forward() to compute position embeddings given hidden_states (for shape) and grid_sizes.
forward ¶
forward(
hidden_states: Tensor,
grid_sizes: list,
trainable_freqs: Tensor | None = None,
) -> Tensor
Precompute RoPE embeddings for the given grid layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hidden_states | Tensor | Tensor [B, S, ...] (used for batch/seq shape and device) | required |
grid_sizes | list | Grid specification (list of [offsets, sizes, totals]) | required |
trainable_freqs | Tensor | None | Optional trainable frequency overrides for t_f < 0 | None |
Returns:
| Type | Description |
|---|---|
Tensor | Complex tensor [B, S, 1, head_dim//2] of precomputed position embeddings |
apply_rope_to_qk ¶
apply_rope_to_qk(
rope: RotaryEmbedding,
query: Tensor,
key: Tensor,
image_rotary_emb: tuple[Tensor, Tensor] | None,
) -> tuple[Tensor, Tensor]
Apply rotary positional embeddings to query and key tensors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rope | RotaryEmbedding | RotaryEmbedding instance for applying position embeddings | required |
query | Tensor | Query tensor [B, S, H, D] | required |
key | Tensor | Key tensor [B, S, H, D] | required |
image_rotary_emb | tuple[Tensor, Tensor] | None | Tuple of (cos, sin) tensors or None | required |
Returns:
| Type | Description |
|---|---|
tuple[Tensor, Tensor] | Tuple of (query, key) with RoPE applied if rotary embeddings provided |
apply_rotary_emb_mindiesd ¶
apply_rotary_emb_mindiesd(
x: Tensor,
cos: Tensor,
sin: Tensor,
interleaved: bool = False,
half_head_dim: bool = True,
) -> Tensor
apply_rotary_emb_torch ¶
x: (batch_size, seqlen, nheads, headdim) cos, sin: (seqlen, rotary_dim / 2) or (batch_size, seqlen, rotary_dim / 2)