Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
nkaenzig committed Oct 11, 2024
1 parent 1934942 commit 26bc47c
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/eva/core/data/dataloaders/dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ class DataLoader:
Mutually exclusive with `batch_size`, `shuffle`, `sampler` and `drop_last`.
"""

num_workers: int | None = None
"""How many workers to use for loading the data.
By default, it will use the number of CPUs available.
"""

collate_fn: Callable | None = None
"""The batching process."""

Expand All @@ -53,16 +59,6 @@ class DataLoader:
prefetch_factor: int | None = 2
"""Number of batches loaded in advance by each worker."""

num_workers: int | None = dataclasses.field(default=None)
"""How many workers to use for loading the data.
By default, it will use the number of CPUs available.
"""

def __post_init__(self):
if self.num_workers is None:
self.num_workers = multiprocessing.cpu_count()

def __call__(self, dataset: datasets.TorchDataset) -> dataloader.DataLoader:
"""Returns the dataloader on the provided dataset.
Expand All @@ -75,7 +71,7 @@ def __call__(self, dataset: datasets.TorchDataset) -> dataloader.DataLoader:
shuffle=self.shuffle,
sampler=self.sampler,
batch_sampler=self.batch_sampler,
num_workers=self.num_workers,
num_workers=self.num_workers or multiprocessing.cpu_count(),
collate_fn=self.collate_fn,
pin_memory=self.pin_memory,
drop_last=self.drop_last,
Expand Down

0 comments on commit 26bc47c

Please sign in to comment.