Okay I seem to have got it to work - later lines in my code were conflicting with this portion. I needed to include create_graph=True in my grad() statement. I guess I don’t fully understand how create_graph and retain_graph work. What I’m seeking to do is at every epoch, along with my prediction, I want to calculate the gradient of my prediction w.r.t the input. The idea is to then implement as part of my loss function. How does including create_graph=True fit into all this? Thanks for your help!
Edit - I also noticed that if I change retain_graph=True it works as well. So it really is a question of which one to utilize and what their differences are. Especially when it comes to speed.