| from torch import nn |
| from torch.nn import functional as F |
| from .unet import UNET, UNET_OutputLayer |
|
|
|
|
| class TimeEmbedding(nn.Module): |
| def __init__(self, n_embd): |
| super().__init__() |
| self.linear_1 = nn.Linear(n_embd, 4 * n_embd) |
| self.linear_2 = nn.Linear(4 * n_embd, 4 * n_embd) |
|
|
| def forward(self, x): |
| |
|
|
| |
| x = self.linear_1(x) |
| |
| |
| x = F.silu(x) |
| |
| |
| x = self.linear_2(x) |
|
|
| return x |
|
|
|
|
| class Diffusion(nn.Module): |
| def __init__(self): |
| super().__init__() |
| self.time_embedding = TimeEmbedding(320) |
| self.unet = UNET() |
| self.final = UNET_OutputLayer(320, 4) |
| |
| def forward(self, latent, context, time): |
| |
| |
| |
|
|
| |
| time = self.time_embedding(time) |
| |
| |
| output = self.unet(latent, context, time) |
| |
| |
| output = self.final(output) |
| |
| |
| return output |