/usr/local/lib64/python3.6/site-packages/torch/ao/sparsity/sparsifier
NameSizeModeActions
__pycache__/-0755rm
base_sparsifier.py75500644editdlrm
utils.py11210644editdlrm
weight_norm_sparsifier.py23020644editdlrm
__init__.py00644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/ao/sparsity/sparsifier/utils.py (1121B)
from torch import nn def module_to_fqn(model, layer, prefix=''): for name, child in model.named_children(): new_name = prefix + '.' + name if child is layer: return new_name child_path = module_to_fqn(child, layer, prefix=new_name) if child_path is not None: return child_path return None def fqn_to_module(model, path): path = path.split('.') for name in path: model = getattr(model, name, None) if model is None: return None return model # Parametrizations class FakeSparsity(nn.Module): r"""Parametrization for the weights. Should be attached to the 'weight' or any other parmeter that requires a mask applied to it. Note:: Once the mask is passed, the variable should not change the id. The contents of the mask can change, but the mask reference itself should not. """ def __init__(self, mask): super().__init__() self.register_buffer('mask', mask) def forward(self, x): assert self.mask.shape == x.shape return self.mask * x