MCPcopy Create free account
hub / github.com/MegaScenes/nvs / forward

Method forward

ldm/modules/diffusionmodules/openaimodel.py:983–1005  ·  view source on GitHub ↗

Apply the model to an input batch. :param x: an [N x C x ...] Tensor of inputs. :param timesteps: a 1-D batch of timesteps. :return: an [N x K] Tensor of outputs.

(self, x, timesteps)

Source from the content-addressed store, hash-verified

981 self.middle_block.apply(convert_module_to_f32)
982
983 def forward(self, x, timesteps):
984 """
985 Apply the model to an input batch.
986 :param x: an [N x C x ...] Tensor of inputs.
987 :param timesteps: a 1-D batch of timesteps.
988 :return: an [N x K] Tensor of outputs.
989 """
990 emb = self.time_embed(timestep_embedding(timesteps, self.model_channels))
991
992 results = []
993 h = x.type(self.dtype)
994 for module in self.input_blocks:
995 h = module(h, emb)
996 if self.pool.startswith("spatial"):
997 results.append(h.type(x.dtype).mean(dim=(2, 3)))
998 h = self.middle_block(h, emb)
999 if self.pool.startswith("spatial"):
1000 results.append(h.type(x.dtype).mean(dim=(2, 3)))
1001 h = th.cat(results, axis=-1)
1002 return self.out(h)
1003 else:
1004 h = h.type(x.dtype)
1005 return self.out(h)
1006

Callers

nothing calls this directly

Calls 1

timestep_embeddingFunction · 0.90

Tested by

no test coverage detected