Skip to content

Commit

Permalink
Merge pull request #605 from prabhatnagarajan/fix_tests
Browse files Browse the repository at this point in the history
Fixes PFN CI tests
  • Loading branch information
muupan authored Nov 25, 2020
2 parents 018a291 + c41db82 commit 736475e
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 65 deletions.
16 changes: 12 additions & 4 deletions .pfnci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ TARGET="$1"
: "${GPU:=0}"
: "${XPYTEST_NUM_THREADS:=$(nproc)}"
: "${PYTHON=python3}"
: "${PYTHON_VERSION=6}"
: "${CHAINER=}"
: "${SLOW:=0}"

Expand Down Expand Up @@ -59,18 +60,25 @@ main() {
--hint="/chainerrl/.pfnci/hint.pbtxt"
)

apt-get update -q -y
apt-get install -qy --no-install-recommends software-properties-common
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:cran/ffmpeg-3
fi

apt-get update -q
apt-get install -qy --no-install-recommends \
"${PYTHON}-dev" "${PYTHON}-pip" "${PYTHON}-setuptools" \
add-apt-repository ppa:deadsnakes/ppa
apt-get update -q -y
apt install -y "${PYTHON}.${PYTHON_VERSION}"


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

if [ "${CHAINER}" != '' ]; then
Expand Down
4 changes: 0 additions & 4 deletions .pfnci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ main() {
# TODO(imos): Use pre-build Docker images instead because latest images are
# not updated frequently.
py3.cpu | py3.gpu ) docker_image=chainer/chainer:latest-python3;;
py2.cpu ) docker_image=chainer/chainer:latest-python2;;
# Unsupported targets.
* )
echo "Unsupported target: ${TARGET}" >&2
Expand All @@ -63,9 +62,6 @@ main() {
docker_args+=(--env="CHAINER=${chainer_version}")
docker_args+=(--env="SLOW=${SLOW:-0}")

case "${TARGET}" in
py2.* ) docker_args+=(--env="PYTHON=python");;
esac

for ZIP in a3c_results.zip dqn_results.zip iqn_results.zip rainbow_results.zip ddpg_results.zip trpo_results.zip ppo_results.zip td3_results.zip sac_results.zip
do
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ install:
script:
- flake8 chainerrl
- flake8 tests
- flake8 examples
- flake8 --ignore=E402,W504 examples
- autopep8 -r chainerrl tests examples --diff | tee check_autopep8
- test ! -s check_autopep8
- pytest -m "not gpu and not slow" -x tests --cov=chainerrl --ignore tests/misc_tests/test_pretrained_models.py
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ChainerRL is a deep reinforcement learning library that implements various state

## Installation

ChainerRL is tested with 3.5.1+. For other requirements, see [requirements.txt](requirements.txt).
ChainerRL is tested with 3.6. For other requirements, see [requirements.txt](requirements.txt).

ChainerRL can be installed via PyPI:
```
Expand Down
3 changes: 1 addition & 2 deletions chainerrl/functions/sum_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def backward(self, inputs, grads):
return [grads[0]] * len(inputs)

def forward_gpu(self, inputs):
n = len(inputs)
ptrs = cuda.cupy.asarray([x.data.ptr for x in inputs],
dtype=cuda.cupy.int64)
y = cuda.elementwise(
Expand All @@ -31,7 +30,7 @@ def forward_gpu(self, inputs):
'for (size_t j = 0; j < n_xs; ++j) {'
' y += xs_[j][i];'
'}',
'sum_arrays'.format(n))(inputs[0], ptrs.data.ptr, len(ptrs))
'sum_arrays')(inputs[0], ptrs.data.ptr, len(ptrs))
return y,


Expand Down
9 changes: 4 additions & 5 deletions chainerrl/functions/weighted_sum_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def backward(self, inputs, grads):
return [w * grads[0] for w in self.weights]

def forward_gpu(self, inputs):
n = len(inputs)
ptrs = cuda.cupy.asarray([x.data.ptr for x in inputs],
dtype=cuda.cupy.int64)
ws = cuda.cupy.asarray(self.weights, dtype=cuda.cupy.float32)
Expand All @@ -35,10 +34,10 @@ def forward_gpu(self, inputs):
'for (size_t j = 0; j < n_xs; ++j) {'
' y += xs_[j][i] * ws[j];'
'}',
'weighted_sum_arrays'.format(n))(inputs[0],
ptrs.data.ptr,
ws,
len(ptrs))
'weighted_sum_arrays')(inputs[0],
ptrs.data.ptr,
ws,
len(ptrs))
return y,


Expand Down
4 changes: 2 additions & 2 deletions chainerrl/links/mlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ def __init__(self, in_size, out_size, hidden_sizes, nonlinearity=F.relu,
def __call__(self, x):
h = x
if self.hidden_sizes:
for l in self.hidden_layers:
h = self.nonlinearity(l(h))
for link in self.hidden_layers:
h = self.nonlinearity(link(h))
return self.output(h)
4 changes: 2 additions & 2 deletions chainerrl/links/mlp_bn.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def __call__(self, x):
if self.normalize_input:
h = self.input_bn(h)
if self.hidden_sizes:
for l in self.hidden_layers:
h = self.nonlinearity(l(h))
for link in self.hidden_layers:
h = self.nonlinearity(link(h))
h = self.output(h)
if self.normalize_output:
h = self.output_bn(h)
Expand Down
22 changes: 11 additions & 11 deletions chainerrl/misc/init_like_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
def init_like_torch(link):
# Mimic torch's default parameter initialization
# TODO(muupan): Use chainer's initializers when it is merged
for l in link.links():
if isinstance(l, L.Linear):
out_channels, in_channels = l.W.shape
for li in link.links():
if isinstance(li, L.Linear):
out_channels, in_channels = li.W.shape
stdv = 1 / np.sqrt(in_channels)
l.W.array[:] = np.random.uniform(-stdv, stdv, size=l.W.shape)
if l.b is not None:
l.b.array[:] = np.random.uniform(-stdv, stdv, size=l.b.shape)
elif isinstance(l, L.Convolution2D):
out_channels, in_channels, kh, kw = l.W.shape
li.W.array[:] = np.random.uniform(-stdv, stdv, size=li.W.shape)
if li.b is not None:
li.b.array[:] = np.random.uniform(-stdv, stdv, size=li.b.shape)
elif isinstance(li, L.Convolution2D):
out_channels, in_channels, kh, kw = li.W.shape
stdv = 1 / np.sqrt(in_channels * kh * kw)
l.W.array[:] = np.random.uniform(-stdv, stdv, size=l.W.shape)
if l.b is not None:
l.b.array[:] = np.random.uniform(-stdv, stdv, size=l.b.shape)
li.W.array[:] = np.random.uniform(-stdv, stdv, size=li.W.shape)
if li.b is not None:
li.b.array[:] = np.random.uniform(-stdv, stdv, size=li.b.shape)
8 changes: 4 additions & 4 deletions chainerrl/q_functions/dueling_dqn.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def __init__(self, n_actions, n_input_channels=4,

def __call__(self, x):
h = x
for l in self.conv_layers:
h = self.activation(l(h))
for link in self.conv_layers:
h = self.activation(link(h))

# Advantage
batch_size = x.shape[0]
Expand Down Expand Up @@ -88,8 +88,8 @@ def __init__(self, n_actions, n_atoms, v_min, v_max,

def __call__(self, x):
h = x
for l in self.conv_layers:
h = self.activation(l(h))
for link in self.conv_layers:
h = self.activation(link(h))

# Advantage
batch_size = x.shape[0]
Expand Down
52 changes: 26 additions & 26 deletions chainerrl/recurrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,52 +91,52 @@ def state_kept(self):
def get_state(chain):
assert isinstance(chain, (chainer.Chain, chainer.ChainList))
state = []
for l in chain.children():
if isinstance(l, chainer.links.LSTM):
state.append((l.c, l.h))
elif isinstance(l, Recurrent):
state.append(l.get_state())
elif isinstance(l, (chainer.Chain, chainer.ChainList)):
state.append(get_state(l))
for link in chain.children():
if isinstance(link, chainer.links.LSTM):
state.append((link.c, link.h))
elif isinstance(link, Recurrent):
state.append(link.get_state())
elif isinstance(link, (chainer.Chain, chainer.ChainList)):
state.append(get_state(link))
else:
state.append(None)
return state


def stateful_links(chain):
for l in chain.children():
if isinstance(l, (chainer.links.LSTM, Recurrent)):
yield l
elif isinstance(l, (chainer.Chain, chainer.ChainList)):
for m in stateful_links(l):
for link in chain.children():
if isinstance(link, (chainer.links.LSTM, Recurrent)):
yield link
elif isinstance(link, (chainer.Chain, chainer.ChainList)):
for m in stateful_links(link):
yield m


def set_state(chain, state):
assert isinstance(chain, (chainer.Chain, chainer.ChainList))
for l, s in zip(chain.children(), state):
if isinstance(l, chainer.links.LSTM):
for link, s in zip(chain.children(), state):
if isinstance(link, chainer.links.LSTM):
c, h = s
# LSTM.set_state doesn't accept None state
if c is not None:
l.set_state(c, h)
elif isinstance(l, Recurrent):
l.set_state(s)
elif isinstance(l, (chainer.Chain, chainer.ChainList)):
set_state(l, s)
link.set_state(c, h)
elif isinstance(link, Recurrent):
link.set_state(s)
elif isinstance(link, (chainer.Chain, chainer.ChainList)):
set_state(link, s)
else:
assert s is None


def reset_state(chain):
assert isinstance(chain, (chainer.Chain, chainer.ChainList))
for l in chain.children():
if isinstance(l, chainer.links.LSTM):
l.reset_state()
elif isinstance(l, Recurrent):
l.reset_state()
elif isinstance(l, (chainer.Chain, chainer.ChainList)):
reset_state(l)
for link in chain.children():
if isinstance(link, chainer.links.LSTM):
link.reset_state()
elif isinstance(link, Recurrent):
link.reset_state()
elif isinstance(link, (chainer.Chain, chainer.ChainList)):
reset_state(link)


class RecurrentChainMixin(Recurrent):
Expand Down
2 changes: 1 addition & 1 deletion docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Installation
How to install ChainerRL
========================

ChainerRL is tested with 3.5.1+. For other requirements, see ``requirements.txt``.
ChainerRL is tested with 3.6. For other requirements, see ``requirements.txt``.

.. literalinclude:: ../requirements.txt
:caption: requirements.txt
Expand Down
2 changes: 1 addition & 1 deletion examples/atlas/train_soft_actor_critic_atlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def make_env(args, seed, test):
raise RuntimeError('roboschool does not work with gym>=0.15.6')
import roboschool # NOQA
env = gym.make(args.env)
# Unwrap TimiLimit wrapper
# Unwrap TimeLimit wrapper
assert isinstance(env, gym.wrappers.TimeLimit)
env = env.env
# Use different random seeds for train and test envs
Expand Down
1 change: 0 additions & 1 deletion examples/grasping/train_dqn_batch_grasping.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ def make_env(idx, test):
maxSteps=max_episode_steps,
isTest=test,
)
assert env.observation_space is None
env.observation_space = gym.spaces.Box(
low=0, high=255, shape=(84, 84, 3), dtype=np.uint8)
# (84, 84, 3) -> (3, 84, 84)
Expand Down

0 comments on commit 736475e

Please sign in to comment.