diff --git a/src/lightning_app/CHANGELOG.md b/src/lightning_app/CHANGELOG.md index 000fd134911da..0f65db620a60b 100644 --- a/src/lightning_app/CHANGELOG.md +++ b/src/lightning_app/CHANGELOG.md @@ -69,6 +69,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fixed PythonServer generating noise on M1 ([#15949](https://github.com/Lightning-AI/lightning/pull/15949)) +- Fixed `ImportError` on Multinode if package not present ([#15963](https://github.com/Lightning-AI/lightning/pull/15963)) + - Fixed multiprocessing breakpoint ([#15950](https://github.com/Lightning-AI/lightning/pull/15950)) - Fixed detection of a Lightning App running in debug mode ([#15951](https://github.com/Lightning-AI/lightning/pull/15951)) diff --git a/src/lightning_app/components/multi_node/lite.py b/src/lightning_app/components/multi_node/lite.py index 36709d409e1a0..003c6dfb1c75a 100644 --- a/src/lightning_app/components/multi_node/lite.py +++ b/src/lightning_app/components/multi_node/lite.py @@ -37,11 +37,14 @@ def run( mps_accelerators = [] for pkg_name in ("lightning.lite", "lightning_" + "lite"): - pkg = importlib.import_module(pkg_name) - lites.append(pkg.LightningLite) - strategies.append(pkg.strategies.DDPSpawnShardedStrategy) - strategies.append(pkg.strategies.DDPSpawnStrategy) - mps_accelerators.append(pkg.accelerators.MPSAccelerator) + try: + pkg = importlib.import_module(pkg_name) + lites.append(pkg.LightningLite) + strategies.append(pkg.strategies.DDPSpawnShardedStrategy) + strategies.append(pkg.strategies.DDPSpawnStrategy) + mps_accelerators.append(pkg.accelerators.MPSAccelerator) + except (ImportError, ModuleNotFoundError): + continue # Used to configure PyTorch progress group os.environ["MASTER_ADDR"] = main_address diff --git a/src/lightning_app/components/multi_node/trainer.py b/src/lightning_app/components/multi_node/trainer.py index 8f25b71d622c1..76d744e24608c 100644 --- a/src/lightning_app/components/multi_node/trainer.py +++ b/src/lightning_app/components/multi_node/trainer.py @@ -37,11 +37,14 @@ def run( mps_accelerators = [] for pkg_name in ("lightning.pytorch", "pytorch_" + "lightning"): - pkg = importlib.import_module(pkg_name) - trainers.append(pkg.Trainer) - strategies.append(pkg.strategies.DDPSpawnShardedStrategy) - strategies.append(pkg.strategies.DDPSpawnStrategy) - mps_accelerators.append(pkg.accelerators.MPSAccelerator) + try: + pkg = importlib.import_module(pkg_name) + trainers.append(pkg.Trainer) + strategies.append(pkg.strategies.DDPSpawnShardedStrategy) + strategies.append(pkg.strategies.DDPSpawnStrategy) + mps_accelerators.append(pkg.accelerators.MPSAccelerator) + except (ImportError, ModuleNotFoundError): + continue # Used to configure PyTorch progress group os.environ["MASTER_ADDR"] = main_address