Lightning-AI / Lightning-AI/pytorch-lightning

`CombinedLoader` takes a long time when `num_workers > 0`

Open
#18,584 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug help wanted performance repro needed ver: 2.0.x
Dominant language
Python
Stars
31.4k
Forks
3.8k
Avg merge
6d 7h
Merged PRs (30d)
6

Description

Bug description

I am currently using CombinedLoader (https://lightning.ai/docs/pytorch/stable/api/lightning.pytorch.utilities.combined_loader.html#lightning.pytorch.utilities.combined_loader.CombinedLoader) to combine multiple datasets. It works fine but I noticed that setting the dataloader with num_workers > 0 causes it to run extremely slow. Is there a logical explanation for this? Feel like this could be a bug otherwise. I attached a chunk of my code to show what I am doing.

What version are you seeing the problem on?

v2.0

How to reproduce the bug
import pytorch_lightning as pl
from lightning.pytorch.utilities.combined_loader import CombinedLoader

class CollectiveDataloader(pl.LightningDataModule):
    def __init__(self, datasets, num_workers=8, batch_size=10, shuffle=True):
        super().__init__()
        self.train_set = CollectiveDataset(
            datasets, num_workers, batch_size, shuffle
        ).datasets

    def train_dataloader(self):
        return CombinedLoader(self.train_set, "sequential")

class CollectiveDataset:
    def __init__(self, datasets, num_workers, batch_size, shuffle):
        # datasets is a dictionary of {dataset_name : Dataset object}
        loaded_datasets = {
            name: DataLoader(
                dataset,
                batch_size=batch_size,
                shuffle=shuffle,
                ### SETTING THIS > 0 RUNS REALLY SLOW ###
                num_workers=num_workers,
            )
            for name, dataset in datasets.items()
        }
        self.datasets = loaded_datasets
Environment
Current environment
#- PyTorch Lightning Version: 2.0.7
#- PyTorch Version: 2.0.1
#- Python version: 3.10.12
#- OS: Linux
#- CUDA/cuDNN version: 12.0

cc @borda

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 with the CombinedLoader entry point and the DataLoader construction shown in the reproduction. Compare the behavior with num_workers set to 0 and greater than 0 using the supplied environment and sequential mode. Done means establishing whether the slowdown is caused by CombinedLoader or the underlying loaders and documenting or fixing the confirmed behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.