MCPcopy Index your code
hub / github.com/CompVis/diff2flow / __init__

Method __init__

diff2flow/models/unet/openaimodel.py:288–315  ·  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

286 """
287
288 def __init__(
289 self,
290 channels,
291 num_heads=1,
292 num_head_channels=-1,
293 use_checkpoint=False,
294 use_new_attention_order=False,
295 ):
296 super().__init__()
297 self.channels = channels
298 if num_head_channels == -1:
299 self.num_heads = num_heads
300 else:
301 assert (
302 channels % num_head_channels == 0
303 ), f"q,k,v channels {channels} is not divisible by num_head_channels {num_head_channels}"
304 self.num_heads = channels // num_head_channels
305 self.use_checkpoint = use_checkpoint
306 self.norm = normalization(channels)
307 self.qkv = conv_nd(1, channels, channels * 3, 1)
308 if use_new_attention_order:
309 # split qkv before split heads
310 self.attention = QKVAttention(self.num_heads)
311 else:
312 # split heads before split qkv
313 self.attention = QKVAttentionLegacy(self.num_heads)
314
315 self.proj_out = zero_module(conv_nd(1, channels, channels, 1))
316
317 def forward(self, x):
318 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