prevent 'torch' has no attribute 'cuda' error in torch_gc, so user can use CPU or WebGPU (#302)

This commit is contained in:
josc146 2024-03-11 19:04:19 +08:00
parent dd89041f72
commit bb1a6191b0

View File

@ -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