42 minutes ago · 22 min read4461 words · Tech · hide

I noticed something odd when I was training some models the other day -- something that went against my understanding of how PyTorch's Automatic Mixed Precision (AMP) training tools worked. In particular, I believed that the GradScaler class filtered out non-finite gradients -- that was based on this comment in the AMP recipe page: # ``scaler.step()`` first unscales the gradients of the optimizer's assigned parameters. # If these gradients do not contain ``inf``s or ``NaN``s, optimizer.step() is then called, # otherwise, optimizer.step() is skipped. However, I was finding that the weights of a model I was training were all being set to NaNs, and while I could see ways that could happen even with finite gradients, none of those appeared to be happening. Understanding your tools properly is an essential part of engineering, so I decided to dig in and find out what was happening -- in particular, what I was misunderstanding about what was going on. This post has the details, but so as…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town