Skip to content

Commit 00f9da7

Browse files
committed
make torch.cuda.empty_cache() a no-op when cuda is not initialized (#4936)
1 parent a5fec26 commit 00f9da7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

torch/cuda/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ def empty_cache():
322322
"""Releases all unoccupied cached memory currently held by the caching
323323
allocator so that those can be used in other GPU application and visible in
324324
`nvidia-smi`."""
325-
_lazy_init()
326-
return torch._C._cuda_emptyCache()
325+
if _initialized:
326+
return torch._C._cuda_emptyCache()
327327

328328

329329
def _host_allocator():

0 commit comments

Comments
 (0)