ddpg(Deep Deterministic Policy Gradient) policy loss grows instead of decreases

Viewed 189

I'm currently training an DDPG net work on a environment with negative reward, the goal is to get the max reward (in other words, to avoid doing actions that leads to negative rewards)

Following the DDPG algorithm, I've set up a policy and a critic network with target networks respectively for training. This is the update function of the policy network

torch::Tensor DDPRLabeler::compute_pi_loss(const Batch &batch_data)
{    
    const torch::Tensor &s = get<0>(batch_data);    
    torch::Tensor loss = -((net->q->forward(s, net->pi->forward(s))).mean());    
    return loss;
}

and this is the update function for the critic network


torch::Tensor DDPRLabeler::compute_q_loss(const Batch &batch_data)
{   
    const torch::Tensor &s = get<0>(batch_data);
    const torch::Tensor &a = get<1>(batch_data);
    const torch::Tensor &r = get<2>(batch_data);
    const torch::Tensor &s_next = get<3>(batch_data);
    const torch::Tensor &done = get<4>(batch_data);    
    torch::Tensor target_qval;
    {
        torch::NoGradGuard no_grad;
        torch::Tensor raw_target_q = (net_tar->q->forward(s_next, net_tar->pi->forward(s_next)));
        target_qval = r + (~done) * gamma * raw_target_q;
    }
    torch::Tensor loss = (net->q->forward(s, a) - target_qval).pow(2).mean();    
    return loss;
}

The loss of the critic decreases as expected, however the loss of the policy network keeps increasing

[The critic network][1] [The policy network][2]

What could possibly be the problem here? I couldn't tell whether it is that the model is not yet trained, or that there's error in my formulation

Any recommendation for the debugging direction will be appreciated.

policy network

critic network

0 Answers
Related