Skip to content

Commit b9c50f1

Browse files
YosuaMichaelNicolasHug
authored andcommitted
[fbsync] fix test_data_loader on Windows and macOS (#5912)
Summary: * fix test_data_loader on Windows and macOS * Update test/test_prototype_builtin_datasets.py Reviewed By: jdsgomes, NicolasHug Differential Revision: D36095692 fbshipit-source-id: 8835f9a92be235ceec929f2b94ec3edb1946afd1 Co-authored-by: Nicolas Hug <[email protected]> Co-authored-by: Nicolas Hug <[email protected]>
1 parent 58c92a3 commit b9c50f1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

test/test_prototype_builtin_datasets.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ def test_serializable(self, test_home, dataset_mock, config):
125125

126126
pickle.dumps(dataset)
127127

128+
# This has to be a proper function, since lambda's or local functions
129+
# cannot be pickled, but this is a requirement for the DataLoader with
130+
# multiprocessing, i.e. num_workers > 0
131+
def _collate_fn(self, batch):
132+
return batch
133+
128134
@pytest.mark.parametrize("num_workers", [0, 1])
129135
@parametrize_dataset_mocks(DATASET_MOCKS)
130136
def test_data_loader(self, test_home, dataset_mock, config, num_workers):
@@ -135,7 +141,7 @@ def test_data_loader(self, test_home, dataset_mock, config, num_workers):
135141
dataset,
136142
batch_size=2,
137143
num_workers=num_workers,
138-
collate_fn=lambda batch: batch,
144+
collate_fn=self._collate_fn,
139145
)
140146

141147
next(iter(dl))

0 commit comments

Comments
 (0)