My torch version is 1.5.1. I found a strange behavior of torch.exp():

import torch
x = torch.ones(2, 1, requires_grad=True)
x = torch.exp(x)
x[0] = 0
out = x.mean()
out.backward()

After running this code, I got a running error:

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [2, 1]], which is output 0 of ExpBackward, is at version 1; expected version 0 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).

However, if I replace torch.exp() with torch.log() or torch.sin() in the code, it works very well. Can anyone help me to find the solution? Thank you very much.
Edit: One thing I forgot to mention. If I add x=x+0 before x[0]=0, the code works well too.