From 0506d51b28e8d5c3a038a8e000ca37375ebf56dd Mon Sep 17 00:00:00 2001 From: simoninithomas Date: Mon, 5 Dec 2022 13:41:34 +0100 Subject: [PATCH] Update the notebook with Omar's feedback --- units/en/unitbonus1/train.mdx | 87 +++++++++++++++-------------------- 1 file changed, 38 insertions(+), 49 deletions(-) diff --git a/units/en/unitbonus1/train.mdx b/units/en/unitbonus1/train.mdx index e8fe982..9adef4c 100644 --- a/units/en/unitbonus1/train.mdx +++ b/units/en/unitbonus1/train.mdx @@ -11,7 +11,7 @@ Bonus Unit 1Thumbnail -In this notebook, we'll reinforce what we learn in the first Unit by **teaching Huggy the Dog to fetch the stick and then play with it directly in your browser** +In this notebook, we'll reinforce what we learned in the first Unit by **teaching Huggy the Dog to fetch the stick and then play with it directly in your browser** ⬇️ Here is an example of what **you will achieve at the end of the unit.** ⬇️ (launch ▶ to see) @@ -39,24 +39,6 @@ At the end of the notebook, you will: - Be able to play **with your trained Huggy directly in your browser**. - - -## This notebook is from Deep Reinforcement Learning Course -Deep RL Course illustration - -In this free course, you will: - -- 📖 Study Deep Reinforcement Learning in **theory and practice**. -- 🧑‍💻 Learn to **use famous Deep RL libraries** such as Stable Baselines3, RL Baselines3 Zoo, CleanRL and Sample Factory 2.0. -- 🤖 Train **agents in unique environments** - -And more check 📚 the syllabus 👉 https://simoninithomas.github.io/deep-rl-course - -Don’t forget to **sign up to the course** (we are collecting your email to be able to **send you the links when each Unit is published and give you information about the challenges and updates).** - - -The best way to keep in touch is to join our discord server to exchange with the community and with us 👉🏻 https://discord.gg/ydHrjt3WP5 - ## Prerequisites 🏗️ Before diving into the notebook, you need to: @@ -65,22 +47,29 @@ Before diving into the notebook, you need to: 🔲 📚 **Read the introduction to Huggy** by doing Bonus Unit 1 +## Set the GPU 💪 +- To **accelerate the agent's training, we'll use a GPU**. To do that, go to `Runtime > Change Runtime type` + +GPU Step 1 + +- `Hardware Accelerator > GPU` + +GPU Step 2 + ## Clone the repository and install the dependencies 🔽 - We need to clone the repository, that **contains the experimental version of the library that allows you to push your trained agent to the Hub.** -```python -%%capture +```bash # Clone this specific repository (can take 3min) -!git clone https://github.com/huggingface/ml-agents/ +git clone https://github.com/huggingface/ml-agents/ ``` -```python -%%capture +```bash # Go inside the repository and install the package (can take 3min) %cd ml-agents -!pip3 install -e ./ml-agents-envs -!pip3 install -e ./ml-agents +pip3 install -e ./ml-agents-envs +pip3 install -e ./ml-agents ``` ## Download and move the environment zip file in `./trained-envs-executables/linux/` @@ -88,26 +77,26 @@ Before diving into the notebook, you need to: - Our environment executable is in a zip file. - We need to download it and place it to `./trained-envs-executables/linux/` -```python -!mkdir ./trained-envs-executables -!mkdir ./trained-envs-executables/linux +```bash +mkdir ./trained-envs-executables +mkdir ./trained-envs-executables/linux ``` -```python -!wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1zv3M95ZJTWHUVOWT6ckq_cm98nft8gdF' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=1zv3M95ZJTWHUVOWT6ckq_cm98nft8gdF" -O ./trained-envs-executables/linux/Huggy.zip && rm -rf /tmp/cookies.txt +```bash +wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1zv3M95ZJTWHUVOWT6ckq_cm98nft8gdF' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=1zv3M95ZJTWHUVOWT6ckq_cm98nft8gdF" -O ./trained-envs-executables/linux/Huggy.zip && rm -rf /tmp/cookies.txt ``` Download the file Huggy.zip from https://drive.google.com/uc?export=download&id=1zv3M95ZJTWHUVOWT6ckq_cm98nft8gdF using `wget`. Check out the full solution to download large files from GDrive [here](https://bcrf.biochem.wisc.edu/2021/02/05/download-google-drive-files-using-wget/) -```python +```bash %%capture -!unzip -d ./trained-envs-executables/linux/ ./trained-envs-executables/linux/Huggy.zip +unzip -d ./trained-envs-executables/linux/ ./trained-envs-executables/linux/Huggy.zip ``` Make sure your file is accessible -```python -!chmod -R 755 ./trained-envs-executables/linux/Huggy +```bash +chmod -R 755 ./trained-envs-executables/linux/Huggy ``` ## Let's recap how this environment works @@ -147,13 +136,13 @@ Our reward function: - *Rotation penalty*: we penalize Huggy if **he spins too much and turns too quickly**. - *Getting to the target reward*: we reward Huggy for **reaching the target**. -## Check the Huggy config file +## Check the Huggy config file - In ML-Agents, you define the **training hyperparameters into config.yaml files.** -- For the scope of this notebook, we're not going to modify the hyperparameters but if you want to try as an experimentation, you should also try to modify some other hyperparameters, Unity provides a very [good documentation explaining each of them here](https://github.com/Unity-Technologies/ml-agents/blob/main/docs/Training-Configuration-File.md). +- For the scope of this notebook, we're not going to modify the hyperparameters, but if you want to try as an experiment, you should also try to modify some other hyperparameters, Unity provides very [good documentation explaining each of them here](https://github.com/Unity-Technologies/ml-agents/blob/main/docs/Training-Configuration-File.md). -- Click here to open the config.yaml: `/content/ml-agents/config/ppo/Huggy.yaml` +- **In the case you want to modify the hyperparameters**, in Google Colab notebook, you can click here to open the config.yaml: `/content/ml-agents/config/ppo/Huggy.yaml` We’re now ready to train our agent 🔥. @@ -164,7 +153,7 @@ To train our agent, we just need to **launch mlagents-learn and select the execu ml learn function -We define four parameters: +With ML Agents, we run a training script. We define four parameters: 1. `mlagents-learn `: the path where the hyperparameter config file is. 2. `--env`: where the environment executable is. @@ -177,10 +166,10 @@ Train the model and use the `--resume` flag to continue training in case of inte -The training will take 30 to 45min depending on your machine, go take a ☕️you deserve it 🤗. +The training will take 30 to 45min depending on your machine (don't forget to **set up a GPU**), go take a ☕️you deserve it 🤗. -```python -!mlagents-learn ./config/ppo/Huggy.yaml --env=./trained-envs-executables/linux/Huggy/Huggy --run-id="Huggy" --no-graphics +```bash +mlagents-learn ./config/ppo/Huggy.yaml --env=./trained-envs-executables/linux/Huggy/Huggy --run-id="Huggy" --no-graphics ``` ## Push the agent to the 🤗 Hub @@ -219,8 +208,8 @@ And we define 4 parameters: If the repo does not exist **it will be created automatically** 4. `--commit-message`: since HF repos are git repository you need to define a commit message. -```python -!mlagents-push-to-hf --run-id="HuggyTraining" --local-dir="./results/Huggy" --repo-id="ThomasSimonini/ppo-Huggy" --commit-message="Huggy" +```bash +mlagents-push-to-hf --run-id="HuggyTraining" --local-dir="./results/Huggy" --repo-id="ThomasSimonini/ppo-Huggy" --commit-message="Huggy" ``` Else, if everything worked you should have this at the end of the process(but with a different url 😆) : @@ -231,7 +220,7 @@ Else, if everything worked you should have this at the end of the process(but wi Your model is pushed to the hub. You can view your model here: https://huggingface.co/ThomasSimonini/ppo-Huggy ``` -It’s the link to your model, it contains a model card that explains how to use it, your Tensorboard and your config file. **What’s awesome is that it’s a git repository, that means you can have different commits, update your repository with a new push etc.** +It’s the link to your model repository. The repository contains a model card that explains how to use the model, your Tensorboard logs and your config file. **What’s awesome is that it’s a git repository, which means you can have different commits, update your repository with a new push, open Pull Requests, etc.** ml learn function @@ -239,7 +228,7 @@ But now comes the best: **being able to play with Huggy online 👀.** ## Play with your Huggy 🐕 -For this step it’s simple: +This step is the simplest: - Open the game Huggy in your browser: https://huggingface.co/spaces/ThomasSimonini/Huggy @@ -250,10 +239,10 @@ For this step it’s simple: 1. In step 1, choose your model repository which is the model id (in my case ThomasSimonini/ppo-Huggy). 2. In step 2, **choose what model you want to replay**: - - I have multiple one, since we saved a model every 500000 timesteps. - - But if I want the more recent I choose Huggy.onnx + - I have multiple ones, since we saved a model every 500000 timesteps. + - But since I want the more recent, I choose `Huggy.onnx` -👉 What’s nice **is to try with different models step to see the improvement of the agent.** +👉 What’s nice **is to try with different models steps to see the improvement of the agent.** Congrats on finishing this bonus unit!