Ho that is a different part of the code ok!
The thing is that if the autograd does not create the graph, that means that the gradient will just always be 0 based on what you computed.
Maybe you can share a full code sample that shows your problem?