MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / _forward

Method _forward

sat/sgm/modules/diffusionmodules/openaimodel.py:320–346  ·  view source on GitHub ↗
(self, x, emb)

Source from the content-addressed store, hash-verified

318 return checkpoint(self._forward, (x, emb), self.parameters(), self.use_checkpoint)
319
320 def _forward(self, x, emb):
321 if self.updown:
322 in_rest, in_conv = self.in_layers[:-1], self.in_layers[-1]
323 h = in_rest(x)
324 h = self.h_upd(h)
325 x = self.x_upd(x)
326 h = in_conv(h)
327 else:
328 h = self.in_layers(x)
329
330 if self.skip_t_emb:
331 emb_out = th.zeros_like(h)
332 else:
333 emb_out = self.emb_layers(emb).type(h.dtype)
334 while len(emb_out.shape) < len(h.shape):
335 emb_out = emb_out[..., None]
336 if self.use_scale_shift_norm:
337 out_norm, out_rest = self.out_layers[0], self.out_layers[1:]
338 scale, shift = th.chunk(emb_out, 2, dim=1)
339 h = out_norm(h) * (1 + scale) + shift
340 h = out_rest(h)
341 else:
342 if self.exchange_temb_dims:
343 emb_out = rearrange(emb_out, "b t c ... -> b c t ...")
344 h = h + emb_out
345 h = self.out_layers(h)
346 return self.skip_connection(x) + h
347
348
349class AttentionBlock(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected