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

Function transform_conv_attns

scripts/convert_dance_diffusion_to_diffusers.py:238–255  ·  view source on GitHub ↗
(new_state_dict, new_k, v)

Source from the content-addressed store, hash-verified

236
237
238def transform_conv_attns(new_state_dict, new_k, v):
239 if len(new_k) == 1:
240 if len(v.shape) == 3:
241 # weight
242 new_state_dict[new_k[0]] = v[:, :, 0]
243 else:
244 # bias
245 new_state_dict[new_k[0]] = v
246 else:
247 # qkv matrices
248 trippled_shape = v.shape[0]
249 single_shape = trippled_shape // 3
250 for i in range(3):
251 if len(v.shape) == 3:
252 new_state_dict[new_k[i]] = v[i * single_shape : (i + 1) * single_shape, :, 0]
253 else:
254 new_state_dict[new_k[i]] = v[i * single_shape : (i + 1) * single_shape]
255 return new_state_dict
256
257
258def main(args):

Callers 1

rename_orig_weightsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected