Frequently Asked Questions
My model reports "cuda runtime error(2): out of memory"
As the error message suggests, you have run out of memory on your GPU.
Since we often deal with large amounts of data in PyTorch, small
mistakes can rapidly cause your program to use up all of your GPU;
fortunately, the fixes in these cases are often simple. Here are a few
common things to check:
Don't accumulate history across your training loop. By default,
computations involving variables that require gradients will keep
history.  This means that you should avoid using such variables in
computations which will live beyond your training loops, e.g., when
tracking statistics. Instead, you should detach the variable or access
its underlying data.
Sometimes, it can be non-obvious when differentiable variables can
occur.  Consider the following training loop (abridged from source):
total_loss = 0
   for i in range(10000):