I am Charmie

メモとログ

PyTorch: at evaluation/test phase

I got a runtime error at evaluation phase of my simple siamese network as RuntimeError: cuda runtime error (2) : out of memory at the line of executing forward pass.

Some comments on stackoverflow suggests to define x and y with volatile=True as

[code lang='python'] for x, y in dataloader: x = torch.autograd.Variable(x.cuda(), volatile=True) y = torch.autograd.Variable(y.cuda(), volatile=True) y_pred = net(x) loss = criterion(y, y_pred) ... [/code] The above code further outputs user warning as UserWarning: volatile was removed and now has no effect. Use with torch.no_grad(): instead, so I uses torch.no_grad as

[code lang='python'] with torch.no_grad(): for x, y in dataloader: y_pred = net(x) loss = criterion(y, y_pred) ... [/code]

Finally, with torch.no_grad(), runtime error doesn't occur!