Multi-GPU prediction gather callback. #21655
|
Hello, I have a super-resolution model that operates on patches. In the validation step, I would like to reassembly selected predictions and save, so I can run some external program to get metrics. It works fine on single GPU. but on multiple GPU (DDP) I have deadlock after this step. Do you have any ideas how to even approach this program? |
Replies: 1 comment 1 reply
|
Hey @konrad-karanowski, this deadlock happens because Use Lightning's def on_validation_epoch_end(self, trainer: Trainer, pl_module: LightningModule) -> None: Let me know if this fixes the deadlock. If it works, could you mark this as the Answer? Helps others with DDP. |
Hey @konrad-karanowski, this deadlock happens because
all_gather_objectis a collective — all ranks must call it, even if they have no data.Use Lightning's
strategy.all_gatherinstead. It's safer and handles the empty-rank case:def on_validation_epoch_end(self, trainer: Trainer, pl_module: LightningModule) -> None:
if not self._should_run(trainer):
return