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

Override num_workers from 0 to 1 in get_pytorch_dataloader #330

Merged
Merged
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
9 changes: 8 additions & 1 deletion src/spdl/dataloader/_pytorch_dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import os
import pickle
import time
import warnings
from collections.abc import Callable, Iterable, Iterator
from concurrent.futures import ProcessPoolExecutor
from multiprocessing.shared_memory import SharedMemory
Expand Down Expand Up @@ -298,8 +299,14 @@ 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:
warnings.warn(
"`num_workers` is 0. Setting `num_workers` to 1 for single process dataloading.",
stacklevel=2,
)
num_workers = 1

buffer_size = prefetch_factor * num_workers

Expand Down
Loading