I am creating my own nn.Module
with its own forward
function and matrix of parameters, P
. But, I would like to impose that part of the matrix of parameters is set to zero and remains zero. Is there a way to do so without defining the matrix using multiple parameters definition?
class Model(nn.Module):
def __init__(self, n_objects):
super(Model, self).__init__()
self.n_objects = n_objects
P = torch.empty(
(self.n_objects, self.n_objects),
requires_grad=True)
nn.init.uniform_(P)
self.P = torch.nn.Parameter(P)
Here, for example, I would like that all the elements in the main diagonal of P
should not change w.r.t. the original values.
Thanks for the help!