(timesteps, dim, max_period=10000)
| 29 | print(out)''' |
| 30 | |
| 31 | def timestep_embedding(timesteps, dim, max_period=10000): |
| 32 | half = dim // 2 |
| 33 | freqs = (-math.log(max_period) * torch.arange(half) / half).exp() |
| 34 | args = timesteps * freqs |
| 35 | return torch.cat( (args.cos(), args.sin()) ).reshape(1, -1) |
| 36 | |
| 37 | timesteps = Tensor([1, 2, 3]).reshape((3, 1)) |
| 38 | dim = 10 |