If you want to restrict a parameter to hold only positive values:
https://pytorch.org/tutorials/intermediate/parametrizations.html 1
It might look something like:
import torch
import torch.nn as nn
import torch.nn.utils.parametrize as parametrize

class Positive(nn.Module):
    def forward(self, X):
        return torch.clamp_min(X, 0)

layer = nn.Linear(3, 3)
parametrize.register_parametrization(layer, "weight", Positive())

This is only available in versions >= 1.9.0 though.