def convert_old_keys_to_new_keys(state_dict_keys: dict, keys_mapping: dict):
    """
    This function should be applied only once, on the concatenated keys to efficiently rename using
    the key mappings.
    """
    output_dict = {}
    if state_dict_keys is not None:
        old_text = "\n".join(state_dict_keys)
        new_text = old_text
        for pattern, replacement in keys_mapping.items():
            if replacement is None:
                new_text = re.sub(pattern, "", new_text)  # an empty line
                continue
            new_text = re.sub(pattern, replacement, new_text)
        output_dict = dict(zip(old_text.split("\n"), new_text.split("\n")))
    return output_dict

    This function should be applied only once, on the concatenated keys to efficiently rename using
    the key mappings.
    
scripts/models-conversions/upernet-hf-to-smp.py