Check, if any of the internal functions is (accidentally) detaching a tensor from the computation graph (e.g. by using a non-differentiable operation) by checking the .grad_fn of intermediate tensors.
If one of them shows None it would mean that this particular tensor is not attached to a graph. Often users try to fix this by rewrapping a tensor and setting requires_grad=True again, which won’t fix the issue.