[Solved] Error regarding inplace operation in PyTorch 0.4 but works fine in 0.3

I am getting the following error using PyTorch 0.4.0 but the code works fine in 0.3.1.

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation

May I know what are the changes from 0.3 to 0.4 that can cause this error? I have few view() operations and then I had to apply contiguous(), will that be a cause for this error?

The error was due to applying flatten_parameters() on RNN object in the forward function. Moving that operation in __init__() solved the issue.

1 Like