thanks for the quick answer. Is there another way to code this self-contained in the nn.Module subclass? Because this would get very, very complicated programming-wise (I have not started the project with this option in mind and combine them early). I have a lot of these modules and a lot of these “l_2” losses. I want to disable the gradients for positive values for some modules and not for others, based on hyper-parameters.