Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in DDP training, run ROC.compute() will results gpu to 100% usage and hang the training process #112

Closed
vilon888 opened this issue Mar 20, 2021 · 11 comments
Labels
bug / fix Something isn't working distributed DDP, etc. help wanted Extra attention is needed Priority Critical task/issue
Milestone

Comments

@vilon888
Copy link

vilon888 commented Mar 20, 2021

🐛 Bug

To Reproduce

follow the sample code like https://github.com/PyTorchLightning/metrics,
we use metric = torchmetrics.ROC()
model.roc_metric = metric

in test epoch,
metric.update (output, target)

and after test epoch, run compute
metric.compute()

hang training process and result two gpu in 100% usage

btw, use the metric code in the pytorch_lightning have the same issue as the standalone package

Environment

  • PyTorch Version (1.7.0+cu101):

  • OS (Linux ubuntu 18.04):

  • How you installed PyTorch (`pip):

  • torchmetrics Version: 0.2.0

  • Python version: 3.6

  • CUDA/cuDNN version: 10.1/7.6.5.32-1+cuda10.1

  • GPU models and configuration: two 2080ti

@vilon888 vilon888 added bug / fix Something isn't working help wanted Extra attention is needed labels Mar 20, 2021
@github-actions
Copy link

Hi! thanks for your contribution!, great first issue!

@Borda Borda added this to the 0.3 milestone Mar 25, 2021
@calebclayreagor
Copy link

calebclayreagor commented Mar 31, 2021

I'm running into the same issue with PrecisionRecallCurve and calling .compute() during or after any step if using ddp

@Borda Borda added the Priority Critical task/issue label Apr 1, 2021
@maximsch2
Copy link
Contributor

@calebclayreagor , how big is your data? PrecisionRecallCurve stores the entire dataset in memory and on compute() it needs to consolidate it on single rank. If your model is big and dataset is big, then at some point model + all predictions/labels will not fit into GPU memory which will lead to NCCL issues/GPU OOMs/hangs.

I have a solution for PrecisionRecall-based metrics in #128 by doing binning to make the compute constant-memory (as opposed O(dataset size) right now). You do trade off a bit of accuracy for it and have to specify number of thresholds to use.

@Borda
Copy link
Member

Borda commented Apr 10, 2021

@SkafteNicki have you check this issue? 🐰

@SkafteNicki
Copy link
Member

@Borda cannot debug myself currently as my local cluster is under maintenance

@calebclayreagor
Copy link

@maximsch2 my dataset is quite large (>6m examples) but it still fits in memory. My problem was actually due to ghost processes, and I solved the issue by doing kill -9 <pid> before starting training in ddp mode. Newbie error.

@Borda
Copy link
Member

Borda commented Apr 19, 2021

@justusschock mind have look?

@maximsch2
Copy link
Contributor

@vilon888 , are you still seeing this issue? Can you check one thing - does your dataloader produce batches of the same size for all workers all the time?

@SkafteNicki , I've finally debugged a similar issue we've been having and it's due to handling of datasets that don't divide evenly in the full number of batches - this makes it so that last batch is partial and different lengths on different workers. This makes preds/target tensors different shape and that breaks gather_all_tensors. We probably need to be smarter there - first gather max shape across all workers, then pad the resulting tensor to that max shape, then truncate back.

@SkafteNicki
Copy link
Member

@maximsch2 I agree that could be a problem.
Are you also seeing this when using torchmetrics as standalone or also when used together with lightning?

The reason that I am asking is that lightning as default is using Pytorchs DistributedSampler that will add additional samples to make sure that all processes gets equal workload
https://github.com/pytorch/pytorch/blob/87242d2393119990ebe9043e854317f02536bdff/torch/utils/data/distributed.py#L105-L114

@maximsch2
Copy link
Contributor

DistributedSamper doesn't work for IterableDataset which is what we usually get due to reading from databases, so we never really use that sampler. This is the fix btw: #220

@SkafteNicki
Copy link
Member

Closing as this as it should have been solved by #220.
Please re-open if the error persist.

@Borda Borda added the distributed DDP, etc. label Aug 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug / fix Something isn't working distributed DDP, etc. help wanted Extra attention is needed Priority Critical task/issue
Projects
None yet
Development

No branches or pull requests

5 participants