Skip to content

Commit c037db0

Browse files
Wauplinrwightman
authored andcommitted
Create repo before cloning with Repository.clone_from
1 parent 3ec5918 commit c037db0

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

timm/models/hub.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,25 +130,28 @@ def push_to_hf_hub(
130130
revision=None,
131131
model_config=None,
132132
):
133+
if isinstance(use_auth_token, str):
134+
token = use_auth_token
135+
else:
136+
token = HfFolder.get_token()
137+
if token is None:
138+
raise ValueError(
139+
"You must login to the Hugging Face hub on this computer by typing `huggingface-cli login` and "
140+
"entering your credentials to use `use_auth_token=True`. Alternatively, you can pass your own "
141+
"token as the `use_auth_token` argument."
142+
)
143+
133144
if repo_namespace_or_url:
134145
repo_owner, repo_name = repo_namespace_or_url.rstrip('/').split('/')[-2:]
135146
else:
136-
if isinstance(use_auth_token, str):
137-
token = use_auth_token
138-
else:
139-
token = HfFolder.get_token()
140-
141-
if token is None:
142-
raise ValueError(
143-
"You must login to the Hugging Face hub on this computer by typing `transformers-cli login` and "
144-
"entering your credentials to use `use_auth_token=True`. Alternatively, you can pass your own "
145-
"token as the `use_auth_token` argument."
146-
)
147-
148147
repo_owner = HfApi().whoami(token)['name']
149148
repo_name = Path(local_dir).name
150149

151-
repo_url = f'https://huggingface.co/{repo_owner}/{repo_name}'
150+
repo_id = f'{repo_owner}/{repo_name}'
151+
repo_url = f'https://huggingface.co/{repo_id}'
152+
153+
# Create repo if doesn't exist yet
154+
HfApi().create_repo(repo_id, token=use_auth_token, exist_ok=True)
152155

153156
repo = Repository(
154157
local_dir,

0 commit comments

Comments
 (0)