No, you don’t need to use requires_grad attribute and could even create the initial regularizer variable as a Python scalar: regularizer = 0.

As long as Autograd doesn’t raise an error, the inplace operation should work fine. In case you are concerned about scripting the model (and loss calculation), you could check if removing the inplace ops would allow more operator fusions, but that might be an edge case.