14
14
15
15
from __future__ import print_function
16
16
17
- from parallel_executor_test_base import TestParallelExecutorBase
18
- import paddle .fluid as fluid
19
- import paddle .fluid .core as core
20
- import numpy as np
21
- import paddle
22
- import paddle .dataset .mnist as mnist
23
17
import unittest
24
- import os
25
18
26
- MNIST_RECORDIO_FILE = "./mnist_test_pe.recordio"
19
+ import numpy as np
20
+ import paddle .fluid .core as core
21
+ import os
22
+ import paddle .fluid as fluid
23
+ from parallel_executor_test_base import TestParallelExecutorBase
27
24
28
25
29
26
def simple_fc_net (use_feed ):
30
- if use_feed :
31
- img = fluid .layers .data (name = 'image' , shape = [784 ], dtype = 'float32' )
32
- label = fluid .layers .data (name = 'label' , shape = [1 ], dtype = 'int64' )
33
- else :
34
- reader = fluid .layers .open_files (
35
- filenames = [MNIST_RECORDIO_FILE ],
36
- shapes = [[- 1 , 784 ], [- 1 , 1 ]],
37
- lod_levels = [0 , 0 ],
38
- dtypes = ['float32' , 'int64' ])
39
- reader = fluid .layers .io .double_buffer (reader )
40
- img , label = fluid .layers .read_file (reader )
27
+ img = fluid .layers .data (name = 'image' , shape = [784 ], dtype = 'float32' )
28
+ label = fluid .layers .data (name = 'label' , shape = [1 ], dtype = 'int64' )
41
29
hidden = img
42
30
for _ in range (4 ):
43
31
hidden = fluid .layers .fc (
@@ -53,17 +41,8 @@ def simple_fc_net(use_feed):
53
41
54
42
55
43
def fc_with_batchnorm (use_feed ):
56
- if use_feed :
57
- img = fluid .layers .data (name = 'image' , shape = [784 ], dtype = 'float32' )
58
- label = fluid .layers .data (name = 'label' , shape = [1 ], dtype = 'int64' )
59
- else :
60
- reader = fluid .layers .open_files (
61
- filenames = [MNIST_RECORDIO_FILE ],
62
- shapes = [[- 1 , 784 ], [- 1 , 1 ]],
63
- lod_levels = [0 , 0 ],
64
- dtypes = ['float32' , 'int64' ])
65
- reader = fluid .layers .io .double_buffer (reader )
66
- img , label = fluid .layers .read_file (reader )
44
+ img = fluid .layers .data (name = 'image' , shape = [784 ], dtype = 'float32' )
45
+ label = fluid .layers .data (name = 'label' , shape = [1 ], dtype = 'int64' )
67
46
68
47
hidden = img
69
48
for _ in range (1 ):
@@ -88,19 +67,6 @@ class TestMNIST(TestParallelExecutorBase):
88
67
@classmethod
89
68
def setUpClass (cls ):
90
69
os .environ ['CPU_NUM' ] = str (4 )
91
- # Convert mnist to recordio file
92
- with fluid .program_guard (fluid .Program (), fluid .Program ()):
93
- reader = paddle .batch (mnist .train (), batch_size = 4 )
94
- feeder = fluid .DataFeeder (
95
- feed_list = [ # order is image and label
96
- fluid .layers .data (
97
- name = 'image' , shape = [784 ]),
98
- fluid .layers .data (
99
- name = 'label' , shape = [1 ], dtype = 'int64' ),
100
- ],
101
- place = fluid .CPUPlace ())
102
- fluid .recordio_writer .convert_reader_to_recordio_file (
103
- MNIST_RECORDIO_FILE , reader , feeder )
104
70
105
71
def _init_data (self ):
106
72
np .random .seed (5 )
@@ -111,10 +77,6 @@ def _init_data(self):
111
77
def _compare_reduce_and_allreduce (self , model , use_cuda ):
112
78
if use_cuda and not core .is_compiled_with_cuda ():
113
79
return
114
- self .check_network_convergence (
115
- model , use_cuda = use_cuda , use_reduce = True )
116
- self .check_network_convergence (
117
- model , use_cuda = use_cuda , allow_op_delay = True , use_reduce = True )
118
80
119
81
img , label = self ._init_data ()
120
82
@@ -140,9 +102,6 @@ def _compare_reduce_and_allreduce(self, model, use_cuda):
140
102
def check_simple_fc_convergence (self , use_cuda , use_reduce = False ):
141
103
if use_cuda and not core .is_compiled_with_cuda ():
142
104
return
143
- self .check_network_convergence (simple_fc_net , use_cuda = use_cuda )
144
- self .check_network_convergence (
145
- simple_fc_net , use_cuda = use_cuda , allow_op_delay = True )
146
105
147
106
img , label = self ._init_data ()
148
107
@@ -199,8 +158,6 @@ def check_batchnorm_fc_convergence(self, use_cuda, use_fast_executor):
199
158
if use_cuda and not core .is_compiled_with_cuda ():
200
159
return
201
160
202
- self .check_network_convergence (fc_with_batchnorm , use_cuda = use_cuda )
203
-
204
161
img , label = self ._init_data ()
205
162
206
163
self .check_network_convergence (
0 commit comments