If this is the way you update your weights and don’t want gradients to flow back this op (which is what you want I expect), you should wrap this op in a with torch.no_grad():. This way the engine will know that you’re not trying to make a differentiable op and just changing a value of the weights:
# More code
optimizer.step()
with torch.no_grad():
  self.conv1.weight.masked_scatter_(self.conv1.weight > self.w_max, self.w_max)