Travis “Target13” Lee
Target13
·
AI & ML interests
Target13/Reinforce-PixelCopter/
├── model.pt # Trained PyTorch policy network
├── hyperparameters.json # Training config (h_size=64, lr=1e-4, etc.)
├── results.json # Eval metrics (mean_reward, std)
├── replay.mp4 # Agent gameplay video (30 FPS)
└── README.md # Auto-generated model card
def push_to_hub(repo_id, model, hyperparameters, eval_env, video_fps=30):
# Full pipeline as shown above
# ...
api.upload_folder(repo_id=repo_id, folder_path=local_dir)
# Call after training
push_to_hub("Target13@huntresslabs/Reinforce-PixelCopter-v0", pixelcopter_policy, hypers, eval_env)HfApi().upload_folder.��push_to_hub is the Hugging Face utility function that uploads trained RL agents from the Deep RL Course directly to the Hub, automating evaluation, video recording, model card generation, and repo creation.��How it worksIt performs a full pipeline in one call:Evaluates the agent on a test environment and saves metrics (mean reward, std, eval datetime) to results.json.Saves the model (e.g., model.pt or .zip), hyperparameters to JSON, and records a replay video (replay.mp4).Generates a Model Card (README.md) with tags, metrics, and environment info using metadata_save.Creates a git repo on the Hub and pushes everything via HfApi().upload_folder.��Quick setup in Colab# Login (one-time)
from huggingface_hub import notebook_login
notebook_login() # Enter your HF token
# Install (if needed)
!pip install huggingface_sb3 stable-baselines3Usage examples from the courseStable Baselines3 / RL Zoo3from rl_zoo3 import push_to_hub # Or huggingface_sb3.push_to_hub
# For a trained model zip file
push_to_hub(
repo_id="yourusername/ppo-LunarLander-v2",
filename="ppo-LunarLander-v2.zip",
commit_message="PPO LunarLander model"
)Or for full packaging:# package_to_hub(model, repo_id, eval_env, hyperparameters)Custom PyTorch model (Unit 4 example)def push_to_hub(repo_id, model, hyperparameters, eval_env, video_fps=30):
# Full pipeline as shown above
# ...
api.upload_folder(repo_id=repo_id, folder_path=local_dir)
# Call after training
push_to_hub("yourusername/Reinforce-PixelCopter-v0", pixelcopter_policy, hypers, eval_env)This creates a repo like https://huggingface.co/yourusername/Reinforce-PixelCopter-v0 with video, metrics, and model files ready to load.�Key benefits for RLShowcase agents: Instant model cards with eval metrics and replay videos.Community sharing: Others can load_from_hub(repo_id) your agent.Leaderboard integration (historical): Auto-submitted scores to course leaderboards.��Common issues & fixesEndless loop / hanging: Use huggingface-cli login locally; check Git LFS setup (git lfs push origin main).��Auth: Generate a token at https://huggingface.co/settings/tokens with "write" scope.�Your trained agent repo will be instantly shareable and playable via the Hub viewer. Need a full code snippet for a specific algo/environment?