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

Class PruningParametrization

intermediate_source/parametrizations.py:334–345  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

332# interest to relax this relation. For example, consider the following implementation
333# of a randomized pruning method:
334class PruningParametrization(nn.Module):
335 def __init__(self, X, p_drop=0.2):
336 super().__init__()
337 # sample zeros with probability p_drop
338 mask = torch.full_like(X, 1.0 - p_drop)
339 self.mask = torch.bernoulli(mask)
340
341 def forward(self, X):
342 return X * self.mask
343
344 def right_inverse(self, A):
345 return A
346
347###############################################################################
348# In this case, it is not true that for every matrix A ``forward(right_inverse(A)) == A``.

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected