MCPcopy Create free account
hub / github.com/TencentARC/BrushNet / prior_attention_to_diffusers

Function prior_attention_to_diffusers

scripts/convert_shap_e_to_diffusers.py:169–201  ·  view source on GitHub ↗
(
    checkpoint, *, diffusers_attention_prefix, original_attention_prefix, attention_head_dim
)

Source from the content-addressed store, hash-verified

167
168
169def prior_attention_to_diffusers(
170 checkpoint, *, diffusers_attention_prefix, original_attention_prefix, attention_head_dim
171):
172 diffusers_checkpoint = {}
173
174 # <original>.c_qkv -> <diffusers>.{to_q, to_k, to_v}
175 [q_weight, k_weight, v_weight], [q_bias, k_bias, v_bias] = split_attentions(
176 weight=checkpoint[f"{original_attention_prefix}.c_qkv.weight"],
177 bias=checkpoint[f"{original_attention_prefix}.c_qkv.bias"],
178 split=3,
179 chunk_size=attention_head_dim,
180 )
181
182 diffusers_checkpoint.update(
183 {
184 f"{diffusers_attention_prefix}.to_q.weight": q_weight,
185 f"{diffusers_attention_prefix}.to_q.bias": q_bias,
186 f"{diffusers_attention_prefix}.to_k.weight": k_weight,
187 f"{diffusers_attention_prefix}.to_k.bias": k_bias,
188 f"{diffusers_attention_prefix}.to_v.weight": v_weight,
189 f"{diffusers_attention_prefix}.to_v.bias": v_bias,
190 }
191 )
192
193 # <original>.c_proj -> <diffusers>.to_out.0
194 diffusers_checkpoint.update(
195 {
196 f"{diffusers_attention_prefix}.to_out.0.weight": checkpoint[f"{original_attention_prefix}.c_proj.weight"],
197 f"{diffusers_attention_prefix}.to_out.0.bias": checkpoint[f"{original_attention_prefix}.c_proj.bias"],
198 }
199 )
200
201 return diffusers_checkpoint
202
203
204def prior_ff_to_diffusers(checkpoint, *, diffusers_ff_prefix, original_ff_prefix):

Calls 2

split_attentionsFunction · 0.70
updateMethod · 0.45

Tested by

no test coverage detected