|
| 1 | +# The Hugging Face Integration |
| 2 | + |
| 3 | +The [Hugging Face Hub 🤗](https://huggingface.co/models?pipeline_tag=reinforcement-learning) is a central place **where anyone can share and download models**. |
| 4 | + |
| 5 | +It allows you to: |
| 6 | +- **Host** your trained models. |
| 7 | +- **Download** trained models from the community. |
| 8 | +- Visualize your agents **playing directly on your browser**. |
| 9 | + |
| 10 | +You can see the list of ml-agents models [here](https://huggingface.co/models?library=ml-agents). |
| 11 | + |
| 12 | +We wrote a **complete tutorial to learn to train your first agent using ML-Agents and publish it to the Hub**: |
| 13 | + |
| 14 | +- A short tutorial where you [teach **Huggy the Dog to fetch the stick** and then play with him directly in your browser](https://huggingface.co/learn/deep-rl-course/unitbonus1/introduction) |
| 15 | +- A [more in-depth tutorial](https://huggingface.co/learn/deep-rl-course/unit5/introduction) |
| 16 | + |
| 17 | +## Download a model from the Hub |
| 18 | + |
| 19 | +You can simply download a model from the Hub using `mlagents-load-from-hf`. |
| 20 | + |
| 21 | +You need to define two parameters: |
| 22 | + |
| 23 | +- `--repo-id`: the name of the Hugging Face repo you want to download. |
| 24 | +- `--local-dir`: the path to download the model. |
| 25 | + |
| 26 | +For instance, I want to load the model with model-id "ThomasSimonini/MLAgents-Pyramids" and put it in the downloads directory: |
| 27 | + |
| 28 | +```sh |
| 29 | +mlagents-load-from-hf --repo-id="ThomasSimonini/MLAgents-Pyramids" --local-dir="./downloads" |
| 30 | +``` |
| 31 | + |
| 32 | +## Upload a model to the Hub |
| 33 | + |
| 34 | +You can simply upload a model to the Hub using `mlagents-push-to-hf` |
| 35 | + |
| 36 | +You need to define four parameters: |
| 37 | + |
| 38 | +- `--run-id`: the name of the training run id. |
| 39 | +- `--local-dir`: where the model was saved |
| 40 | +- `--repo-id`: the name of the Hugging Face repo you want to create or update. It’s always <your huggingface username>/<the repo name> If the repo does not exist it will be created automatically |
| 41 | +- `--commit-message`: since HF repos are git repositories you need to give a commit message. |
| 42 | + |
| 43 | +For instance, I want to upload my model trained with run-id "SnowballTarget1" to the repo-id: ThomasSimonini/ppo-SnowballTarget: |
| 44 | + |
| 45 | +```sh |
| 46 | + mlagents-push-to-hf --run-id="SnowballTarget1" --local-dir="./results/SnowballTarget1" --repo-id="ThomasSimonini/ppo-SnowballTarget" --commit-message="First Push" |
| 47 | +``` |
| 48 | + |
| 49 | +## Visualize an agent playing |
| 50 | + |
| 51 | +You can watch your agent playing directly in your browser (if the environment is from the [ML-Agents official environments](Learning-Environment-Examples.md)) |
| 52 | + |
| 53 | +- Step 1: Go to https://huggingface.co/unity and select the environment demo. |
| 54 | +- Step 2: Find your model_id in the list. |
| 55 | +- Step 3: Select your .nn /.onnx file. |
| 56 | +- Step 4: Click on Watch the agent play |
0 commit comments