|
|
|
@ -14,30 +14,18 @@
|
|
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
|
|
from parallel_executor_test_base import TestParallelExecutorBase
|
|
|
|
|
import paddle.fluid as fluid
|
|
|
|
|
import paddle.fluid.core as core
|
|
|
|
|
import numpy as np
|
|
|
|
|
import paddle
|
|
|
|
|
import paddle.dataset.mnist as mnist
|
|
|
|
|
import unittest
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
MNIST_RECORDIO_FILE = "./mnist_test_pe.recordio"
|
|
|
|
|
import numpy as np
|
|
|
|
|
import paddle.fluid.core as core
|
|
|
|
|
import os
|
|
|
|
|
import paddle.fluid as fluid
|
|
|
|
|
from parallel_executor_test_base import TestParallelExecutorBase
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def simple_fc_net(use_feed):
|
|
|
|
|
if use_feed:
|
|
|
|
|
img = fluid.layers.data(name='image', shape=[784], dtype='float32')
|
|
|
|
|
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
|
|
|
|
|
else:
|
|
|
|
|
reader = fluid.layers.open_files(
|
|
|
|
|
filenames=[MNIST_RECORDIO_FILE],
|
|
|
|
|
shapes=[[-1, 784], [-1, 1]],
|
|
|
|
|
lod_levels=[0, 0],
|
|
|
|
|
dtypes=['float32', 'int64'])
|
|
|
|
|
reader = fluid.layers.io.double_buffer(reader)
|
|
|
|
|
img, label = fluid.layers.read_file(reader)
|
|
|
|
|
img = fluid.layers.data(name='image', shape=[784], dtype='float32')
|
|
|
|
|
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
|
|
|
|
|
hidden = img
|
|
|
|
|
for _ in range(4):
|
|
|
|
|
hidden = fluid.layers.fc(
|
|
|
|
@ -53,17 +41,8 @@ def simple_fc_net(use_feed):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def fc_with_batchnorm(use_feed):
|
|
|
|
|
if use_feed:
|
|
|
|
|
img = fluid.layers.data(name='image', shape=[784], dtype='float32')
|
|
|
|
|
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
|
|
|
|
|
else:
|
|
|
|
|
reader = fluid.layers.open_files(
|
|
|
|
|
filenames=[MNIST_RECORDIO_FILE],
|
|
|
|
|
shapes=[[-1, 784], [-1, 1]],
|
|
|
|
|
lod_levels=[0, 0],
|
|
|
|
|
dtypes=['float32', 'int64'])
|
|
|
|
|
reader = fluid.layers.io.double_buffer(reader)
|
|
|
|
|
img, label = fluid.layers.read_file(reader)
|
|
|
|
|
img = fluid.layers.data(name='image', shape=[784], dtype='float32')
|
|
|
|
|
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
|
|
|
|
|
|
|
|
|
|
hidden = img
|
|
|
|
|
for _ in range(1):
|
|
|
|
@ -88,19 +67,6 @@ class TestMNIST(TestParallelExecutorBase):
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpClass(cls):
|
|
|
|
|
os.environ['CPU_NUM'] = str(4)
|
|
|
|
|
# Convert mnist to recordio file
|
|
|
|
|
with fluid.program_guard(fluid.Program(), fluid.Program()):
|
|
|
|
|
reader = paddle.batch(mnist.train(), batch_size=4)
|
|
|
|
|
feeder = fluid.DataFeeder(
|
|
|
|
|
feed_list=[ # order is image and label
|
|
|
|
|
fluid.layers.data(
|
|
|
|
|
name='image', shape=[784]),
|
|
|
|
|
fluid.layers.data(
|
|
|
|
|
name='label', shape=[1], dtype='int64'),
|
|
|
|
|
],
|
|
|
|
|
place=fluid.CPUPlace())
|
|
|
|
|
fluid.recordio_writer.convert_reader_to_recordio_file(
|
|
|
|
|
MNIST_RECORDIO_FILE, reader, feeder)
|
|
|
|
|
|
|
|
|
|
def _init_data(self):
|
|
|
|
|
np.random.seed(5)
|
|
|
|
@ -111,10 +77,6 @@ class TestMNIST(TestParallelExecutorBase):
|
|
|
|
|
def _compare_reduce_and_allreduce(self, model, use_cuda):
|
|
|
|
|
if use_cuda and not core.is_compiled_with_cuda():
|
|
|
|
|
return
|
|
|
|
|
self.check_network_convergence(
|
|
|
|
|
model, use_cuda=use_cuda, use_reduce=True)
|
|
|
|
|
self.check_network_convergence(
|
|
|
|
|
model, use_cuda=use_cuda, allow_op_delay=True, use_reduce=True)
|
|
|
|
|
|
|
|
|
|
img, label = self._init_data()
|
|
|
|
|
|
|
|
|
@ -140,9 +102,6 @@ class TestMNIST(TestParallelExecutorBase):
|
|
|
|
|
def check_simple_fc_convergence(self, use_cuda, use_reduce=False):
|
|
|
|
|
if use_cuda and not core.is_compiled_with_cuda():
|
|
|
|
|
return
|
|
|
|
|
self.check_network_convergence(simple_fc_net, use_cuda=use_cuda)
|
|
|
|
|
self.check_network_convergence(
|
|
|
|
|
simple_fc_net, use_cuda=use_cuda, allow_op_delay=True)
|
|
|
|
|
|
|
|
|
|
img, label = self._init_data()
|
|
|
|
|
|
|
|
|
@ -199,8 +158,6 @@ class TestMNIST(TestParallelExecutorBase):
|
|
|
|
|
if use_cuda and not core.is_compiled_with_cuda():
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
self.check_network_convergence(fc_with_batchnorm, use_cuda=use_cuda)
|
|
|
|
|
|
|
|
|
|
img, label = self._init_data()
|
|
|
|
|
|
|
|
|
|
self.check_network_convergence(
|
|
|
|
|