MCPcopy Create free account
hub / github.com/DPS2022/diffusion-posterior-sampling / __init__

Method __init__

guided_diffusion/unet.py:338–365  ·  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

336 """
337
338 def __init__(
339 self,
340 channels,
341 num_heads=1,
342 num_head_channels=-1,
343 use_checkpoint=False,
344 use_new_attention_order=False,
345 ):
346 super().__init__()
347 self.channels = channels
348 if num_head_channels == -1:
349 self.num_heads = num_heads
350 else:
351 assert (
352 channels % num_head_channels == 0
353 ), f"q,k,v channels {channels} is not divisible by num_head_channels {num_head_channels}"
354 self.num_heads = channels // num_head_channels
355 self.use_checkpoint = use_checkpoint
356 self.norm = normalization(channels)
357 self.qkv = conv_nd(1, channels, channels * 3, 1)
358 if use_new_attention_order:
359 # split qkv before split heads
360 self.attention = QKVAttention(self.num_heads)
361 else:
362 # split heads before split qkv
363 self.attention = QKVAttentionLegacy(self.num_heads)
364
365 self.proj_out = zero_module(conv_nd(1, channels, channels, 1))
366
367 def forward(self, x):
368 return checkpoint(self._forward, (x,), self.parameters(), True)

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected