Sharded data loading with DDP #8795
Unanswered
niansong1996
asked this question in
DDP / multi-GPU / multi-node
Replies: 1 comment 1 reply
-
Dear @niansong1996, By default, Lightning assumes the same dataset is being loaded on all ranks and a DistributedSampler is injected within the DataLoader to assign each rank a sub-part of the dataset. In your case, you have already created the shard. You could make your dataset rank aware as follow. Using an IterableDataset is also a good solution. class Dataset(Dataset):
def __init__(self, global_rank = ..):
self.list_shards = [...]
self.current_shard = self.list_shards[global_rank]
self.data = load(self.current_shard)
def __getitem__(self, index):
return len(self.data[idx])
def __len__(self):
return len(self.data)
class DataModule()
def prepare_data(self):
# create shard if they don't exist
def train_dataloader(self):
ds = Dataset(self.trainer.global_rank)
return DataLoader(ds)
# prevent Lightning to inject DDSampler
Trainer(replace_sampler_ddp=False) Here is a good reference: https://github.com/webdataset/webdataset |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Relatively new to Lightning, has been struggling with this for a few days. I am wondering what is the right way to do data reading/loading under DDP.
More details:
train_shard_0.jsonl
,train_shard_1.jsonl
, etc), while# shards = # gpus
;torch.distributed.get_rank()
to directLightningDataModule
on each process to read a specific shard of the dataset;batchs_size=4
, the first batch would have process 0 load examples[0, 1, 2, 3]
and process 1 load[4, 5, 6, 7]
, as if they are still a copy of the same dataset, which make the sharding meaningless;So I am wondering what is the best practice for data reading/loading under DDP, and whether I would need to define my own customized
Dataloader
or other classes to make it right. Thanks for help of any kind!Beta Was this translation helpful? Give feedback.
All reactions