diff --git a/backend-python/utils/torch.py b/backend-python/utils/torch.py index 426d03a..637c391 100644 --- a/backend-python/utils/torch.py +++ b/backend-python/utils/torch.py @@ -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