Extract some coefficients at specified timesteps, then reshape to [batch_size, 1, 1, 1, 1, ...] for broadcasting purposes.
(v, t, x_shape)
| 12 | |
| 13 | |
| 14 | def extract(v, t, x_shape): |
| 15 | """ |
| 16 | Extract some coefficients at specified timesteps, then reshape to |
| 17 | [batch_size, 1, 1, 1, 1, ...] for broadcasting purposes. |
| 18 | """ |
| 19 | device = t.device |
| 20 | out = torch.gather(v, index=t, dim=0).float().to(device) |
| 21 | return out.view([t.shape[0]] + [1] * (len(x_shape) - 1)) |
| 22 | |
| 23 | |
| 24 | class GaussianDiffusion(nn.Module): |
no outgoing calls
no test coverage detected