(self, dim, n_heads, d_head, dropout=0., context_dim=None, gated_ff=True, checkpoint=True,
disable_self_attn=False)
| 249 | "softmax-xformers": MemoryEfficientCrossAttention |
| 250 | } |
| 251 | def __init__(self, dim, n_heads, d_head, dropout=0., context_dim=None, gated_ff=True, checkpoint=True, |
| 252 | disable_self_attn=False): |
| 253 | super().__init__() |
| 254 | attn_mode = "softmax-xformers" if XFORMERS_IS_AVAILBLE else "softmax" |
| 255 | assert attn_mode in self.ATTENTION_MODES |
| 256 | attn_cls = self.ATTENTION_MODES[attn_mode] |
| 257 | self.disable_self_attn = disable_self_attn |
| 258 | self.attn1 = attn_cls(query_dim=dim, heads=n_heads, dim_head=d_head, dropout=dropout, |
| 259 | context_dim=context_dim if self.disable_self_attn else None) # is a self-attention if not self.disable_self_attn |
| 260 | self.ff = FeedForward(dim, dropout=dropout, glu=gated_ff) |
| 261 | self.attn2 = attn_cls(query_dim=dim, context_dim=context_dim, |
| 262 | heads=n_heads, dim_head=d_head, dropout=dropout) # is self-attn if context is none |
| 263 | self.norm1 = nn.LayerNorm(dim) |
| 264 | self.norm2 = nn.LayerNorm(dim) |
| 265 | self.norm3 = nn.LayerNorm(dim) |
| 266 | self.checkpoint = checkpoint |
| 267 | |
| 268 | def forward(self, x, context=None): |
| 269 | return checkpoint(self._forward, (x, context), self.parameters(), self.checkpoint) |
nothing calls this directly
no test coverage detected