Skip to content

Commit

Permalink
[rllib] PPO doesn't work with fractional num gpus (#3396)
Browse files Browse the repository at this point in the history
* frac ppo

* gpu test
  • Loading branch information
ericl authored Nov 27, 2018
1 parent aa94d3d commit e3c088f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion python/ray/rllib/optimizers/multi_gpu_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import print_function

import logging
import math
import numpy as np
from collections import defaultdict
import tensorflow as tf
Expand Down Expand Up @@ -44,7 +45,9 @@ def _init(self,
if not num_gpus:
self.devices = ["/cpu:0"]
else:
self.devices = ["/gpu:{}".format(i) for i in range(num_gpus)]
self.devices = [
"/gpu:{}".format(i) for i in range(int(math.ceil(num_gpus)))
]
self.batch_size = int(sgd_batch_size / len(self.devices)) * len(
self.devices)
assert self.batch_size % len(self.devices) == 0
Expand Down
8 changes: 8 additions & 0 deletions test/jenkins_tests/run_multi_node_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ docker run --rm --shm-size=10G --memory=10G $DOCKER_SHA \
--stop '{"training_iteration": 2}' \
--config '{"simple_optimizer": true, "num_sgd_iter": 2, "model": {"use_lstm": true}}'

docker run --rm --shm-size=10G --memory=10G $DOCKER_SHA \
python /ray/python/ray/rllib/train.py \
--env CartPole-v1 \
--run PPO \
--stop '{"training_iteration": 2}' \
--config '{"num_gpus": 0.1}' \
--ray-num-gpus 1

docker run --rm --shm-size=10G --memory=10G $DOCKER_SHA \
python /ray/python/ray/rllib/train.py \
--env CartPole-v1 \
Expand Down

0 comments on commit e3c088f

Please sign in to comment.