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. attention
(
self,
hidden_states: torch.FloatTensor,
encoder_hidden_states: Optional[torch.FloatTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
**cross_attention_kwargs,
)
| 494 | return lora_processor |
| 495 | |
| 496 | def forward( |
| 497 | self, |
| 498 | hidden_states: torch.FloatTensor, |
| 499 | encoder_hidden_states: Optional[torch.FloatTensor] = None, |
| 500 | attention_mask: Optional[torch.FloatTensor] = None, |
| 501 | **cross_attention_kwargs, |
| 502 | ) -> torch.Tensor: |
| 503 | r""" |
| 504 | The forward method of the `Attention` class. |
| 505 | |
| 506 | Args: |
| 507 | hidden_states (`torch.Tensor`): |
| 508 | The hidden states of the query. |
| 509 | encoder_hidden_states (`torch.Tensor`, *optional*): |
| 510 | The hidden states of the encoder. |
| 511 | attention_mask (`torch.Tensor`, *optional*): |
| 512 | The attention mask to use. If `None`, no mask is applied. |
| 513 | **cross_attention_kwargs: |
| 514 | Additional keyword arguments to pass along to the cross attention. |
| 515 | |
| 516 | Returns: |
| 517 | `torch.Tensor`: The output of the attention layer. |
| 518 | """ |
| 519 | # The `Attention` class can call different attention processors / attention functions |
| 520 | # here we simply pass along all tensors to the selected processor class |
| 521 | # For standard processors that are defined here, `**cross_attention_kwargs` is empty |
| 522 | return self.processor( |
| 523 | self, |
| 524 | hidden_states, |
| 525 | encoder_hidden_states=encoder_hidden_states, |
| 526 | attention_mask=attention_mask, |
| 527 | **cross_attention_kwargs, |
| 528 | ) |
| 529 | |
| 530 | def batch_to_head_dim(self, tensor: torch.Tensor) -> torch.Tensor: |
| 531 | r""" |
nothing calls this directly
no outgoing calls
no test coverage detected