From 55821ca244fe1ad6f2d1fc193dfe1cb95366481b Mon Sep 17 00:00:00 2001 From: Rocco Moretti Date: Mon, 10 Nov 2025 14:32:20 -0600 Subject: [PATCH 1/4] Catch issue with partial mpi4py installation. Depending on precise install, mpi4py may be installed without `MPI` being present. Catch that case in the detect() function, and treat it as if mpi4py is not installed. --- src/lightning/fabric/plugins/environments/mpi.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lightning/fabric/plugins/environments/mpi.py b/src/lightning/fabric/plugins/environments/mpi.py index dd4897663d187..5b031b5275f16 100644 --- a/src/lightning/fabric/plugins/environments/mpi.py +++ b/src/lightning/fabric/plugins/environments/mpi.py @@ -73,7 +73,10 @@ def detect() -> bool: if not _MPI4PY_AVAILABLE: return False - from mpi4py import MPI + try: + from mpi4py import MPI + except ImportError: + return False return MPI.COMM_WORLD.Get_size() > 1 From 96f630f2feb57cee8e03d56d70a49b5d938098c3 Mon Sep 17 00:00:00 2001 From: deependujha Date: Wed, 19 Nov 2025 18:57:08 +0530 Subject: [PATCH 2/4] update --- src/lightning/fabric/CHANGELOG.md | 2 +- src/lightning/fabric/plugins/environments/mpi.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lightning/fabric/CHANGELOG.md b/src/lightning/fabric/CHANGELOG.md index 307975e1619bd..64eac279c3261 100644 --- a/src/lightning/fabric/CHANGELOG.md +++ b/src/lightning/fabric/CHANGELOG.md @@ -25,7 +25,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Fixed -- +- Fix issue with partial mpi4py installation ([#21353](https://github.com/Lightning-AI/pytorch-lightning/pull/21353)) --- diff --git a/src/lightning/fabric/plugins/environments/mpi.py b/src/lightning/fabric/plugins/environments/mpi.py index 5b031b5275f16..cb7473d52c6e7 100644 --- a/src/lightning/fabric/plugins/environments/mpi.py +++ b/src/lightning/fabric/plugins/environments/mpi.py @@ -74,6 +74,7 @@ def detect() -> bool: return False try: + # mpi4py may be installed without MPI being present from mpi4py import MPI except ImportError: return False From 79ef4ff06864d480f791bf079dcd5b549060fa6d Mon Sep 17 00:00:00 2001 From: deependujha Date: Wed, 19 Nov 2025 18:59:30 +0530 Subject: [PATCH 3/4] update --- src/lightning/fabric/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lightning/fabric/CHANGELOG.md b/src/lightning/fabric/CHANGELOG.md index 64eac279c3261..ccc4d6dd328a4 100644 --- a/src/lightning/fabric/CHANGELOG.md +++ b/src/lightning/fabric/CHANGELOG.md @@ -25,7 +25,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Fixed -- Fix issue with partial mpi4py installation ([#21353](https://github.com/Lightning-AI/pytorch-lightning/pull/21353)) +- Fix issue in detecting MPIEnvironment with partial mpi4py installation ([#21353](https://github.com/Lightning-AI/pytorch-lightning/pull/21353)) --- From 7194bf6d19742f50d2b3f90d4d7b682b9419bfad Mon Sep 17 00:00:00 2001 From: deependujha Date: Wed, 19 Nov 2025 23:56:54 +0530 Subject: [PATCH 4/4] update --- src/lightning/fabric/CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lightning/fabric/CHANGELOG.md b/src/lightning/fabric/CHANGELOG.md index b3f59f1fbb08b..b8c1af644ad4a 100644 --- a/src/lightning/fabric/CHANGELOG.md +++ b/src/lightning/fabric/CHANGELOG.md @@ -27,8 +27,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fixed issue in detecting MPIEnvironment with partial mpi4py installation ([#21353](https://github.com/Lightning-AI/pytorch-lightning/pull/21353)) -- Fixed `EADDRINUSE` errors in distributed tests with port manager and retry logic ([#21309](https://github.com/Lightning-AI/pytorch-lightning/pull/21309)) - - Learning rate scheduler is stepped at the end of epoch when `on_train_batch_start` returns -1 ([#21296](https://github.com/Lightning-AI/pytorch-lightning/issues/21296)).