【发布时间】:2021-09-18 01:50:21
【问题描述】:
我使用带有批量推理的 pytorch 运行模型。我想将该模型的输出保存到一个列表中,因为稍后我需要它来进行其他计算。问题是,如果我将模型的输出附加到我的列表“输出”中,它会填满 gpu 内存。 模型的输出是一个列表。 有没有办法将列表移动到 RAM 中?
if __name__ == "__main__":
output = []
with torch.no_grad():
for i in input_split:
try:
preds = model(i)
output.append(preds)
del preds
gc.collect()
torch.cuda.empty_cache()
except RuntimeError as e:
print("Failed")
【问题讨论】: