I put

self.conv1.weight.masked_scatter_(self.conv1.weight > self.w_max, self.w_max)

as the first line in forward(), but I’m getting:

RuntimeError: a leaf Variable that requires grad has been used in an in-place operation.