| 65 | self.norm = nn.LayerNorm(output_dim // 2, norm_eps, norm_elementwise_affine) |
| 66 | |
| 67 | def forward( |
| 68 | self, x: torch.Tensor, timestep: Optional[torch.Tensor] = None, temb: Optional[torch.Tensor] = None |
| 69 | ) -> torch.Tensor: |
| 70 | if self.emb is not None: |
| 71 | temb = self.emb(timestep) |
| 72 | |
| 73 | temb = self.linear(self.silu(temb)) |
| 74 | |
| 75 | if self.chunk_dim == 1: |
| 76 | # This is a bit weird why we have the order of "shift, scale" here and "scale, shift" in the |
| 77 | # other if-branch. This branch is specific to CogVideoX for now. |
| 78 | shift, scale = temb.chunk(2, dim=1) |
| 79 | shift = shift[:, None, :] |
| 80 | scale = scale[:, None, :] |
| 81 | else: |
| 82 | scale, shift = temb.chunk(2, dim=0) |
| 83 | |
| 84 | x = self.norm(x) * (1 + scale) + shift |
| 85 | return x |
| 86 | |
| 87 | |
| 88 | class FP32LayerNorm(nn.LayerNorm): |