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 use of 'Repository' when pushing to hub with HfApi #462

Closed
wants to merge 9 commits into from
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
### New Features

### Bug fixes
- Replaced deprecated use of `Repository` when pushing to huggingface hub by the
recommended `HfApi` (see https://huggingface.co/docs/huggingface_hub/concepts/git_vs_http).

### Documentation

Expand Down Expand Up @@ -92,6 +94,7 @@
- Huggingface push to hub now accepts a `--n-timesteps` argument to adjust the length of the video
- Fixed `record_video` steps (before it was stepping in a closed env)


## Release 1.8.0 (2023-04-07)

**New Documentation, Multi-Env HerReplayBuffer**
Expand Down
17 changes: 9 additions & 8 deletions rl_zoo3/push_to_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,10 @@ def package_to_hub(
private=False,
exist_ok=True,
)

# Git pull
repo_local_path = Path(local_repo_path) / repo_name
repo = Repository(repo_local_path, clone_from=repo_url)
repo.git_pull(rebase=True)

repo.lfs_track(["*.mp4"])

# Retrieve current repo state
api.hf_hub_download(repo_id=repo_id, local_dir=local_repo_path)
# Step 1: Save the model
print("Saving model to:", repo_local_path / model_name)
model.save(repo_local_path / model_name)
Expand Down Expand Up @@ -269,8 +265,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 Expand Up @@ -378,6 +373,12 @@ def package_to_hub(
env_kwargs=env_kwargs,
)

if is_atari:
# Patch Atari for rendering
# see https://github.com/mgbellemare/Arcade-Learning-Environment/pull/476
eval_env.unwrapped.render_mode = env_kwargs.get("render_mode")
eval_env.render_mode = env_kwargs.get("render_mode")

kwargs = dict(seed=args.seed)
if algo in off_policy_algos:
# Dummy buffer size as we don't need memory to enjoy the trained agent
Expand Down
6 changes: 6 additions & 0 deletions rl_zoo3/record_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@
if video_folder is None:
video_folder = os.path.join(log_path, "videos")

if is_atari:
# Patch Atari for rendering
# see https://github.com/mgbellemare/Arcade-Learning-Environment/pull/476
env.unwrapped.render_mode = env_kwargs.get("render_mode")
env.render_mode = env_kwargs.get("render_mode")

# Note: apparently it renders by default
env = VecVideoRecorder(
env,
Expand Down
Loading