r""" The forward method of the `Attention` class. Args: hidden_states (`torch.Tensor`): The hidden states of the query. encoder_hidden_states (`torch.Tensor`, *optional*): The hidden states of the encoder. a
(
self,
hidden_states: torch.FloatTensor,
encoder_hidden_states: Optional[torch.FloatTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
iter_cur=None,
save_kv=None,
source_masks=None,
target_masks=None,
long_context=None,
**cross_attention_kwargs,
)
| 483 | return lora_processor |
| 484 | |
| 485 | def forward( |
| 486 | self, |
| 487 | hidden_states: torch.FloatTensor, |
| 488 | encoder_hidden_states: Optional[torch.FloatTensor] = None, |
| 489 | attention_mask: Optional[torch.FloatTensor] = None, |
| 490 | iter_cur=None, |
| 491 | save_kv=None, |
| 492 | source_masks=None, |
| 493 | target_masks=None, |
| 494 | long_context=None, |
| 495 | **cross_attention_kwargs, |
| 496 | ) -> torch.Tensor: |
| 497 | r""" |
| 498 | The forward method of the `Attention` class. |
| 499 | |
| 500 | Args: |
| 501 | hidden_states (`torch.Tensor`): |
| 502 | The hidden states of the query. |
| 503 | encoder_hidden_states (`torch.Tensor`, *optional*): |
| 504 | The hidden states of the encoder. |
| 505 | attention_mask (`torch.Tensor`, *optional*): |
| 506 | The attention mask to use. If `None`, no mask is applied. |
| 507 | **cross_attention_kwargs: |
| 508 | Additional keyword arguments to pass along to the cross attention. |
| 509 | |
| 510 | Returns: |
| 511 | `torch.Tensor`: The output of the attention layer. |
| 512 | """ |
| 513 | # The `Attention` class can call different attention processors / attention functions |
| 514 | # here we simply pass along all tensors to the selected processor class |
| 515 | # For standard processors that are defined here, `**cross_attention_kwargs` is empty |
| 516 | if iter_cur is not None and save_kv is not None: |
| 517 | return self.processor( |
| 518 | self, |
| 519 | hidden_states, |
| 520 | encoder_hidden_states=encoder_hidden_states, |
| 521 | attention_mask=attention_mask, |
| 522 | iter_cur=iter_cur, |
| 523 | save_kv=save_kv, |
| 524 | source_masks=source_masks, |
| 525 | target_masks=target_masks, |
| 526 | long_context=long_context, |
| 527 | **cross_attention_kwargs, |
| 528 | ) |
| 529 | else: |
| 530 | return self.processor( |
| 531 | self, |
| 532 | hidden_states, |
| 533 | encoder_hidden_states=encoder_hidden_states, |
| 534 | attention_mask=attention_mask, |
| 535 | **cross_attention_kwargs, |
| 536 | ) |
| 537 | |
| 538 | def batch_to_head_dim(self, tensor: torch.Tensor) -> torch.Tensor: |
| 539 | r""" |
nothing calls this directly
no outgoing calls
no test coverage detected