| 75 | |
| 76 | |
| 77 | class DecoderLayer(nn.Module): |
| 78 | |
| 79 | def __init__(self, |
| 80 | sa_block_cfg=None, |
| 81 | ca_block_cfg=None, |
| 82 | ffn_cfg=None): |
| 83 | super().__init__() |
| 84 | self.sa_block = build_attention(sa_block_cfg) |
| 85 | self.ca_block = build_attention(ca_block_cfg) |
| 86 | self.ffn = FFN(**ffn_cfg) |
| 87 | |
| 88 | def forward(self, **kwargs): |
| 89 | if self.sa_block is not None: |
| 90 | x = self.sa_block(**kwargs) |
| 91 | kwargs.update({'x': x}) |
| 92 | if self.ca_block is not None: |
| 93 | x = self.ca_block(**kwargs) |
| 94 | kwargs.update({'x': x}) |
| 95 | if self.ffn is not None: |
| 96 | x = self.ffn(**kwargs) |
| 97 | return x |
| 98 | |
| 99 | |
| 100 | class DiffusionTransformer(BaseModule, metaclass=ABCMeta): |