ptrblck:

If so, does the code also raise the error, if you call detach_().requires_grad_() outside of the forward on the returned samples?


So I moved the detach_().requires_grad_() outside the forward method and it crashes like before. I’ve tried a few different ways of doing this and I think I have an idea as to what’s causing it.
@torch.no_grad()
def forward(self, burn_in: int) -> Tuple[Tensor, Tensor]:
  self.acceptance.zero_()
    
  for i in range(burn_in+1): #check +1 here
    self.step()
  #return self.chains.detach_().requires_grad_(), self.acceptance.detach_() #doesn't work
  return self.chains.detach_(), self.acceptance.detach_() #works
  return self.chains.detach().requires_grad_(), self.acceptance.detach_() #works

So it seems perhaps the issue arises from calling an in-place op on an in-place op?