(self, input_tensor, attn_mask=None)
| 138 | self.to_out = nn.Sequential(nn.Linear(dim_inner, in_channels, bias=bias), nn.Dropout(dropout)) |
| 139 | |
| 140 | def forward(self, input_tensor, attn_mask=None): |
| 141 | hidden_states = self.group_norm(input_tensor.transpose(1, 2)).transpose(1, 2) |
| 142 | batch_size = hidden_states.shape[0] |
| 143 | |
| 144 | q = self.to_q(hidden_states) |
| 145 | k = self.to_k(hidden_states) |
| 146 | v = self.to_v(hidden_states) |
| 147 | |
| 148 | q = q.view(batch_size, -1, self.num_heads, self.head_dim).transpose(1, 2) |
| 149 | k = k.view(batch_size, -1, self.num_heads, self.head_dim).transpose(1, 2) |
| 150 | v = v.view(batch_size, -1, self.num_heads, self.head_dim).transpose(1, 2) |
| 151 | |
| 152 | if attn_mask is not None: |
| 153 | attn_mask = attn_mask.view(batch_size, self.num_heads, -1, attn_mask.shape[-1]) |
| 154 | hidden_states = F.scaled_dot_product_attention(q, k, v, attn_mask=attn_mask) |
| 155 | hidden_states = hidden_states.transpose(1, 2).reshape(batch_size, -1, self.num_heads * self.head_dim) |
| 156 | hidden_states = self.to_out(hidden_states) |
| 157 | if self.residual_connection: |
| 158 | output_tensor = input_tensor + hidden_states |
| 159 | return output_tensor |
| 160 | |
| 161 | |
| 162 | class UNetMidBlockCausal3D(nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected