Skip to content

Commit 2716b6a

Browse files
KumoLiuericspod
andauthored
Remove device count cache when import monai (#7581)
workaround for #7575 ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
1 parent e5bebfc commit 2716b6a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

monai/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@
8383
from .utils.tf32 import detect_default_tf32
8484

8585
detect_default_tf32()
86+
import torch
87+
88+
# workaround related to https://github.com/Project-MONAI/MONAI/issues/7575
89+
if hasattr(torch.cuda.device_count, "cache_clear"):
90+
torch.cuda.device_count.cache_clear()
8691
except BaseException:
8792
from .utils.misc import MONAIEnvVars
8893

0 commit comments

Comments
 (0)