Skip to content

Commit

Permalink
Override num_workers from 0 to 1 in get_pytorch_dataloader
Browse files Browse the repository at this point in the history
Summary: To support a similar interface to the pytorch dataloader, we set `num_workers` to 1 if the input `num_workers` is 0 in `get_pytorch_dataloader`

Differential Revision: D68357865
  • Loading branch information
Victor Bourgin authored and facebook-github-bot committed Jan 17, 2025
1 parent 4fc0bc2 commit 2cdaf42
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/spdl/dataloader/_pytorch_dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,13 @@ def get_pytorch_dataloader(
if timeout is not None and timeout < 0:
raise ValueError(f"`timeout` must be positive. Found: {timeout}.")

if num_workers < 1:
if num_workers < 0:
raise ValueError(f"`num_workers` must be greater than 0. Found: {num_workers}")
elif num_workers == 0:
_LG.warning(
"`num_workers` is 0. Setting `num_workers` to 1 for single process dataloading."
)
num_workers = 1

buffer_size = prefetch_factor * num_workers

Expand Down

0 comments on commit 2cdaf42

Please sign in to comment.