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

Function make_attn

ldm/modules/diffusionmodules/model.py:287–304  ·  view source on GitHub ↗
(in_channels, attn_type="vanilla", attn_kwargs=None)

Source from the content-addressed store, hash-verified

285
286
287def make_attn(in_channels, attn_type="vanilla", attn_kwargs=None):
288 assert attn_type in ["vanilla", "vanilla-xformers", "memory-efficient-cross-attn", "linear", "none"], f'attn_type {attn_type} unknown'
289 if XFORMERS_IS_AVAILBLE and attn_type == "vanilla":
290 attn_type = "vanilla-xformers"
291 print(f"making attention of type '{attn_type}' with {in_channels} in_channels")
292 if attn_type == "vanilla":
293 assert attn_kwargs is None
294 return AttnBlock(in_channels)
295 elif attn_type == "vanilla-xformers":
296 print(f"building MemoryEfficientAttnBlock with {in_channels} in_channels...")
297 return MemoryEfficientAttnBlock(in_channels)
298 elif type == "memory-efficient-cross-attn":
299 attn_kwargs["query_dim"] = in_channels
300 return MemoryEfficientCrossAttentionWrapper(**attn_kwargs)
301 elif attn_type == "none":
302 return nn.Identity(in_channels)
303 else:
304 raise NotImplementedError()
305
306
307class Model(nn.Module):

Callers 3

__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85

Calls 3

AttnBlockClass · 0.85

Tested by

no test coverage detected