utils/create_dummy_models.py/upload_model
def upload_model(model_dir, organization):
    """Upload the tiny models"""

    arch_name = model_dir.split(os.path.sep)[-1]
    repo_name = f"tiny-random-{arch_name}"

    repo_exist = False
    error = None
    try:
        create_repo(repo_id=f"{organization}/{repo_name}", exist_ok=False, repo_type="model")
    except Exception as e:
        error = e
        if "You already created" in str(e):
            error = None
            logger.warning("Remote repository exists and will be cloned.")
            repo_exist = True
            try:
                create_repo(repo_id=repo_name, organization=organization, exist_ok=True, repo_type="model")
            except Exception as e:
                error = e
    if error is not None:
        raise error

    with tempfile.TemporaryDirectory() as tmpdir:
        repo = Repository(local_dir=tmpdir, clone_from=f"{organization}/{repo_name}")
        repo.git_pull()
        shutil.copytree(model_dir, tmpdir, dirs_exist_ok=True)

        if repo_exist:
            # Open a PR on the existing Hub repo.
            hub_pr_url = upload_folder(
                folder_path=model_dir,
                repo_id=f"{organization}/{repo_name}",
                repo_type="model",
                commit_message=f"Update tiny models for {arch_name}",
                commit_description=f"Upload tiny models for {arch_name}",
                create_pr=True,
            )
            logger.warning(f"PR open in {hub_pr_url}.")
        else:
            # Push to Hub repo directly
            repo.git_add(auto_lfs_track=True)
            repo.git_commit(f"Upload tiny models for {arch_name}")
            repo.git_push(blocking=True)  # this prints a progress bar with the upload
            logger.warning(f"Tiny models {arch_name} pushed to {organization}/{repo_name}.")