I was looking for how to add a L2 norm of a parameter to the loss function. And I did as suggested above, however,  there comes a bug:
RuntimeError: Trying to backward through the graph a second time, but the buffers have already been freed. Specify retain_graph=True when calling backward the first time.

How should I solve this problem? Thank you very much.