Update utils.py

This commit is contained in:
Aseem Saxena 2025-04-24 13:10:37 -07:00 committed by GitHub
parent 5fe4119d53
commit 88644341ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -118,16 +118,16 @@ def state_dict_key_replace(state_dict, keys_to_replace):
return state_dict
def state_dict_prefix_replace(state_dict, replace_prefix, filter_keys=False):
if not filter_keys:
return {}
else:
out = state_dict
if filter_keys:
out = {}
for old_prefix, new_prefix in replace_prefix.items():
keys_to_replace = [key for key in state_dict if key.startswith(old_prefix)]
for key in keys_to_replace:
new_key = new_prefix + key[len(old_prefix):]
out[new_key] = state_dict.pop(key)
return out
else:
out = state_dict
return out
def transformers_convert(sd, prefix_from, prefix_to, number):