MCPcopy Create free account
hub / github.com/thygate/stable-diffusion-webui-depthmap-script / forward

Method forward

dmidas/backbones/next_vit.py:245–273  ·  view source on GitHub ↗
(self, x)

Source from the content-addressed store, hash-verified

243 self.is_bn_merged = True
244
245 def forward(self, x):
246 B, N, C = x.shape
247 q = self.q(x)
248 q = q.reshape(B, N, self.num_heads, int(C // self.num_heads)).permute(0, 2, 1, 3)
249
250 if self.sr_ratio > 1:
251 x_ = x.transpose(1, 2)
252 x_ = self.sr(x_)
253 if not torch.onnx.is_in_onnx_export() and not self.is_bn_merged:
254 x_ = self.norm(x_)
255 x_ = x_.transpose(1, 2)
256 k = self.k(x_)
257 k = k.reshape(B, -1, self.num_heads, int(C // self.num_heads)).permute(0, 2, 3, 1)
258 v = self.v(x_)
259 v = v.reshape(B, -1, self.num_heads, int(C // self.num_heads)).permute(0, 2, 1, 3)
260 else:
261 k = self.k(x)
262 k = k.reshape(B, -1, self.num_heads, int(C // self.num_heads)).permute(0, 2, 3, 1)
263 v = self.v(x)
264 v = v.reshape(B, -1, self.num_heads, int(C // self.num_heads)).permute(0, 2, 1, 3)
265 attn = (q @ k) * self.scale
266
267 attn = attn.softmax(dim=-1)
268 attn = self.attn_drop(attn)
269
270 x = (attn @ v).transpose(1, 2).reshape(B, N, C)
271 x = self.proj(x)
272 x = self.proj_drop(x)
273 return x
274
275
276class NTB(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected