MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / __init__

Method __init__

sat/sgm/modules/diffusionmodules/openaimodel.py:356–383  ·  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

354 """
355
356 def __init__(
357 self,
358 channels,
359 num_heads=1,
360 num_head_channels=-1,
361 use_checkpoint=False,
362 use_new_attention_order=False,
363 ):
364 super().__init__()
365 self.channels = channels
366 if num_head_channels == -1:
367 self.num_heads = num_heads
368 else:
369 assert (
370 channels % num_head_channels == 0
371 ), f"q,k,v channels {channels} is not divisible by num_head_channels {num_head_channels}"
372 self.num_heads = channels // num_head_channels
373 self.use_checkpoint = use_checkpoint
374 self.norm = normalization(channels)
375 self.qkv = conv_nd(1, channels, channels * 3, 1)
376 if use_new_attention_order:
377 # split qkv before split heads
378 self.attention = QKVAttention(self.num_heads)
379 else:
380 # split heads before split qkv
381 self.attention = QKVAttentionLegacy(self.num_heads)
382
383 self.proj_out = zero_module(conv_nd(1, channels, channels, 1))
384
385 def forward(self, x, **kwargs):
386 # TODO add crossframe attention and use mixed checkpoint

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected