The code for SGD is very readable given that you know how it works: https://pytorch.org/docs/stable/_modules/torch/optim/sgd.html 5
You might ignore in-place operations they tend to use, and also ignore the “param_groups” if you don’t care.