MCPcopy Create free account
hub / github.com/huggingface/diffusers / set_attn_processor

Method set_attn_processor

src/diffusers/models/attention.py:64–96  ·  view source on GitHub ↗

r""" Sets the attention processor to use to compute attention. Parameters: processor (`dict` of `AttentionProcessor` or only `AttentionProcessor`): The instantiated processor class or a dictionary of processor classes that will be set as the processor

(self, processor: AttentionProcessor | dict[str, AttentionProcessor])

Source from the content-addressed store, hash-verified

62 return processors
63
64 def set_attn_processor(self, processor: AttentionProcessor | dict[str, AttentionProcessor]):
65 r"""
66 Sets the attention processor to use to compute attention.
67
68 Parameters:
69 processor (`dict` of `AttentionProcessor` or only `AttentionProcessor`):
70 The instantiated processor class or a dictionary of processor classes that will be set as the processor
71 for **all** `Attention` layers.
72
73 If `processor` is a dict, the key needs to define the path to the corresponding cross attention
74 processor. This is strongly recommended when setting trainable attention processors.
75
76 """
77 count = len(self.attn_processors.keys())
78
79 if isinstance(processor, dict) and len(processor) != count:
80 raise ValueError(
81 f"A dict of processors was passed, but the number of processors {len(processor)} does not match the"
82 f" number of attention layers: {count}. Please make sure to pass {count} processor classes."
83 )
84
85 def fn_recursive_attn_processor(name: str, module: torch.nn.Module, processor):
86 if hasattr(module, "set_processor"):
87 if not isinstance(processor, dict):
88 module.set_processor(processor)
89 else:
90 module.set_processor(processor.pop(f"{name}.processor"))
91
92 for sub_name, child in module.named_children():
93 fn_recursive_attn_processor(f"{name}.{sub_name}", child, processor)
94
95 for name, module in self.named_children():
96 fn_recursive_attn_processor(name, module, processor)
97
98 def fuse_qkv_projections(self):
99 """

Callers 15

load_attn_procsMethod · 0.45
unload_ip_adapterMethod · 0.45
unload_ip_adapterMethod · 0.45
unload_ip_adapterMethod · 0.45
unload_ip_adapterMethod · 0.45
convert_modelsFunction · 0.45
make_transformerFunction · 0.45

Calls

no outgoing calls