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

Method __init__

ldm/modules/diffusionmodules/openaimodel.py:286–313  ·  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

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