MCPcopy Create free account
hub / github.com/SkyworkAI/DeepResearchAgent / DataLoader

Class DataLoader

src/data/dataloader.py:13–56  ·  view source on GitHub ↗

A wrapper for `torch.utils.data.DataLoader` to support both distributed and non-distributed training. Automatically handles sampler logic for train/eval mode and distributed settings.

Source from the content-addressed store, hash-verified

11
12@DATALOADER.register_module(force=True)
13class DataLoader(torch.utils.data.DataLoader):
14 """
15 A wrapper for `torch.utils.data.DataLoader` to support both distributed and non-distributed training.
16 Automatically handles sampler logic for train/eval mode and distributed settings.
17 """
18
19 def __init__(
20 self,
21 dataset: Dataset,
22 collate_fn: Any,
23 batch_size: int = 4,
24 shuffle: bool = False,
25 drop_last: bool = False,
26 pin_memory: bool = False,
27 num_workers: int = 0,
28 distributed: bool = False,
29 train: bool = True,
30 **kwargs,
31 ):
32 if train:
33 if distributed:
34 num_device = get_world_size()
35 rank = get_rank()
36 sampler = DistributedSampler(
37 dataset,
38 num_replicas=num_device,
39 rank=rank,
40 shuffle=True # always shuffle for train
41 )
42 else:
43 sampler = RandomSampler(dataset) if shuffle else SequentialSampler(dataset)
44 else:
45 sampler = SequentialSampler(dataset)
46
47 super().__init__(
48 dataset=dataset,
49 batch_size=batch_size,
50 sampler=sampler,
51 drop_last=drop_last,
52 pin_memory=pin_memory,
53 num_workers=num_workers,
54 collate_fn=collate_fn,
55 **kwargs,
56 )

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected