MCPcopy
hub / github.com/openai/guided-diffusion / __init__

Method __init__

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

265 """
266
267 def __init__(
268 self,
269 channels,
270 num_heads=1,
271 num_head_channels=-1,
272 use_checkpoint=False,
273 use_new_attention_order=False,
274 ):
275 super().__init__()
276 self.channels = channels
277 if num_head_channels == -1:
278 self.num_heads = num_heads
279 else:
280 assert (
281 channels % num_head_channels == 0
282 ), f"q,k,v channels {channels} is not divisible by num_head_channels {num_head_channels}"
283 self.num_heads = channels // num_head_channels
284 self.use_checkpoint = use_checkpoint
285 self.norm = normalization(channels)
286 self.qkv = conv_nd(1, channels, channels * 3, 1)
287 if use_new_attention_order:
288 # split qkv before split heads
289 self.attention = QKVAttention(self.num_heads)
290 else:
291 # split heads before split qkv
292 self.attention = QKVAttentionLegacy(self.num_heads)
293
294 self.proj_out = zero_module(conv_nd(1, channels, channels, 1))
295
296 def forward(self, x):
297 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