Lightning-AI / Lightning-AI/pytorch-lightning

Distributed mode overwrites the user's choice for dataloaders shuffling

Open
#10,170 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

data handling feature help wanted
Dominant language
Python
Stars
31.4k
Forks
3.8k
Avg merge
6d 7h
Merged PRs (30d)
6

Description

## 🐛 Bug
I ordered my training data in a specific manner and passed it to the DataLoader with `shuffle=False` (I use `reload_dataloaders_every_n_epochs=1` to control it every epoch). Then, I found out that running in distributed mode re-creates the train dataloader and always set `shuffle=True`. The opposite happens for the val dataloader.

I think that the re-creation of the dataloaders must be using the same shuffle setting the original dataloaders had.
Is there any reason not to do so?

---
Here is the related code with the hard-coded shuffle values:

train - shuffle forced to be true
https://github.com/PyTorchLightning/pytorch-lightning/blob/c33df2639f19d49c5e7520294e3221efe402d684/pytorch_lightning/trainer/data_loading.py#L330-L333

val - shuffle forced to be true
https://github.com/PyTorchLightning/pytorch-lightning/blob/c33df2639f19d49c5e7520294e3221efe402d684/pytorch_lightning/trainer/data_loading.py#L442-L443

cc @borda @justusschock @awaelchli

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in pytorch_lightning/trainer/data_loading.py at the linked train-loader lines 330-333 and validation-loader lines 442-443. Trace how distributed mode recreates each DataLoader and preserve the original shuffle choices for both loaders. Done means user-specified train and validation shuffling remains unchanged in distributed mode, with the relevant dataloader tests passing.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
distributed-systems, machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.