What's the best way to handle exception "cuda runtime error (2) : out of memory"?

Thanks, actually I met the problem mentioned here:

When I tried to clear the grad after the exception, another Exception was raised when calling zero_grad().