Created
July 23, 2015 03:10
-
-
Save ShigekiKarita/4293f886765a1ed4a144 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from https://github.com/pfnet/chainer/blob/master/tests/functions_tests/test_split_axis.py | |
# "setUp()" modified and "@condition.retry()" added | |
import unittest | |
import numpy | |
import chainer | |
from chainer import cuda | |
from chainer import functions | |
from chainer import gradient_check | |
from chainer import testing | |
from chainer.testing import attr, condition | |
if cuda.available: | |
cuda.init() | |
retry = 100 | |
class TestSplitAxis0(unittest.TestCase): | |
def setUp(self): | |
a = numpy.random.randint(1, 100) | |
b = numpy.random.randint(3, 100) | |
c = numpy.random.randint(1, b - 2) | |
d = numpy.random.randint(c + 1, b) | |
self.x = numpy.arange(a * b, dtype=numpy.float32).reshape(a, b) | |
self.ys = [self.x[:,:c], self.x[:,c:d], self.x[:,d:]] | |
self.ys_section = [c, d] | |
self.axis = 1 | |
def check_forward(self, x_data, ys_data, indices_or_sections, axis): | |
x = chainer.Variable(x_data) | |
ys = functions.split_axis(x, indices_or_sections, axis) | |
for yd, y in zip(ys_data, ys): | |
gradient_check.assert_allclose(yd, y.data, atol=0, rtol=0) | |
# NOTE: added | |
z = functions.concat(ys) | |
gradient_check.assert_allclose(x.data, z.data) | |
@condition.retry(retry) | |
def test_forward_cpu(self): | |
self.check_forward(self.x, self.ys, self.ys_section, self.axis) | |
@condition.retry(retry) | |
@attr.gpu | |
def test_forward_gpu(self): | |
self.check_forward( | |
cuda.to_gpu(self.x), | |
[cuda.to_gpu(y.copy()) for y in self.ys], | |
self.ys_section, axis=self.axis) | |
def check_backward(self, x_data, indices_or_sections, axis): | |
x = chainer.Variable(x_data) | |
ys = functions.split_axis(x, indices_or_sections, axis) | |
for y in ys: | |
y.grad = y.data | |
ys[0].backward() | |
gradient_check.assert_allclose(x.data, x.grad, atol=0, rtol=0) | |
@condition.retry(retry) | |
def test_backward_cpu(self): | |
self.check_backward(self.x, self.ys_section, axis=self.axis) | |
@condition.retry(retry) | |
@attr.gpu | |
def test_backward_gpu(self): | |
self.check_backward( | |
cuda.to_gpu(self.x), self.ys_section, axis=self.axis) | |
testing.run_module(__name__, __file__) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.... | |
---------------------------------------------------------------------- | |
Ran 4 tests in 0.244s | |
OK |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
...F | |
====================================================================== | |
FAIL: test_forward_gpu (mytest_split_axis.TestSplitAxis0) | |
---------------------------------------------------------------------- | |
Traceback (most recent call last): | |
File "/home/karita/.virtualenvs/v3.4.3/lib/python3.4/site-packages/chainer-1.1.1-py3.4.egg/chainer/testing/condition.py", line 77, in wrapper | |
fail() | |
File "/home/karita/.virtualenvs/v3.4.3/lib/python3.4/site-packages/chainer-1.1.1-py3.4.egg/chainer/testing/condition.py", line 57, in fail | |
instance.fail(msg) | |
AssertionError: | |
Fail: 100, Success: 0 | |
The first error message: | |
Traceback (most recent call last): | |
File "/home/karita/.virtualenvs/v3.4.3/lib/python3.4/site-packages/chainer-1.1.1-py3.4.egg/chainer/testing/condition.py", line 63, in <lambda> | |
lambda: f(*args, **kwargs), | |
File "/tmp/mytest_split_axis.py", line 52, in test_forward_gpu | |
self.ys_section, axis=self.axis) | |
File "/tmp/mytest_split_axis.py", line 39, in check_forward | |
z = functions.concat(ys) | |
File "/home/karita/.virtualenvs/v3.4.3/lib/python3.4/site-packages/chainer-1.1.1-py3.4.egg/chainer/functions/concat.py", line 112, in concat | |
return Concat(axis=axis)(*xs) | |
File "/home/karita/.virtualenvs/v3.4.3/lib/python3.4/site-packages/chainer-1.1.1-py3.4.egg/chainer/function.py", line 166, in __call__ | |
outputs = self.forward(in_data) | |
File "/home/karita/.virtualenvs/v3.4.3/lib/python3.4/site-packages/chainer-1.1.1-py3.4.egg/chainer/function.py", line 252, in forward | |
return self.forward_gpu(inputs) | |
File "/home/karita/.virtualenvs/v3.4.3/lib/python3.4/site-packages/chainer-1.1.1-py3.4.egg/chainer/functions/concat.py", line 78, in forward_gpu | |
kernel(x, y, cdimx, self.cdimy, self.rdim, coffset) | |
File "/home/karita/.virtualenvs/v3.4.3/lib/python3.4/site-packages/pycuda/elementwise.py", line 236, in __call__ | |
func.prepared_async_call(grid, block, stream, *invocation_args) | |
File "/home/karita/.virtualenvs/v3.4.3/lib/python3.4/site-packages/pycuda/driver.py", line 508, in function_prepared_async_call | |
arg_buf = pack(func.arg_format, *args) | |
struct.error: required argument is not an integer | |
---------------------------------------------------------------------- | |
Ran 4 tests in 0.393s | |
FAILED (failures=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment