Langchain-Chatchat/utils/__init__.py

14 lines
512 B
Python
Raw Normal View History

2023-05-03 13:14:36 +08:00
import torch
2023-05-04 20:48:36 +08:00
def torch_gc():
if torch.cuda.is_available():
2023-05-04 20:48:36 +08:00
# with torch.cuda.device(DEVICE):
torch.cuda.empty_cache()
torch.cuda.ipc_collect()
elif torch.backends.mps.is_available():
2023-05-03 10:08:35 +08:00
try:
2023-05-03 22:31:28 +08:00
from torch.mps import empty_cache
empty_cache()
2023-05-03 10:08:35 +08:00
except Exception as e:
print(e)
print("如果您使用的是 macOS 建议将 pytorch 版本升级至 2.0.0 或更高版本,以支持及时清理 torch 产生的内存占用。")