How do I add L1/L2 regularization in PyTorch without manually computing it?
See the documentation. Add a weight_decay parameter to the optimizer for L2 regularization.
weight_decay