The error is usually thrown, if you detach a tensor from the computation graph, e.g. by:

calling tensor.detach() on it directly
transforming it to a numpy array or a Python literal
recreating a tensor via torch.tensor(tensor)


Could you check your code for any of these ops?