Projects caption embeddings. Also handles dropout for classifier-free guidance. Adapted from https://github.com/PixArt-alpha/PixArt-alpha/blob/master/diffusion/model/nets/PixArt_blocks.py
| 296 | |
| 297 | |
| 298 | class PixArtAlphaTextProjection(nn.Module): |
| 299 | """ |
| 300 | Projects caption embeddings. Also handles dropout for classifier-free guidance. |
| 301 | |
| 302 | Adapted from https://github.com/PixArt-alpha/PixArt-alpha/blob/master/diffusion/model/nets/PixArt_blocks.py |
| 303 | """ |
| 304 | |
| 305 | def __init__(self, in_features, hidden_size): |
| 306 | super().__init__() |
| 307 | self.linear_1 = nn.Linear( |
| 308 | in_features, |
| 309 | hidden_size, |
| 310 | bias=True, |
| 311 | ) |
| 312 | self.act_1 = nn.GELU(approximate="tanh") |
| 313 | self.linear_2 = nn.Linear( |
| 314 | hidden_size, |
| 315 | hidden_size, |
| 316 | bias=True, |
| 317 | ) |
| 318 | |
| 319 | def forward(self, caption): |
| 320 | hidden_states = self.linear_1(caption) |
| 321 | hidden_states = self.act_1(hidden_states) |
| 322 | hidden_states = self.linear_2(hidden_states) |
| 323 | return hidden_states |
| 324 | |
| 325 | |
| 326 | class Attention(nn.Module): |