MOSS
MOSS copied to clipboard
推理时,显卡内存慢慢占满,怎么释放
使用moss-moon-003-sft-int4,单卡推理,显卡内存随着推理,慢慢占满,怎样设置,推理完一个问题后, 释放显卡内存
从表现上看,会自动释放

在生成完之后执行这个函数:(双卡情况)
import torch
def torch_gc():
if torch.cuda.is_available():
with torch.cuda.device('cuda:0'):
torch.cuda.empty_cache()
torch.cuda.ipc_collect()
with torch.cuda.device('cuda:1'):
torch.cuda.empty_cache()
torch.cuda.ipc_collect()