import os import torch import hashlib import datetime from collections import OrderedDict def replace_keys_in_dict(d, old_key_part, new_key_part): # Use OrderedDict if the original is an OrderedDict if isinstance(d, OrderedDict): updated_dict = OrderedDict() else: updated_dict = {} for key, value in d.items(): # Replace the key part if found new_key = key.replace(old_key_part, new_key_part) # If the value is a dictionary, apply the function recursively if isinstance(value, dict): value = replace_keys_in_dict(value, old_key_part, new_key_part) updated_dict[new_key] = value return updated_dict