From 1e4b4d7d3739a969fd3eb31d6192ae34eab41897 Mon Sep 17 00:00:00 2001 From: Yang Yang Date: Tue, 23 Jan 2018 22:40:44 +0000 Subject: [PATCH 1/3] add multiple input test --- .../paddle/v2/fluid/tests/test_parallel_op.py | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/python/paddle/v2/fluid/tests/test_parallel_op.py b/python/paddle/v2/fluid/tests/test_parallel_op.py index dfde492c7c..49bddd1b42 100644 --- a/python/paddle/v2/fluid/tests/test_parallel_op.py +++ b/python/paddle/v2/fluid/tests/test_parallel_op.py @@ -159,7 +159,7 @@ class ParallelOpTest(BaseParallelForTest): def test_simple_fc(self): self.run_test( - callback=ParallelOpTest.__network__, + callback=self.__network__, feed={ 'img': numpy.random.random(size=(51, 784)).astype('float32') }, @@ -167,10 +167,31 @@ class ParallelOpTest(BaseParallelForTest): def test_fc_with_tiny_data(self): self.run_test( - callback=ParallelOpTest.__network__, + callback=self.__network__, feed={'img': numpy.random.random(size=(1, 784)).astype('float32')}, fetch=['fc1.w@GRAD']) +class ParallelOpTestMultipleInput(BaseParallelForTest): + @staticmethod + def __network__(): + x = fluid.layers.data(shape=[784], dtype='float32', name='img1', stop_gradient=False) + y = fluid.layers.data(shape=[784], dtype='float32', name='img2', stop_gradient=False) + yield [x, y] + x = x + y + hidden = fluid.layers.fc(input=x, size=200, param_attr='fc1.w') + loss = fluid.layers.mean(x=hidden) + yield loss + + def test_simple_fc(self): + self.run_test( + callback=self.__network__, + feed={ + 'img1': numpy.random.random(size=(51, 784)).astype('float32'), + 'img2': numpy.random.random(size=(51, 784)).astype('float32') + }, + fetch=['fc1.w@GRAD']) + + if __name__ == '__main__': unittest.main() From 003dc79b41cf53a183a24422956125ea5a9cd85e Mon Sep 17 00:00:00 2001 From: Yang Yang Date: Tue, 23 Jan 2018 22:45:17 +0000 Subject: [PATCH 2/3] add multiple fc layers --- python/paddle/v2/fluid/tests/test_parallel_op.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/python/paddle/v2/fluid/tests/test_parallel_op.py b/python/paddle/v2/fluid/tests/test_parallel_op.py index 49bddd1b42..09424619a1 100644 --- a/python/paddle/v2/fluid/tests/test_parallel_op.py +++ b/python/paddle/v2/fluid/tests/test_parallel_op.py @@ -179,8 +179,10 @@ class ParallelOpTestMultipleInput(BaseParallelForTest): y = fluid.layers.data(shape=[784], dtype='float32', name='img2', stop_gradient=False) yield [x, y] x = x + y - hidden = fluid.layers.fc(input=x, size=200, param_attr='fc1.w') - loss = fluid.layers.mean(x=hidden) + hidden1 = fluid.layers.fc(input=x, size=200, param_attr='fc1.w') + hidden2 = fluid.layers.fc(input=hidden1, size=200, param_attr='fc2.w') + hidden3 = fluid.layers.fc(input=hidden2, size=200, param_attr='fc3.w') + loss = fluid.layers.mean(x=hidden3) yield loss def test_simple_fc(self): @@ -190,7 +192,7 @@ class ParallelOpTestMultipleInput(BaseParallelForTest): 'img1': numpy.random.random(size=(51, 784)).astype('float32'), 'img2': numpy.random.random(size=(51, 784)).astype('float32') }, - fetch=['fc1.w@GRAD']) + fetch=['fc1.w@GRAD', 'fc2.w@GRAD', 'fc3.w@GRAD']) if __name__ == '__main__': From 0f8489c42e1eb3bb33c87e4bec878bdcebbfe78c Mon Sep 17 00:00:00 2001 From: Yang Yu Date: Wed, 24 Jan 2018 14:59:22 +0800 Subject: [PATCH 3/3] Fix style --- python/paddle/v2/fluid/tests/test_parallel_op.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/python/paddle/v2/fluid/tests/test_parallel_op.py b/python/paddle/v2/fluid/tests/test_parallel_op.py index 09424619a1..5394df7360 100644 --- a/python/paddle/v2/fluid/tests/test_parallel_op.py +++ b/python/paddle/v2/fluid/tests/test_parallel_op.py @@ -175,8 +175,10 @@ class ParallelOpTest(BaseParallelForTest): class ParallelOpTestMultipleInput(BaseParallelForTest): @staticmethod def __network__(): - x = fluid.layers.data(shape=[784], dtype='float32', name='img1', stop_gradient=False) - y = fluid.layers.data(shape=[784], dtype='float32', name='img2', stop_gradient=False) + x = fluid.layers.data( + shape=[784], dtype='float32', name='img1', stop_gradient=False) + y = fluid.layers.data( + shape=[784], dtype='float32', name='img2', stop_gradient=False) yield [x, y] x = x + y hidden1 = fluid.layers.fc(input=x, size=200, param_attr='fc1.w')