Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding L1/L2 regularization in PyTorch?

Is there any way, I can add simple L1/L2 regularization in PyTorch? We can probably compute the regularized loss by simply adding the data_loss with the reg_loss but is there any explicit way, any support from PyTorch library to do it more easily without doing it manually?

like image 831
Wasi Ahmad Avatar asked Mar 09 '17 19:03

Wasi Ahmad


1 Answers

Following should help for L2 regularization:

optimizer = torch.optim.Adam(model.parameters(), lr=1e-4, weight_decay=1e-5) 
like image 147
devil in the detail Avatar answered Sep 22 '22 17:09

devil in the detail