Skip to content

Commit 7c194ac

Browse files
authored
Merge pull request #9929 from JiayiFeng/make_for_parallel_default_true
make for_parallel default True
2 parents f738691 + c6fc6a3 commit 7c194ac

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

python/paddle/fluid/layers/io.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
__all__ = [
2323
'data', 'BlockGuardServ', 'ListenAndServ', 'Send', 'open_recordio_file',
24-
'open_files', 'read_file', 'shuffle', 'double_buffer'
24+
'open_files', 'read_file', 'shuffle', 'batch', 'double_buffer'
2525
]
2626

2727

@@ -290,7 +290,7 @@ def open_recordio_file(filename,
290290
lod_levels,
291291
dtypes,
292292
pass_num=1,
293-
for_parallel=False):
293+
for_parallel=True):
294294
"""
295295
Open a RecordIO file
296296
@@ -364,7 +364,7 @@ def open_files(filenames,
364364
thread_num,
365365
buffer_size=None,
366366
pass_num=1,
367-
for_parallel=False):
367+
for_parallel=True):
368368
"""
369369
Open files
370370
@@ -476,6 +476,11 @@ def shuffle(reader, buffer_size):
476476
'create_shuffle_reader', reader, {'buffer_size': int(buffer_size)})
477477

478478

479+
def batch(reader, batch_size):
480+
return __create_unshared_decorated_reader__(
481+
'create_batch_reader', reader, {'batch_size': int(batch_size)})
482+
483+
479484
def double_buffer(reader, place=None):
480485
attrs = dict()
481486
if place is not None:

python/paddle/fluid/tests/unittests/test_multi_file_reader.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ def main(self, thread_num):
6969
break
7070
batch_count += 1
7171
self.assertLessEqual(img_val.shape[0], self.batch_size)
72-
data_files.reset()
7372
self.assertEqual(batch_count, self.num_batch * 3)
7473

7574
def test_main(self):

python/paddle/fluid/tests/unittests/test_multi_pass_reader.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ def test_main(self):
4343
filename='./mnist.recordio',
4444
shapes=[(-1, 784), (-1, 1)],
4545
lod_levels=[0, 0],
46-
dtypes=['float32', 'int64'])
47-
data_file = fluid.layers.io.multi_pass(
48-
reader=data_file, pass_num=self.pass_num)
46+
dtypes=['float32', 'int64'],
47+
pass_num=self.pass_num)
4948
img, label = fluid.layers.read_file(data_file)
5049

5150
if fluid.core.is_compiled_with_cuda():
@@ -65,5 +64,4 @@ def test_main(self):
6564
break
6665
batch_count += 1
6766
self.assertLessEqual(img_val.shape[0], self.batch_size)
68-
data_file.reset()
6967
self.assertEqual(batch_count, self.num_batch * self.pass_num)

python/paddle/fluid/tests/unittests/test_recordio_reader.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ def test_main(self, decorator_callback=None):
7474

7575
avg_loss_np.append(tmp)
7676
batch_id += 1
77-
data_file.reset()
7877
self.assertEqual(batch_id, self.num_batches)
7978
self.assertLess(avg_loss_np[-1], avg_loss_np[0])
8079

8180
def test_shuffle_reader(self):
82-
self.test_main(decorator_callback=lambda reader: fluid.layers.io.shuffle(reader, buffer_size=200))
81+
self.test_main(decorator_callback=lambda reader: fluid.layers.io.shuffle(
82+
reader, buffer_size=200))
8383

8484
def test_double_buffer_reader(self):
8585
self.test_main(decorator_callback=lambda reader: fluid.layers.io.double_buffer(reader,
86-
place='cuda:0' if fluid.core.is_compiled_with_cuda() else 'cpu'))
86+
place='cuda:0' if fluid.core.is_compiled_with_cuda() else 'cpu'))

0 commit comments

Comments
 (0)