How to create an optimizer given a loss function

Thank you for your kindly help! It helps me to understand Pytorch a lot!