MCPcopy Create free account
hub / github.com/pytorch/tutorials / LinearSymmetric

Class LinearSymmetric

intermediate_source/parametrizations.py:64–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62###############################################################################
63# We can then use this idea to implement a linear layer with symmetric weights
64class LinearSymmetric(nn.Module):
65 def __init__(self, n_features):
66 super().__init__()
67 self.weight = nn.Parameter(torch.rand(n_features, n_features))
68
69 def forward(self, x):
70 A = symmetric(self.weight)
71 return x @ A
72
73###############################################################################
74# The layer can be then used as a regular linear layer

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected