Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated huggingface_hub.Repository by HfApi #465

Merged
merged 6 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### New Features

### Bug fixes
- Replaced deprecated `huggingface_hub.Repository` when pushing to Hugging Face Hub by the recommended `HfApi` (see https://huggingface.co/docs/huggingface_hub/concepts/git_vs_http) (@cochaviz)

### Documentation

Expand Down
14 changes: 8 additions & 6 deletions rl_zoo3/push_to_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,15 @@ def package_to_hub(
private=False,
exist_ok=True,
)

# Git pull
# Retrieve current repo state
repo_local_path = Path(local_repo_path) / repo_name
repo = Repository(repo_local_path, clone_from=repo_url)
repo.git_pull(rebase=True)
api.snapshot_download(repo_id=repo_id, local_dir=repo_local_path)

repo.lfs_track(["*.mp4"])
qgallouedec marked this conversation as resolved.
Show resolved Hide resolved
# Add mp4 files to .gitattributes
with open(repo_local_path / ".gitattributes", "a+") as f:
f.seek(0) # Move the file pointer to the beginning of the file
if not any("*.mp4" in line for line in f):
araffin marked this conversation as resolved.
Show resolved Hide resolved
f.write("*.mp4 filter=lfs diff=lfs merge=lfs -text\n")

# Step 1: Save the model
print("Saving model to:", repo_local_path / model_name)
Expand Down Expand Up @@ -269,7 +271,7 @@ def package_to_hub(
save_model_card(repo_local_path, generated_model_card, metadata)

msg.info(f"Pushing repo {repo_name} to the Hugging Face Hub")
repo.push_to_hub(commit_message=commit_message)
api.upload_folder(repo_id=repo_id, folder_path=repo_local_path, commit_message=commit_message)

msg.info(f"Your model is pushed to the hub. You can view your model here: {repo_url}")
return repo_url
Expand Down
Loading