MCPcopy
hub / github.com/ali-vilab/AnyDoor / __init__

Method __init__

ldm/modules/diffusionmodules/openaimodel.py:284–311  ·  view source on GitHub ↗
(
        self,
        channels,
        num_heads=1,
        num_head_channels=-1,
        use_checkpoint=False,
        use_new_attention_order=False,
    )

Source from the content-addressed store, hash-verified

282 """
283
284 def __init__(
285 self,
286 channels,
287 num_heads=1,
288 num_head_channels=-1,
289 use_checkpoint=False,
290 use_new_attention_order=False,
291 ):
292 super().__init__()
293 self.channels = channels
294 if num_head_channels == -1:
295 self.num_heads = num_heads
296 else:
297 assert (
298 channels % num_head_channels == 0
299 ), f"q,k,v channels {channels} is not divisible by num_head_channels {num_head_channels}"
300 self.num_heads = channels // num_head_channels
301 self.use_checkpoint = use_checkpoint
302 self.norm = normalization(channels)
303 self.qkv = conv_nd(1, channels, channels * 3, 1)
304 if use_new_attention_order:
305 # split qkv before split heads
306 self.attention = QKVAttention(self.num_heads)
307 else:
308 # split heads before split qkv
309 self.attention = QKVAttentionLegacy(self.num_heads)
310
311 self.proj_out = zero_module(conv_nd(1, channels, channels, 1))
312
313 def forward(self, x):
314 return checkpoint(self._forward, (x,), self.parameters(), True) # TODO: check checkpoint usage, is True # TODO: fix the .half call!!!

Callers

nothing calls this directly

Calls 6

normalizationFunction · 0.90
conv_ndFunction · 0.90
zero_moduleFunction · 0.90
QKVAttentionClass · 0.85
QKVAttentionLegacyClass · 0.85
__init__Method · 0.45

Tested by

no test coverage detected