(self, noise_level)
| 214 | self.dim = dim |
| 215 | |
| 216 | def forward(self, noise_level): |
| 217 | count = self.dim // 2 |
| 218 | step = ( |
| 219 | torch.arange(count, dtype=noise_level.dtype, device=noise_level.device) |
| 220 | / count |
| 221 | ) |
| 222 | encoding = noise_level.unsqueeze(1) * torch.exp( |
| 223 | -math.log(1e4) * step.unsqueeze(0) |
| 224 | ) |
| 225 | encoding = torch.cat([torch.sin(encoding), torch.cos(encoding)], dim=-1) |
| 226 | return encoding |
| 227 | |
| 228 | |
| 229 | class FeatureWiseAffine(nn.Module): |