8000 Add ChainerX test to `test_allreduce_persistent.py` by keisukefukuda · Pull Request #8412 · chainer/chainer · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add ChainerX test to test_allreduce_persistent.py #8412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import chainer
from chainer.backends.cuda import cupy
import chainer.testing
import chainer.testing.attr
import unittest

import chainermn
from chainermn.testing.device import get_device


class ExampleModel(chainer.Chain):
Expand All @@ -20,7 +20,14 @@ def __init__(self, n_in=3, n_units=5, n_out=2):

class TestAllreducePersistent(unittest.TestCase):

def _test(self, comm, model):
def _test(self, comm, model, use_gpu, use_chx):
if use_gpu:
# Use CuPy's Device class to force call cudaSetDevice()
chainer.cuda.get_device_from_id(comm.intra_rank).use()

device = get_device(comm.intra_rank if use_gpu else None, use_chx)
model.to_device(device)

rank = comm.rank
model.bn1.avg_mean.fill(rank * 1)
model.bn2.avg_mean.fill(rank * 2)
Expand All @@ -39,14 +46,13 @@ def _test(self, comm, model):

def test_allreduce_persistent_cpu(self):
comm = chainermn.create_communicator('naive')
self._test(comm, ExampleModel())
model = ExampleModel()
self._test(comm, model, False, False) # CPU test (numpy)
self._test(comm, model, False, True) # CPU test (ChainerX)

@chainer.testing.attr.gpu
def test_allreduce_persistent_gpu(self):
comm = chainermn.create_communicator('flat')
device = comm.intra_rank
chainer.cuda.get_device_from_id(device).use()

model = ExampleModel()
model.to_device(cupy.cuda.Device(device))
self._test(comm, model)
self._test(comm, model, True, False) # GPU test (CuPy)
self._test(comm, model, True, True) # GPU test (ChainerX)
0