A sequential module that passes timestep embeddings to the children that support it as an extra input.
| 78 | |
| 79 | |
| 80 | class TimestepEmbedSequential(nn.Sequential, TimestepBlock): |
| 81 | """ |
| 82 | A sequential module that passes timestep embeddings to the children that |
| 83 | support it as an extra input. |
| 84 | """ |
| 85 | |
| 86 | def forward( |
| 87 | self, |
| 88 | x: th.Tensor, |
| 89 | emb: th.Tensor, |
| 90 | context: Optional[th.Tensor] = None, |
| 91 | image_only_indicator: Optional[th.Tensor] = None, |
| 92 | time_context: Optional[int] = None, |
| 93 | num_video_frames: Optional[int] = None, |
| 94 | ): |
| 95 | from ...modules.diffusionmodules.video_model import VideoResBlock |
| 96 | |
| 97 | for layer in self: |
| 98 | module = layer |
| 99 | |
| 100 | if isinstance(module, TimestepBlock) and not isinstance(module, VideoResBlock): |
| 101 | x = layer(x, emb) |
| 102 | elif isinstance(module, VideoResBlock): |
| 103 | x = layer(x, emb, num_video_frames, image_only_indicator) |
| 104 | elif isinstance(module, SpatialVideoTransformer): |
| 105 | x = layer( |
| 106 | x, |
| 107 | context, |
| 108 | time_context, |
| 109 | num_video_frames, |
| 110 | image_only_indicator, |
| 111 | ) |
| 112 | elif isinstance(module, SpatialTransformer): |
| 113 | x = layer(x, context) |
| 114 | else: |
| 115 | x = layer(x) |
| 116 | return x |
| 117 | |
| 118 | |
| 119 | class Upsample(nn.Module): |