Lightning-AI / Lightning-AI/pytorch-lightning
Dataloader on multi-gpu jobs only surpport to manipulate on local_rank=0, is there a way tom manipulate every device?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 31.4k
- Forks
- 3.8k
- Avg merge
- 6d 7h
- Merged PRs (30d)
- 6
Description
### Bug description
If we use ddp strategy, dataloader on multi-gpu jobs only surpport to manipulate on local_rank=0, local rank 0 need very high memory space, but every device has the same memory. The more devices, the higher memory on local rank 0. So we can not run some large case, which need higher memory, or lead to waste the memory space. Can you give me an advice to how to use lighting for large case?
### What version are you seeing the problem on?
master
### How to reproduce the bug
```python
maybe need to fix the code below:
def prepare_data(self) -> None:
trainer = self.trainer
# on multi-gpu jobs we only want to manipulate (download, etc) on node_rank=0, local_rank=0
# or in the case where each node needs to do its own manipulation in which case just local_rank=0
local_rank_zero = trainer.local_rank == 0
global_rank_zero = trainer.local_rank == 0 and trainer.node_rank == 0
datamodule = trainer.datamodule
lightning_module = trainer.lightning_module
# handle datamodule prepare data:
if datamodule is not None and is_overridden("prepare_data", datamodule):
prepare_data_per_node = datamodule.prepare_data_per_node
with _InfiniteBarrier():
if (prepare_data_per_node and local_rank_zero) or (not prepare_data_per_node and global_rank_zero):
call._call_lightning_datamodule_hook(trainer, "prepare_data")
```
### Error messages and logs
```
# Error messages and logs here please
```
### Environment
Current environment
```
#- Lightning Component (e.g. Trainer, LightningModule, LightningApp, LightningWork, LightningFlow):
#- PyTorch Lightning Version (e.g., 1.5.0):
#- Lightning App Version (e.g., 0.5.2):
#- PyTorch Version (e.g., 2.0):
#- Python version (e.g., 3.9):
#- OS (e.g., Linux):
#- CUDA/cuDNN version:
#- GPU models and configuration:
#- How you installed Lightning(`conda`, `pip`, source):
#- Running environment of LightningApp (e.g. local, cloud):
```
### More info
_No response_
cc @tchaton @justusschock @lantiga
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the prepare_data entry point and the shown _InfiniteBarrier and rank-selection logic under DDP. Reproduce the multi-GPU behavior described for dataloaders, then determine the intended per-device manipulation semantics and verify that memory use and prepare_data execution match that behavior across ranks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- distributed-systems, machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100