As you note in your comment, writing into Pin_predicted with
an index is an inplace modification and could well be the
cause of the error you are seeing.
The code you posted doesn’t show any call to .backward(),
so it’s not possible to track down where things are going wrong.
You can find some suggestions for locating and fixing
inplace-modification errors in this post: