apply_rope_3d_bhl#
- apply_rope_3d_bhl(x, rope_3d_cache)#
Apply 3D RoPE to a tensor laid out as [batch_size, hidden_dim, D, H, W].
The channel dimension C is split into three equal parts:
C_z,C_y, andC_x. RoPE is applied independently along Z (toC_z), Y (toC_y), and X (toC_x). For pairwise rotations,Cmust be divisible by 6 so that each third is even.- Parameters:
x (Tensor) – Input tensor of shape
[batch_size, hidden_dim, D, H, W]withhidden_dim % 6 == 0.rope_3d_cache (tuple[Tensor, Tensor, Tensor, Tensor, Tensor, Tensor]) – tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor] The cache of 3D RoPE cos/sin for z, y, and x axes, organized as (cos_z, sin_z, cos_y, sin_y, cos_x, sin_x).
- Returns:
Tensor with the same shape as
x. Rotations are written back in-place via views to reduce allocations.- Return type:
- Broadcasting:
cos_z/sin_z are reshaped to
[1, hidden_dim/3, D, 1, 1]for the first third.cos_y/sin_y are reshaped to
[1, hidden_dim/3, 1, H, 1]for the second third.cos_x/sin_x are reshaped to
[1, hidden_dim/3, 1, 1, W]for the final third.