Thanks for the answer. Actually I found a hidden inplace operation in some other part of the code, which I didn’t posted. I didn’t realize that this was an inplace operation:
feature[0] = feature[0].detach()