Skip to content

Instantly share code, notes, and snippets.

@MilesCranmer
Created March 3, 2021 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MilesCranmer/25442a0058d98b9ae4647439537a41f2 to your computer and use it in GitHub Desktop.
Save MilesCranmer/25442a0058d98b9ae4647439537a41f2 to your computer and use it in GitHub Desktop.
Trick to step backwards if a NaN occurs

Before training:

last = model.state_dict()

Inside training loop, after computing loss:

if torch.isnan(loss).sum().item():
    model.load_state_dict(last)
else:
    last = model.state_dict()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment