Now that @Naman-ntc summoned me:
The easy way is in __init__
self.eps = 1e-7
weight_raw = torch.nn.Parameter(torch.randn(n,m))

and then
weight = self.weight_raw / self.weight_raw.sum(1, keepdim=True).clamp(min=self.eps)

in forward. There are much more elaborate ways let’s see if this works for you. For example, you can construct a wrapper that does this, see torch.nn.utils.spectral_norm 99, but it probably overkill unless you’re sure you need it.
Best regards
Thomas
P.S.: Maybe add an “s” to the topic, in case you want to search for it later.