Configurable gradient clipping to avoid exploding gradients #38
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In an early training run on the original grid data, I ran into NaNs for losses.
After adding gradient logging locally, I discovered some major spikes in the gradients. This indicates that exploding gradients are likely the cause of the NaNs.
Indeed, after adding gradient clipping to avoid the large spikes, I ran 10 epochs on the original gridded data without any NaNs for losses. This will be another hyperparameter for us to tune.
I suspect smarter weight initialization, learning rate adjustments, and revisiting normalization will help stabilize the gradients, but in the meantime, gradient clipping will prevent them from spiraling out of control.
Note: I'm basing this PR on
hananol/setup-ptlightningsince this configuration change is being passed into the Lightning trainer. However, no need to block merging #26 on this PR. I can rebase ontomainonce the PyTorch Lightning refactor is merged.