<p>Yes, the loss must coverage, because of the loss value means the difference between expected Q value and current Q value. Only when loss value converges, the current approaches optimal Q value. If it diverges, this means your approximation value is less and less accurate. </p>

<p>Maybe you can try adjusting the update frequency of the target network or check the gradient of each update (add gradient clipping). The addition of the target network increases the stability of the Q-learning. </p>

<p>In Deepmind's 2015 Nature paper, it states that:</p>

<blockquote>
  <p>The second modification to online Q-learning aimed at further improving the stability of our method with neural networks is to use a separate network for generating the traget yj in the Q-learning update. More precisely, every C updates we clone the network Q to obtain a target network Q' and use Q' for generating the Q-learning targets y<sub>j</sub> for the following C updates to Q. 
  This modification makes the algorithm more stable compared to standard online Q-learning, where an update that increases Q(s<sub>t</sub>,a<sub>t</sub>) often also increases Q(s<sub>t+1</sub>, a) for all a and hence also increases the target y<sub>j</sub>, possibly leading to oscillations or divergence of the policy. Generating the targets using the older set of parameters adds a delay between the time an update to Q is made and the time the update affects the targets y<sub>j</sub>, making divergence or oscillations much more unlikely.  </p>
</blockquote>

<p><a href="https://web.stanford.edu/class/psych209/Readings/MnihEtAlHassibis15NatureControlDeepRL.pdf" rel="noreferrer">Human-level control through deep reinforcement
learning, Mnih et al., 2015</a></p>

<p>I've made an experiment for another person asked similar questions in the Cartpole environment, and the update frequency of 100 solves the problem (achieve a maximum of 200 steps).</p>

<p>When C (update frequency) = 2, Plotting of the average loss:
<a href="https://i.stack.imgur.com/87cNB.png" rel="noreferrer"><img src="https://i.stack.imgur.com/87cNB.png" alt="C=2"></a></p>

<p>C = 10</p>

<p><a href="https://i.stack.imgur.com/fSn8s.png" rel="noreferrer"><img src="https://i.stack.imgur.com/fSn8s.png" alt="C=10"></a></p>

<p>C = 100</p>

<p><a href="https://i.stack.imgur.com/gsWjT.png" rel="noreferrer"><img src="https://i.stack.imgur.com/gsWjT.png" alt="enter image description here"></a></p>

<p>C = 1000</p>

<p><a href="https://i.stack.imgur.com/38hY9.png" rel="noreferrer"><img src="https://i.stack.imgur.com/38hY9.png" alt="enter image description here"></a></p>

<p>C = 10000</p>

<p><a href="https://i.stack.imgur.com/yscNN.png" rel="noreferrer"><img src="https://i.stack.imgur.com/yscNN.png" alt="enter image description here"></a></p>

<p>If the divergence of loss value is caused by gradient explode, you can clip the gradient. In Deepmind's 2015 DQN, the author clipped the gradient by limiting the value within [-1, 1]. In the other case, the author of <a href="https://arxiv.org/pdf/1511.05952.pdf" rel="noreferrer">Prioritized Experience Replay</a> clip gradient by limiting the norm within 10. Here're the examples:</p>

<p>DQN gradient clipping: </p>

<pre class="lang-py prettyprint-override"><code>    optimizer.zero_grad()
    loss.backward()
    for param in model.parameters():
        param.grad.data.clamp_(-1, 1)
    optimizer.step()
</code></pre>

<p>PER gradient clipping:</p>

<pre class="lang-py prettyprint-override"><code>    optimizer.zero_grad()
    loss.backward()
    if self.grad_norm_clipping:
       torch.nn.utils.clip_grad.clip_grad_norm_(self.model.parameters(), 10)
   optimizer.step()
</code></pre>
DQN - Q-Loss not converging
<p>I'm using the DQN algorithm to train an agent in my environment, that looks like this:</p>

<ul>
<li>Agent is controlling a car by picking discrete actions (left, right, up, down)</li>
<li>The goal is to drive at a desired speed without crashing into other cars</li>
<li>The state contains the velocities and positions of the agent's car and the surrounding cars</li>
<li>Rewards: -100 for crashing into other cars, positive reward according to the absolute difference to the desired speed (+50 if driving at desired speed)</li>
</ul>

<p>I have already adjusted some hyperparameters (network architecture, exploration, learning rate) which gave me some descent results, but still not as good as it should/could be. The rewards per epiode are increasing during training. The Q-values are converging, too (see figure <a href="https://i.stack.imgur.com/vU1yu.png" rel="noreferrer">1</a>). However, for all different settings of hyperparameter the Q-loss is not converging (see figure <a href="https://i.stack.imgur.com/cG4jt.png" rel="noreferrer">2</a>). I assume, that the lacking convergence of the Q-loss might be the limiting factor for better results.</p>

<p><a href="https://i.stack.imgur.com/vU1yu.png" rel="noreferrer">Q-value of one discrete action durnig training</a></p>

<p><a href="https://i.stack.imgur.com/cG4jt.png" rel="noreferrer">Q-loss during training</a></p>

<p>I'm using a target network which is updated every 20k timesteps. The Q-loss is calculated as MSE.</p>

<p>Do you have ideas why the Q-loss is not converging?
Does the Q-Loss have to converge for DQN algorithm? I'm wondering, why Q-loss is not discussed in most of the papers.</p>