![](/img/trans.png)
[英]In language modeling, why do I have to init_hidden weights before every new epoch of training? (pytorch)
[英]In pytorch, I want to save the the output in every epoch for late caculation. But it leads to OUT OF MEMORY ERROR after several epochs,
在 pytorch 中,我想保存每个 epoch 中的输出以供后期计算。 但它会在几个时期后导致 OUT OF MEMORY ERROR。 代码如下:
L=[]
optimizer.zero_grad()
for i, (input, target) in enumerate(train_loader):
output = model(input)
L.append(output)
*** updata my model to minimize a loss function. List L will be used here.
我知道原因是因为 pytorch 保存了每个时代的所有计算图。 但是损失函数只能在得到所有的预测结果后才能计算
有没有办法训练我的模型?
你在 GPU 上训练吗?
如果是这样,你可以像移动它的主内存
L.append(output.detach().cpu())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.