MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / renew_attention_paths

Function renew_attention_paths

diffusers/scripts/convert_svd_to_diffusers.py:186–210  ·  view source on GitHub ↗

Updates paths inside attentions to the new naming scheme (local renaming)

(old_list, n_shave_prefix_segments=0)

Source from the content-addressed store, hash-verified

184
185
186def renew_attention_paths(old_list, n_shave_prefix_segments=0):
187 """
188 Updates paths inside attentions to the new naming scheme (local renaming)
189 """
190 mapping = []
191 for old_item in old_list:
192 new_item = old_item
193
194 # new_item = new_item.replace('norm.weight', 'group_norm.weight')
195 # new_item = new_item.replace('norm.bias', 'group_norm.bias')
196
197 # new_item = new_item.replace('proj_out.weight', 'proj_attn.weight')
198 # new_item = new_item.replace('proj_out.bias', 'proj_attn.bias')
199
200 # new_item = shave_segments(new_item, n_shave_prefix_segments=n_shave_prefix_segments)
201 new_item = new_item.replace("time_stack", "temporal_transformer_blocks")
202
203 new_item = new_item.replace("time_pos_embed.0.bias", "time_pos_embed.linear_1.bias")
204 new_item = new_item.replace("time_pos_embed.0.weight", "time_pos_embed.linear_1.weight")
205 new_item = new_item.replace("time_pos_embed.2.bias", "time_pos_embed.linear_2.bias")
206 new_item = new_item.replace("time_pos_embed.2.weight", "time_pos_embed.linear_2.weight")
207
208 mapping.append({"old": old_item, "new": new_item})
209
210 return mapping
211
212
213def shave_segments(path, n_shave_prefix_segments=1):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected