Jumping loss after a few epochs

FMM: <p>When training my model, I can observe that at some point my loss jumps to a relatively high value for different training runs. The picture shows a good convergence until epoch 24.</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/9/d/9d5ae47419115b980ddc4b516b3447432231544f.png" data-download-href="https://discuss.pytorch.org/uploads/default/9d5ae47419115b980ddc4b516b3447432231544f" title="{39A6BF0C-DB9A-4C2A-9E60-A06C52E989FC}"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/9/d/9d5ae47419115b980ddc4b516b3447432231544f_2_690x195.png" alt="{39A6BF0C-DB9A-4C2A-9E60-A06C52E989FC}" data-base62-sha1="ms1HkEF6OGhqaB6f4Q6mlojgTiD" width="690" height="195" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/9/d/9d5ae47419115b980ddc4b516b3447432231544f_2_690x195.png, https://discuss.pytorch.org/uploads/default/optimized/3X/9/d/9d5ae47419115b980ddc4b516b3447432231544f_2_1035x292.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/9/d/9d5ae47419115b980ddc4b516b3447432231544f.png 2x" data-dominant-color="FAF8F8"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">{39A6BF0C-DB9A-4C2A-9E60-A06C52E989FC}</span><span class="informations">1190×337 38.2 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>What could be the reason for this behaviour?<br>
I am training a transformer model on a masked reconstruction task with MSE loss. I use gradient norm clipping to prevent the gradients from exploding.<br>
I am happy to provide more details about my training parameters if needed!</p>

JuanFMontesinos: <p>You probably have a wrong sample in your training set. Maybe preprocessing issue, overflow etc… Just track the loss and inspect the batch where it happens</p>

FMM: <p>However, as this only happened after a few epochs, the model has seen this sample several times. Why should this cause a problem later, but not earlier?</p>

JuanFMontesinos: <p>I’d say masked reconstruction typically works with random masking. Thus I’d doubt your dataloader is producing the same sample twice. But among all possibilities (dataloader issues, unstabilities in training etc…) the simplest one is looking at the data. Could be normalization issues too (zero divisions) which happen rarely but sometimes stars align.<br>
Reproduce the leak couple of times and observe what’s wrong. If you find nothing strange it could be scheduler issues if you use a fancy one.<br>
Once every 24 epochs that apparently happens quite often doesn’t seem too infrequent to me.</p>

FMM: <p>Most of the time I can restart the training and the same problem doesn’t happen again. This could indicate that there is a very low probability of producing a bad mask (however defined).<br>
By “fancy scheduler” do you mean a learning rate scheduler?</p>

yassineAlouini: <p>Could this be a bad data + shuffling issue? In the sense, you have good data first and then at some point the “bad” data gets in the front?<br>
Try to re-run the same script with fewer data point and check if you get the same issue.</p>