(self, x)
| 194 | self.proj = nn.Linear(embed_dim, embed_dim) |
| 195 | |
| 196 | def forward(self, x): |
| 197 | B, N, C = x.shape |
| 198 | qkv = self.qkv(x).reshape(B, N, 3, self.num_heads, self.head_dim).permute(2, 0, 3, 1, 4) |
| 199 | q, k, v = qkv[0], qkv[1], qkv[2] |
| 200 | |
| 201 | attn = (q @ k.transpose(-2, -1)) * self.scale |
| 202 | attn = F.softmax(attn, dim=-1) |
| 203 | |
| 204 | x = (attn @ v).transpose(1, 2).reshape(B, N, C) |
| 205 | x = self.proj(x) |
| 206 | |
| 207 | return x |
nothing calls this directly
no outgoing calls
no test coverage detected