Skip to content

Commit

Permalink
Adding a notebook for Unity executables on SageMaker RL (aws#1489)
Browse files Browse the repository at this point in the history
* minor changes on launcher script

* Adding a sample notebook for Unity executables with SageMaker RL

* update README; update notebook intro; update Dockerfile and train preset

Co-authored-by: yoheigon <[email protected]>
Co-authored-by: henryyuanheng-wang <[email protected]>
  • Loading branch information
3 people authored Sep 16, 2020
1 parent 137d40e commit 93ce04f
Show file tree
Hide file tree
Showing 9 changed files with 875 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ The following provide examples demonstrating different capabilities of Amazon Sa
- [Stable Baselines](reinforcement_learning/rl_roboschool_stable_baselines) In this notebook example, we will make the HalfCheetah agent learn to walk using the stable-baselines, which are a set of improved implementations of Reinforcement Learning (RL) algorithms based on OpenAI Baselines.
- [Travelling Salesman](reinforcement_learning/rl_traveling_salesman_vehicle_routing_coach) is a classic NP hard problem, which this notebook solves with AWS SageMaker RL.
- [Tic-tac-toe](reinforcement_learning/rl_tic_tac_toe_coach_customEnv) is a simple implementation of a custom Gym environment to train and deploy an RL agent in Coach that then plays tic-tac-toe interactively in a Jupyter Notebook.
- [Unity Game Agent](reinforcement_learning/rl_unity_ray) shows how to use RL algorithms to train an agent to play Unity3D game.

### Scientific Details of Algorithms

Expand Down
1 change: 1 addition & 0 deletions reinforcement_learning/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ These examples demonstrate how to train reinforcement learning models on SageMak
- [Tic-tac-toe](rl_tic_tac_toe_coach_customEnv) uses RL to train a policy and then plays locally and interactively within the notebook.
- [Traveling Salesman and Vehicle Routing](rl_traveling_salesman_vehicle_routing_coach) is an example of using RL to address operations research problems.
- [Game Server Auto-pilot](rl_game_server_autopilot) Reduce player wait time by autoscaling game-servers deployed in EKS cluster using RL to add and remove EC2 instances as per dynamic player usage.
- [Unity Game Agent](rl_unity_ray) shows how to use RL algorithms to train an agent to play Unity3D game.

### FAQ
https://github.com/awslabs/amazon-sagemaker-examples#faq
2 changes: 1 addition & 1 deletion reinforcement_learning/common/sagemaker_rl/ray_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def get_all_host_names(self):

def ray_init_config(self):
num_workers = max(self.num_cpus, 3)
config = {"num_cpus": num_workers, "num_gpus": self.num_gpus}
config = {"num_cpus": num_workers, "num_gpus": self.num_gpus, "webui_host": '127.0.0.1'}

if self.is_master_node:
all_wokers_host_names = self.get_all_host_names()[1:]
Expand Down
25 changes: 25 additions & 0 deletions reinforcement_learning/rl_unity_ray/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ARG CPU_OR_GPU
ARG AWS_REGION
FROM 462105765813.dkr.ecr.${AWS_REGION}.amazonaws.com/sagemaker-rl-ray-container:ray-0.8.2-tf-${CPU_OR_GPU}-py36

WORKDIR /opt/ml

# Unity dependencies

RUN pip install --upgrade \
pip \
gym-unity \
mlagents-envs

RUN pip install sagemaker-containers --upgrade

ENV PYTHONUNBUFFERED 1

############################################
# Test Installation
############################################
# Test to verify if all required dependencies installed successfully or not.
RUN python -c "import gym;import sagemaker_containers.cli.train;import ray; from sagemaker_containers.cli.train import main; from mlagents_envs.environment import UnityEnvironment; from mlagents_envs.registry import default_registry; from gym_unity.envs import UnityToGymWrapper"

# Make things a bit easier to debug
WORKDIR /opt/ml/code
13 changes: 13 additions & 0 deletions reinforcement_learning/rl_unity_ray/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Unity3D Game with Amazon SageMaker RL

This folder contains examples of how to use RL to train an agent to play Unity3D game using Amazon SageMaker Reinforcement Learning. Customer can choose using [example environment](https://github.com/Unity-Technologies/ml-agents/blob/742c2fbf01188fbf27e82d5a7d9b5fd42f0de67a/docs/Learning-Environment-Examples.md) provided by Unity Toolkit or bring their own customized Unity executables.


## Contents

* `rl_unity_ray.ipynb`: notebook for training an RL agent.


* `src/`
* `train-unity.py`: Entrypoint file to starting a training job
* `evaluate-unity.py`: Entrypoint file to starting a evaluation job
1 change: 1 addition & 0 deletions reinforcement_learning/rl_unity_ray/common
Loading

0 comments on commit 93ce04f

Please sign in to comment.