MCPcopy Create free account
hub / github.com/OpenImagingLab/FlashVSR / forward

Method forward

diffsynth/models/cog_dit.py:286–324  ·  view source on GitHub ↗
(self, hidden_states, timestep, prompt_emb, image_rotary_emb=None, tiled=False, tile_size=90, tile_stride=30, use_gradient_checkpointing=False)

Source from the content-addressed store, hash-verified

284
285
286 def forward(self, hidden_states, timestep, prompt_emb, image_rotary_emb=None, tiled=False, tile_size=90, tile_stride=30, use_gradient_checkpointing=False):
287 if tiled:
288 return TileWorker2Dto3D().tiled_forward(
289 forward_fn=lambda x: self.forward(x, timestep, prompt_emb),
290 model_input=hidden_states,
291 tile_size=tile_size, tile_stride=tile_stride,
292 tile_device=hidden_states.device, tile_dtype=hidden_states.dtype,
293 computation_device=self.context_embedder.weight.device, computation_dtype=self.context_embedder.weight.dtype
294 )
295 num_frames, height, width = hidden_states.shape[-3:]
296 if image_rotary_emb is None:
297 image_rotary_emb = self.prepare_rotary_positional_embeddings(height, width, num_frames, device=self.context_embedder.weight.device)
298 hidden_states = self.patchify(hidden_states)
299 time_emb = self.time_embedder(timestep, dtype=hidden_states.dtype)
300 prompt_emb = self.context_embedder(prompt_emb)
301
302 def create_custom_forward(module):
303 def custom_forward(*inputs):
304 return module(*inputs)
305 return custom_forward
306
307 for block in self.blocks:
308 if self.training and use_gradient_checkpointing:
309 hidden_states, prompt_emb = torch.utils.checkpoint.checkpoint(
310 create_custom_forward(block),
311 hidden_states, prompt_emb, time_emb, image_rotary_emb,
312 use_reentrant=False,
313 )
314 else:
315 hidden_states, prompt_emb = block(hidden_states, prompt_emb, time_emb, image_rotary_emb)
316
317 hidden_states = torch.cat([prompt_emb, hidden_states], dim=1)
318 hidden_states = self.norm_final(hidden_states)
319 hidden_states = hidden_states[:, prompt_emb.shape[1]:]
320 hidden_states = self.norm_out(hidden_states, prompt_emb, time_emb)
321 hidden_states = self.proj_out(hidden_states)
322 hidden_states = self.unpatchify(hidden_states, height, width)
323
324 return hidden_states
325
326
327 @staticmethod

Callers 1

tiled_forwardMethod · 0.95

Calls 6

unpatchifyMethod · 0.95
TileWorker2Dto3DClass · 0.85
create_custom_forwardFunction · 0.85
tiled_forwardMethod · 0.45
patchifyMethod · 0.45

Tested by

no test coverage detected