Skip to content

Commit 43ab98b

Browse files
committed
fix _try_import function not defined issue in fabric
1 parent eae6682 commit 43ab98b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/lightning/fabric/utilities/imports.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@
3636
_PYTHON_GREATER_EQUAL_3_10_0 = (sys.version_info.major, sys.version_info.minor) >= (3, 10)
3737

3838

39+
@functools.lru_cache(maxsize=128)
40+
def _try_import_module(module_name: str) -> bool:
41+
try:
42+
__import__(module_name)
43+
return True
44+
# added also AttributeError fro case of impoerts like pl.LightningModule
45+
except (ImportError, AttributeError) as err:
46+
rank_zero_warn(f"Import of {module_name} package failed for some compatibility issues: \n{err}")
47+
return False
48+
49+
3950
@functools.lru_cache(maxsize=1)
4051
def _lightning_xpu_available() -> bool:
4152
# This is defined as a function instead of a constant to avoid circular imports, because `lightning_xpu`

0 commit comments

Comments
 (0)