Skip to content

Commit

Permalink
cloud integration
Browse files Browse the repository at this point in the history
  • Loading branch information
vwxyzjn committed May 12, 2021
1 parent 2f86b05 commit 0156ba2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 33 deletions.
26 changes: 8 additions & 18 deletions cleanrl/utils/submit_exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

parser = argparse.ArgumentParser(description='CleanRL Experiment Submission')
# experiment generation
parser.add_argument('--exp-script', type=str, default="exp.sh",
parser.add_argument('--exp-script', type=str, default="debug.sh",
help='the file name of this experiment')
parser.add_argument('--algo', type=str, default="ppo.py",
help='the algorithm that will be used')
Expand All @@ -22,15 +22,13 @@
help='total timesteps of the experiments')
parser.add_argument('--other-args', type=str, default="",
help="the entity (team) of wandb's project")
parser.add_argument('--wandb-project-name', type=str, default="cleanRL",
help="the wandb's project name")

# experiment submission
parser.add_argument('--job-queue', type=str, default="cleanrl",
help='the name of the job queue')
parser.add_argument('--wandb-key', type=str, default="",
help='the wandb key. If not provided, the script will try to read the env variable `WANDB_KEY`')
parser.add_argument('--docker-repo', type=str, default="vwxyzjn/gym-microrts:latest",
parser.add_argument('--docker-repo', type=str, default="vwxyzjn/cleanrl:latest",
help='the name of the job queue')
parser.add_argument('--job-definition', type=str, default="cleanrl",
help='the name of the job definition')
Expand All @@ -53,29 +51,21 @@

args = parser.parse_args()

template = '''
for seed in {{1..2}}
final_str = f'''
for seed in {{1..{args.num_seed}}}
do
(sleep 0.3 && nohup xvfb-run -a python {} \\
--gym-id {} \\
--total-timesteps {} \\
--wandb-project-name {} \\
(sleep 0.3 && nohup xvfb-run -a python {args.algo} \\
{args.other_args} \\
--seed $seed
--prod-mode \\
{} \\
--capture-video \\
--seed $seed
) >& /dev/null &
done
'''

final_str = ""
for env in args.gym_ids:
final_str += template.format(args.algo, env, args.total_timesteps, args.wandb_project_name, args.other_args)

with open(f"{args.exp_script}", "w+") as f:
f.write(final_str)


# get env variable values
if not args.wandb_key:
args.wandb_key = os.environ['WANDB_KEY']
Expand All @@ -96,7 +86,7 @@
final_run_cmds[-1] = ['curl', '-O', link, ';'] + final_run_cmds[-1]


run_ids = [wandb.util.generate_id() for _ in range (len(args.gym_ids)*args.num_seed)]
run_ids = [wandb.util.generate_id() for _ in range (args.num_seed)]

final_str = ""
cores = 40
Expand Down
53 changes: 38 additions & 15 deletions cloud/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,79 @@ easy to manage and reproducible, we use Terraform to spin up services.

```bash
wandb login
pip install cleanrl --upgrade
git clone https://github.com/vwxyzjn/cleanrl
cd cleanrl/cloud
terraform init
terraform apply
pip install awscli
python -m awscli authenticate

# submit a job using AWS's compute-optimized spot instances
python -m cleanrl.utils.submit_exp --exp-script ppo.sh \
--algo ppo.py \
# dry run to inspect the generated docker command
python -m cleanrl.utils.submit_exp --algo ppo.py \
--other-args "--gym-id CartPole-v0 --wandb-project-name cleanrl --total-timesteps 100000 --cuda True" \
--job-queue cpu_spot \
--job-definition cleanrl \
--num-seed 1 \
--num-vcpu 1 \
--num-memory 2000 \
--num-hours 48.0
```
The generated docker command should look like
```
docker run -d --cpuset-cpus="0" -e WANDB=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -e WANDB_RESUME=allow -e WANDB_RUN_ID=2avt9i7l vwxyzjn/cleanrl:latest /bin/bash -c "python ppo.py --gym-id CartPole-v0 --wandb-project-name cleanrl --total-timesteps 100000 --cuda True --seed 1"
```

# submit a job using AWS's accelerated-computing spot instances
python -m cleanrl.utils.submit_exp --exp-script ppo_atari_visual.sh \
--algo ppo_atari_visual.py \
Submit a job using AWS's compute-optimized spot instances
```
python -m cleanrl.utils.submit_exp --algo ppo.py \
--other-args "--gym-id CartPole-v0 --wandb-project-name cleanrl --total-timesteps 100000 --cuda True" \
--job-queue cpu_spot \
--job-definition cleanrl \
--num-seed 1 \
--num-vcpu 1 \
--num-memory 2000 \
--num-hours 48.0 \
--submit-aws
```

Submit a job using AWS's accelerated-computing spot instances
```
python -m cleanrl.utils.submit_exp --algo ppo_atari_visual.py \
--other-args "--gym-id BreakoutNoFrameskip-v4 --wandb-project-name cleanrl --cuda True" \
--job-queue gpu_spot \
--job-definition cleanrl \
--num-seed 1 \
--num-vcpu 1 \
--num-gpu 1 \
--num-memory 4000 \
--num-hours 48.0
--num-hours 48.0 \
--submit-aws
```

# submit a job using AWS's compute-optimized on-demand instances
python -m cleanrl.utils.submit_exp --exp-script ppo.sh \
--algo ppo.py \
Submit a job using AWS's compute-optimized on-demand instances
```
python -m cleanrl.utils.submit_exp --algo ppo.py \
--other-args "--gym-id CartPole-v0 --wandb-project-name cleanrl --total-timesteps 100000 --cuda True" \
--job-queue cpu_on_demand \
--job-definition cleanrl \
--num-seed 1 \
--num-vcpu 1 \
--num-memory 2000 \
--num-hours 48.0
--num-hours 48.0 \
--submit-aws
```

# submit a job using AWS's accelerated-computing on-demand instances
python -m cleanrl.utils.submit_exp --exp-script ppo_atari_visual.sh \
--algo ppo_atari_visual.py \
Submit a job using AWS's accelerated-computing on-demand instances
```
python -m cleanrl.utils.submit_exp --algo ppo_atari_visual.py \
--other-args "--gym-id BreakoutNoFrameskip-v4 --wandb-project-name cleanrl --cuda True" \
--job-queue gpu_on_demand \
--job-definition cleanrl \
--num-seed 1 \
--num-vcpu 1 \
--num-gpu 1 \
--num-memory 4000 \
--num-hours 48.0
--num-hours 48.0 \
--submit-aws
```

0 comments on commit 0156ba2

Please sign in to comment.