Skip to content

Commit

Permalink
prevent 'torch' has no attribute 'cuda' error in torch_gc, so user ca…
Browse files Browse the repository at this point in the history
…n use CPU or WebGPU (#302)
  • Loading branch information
josStorer committed Mar 11, 2024
1 parent dd89041 commit bb1a619
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions backend-python/utils/torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ def set_torch():


def torch_gc():
import torch
try:
import torch

if torch.cuda.is_available():
with torch.cuda.device(0):
torch.cuda.empty_cache()
torch.cuda.ipc_collect()
if torch.cuda.is_available():
with torch.cuda.device(0):
torch.cuda.empty_cache()
torch.cuda.ipc_collect()
except:
pass # prevent 'torch' has no attribute 'cuda' error, so user can use CPU or WebGPU

0 comments on commit bb1a619

Please sign in to comment.