(self, x: torch.Tensor, emb: torch.Tensor)
| 139 | self.linear = nn.Linear(embedding_dim, out_dim * 2) |
| 140 | |
| 141 | def forward(self, x: torch.Tensor, emb: torch.Tensor) -> torch.Tensor: |
| 142 | if self.act: |
| 143 | emb = self.act(emb) |
| 144 | emb = self.linear(emb) |
| 145 | emb = emb[:, :, None, None] |
| 146 | scale, shift = emb.chunk(2, dim=1) |
| 147 | |
| 148 | x = F.group_norm(x, self.num_groups, eps=self.eps) |
| 149 | x = x * (1 + scale) + shift |
| 150 | return x |
| 151 | |
| 152 | |
| 153 | class AdaLayerNormContinuous(nn.Module): |