(self, h_: torch.Tensor)
| 153 | self.proj_out = torch.nn.Conv2d(in_channels, in_channels, kernel_size=1, stride=1, padding=0) |
| 154 | |
| 155 | def attention(self, h_: torch.Tensor) -> torch.Tensor: |
| 156 | h_ = self.norm(h_) |
| 157 | q = self.q(h_) |
| 158 | k = self.k(h_) |
| 159 | v = self.v(h_) |
| 160 | |
| 161 | b, c, h, w = q.shape |
| 162 | q, k, v = map(lambda x: rearrange(x, "b c h w -> b 1 (h w) c").contiguous(), (q, k, v)) |
| 163 | h_ = torch.nn.functional.scaled_dot_product_attention(q, k, v) # scale is dim ** -0.5 per default |
| 164 | # compute attention |
| 165 | |
| 166 | return rearrange(h_, "b 1 (h w) c -> b c h w", h=h, w=w, c=c, b=b) |
| 167 | |
| 168 | def forward(self, x, **kwargs): |
| 169 | h_ = x |
no outgoing calls
no test coverage detected