Jean-Rassaire:

The problem is that the statistical model required local libraries.


In case you are using other libraries and are “leaving” PyTorch, note that this will detach the computation graph as well (e.g. if you are using numpy). In these cases you would have to implement a custom autograd.Function with the manual definition of the backward pass.
Also check if you are rewrapping any tensors via x = torch.tensor(x, requires_grad=True) as this will also detach the tensor.