Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix structure infos conflict in static return_list mode #43291

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions python/paddle/fluid/dataloader/dataloader_iter.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,12 @@ def __next__(self):
data = self._reader.read_next_list()
for i in range(len(data)):
data[i] = data[i]._move_to_list()
data = [
_restore_batch(d, s) for d, s in zip(
data, self._structure_infos[:len(self._places)])
structs = [
self._structure_infos.pop(0)
for _ in range(len(self._places))
]
self._structure_infos = self._structure_infos[
len(self._places):]
data = [_restore_batch(d, s) \
for d, s in zip(data, structs)]
# static graph organized data on multi-device with list, if
# place number is 1, there is only 1 device, extra the data
# from list for devices to be compatible with dygraph mode
Expand Down Expand Up @@ -750,12 +750,12 @@ def __next__(self):
data = self._reader.read_next_list()
for i in range(len(data)):
data[i] = data[i]._move_to_list()
data = [
_restore_batch(d, s) for d, s in zip(
data, self._structure_infos[:len(self._places)])
structs = [
self._structure_infos.pop(0)
for _ in range(len(self._places))
]
self._structure_infos = self._structure_infos[
len(self._places):]
data = [_restore_batch(d, s) \
for d, s in zip(data, structs)]
# static graph organized data on multi-device with list, if
# place number is 1, there is only 1 device, extra the data
# from list for devices to be compatible with dygraph mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import multiprocessing
import numpy as np

import paddle
import paddle.fluid as fluid
from paddle.io import Dataset, BatchSampler, DataLoader

Expand Down Expand Up @@ -182,7 +183,7 @@ def test_main(self):

class TestStaticDataLoaderReturnList(unittest.TestCase):

def test_single_place(self):
def run_single_place(self, num_workers):
scope = fluid.Scope()
image = fluid.data(name='image',
shape=[None, IMAGE_SIZE],
Expand All @@ -192,7 +193,7 @@ def test_single_place(self):
dataset = RandomDataset(SAMPLE_NUM, CLASS_NUM)
dataloader = DataLoader(dataset,
feed_list=[image, label],
num_workers=0,
num_workers=num_workers,
batch_size=BATCH_SIZE,
drop_last=True,
return_list=True)
Expand All @@ -203,7 +204,7 @@ def test_single_place(self):
assert not isinstance(d[0], list)
assert not isinstance(d[1], list)

def test_multi_place(self):
def run_multi_place(self, num_workers):
scope = fluid.Scope()
image = fluid.data(name='image',
shape=[None, IMAGE_SIZE],
Expand All @@ -213,7 +214,7 @@ def test_multi_place(self):
dataset = RandomDataset(SAMPLE_NUM, CLASS_NUM)
dataloader = DataLoader(dataset,
feed_list=[image, label],
num_workers=0,
num_workers=num_workers,
batch_size=BATCH_SIZE,
places=[fluid.CPUPlace()] * 2,
drop_last=True,
Expand All @@ -225,6 +226,12 @@ def test_multi_place(self):
assert isinstance(d[0], list)
assert isinstance(d[1], list)

def test_main(self):
paddle.enable_static()
for num_workers in [0, 2]:
self.run_single_place(num_workers)
self.run_multi_place(num_workers)


class RandomBatchedDataset(Dataset):

Expand Down