I am quite new to PyTorch and the community, so please bear with me on this.
I want to have a neural network propose rewards for the states in a reinforcement learning task. After running my RL algorithm using these proposed rewards, I expect to have an estimated policy.
I want the loss of the network to be the distance between the estimated policy and the actual policy, which I already have. (The objective here is to learn the rewards, not the policy.)

I implemented my algorithm using numpy but now I’m trying to incorporate PyTorch and it looks desperate. Feeding states to obtain reward propositions was pretty straightforward, I did a simple forward pass. But upon receiving the rewards, I had to use detach() to get these values to calculate the loss and now, I cannot backpropagate since I have broken the computation graph when I use detach(). This is my problem.
Now, I only see two possibilities: 1) move everything to pytorch and abandon numpy 2) try to come up with a hybrid solution.
My questions are:

Is option 2 doable using PyTorch?


If so, what do I need to do to have the gradients calculated automatically?

And if not, is option 1 doable using PyTorch? Do I have to move all my code to PyTorch?



Many thanks for taking your time.