You can clip the weights after the optimizer update each time or you can over-ride the forward call of Linear layer to do it before multiplying with input. If you are doing the latter, you could also apply tanh or sigmoid to the weights before doing the dot product.
Smooth ways of achieving this would be to simply include L1 or L2 penalty on the weights.
This is a very specific requirement, so I think there won’t be a basic way to do this.