(
self,
x: torch.Tensor,
encoder_hidden_states: torch.Tensor,
attn_mask=None
)
| 527 | self.core_attention = self.attn_processor(attn_type=attn_type) |
| 528 | |
| 529 | def forward( |
| 530 | self, |
| 531 | x: torch.Tensor, |
| 532 | encoder_hidden_states: torch.Tensor, |
| 533 | attn_mask=None |
| 534 | ): |
| 535 | xq = self.wq(x) |
| 536 | xq = xq.view(*xq.shape[:-1], self.n_heads, self.head_dim) |
| 537 | |
| 538 | xkv = self.wkv(encoder_hidden_states) |
| 539 | xkv = xkv.view(*xkv.shape[:-1], self.n_heads, 2*self.head_dim) |
| 540 | |
| 541 | xk, xv = torch.split(xkv, [self.head_dim]*2, dim=-1) ## seq_len, n, dim |
| 542 | |
| 543 | if self.with_qk_norm: |
| 544 | xq = self.q_norm(xq) |
| 545 | xk = self.k_norm(xk) |
| 546 | |
| 547 | output = self.core_attention( |
| 548 | xq, |
| 549 | xk, |
| 550 | xv, |
| 551 | attn_mask=attn_mask |
| 552 | ) |
| 553 | |
| 554 | output = rearrange(output, 'b s h d -> b s (h d)') |
| 555 | output = self.wo(output) |
| 556 | |
| 557 | return output |
| 558 | |
| 559 | |
| 560 | class GELU(nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected