MCPcopy Index your code
hub / github.com/huggingface/diffusers / text_encoder_attn_modules

Function text_encoder_attn_modules

src/diffusers/loaders/__init__.py:33–51  ·  view source on GitHub ↗
(text_encoder)

Source from the content-addressed store, hash-verified

31if is_transformers_available():
32
33 def text_encoder_attn_modules(text_encoder):
34 deprecate(
35 "text_encoder_attn_modules in `models`",
36 "0.27.0",
37 "`text_encoder_lora_state_dict` is deprecated and will be removed in 0.27.0. Make sure to retrieve the weights using `get_peft_model`. See https://huggingface.co/docs/peft/v0.6.2/en/quicktour#peftmodel for more information.",
38 )
39 from transformers import CLIPTextModel, CLIPTextModelWithProjection
40
41 attn_modules = []
42
43 if isinstance(text_encoder, (CLIPTextModel, CLIPTextModelWithProjection)):
44 for i, layer in enumerate(text_encoder.text_model.encoder.layers):
45 name = f"text_model.encoder.layers.{i}.self_attn"
46 mod = layer.self_attn
47 attn_modules.append((name, mod))
48 else:
49 raise ValueError(f"do not know how to get attention modules for: {text_encoder.__class__.__name__}")
50
51 return attn_modules
52
53
54_import_structure = {}

Callers 1

Calls 1

deprecateFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…