def edit_files_for_hf_compatibility(
    folder: str,
    flatten_imports_prefix: Sequence[str] = ('llmfoundry',),
    remove_imports_prefix: Sequence[str] = (
        'composer',
        'omegaconf',
        'llmfoundry.metrics',
        'llmfoundry.eval',
        'llmfoundry.utils.builders',
    ),
) -> None:
    """Edit files to be compatible with Hugging Face Hub.

    Args:
        folder (str): The folder to process.
        flatten_imports_prefix (Sequence[str], optional): Sequence of prefixes to flatten. Defaults to ('llmfoundry',).
        remove_imports_prefix (Sequence[str], optional): Sequence of prefixes to remove. Takes precedence over flattening.
            Defaults to ('composer', 'omegaconf', 'llmfoundry.metrics', 'llmfoundry.utils.builders').
    """
    listed_dir = os.listdir(folder)

    # Try to acquire the config file to determine which python file is the entrypoint file
    config_file_exists = 'config.json' in listed_dir
    with open(os.path.join(folder, 'config.json'), 'r') as _f:
        config = json.load(_f)

    # If the config file exists, the entrypoint files would be specified in the auto map
    entrypoint_files = set()
    if config_file_exists:
        for value in config.get('auto_map', {}).values():
            split_path = value.split('.')
            if len(split_path) > 1:
                entrypoint_files.add(split_path[0] + '.py')

    files_to_process = [
        os.path.join(folder, filename)
        for filename in listed_dir
        if filename.endswith('.py')
    ]
    files_processed_and_queued = set(files_to_process)

    while len(files_to_process) > 0:
        to_process = files_to_process.pop()
        if os.path.isfile(to_process) and to_process.endswith('.py'):
            to_add = process_file(
                to_process,
                folder,
                flatten_imports_prefix,
                remove_imports_prefix,
            )
            for file in to_add:
                if file not in files_processed_and_queued:
                    files_to_process.append(file)
                    files_processed_and_queued.add(file)

    # For each entrypoint, determine which imports are missing, and add them
    # This is because HF does not recursively search imports when determining
    # which files to copy into its modules cache
    all_relative_imports = {
        os.path.splitext(os.path.basename(f))[0]
        for f in files_processed_and_queued
    }
    # Filter out __init__ files
    all_relative_imports = {
        relative_import for relative_import in all_relative_imports
        if relative_import not in {'__init__', 'modeling_mpt'}
    }
    for entrypoint in entrypoint_files:
        file_path = os.path.join(folder, entrypoint)
        if not os.path.exists(file_path):
            continue
        existing_relative_imports = get_all_relative_imports(
            os.path.join(folder, entrypoint),
        )
        # Add in all entrypoints so we don't create a circular import
        for sub_entrypoint in entrypoint_files:
            existing_relative_imports.add(os.path.splitext(sub_entrypoint)[0])
        missing_relative_imports = all_relative_imports - existing_relative_imports
        add_relative_imports(
            os.path.join(folder, entrypoint),
            missing_relative_imports,
        )
Edit files to be compatible with Hugging Face Hub.

    Args:
        folder (str): The folder to process.
        flatten_imports_prefix (Sequence[str], optional): Sequence of prefixes to flatten. Defaults to ('llmfoundry',).
        remove_imports_prefix (Sequence[str], optional): Sequence of prefixes to remove. Takes precedence over flattening.
            Defaults to ('composer', 'omegaconf', 'llmfoundry.metrics', 'llmfoundry.utils.builders').
    
llmfoundry/utils/huggingface_hub_utils.py