Thank you,
It worked well!!
but I had to modify some of part  to get a correct gradient
# before
weights = torch.where( abs(weights) < self.cw - self.dw, torch.tensor(0.).to(device),weights)
# after
weights_out = torch.where( abs(weights) < self.cw - self.dw, torch.tensor(0.).to(device),weights)

in this way
Thank you very much!!!