Pre-calculate rotary position embedding for position_ids. Args: rotary_dim (int): Dimension of rotary embeddings (head dimension) base (float, optional): Base value used to compute the inverse frequencies. Default: 10000.0. positi
(
rotary_dim: int,
base: 10000.0,
position_ids: paddle.Tensor,
model_config: Optional[ModelConfig] = None,
partial_rotary_factor: int = 1,
)
| 370 | |
| 371 | |
| 372 | def get_rope( |
| 373 | rotary_dim: int, |
| 374 | base: 10000.0, |
| 375 | position_ids: paddle.Tensor, |
| 376 | model_config: Optional[ModelConfig] = None, |
| 377 | partial_rotary_factor: int = 1, |
| 378 | ) -> paddle.Tensor: |
| 379 | """ |
| 380 | Pre-calculate rotary position embedding for position_ids. |
| 381 | |
| 382 | Args: |
| 383 | rotary_dim (int): |
| 384 | Dimension of rotary embeddings (head dimension) |
| 385 | base (float, optional): |
| 386 | Base value used to compute the inverse frequencies. |
| 387 | Default: 10000.0. |
| 388 | position_ids (paddle.Tensor): |
| 389 | Tensor containing position indices of input tokens. |
| 390 | model_config (Optional[ModelConfig]): |
| 391 | Model configuration object containing architecture information. |
| 392 | If provided, determines RoPE implementation based on model architecture. |
| 393 | partial_rotary_factor (int, optional): |
| 394 | Factor controlling partial rotary application. |
| 395 | Default: 1 (apply to all dimensions). |
| 396 | """ |
| 397 | if current_platform.is_xpu(): |
| 398 | return get_rope_xpu(rotary_dim, base, position_ids, model_config, partial_rotary_factor) |
| 399 | else: |
| 400 | return get_rope_impl(rotary_dim, base, position_ids, model_config, partial_rotary_factor) |
| 401 | |
| 402 | |
| 403 | class ErnieVlRotaryEmbedding3D: |