I was trying to place explicit weight constraints on my network layers using your suggested approach, I found that nothing was changing until I added this line (correct me if I’m wrong):
def __call__(self, module):
    # filter the variables to get the ones you want
    if hasattr(module, 'weight'):
        w = module.weight.data
        w = w.clamp(-1,1)
        module.weight.data = w

Just a heads up for anyone trying to implement this in the future!