MOSS icon indicating copy to clipboard operation
MOSS copied to clipboard

推理时,显卡内存慢慢占满,怎么释放

Open guiniao opened this issue 2 years ago • 2 comments

使用moss-moon-003-sft-int4,单卡推理,显卡内存随着推理,慢慢占满,怎样设置,推理完一个问题后, 释放显卡内存

guiniao avatar Apr 28 '23 08:04 guiniao

从表现上看,会自动释放

图片

linonetwo avatar Apr 28 '23 13:04 linonetwo

在生成完之后执行这个函数:(双卡情况)

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()

LeonG7 avatar May 08 '23 10:05 LeonG7