MCPcopy Create free account
hub / github.com/VisionXLab/OF-Diff / __init__

Method __init__

ldm/modules/attention.py:251–266  ·  view source on GitHub ↗
(self, dim, n_heads, d_head, dropout=0., context_dim=None, gated_ff=True, checkpoint=True,
                 disable_self_attn=False)

Source from the content-addressed store, hash-verified

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)

Callers

nothing calls this directly

Calls 2

FeedForwardClass · 0.85
__init__Method · 0.45

Tested by

no test coverage detected