Skip to content

Commit

Permalink
Merge branch 'master' into fix-sarsa-gpu
Browse files Browse the repository at this point in the history
  • Loading branch information
muupan authored Aug 26, 2019
2 parents 65adc56 + 2e1a034 commit 0b78e07
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 11 deletions.
14 changes: 13 additions & 1 deletion .pfnci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,19 @@ main() {
--hint="/chainerrl/.pfnci/hint.pbtxt"
)

UBUNTU_VERSION_ID=$(grep DISTRIB_RELEASE /etc/lsb-release | cut -d "=" -f2)
if [ "$UBUNTU_VERSION_ID" = "16.04" ]; then
# Because ffmpeg of ubuntu 16.04 causes segmentation fault,
# we use jonathonf/ffmpeg-3
apt-get update -q
apt-get install -qy --no-install-recommends software-properties-common
add-apt-repository ppa:jonathonf/ffmpeg-3
fi

apt-get update -q
apt-get install -qy --no-install-recommends \
"${PYTHON}-dev" "${PYTHON}-pip" "${PYTHON}-setuptools" \
zlib1g-dev make cmake g++ git
zlib1g-dev make cmake g++ git ffmpeg freeglut3-dev xvfb

if [ "${CHAINER}" != '' ]; then
"${PYTHON}" -m pip install "chainer==${CHAINER}"
Expand All @@ -77,7 +86,10 @@ main() {
git config --global user.email "you@example.com"
git config --global user.name "Your Name"

# Xvfb's default screen is 1280x1024x8, which seems to cause a problem.
# https://bugzilla.redhat.com/show_bug.cgi?id=904851
OMP_NUM_THREADS=1 PYTHONHASHSEED=0 \
xvfb-run --server-args="-screen 0 1280x800x24" \
xpytest "${xpytest_args[@]}" '/chainerrl/tests/**/test_*.py'
}

Expand Down
2 changes: 1 addition & 1 deletion chainerrl/agents/a2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def __init__(self, model, optimizer, gamma, num_processes,
self.model = model
self.gpu = gpu
if gpu is not None and gpu >= 0:
chainer.cuda.get_device(gpu).use()
chainer.cuda.get_device_from_id(gpu).use()
self.model.to_gpu(device=gpu)

self.optimizer = optimizer
Expand Down
2 changes: 1 addition & 1 deletion chainerrl/agents/ddpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def __init__(self, model, actor_optimizer, critic_optimizer, replay_buffer,
self.model = model

if gpu is not None and gpu >= 0:
cuda.get_device(gpu).use()
cuda.get_device_from_id(gpu).use()
self.model.to_gpu(device=gpu)

self.xp = self.model.xp
Expand Down
2 changes: 1 addition & 1 deletion chainerrl/agents/dqn.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def __init__(self, q_function, optimizer, replay_buffer, gamma,
self.q_function = q_function # For backward compatibility

if gpu is not None and gpu >= 0:
cuda.get_device(gpu).use()
cuda.get_device_from_id(gpu).use()
self.model.to_gpu(device=gpu)

self.xp = self.model.xp
Expand Down
2 changes: 1 addition & 1 deletion chainerrl/agents/pgt.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(self, model, actor_optimizer, critic_optimizer, replay_buffer,
self.model = model

if gpu is not None and gpu >= 0:
cuda.get_device(gpu).use()
cuda.get_device_from_id(gpu).use()
self.model.to_gpu(device=gpu)

self.xp = self.model.xp
Expand Down
2 changes: 1 addition & 1 deletion examples/gym/train_pcl_gym.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def make_env(process_idx, test):
)

if not args.train_async and args.gpu >= 0:
chainer.cuda.get_device(args.gpu).use()
chainer.cuda.get_device_from_id(args.gpu).use()
model.to_gpu(args.gpu)

if args.train_async:
Expand Down
2 changes: 1 addition & 1 deletion examples/gym/train_reinforce_gym.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def make_env(test):
os.path.join(args.outdir, 'model'))

if args.gpu >= 0:
chainer.cuda.get_device(args.gpu).use()
chainer.cuda.get_device_from_id(args.gpu).use()
model.to_gpu(args.gpu)

opt = chainer.optimizers.Adam(alpha=args.lr)
Expand Down
2 changes: 1 addition & 1 deletion examples/mujoco/train_trpo_gym.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def make_env(test):

# Draw the computational graph and save it in the output directory.
fake_obs = chainer.Variable(
policy.xp.zeros_like(obs_space.low, dtype=np.float32)[None],
policy.xp.zeros(obs_space.low.shape, dtype=np.float32)[None],
name='observation')
chainerrl.misc.draw_computational_graph(
[policy(fake_obs)], os.path.join(args.outdir, 'policy'))
Expand Down
2 changes: 1 addition & 1 deletion tests/agents_tests/test_reinforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def phi(x):
)

if gpu >= 0:
chainer.cuda.get_device(gpu).use()
chainer.cuda.get_device_from_id(gpu).use()
model.to_gpu()

opt = optimizers.Adam()
Expand Down
7 changes: 6 additions & 1 deletion tests/links_tests/test_stateless_recurrent_sequential.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@

import chainer
from chainer import functions as F
from chainer.functions.connection.n_step_lstm import _lstm
try:
# chainer<=7.0.0b2
from chainer.functions.connection.n_step_lstm import _lstm
except ImportError:
# chainer>=7.0.0b3 (https://github.com/chainer/chainer/pull/7725)
from chainer.functions.rnn.n_step_lstm import _lstm
from chainer import links as L
from chainer import testing
import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion tests/test_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TestSampleDiscreteActions(unittest.TestCase):

def _test(self, gpu):
if gpu >= 0:
chainer.cuda.get_device(gpu).use()
chainer.cuda.get_device_from_id(gpu).use()
xp = chainer.cuda.cupy
else:
xp = np
Expand Down

0 comments on commit 0b78e07

Please sign in to comment.