MCPcopy Create free account
hub / github.com/CompVis/diff2flow / make_attn

Function make_attn

diff2flow/kl_autoencoder.py:231–244  ·  view source on GitHub ↗
(in_channels, attn_type="vanilla", natten_kernel_size=-1, use_null_attention=False)

Source from the content-addressed store, hash-verified

229
230
231def make_attn(in_channels, attn_type="vanilla", natten_kernel_size=-1, use_null_attention=False):
232 if attn_type == "vanilla":
233 assert not (use_null_attention and natten_kernel_size > -1), "use_null_attention and natten_kernel_size > -1 are mutually exclusive"
234 if natten_kernel_size > -1 and not NATTEN_IS_AVAILBLE:
235 raise ValueError("natten_kernel_size > -1 but natten is not available")
236 if use_null_attention:
237 print(f"Using null attention to save memory and compute...")
238 return MemoryEfficientAttnBlock(in_channels, natten_kernel_size=natten_kernel_size, use_null_attention=use_null_attention)
239
240 elif attn_type == "none":
241 return nn.Identity(in_channels)
242
243 else:
244 raise NotImplementedError(f"attn_type {attn_type} not implemented")
245
246
247""" Encoder and Decoder """

Callers 2

__init__Method · 0.85
__init__Method · 0.85

Calls 1

Tested by

no test coverage detected