def prune_params(layer: nn.PReLU, idxs: list) -> nn.Module: if layer.num_parameters == 1: return layer keep_idxs = list(set(range(layer.num_parameters)) - set(idxs)) layer.num_parameters = layer.num_parameters - len(idxs) layer.weight = torch.nn.Parameter(layer.weight.data.clone()[keep_idxs]) return layer
def prune_prelu(layer: nn.PReLU, idxs: list, inplace: bool = True, dry_run: bool = False): """Prune PReLU layers, e.g. [128] => [64] or [1] => [1] (no pruning if prelu has only 1 parameter) Args: layer: a PReLU layer. idxs: pruning index. """ num_pruned = 0 if layer.num_parameters == 1 else len(idxs) if dry_run: return layer, num_pruned if not inplace: layer = deepcopy(layer) if layer.num_parameters == 1: return layer, num_pruned keep_idxs = [i for i in range(layer.num_parameters) if i not in idxs] layer.num_parameters = layer.num_parameters - len(idxs) layer.weight = torch.nn.Parameter(layer.weight.data.clone()[keep_idxs]) return layer, num_pruned
def prune_prelu(layer: nn.PReLU, idxs: list, inplace: bool = True, dry_run: bool = False): #line:147 "" #line:153 OOO00O000O0OO0O0O = 0 if layer.num_parameters == 1 else len( idxs) #line:154 if dry_run: #line:155 return layer, OOO00O000O0OO0O0O #line:156 if not inplace: #line:157 layer = deepcopy(layer) #line:158 if layer.num_parameters == 1: return layer, OOO00O000O0OO0O0O #line:159 OO0OOOOO0OO00O0O0 = [ OOOO00OOOOOOO00O0 for OOOO00OOOOOOO00O0 in range(layer.num_parameters) if OOOO00OOOOOOO00O0 not in idxs ] #line:160 layer.num_parameters = layer.num_parameters - len(idxs) #line:161 layer.weight = torch.nn.Parameter( layer.weight.data.clone()[OO0OOOOO0OO00O0O0]) #line:162 return layer, OOO00O000O0OO0O0O #line:163
def prune_prelu(OO0O00OO0O0O000O0: nn.PReLU, OOOOO0O000O00O0OO: list, inplace: bool = True, dry_run: bool = False): #line:147 "" #line:153 OOOO00OOOOO000OO0 = 0 if OO0O00OO0O0O000O0.num_parameters == 1 else len( OOOOO0O000O00O0OO) #line:154 if dry_run: #line:155 return OO0O00OO0O0O000O0, OOOO00OOOOO000OO0 #line:156 if not inplace: #line:157 OO0O00OO0O0O000O0 = deepcopy(OO0O00OO0O0O000O0) #line:158 if OO0O00OO0O0O000O0.num_parameters == 1: return OO0O00OO0O0O000O0, OOOO00OOOOO000OO0 #line:159 OO0000O0O0OO00000 = [ OO0OOO000OOOOO000 for OO0OOO000OOOOO000 in range(OO0O00OO0O0O000O0.num_parameters) if OO0OOO000OOOOO000 not in OOOOO0O000O00O0OO ] #line:160 OO0O00OO0O0O000O0.num_parameters = OO0O00OO0O0O000O0.num_parameters - len( OOOOO0O000O00O0OO) #line:161 OO0O00OO0O0O000O0.weight = torch.nn.Parameter( OO0O00OO0O0O000O0.weight.data.clone()[OO0000O0O0OO00000]) #line:162 return OO0O00OO0O0O000O0, OOOO00OOOOO000OO0 #line:163