project_name
string
class_name
string
class_modifiers
string
class_implements
int64
class_extends
int64
function_name
string
function_body
string
cyclomatic_complexity
int64
NLOC
int64
num_parameter
int64
num_token
int64
num_variable
int64
start_line
int64
end_line
int64
function_index
int64
function_params
string
function_variable
string
function_return_type
string
function_body_line_type
string
function_num_functions
int64
function_num_lines
int64
outgoing_function_count
int64
outgoing_function_names
string
incoming_function_count
int64
incoming_function_names
string
lexical_representation
string
pytorch_ao
public
public
0
0
__call__
def __call__(self, module, input, output):if getattr(module, "_bias", None) is not None:bias = module._bias.dataif self.prune_bias:bias[~self.param.mask] = 0# reshape bias to broadcast over output dimensionsidx = [1] * len(output.shape)idx[1] = -1bias = bias.reshape(idx)output += biasreturn output
3
10
4
79
0
51
63
51
null
[]
None
null
0
0
0
null
0
null
The function (__call__) defined within the public class called public.The function start at line 51 and ends at 63. It contains 10 lines of code and it has a cyclomatic complexity of 3. It takes 4 parameters, represented as [51.0] and does not return any value..
pytorch_ao
public
public
0
0
_remove_bias_handles
def _remove_bias_handles(module: nn.Module) -> None:if hasattr(module, "_forward_hooks"):bias_hooks: List[int] = []for key, hook in module._forward_hooks.items():if isinstance(hook, BiasHook):bias_hooks.append(key)for key in bias_hooks:del module._forward_hooks[key]
5
8
1
67
0
22
30
22
null
[]
None
null
0
0
0
null
0
null
The function (_remove_bias_handles) defined within the public class called public.The function start at line 22 and ends at 30. It contains 8 lines of code and it has a cyclomatic complexity of 5. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_get_adjusted_next_layer_bias
def _get_adjusted_next_layer_bias(next_layer: nn.Module, pruned_biases: Tensor, mask: Tensor) -> nn.Parameter:r"""Returns new adjusted bias for the second supported module"""if parametrize.is_parametrized(next_layer):# need to access original weightparametrization_dict = cast(nn.ModuleDict, next_layer.parametrizations)...
8
38
3
257
8
33
80
33
null
['next_weight', 'scaling_product', 'scaled_biases', 'weight_parameterizations', 'parametrization_dict', 'sum_range', 'scaling_weight', 'adjusted_bias']
None
null
0
0
0
null
0
null
The function (_get_adjusted_next_layer_bias) defined within the public class called public.The function start at line 33 and ends at 80. It contains 38 lines of code and it has a cyclomatic complexity of 8. It takes 3 parameters, represented as [33.0] and does not return any value..
pytorch_ao
public
public
0
0
_prune_module_bias
def _prune_module_bias(module: nn.Module, mask: Tensor) -> None:r"""Applies mask to given modules bias"""# prune bias along with weights, discard pruned indices of biasoriginal_bias = cast(Tensor, getattr(module, "_bias", module.bias))if original_bias is not None:module.bias = nn.Parameter(original_bias[mask])#remove _...
3
6
2
67
1
83
92
83
null
['original_bias']
None
null
0
0
0
null
0
null
The function (_prune_module_bias) defined within the public class called public.The function start at line 83 and ends at 92. It contains 6 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [83.0] and does not return any value..
pytorch_ao
public
public
0
0
_propogate_module_bias
def _propogate_module_bias(module: nn.Module, mask: Tensor) -> Optional[Tensor]:r"""In the case that we need to propagate biases, this function will return the biases we need"""# set current module biasif module.bias is not None:module.bias = nn.Parameter(cast(Tensor, module.bias)[mask])elif getattr(module, "_bias", No...
5
12
2
129
1
95
114
95
null
['pruned_biases']
None
null
0
0
0
null
0
null
The function (_propogate_module_bias) defined within the public class called public.The function start at line 95 and ends at 114. It contains 12 lines of code and it has a cyclomatic complexity of 5. It takes 2 parameters, represented as [95.0] and does not return any value..
pytorch_ao
public
public
0
0
_prune_linear_helper
def _prune_linear_helper(linear: nn.Linear) -> Tensor:# expects linear to be a parameterized linear moduleparametrization_dict = cast(nn.ModuleDict, linear.parametrizations)weight_parameterizations = cast(ParametrizationList, parametrization_dict.weight)for p in weight_parameterizations:if isinstance(p, FakeStructuredS...
3
12
1
108
3
118
132
118
null
['parametrization_dict', 'mask', 'weight_parameterizations']
None
null
0
0
0
null
0
null
The function (_prune_linear_helper) defined within the public class called public.The function start at line 118 and ends at 132. It contains 12 lines of code and it has a cyclomatic complexity of 3. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
prune_linear
def prune_linear(linear: nn.Linear) -> None:mask = _prune_linear_helper(linear)if getattr(linear, "prune_bias", False):_prune_module_bias(linear, mask)
2
4
1
33
1
135
138
135
null
['mask']
None
null
0
0
0
null
0
null
The function (prune_linear) defined within the public class called public.The function start at line 135 and ends at 138. It contains 4 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
prune_linear_linear
def prune_linear_linear(linear1: nn.Linear, linear2: nn.Linear) -> None:prune_linear_activation_linear(linear1, None, linear2)
1
2
2
25
0
141
142
141
null
[]
None
null
0
0
0
null
0
null
The function (prune_linear_linear) defined within the public class called public.The function start at line 141 and ends at 142. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [141.0] and does not return any value..
pytorch_ao
public
public
0
0
prune_linear_activation_linear
def prune_linear_activation_linear(linear1: nn.Linear,activation: Optional[Callable[[Tensor], Tensor]],linear2: nn.Linear,):mask = _prune_linear_helper(linear1)if getattr(linear1, "prune_bias", False):_prune_module_bias(linear1, mask)else:pruned_biases = _propogate_module_bias(linear1, mask)if pruned_biases is not None...
5
27
3
186
4
145
173
145
null
['parametrization_dict', 'pruned_biases', 'mask', 'weight_parameterizations']
None
null
0
0
0
null
0
null
The function (prune_linear_activation_linear) defined within the public class called public.The function start at line 145 and ends at 173. It contains 27 lines of code and it has a cyclomatic complexity of 5. It takes 3 parameters, represented as [145.0] and does not return any value..
pytorch_ao
public
public
0
0
_prune_conv2d_helper
def _prune_conv2d_helper(conv2d: nn.Conv2d) -> Tensor:parametrization_dict = cast(nn.ModuleDict, conv2d.parametrizations)weight_parameterizations = cast(ParametrizationList, parametrization_dict.weight)for p in weight_parameterizations:if isinstance(p, FakeStructuredSparsity):mask = cast(Tensor, p.mask)with torch.no_gr...
3
12
1
108
3
177
190
177
null
['parametrization_dict', 'mask', 'weight_parameterizations']
None
null
0
0
0
null
0
null
The function (_prune_conv2d_helper) defined within the public class called public.The function start at line 177 and ends at 190. It contains 12 lines of code and it has a cyclomatic complexity of 3. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
prune_conv2d_padded
def prune_conv2d_padded(conv2d_1: nn.Conv2d) -> None:parametrization_dict = cast(nn.ModuleDict, conv2d_1.parametrizations)weight_parameterizations = cast(ParametrizationList, parametrization_dict.weight)for p in weight_parameterizations:if isinstance(p, FakeStructuredSparsity):mask = cast(Tensor, p.mask)with torch.no_g...
7
25
1
205
4
193
223
193
null
['parametrization_dict', 'mask', 'new_bias', 'weight_parameterizations']
None
null
0
0
0
null
0
null
The function (prune_conv2d_padded) defined within the public class called public.The function start at line 193 and ends at 223. It contains 25 lines of code and it has a cyclomatic complexity of 7. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
prune_conv2d
def prune_conv2d(conv2d: nn.Conv2d) -> None:mask = _prune_conv2d_helper(conv2d)if getattr(conv2d, "prune_bias", False):_prune_module_bias(conv2d, mask)
2
4
1
33
1
226
229
226
null
['mask']
None
null
0
0
0
null
0
null
The function (prune_conv2d) defined within the public class called public.The function start at line 226 and ends at 229. It contains 4 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
prune_conv2d_conv2d
def prune_conv2d_conv2d(conv2d_1: nn.Conv2d, conv2d_2: nn.Conv2d) -> None:prune_conv2d_activation_conv2d(conv2d_1, None, conv2d_2)
1
2
2
25
0
232
233
232
null
[]
None
null
0
0
0
null
0
null
The function (prune_conv2d_conv2d) defined within the public class called public.The function start at line 232 and ends at 233. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [232.0] and does not return any value..
pytorch_ao
public
public
0
0
prune_conv2d_activation_conv2d
def prune_conv2d_activation_conv2d(conv2d_1: nn.Conv2d,activation: Optional[Callable[[Tensor], Tensor]],conv2d_2: nn.Conv2d,):r"""Fusion Pattern for conv2d -> some activation module / function -> conv2d layers"""parametrization_dict = cast(nn.ModuleDict, conv2d_1.parametrizations)weight_parameterizations = cast(Paramet...
14
51
3
328
5
236
291
236
null
['prune_bias', 'parametrization_dict', 'mask', 'pruned_biases', 'weight_parameterizations']
None
null
0
0
0
null
0
null
The function (prune_conv2d_activation_conv2d) defined within the public class called public.The function start at line 236 and ends at 291. It contains 51 lines of code and it has a cyclomatic complexity of 14. It takes 3 parameters, represented as [236.0] and does not return any value..
pytorch_ao
public
public
0
0
prune_conv2d_pool_activation_conv2d
def prune_conv2d_pool_activation_conv2d(c1: nn.Conv2d,pool: nn.Module,activation: Optional[Callable[[Tensor], Tensor]],c2: nn.Conv2d,) -> None:prune_conv2d_activation_conv2d(c1, activation, c2)
1
7
4
46
0
294
300
294
null
[]
None
null
0
0
0
null
0
null
The function (prune_conv2d_pool_activation_conv2d) defined within the public class called public.The function start at line 294 and ends at 300. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [294.0] and does not return any value..
pytorch_ao
public
public
0
0
prune_conv2d_activation_pool_conv2d
def prune_conv2d_activation_pool_conv2d(c1: nn.Conv2d,activation: Optional[Callable[[Tensor], Tensor]],pool: nn.Module,c2: nn.Conv2d,) -> None:prune_conv2d_activation_conv2d(c1, activation, c2)
1
7
4
46
0
303
309
303
null
[]
None
null
0
0
0
null
0
null
The function (prune_conv2d_activation_pool_conv2d) defined within the public class called public.The function start at line 303 and ends at 309. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [303.0] and does not return any value..
pytorch_ao
public
public
0
0
prune_conv2d_pool_flatten_linear
def prune_conv2d_pool_flatten_linear(conv2d: nn.Conv2d,pool: nn.Module,flatten: Optional[Callable[[Tensor], Tensor]],linear: nn.Linear,) -> None:mask = _prune_conv2d_helper(conv2d)# We map the pruned indices of the Conv2d output to the flattened indices of the Linear following the Flatten layer.# we determine the flatt...
6
46
4
319
9
312
366
312
null
['flattened_pruned_biases', 'conv2d_oc', 'flatten_scale', 'parametrization_dict', 'mask', 'linear_ic', 'pruned_biases', 'weight_parameterizations', 'flattened_mask']
None
null
0
0
0
null
0
null
The function (prune_conv2d_pool_flatten_linear) defined within the public class called public.The function start at line 312 and ends at 366. It contains 46 lines of code and it has a cyclomatic complexity of 6. It takes 4 parameters, represented as [312.0] and does not return any value..
pytorch_ao
public
public
0
0
prune_lstm_output_linear
def prune_lstm_output_linear(lstm: nn.LSTM, getitem: Callable, linear: nn.Linear) -> None:prune_lstm_output_layernorm_linear(lstm, getitem, None, linear)
1
4
3
31
0
369
372
369
null
[]
None
null
0
0
0
null
0
null
The function (prune_lstm_output_linear) defined within the public class called public.The function start at line 369 and ends at 372. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [369.0] and does not return any value..
pytorch_ao
public
public
0
0
prune_lstm_output_layernorm_linear
def prune_lstm_output_layernorm_linear(lstm: nn.LSTM,getitem: Callable,layernorm: Optional[nn.LayerNorm],linear: nn.Linear,) -> None:for i in range(lstm.num_layers):if parametrize.is_parametrized(lstm, f"weight_ih_l{i}"):parametrization_dict = cast(nn.ModuleDict, lstm.parametrizations)weight_parameterizations = cast(Pa...
8
93
4
614
9
375
483
375
null
['next_layer_weight', 'W_ho', 'W_hi', 'W_hf', 'parametrization_dict', 'mask', 'W_hg', 'new_weight', 'weight_parameterizations']
None
null
0
0
0
null
0
null
The function (prune_lstm_output_layernorm_linear) defined within the public class called public.The function start at line 375 and ends at 483. It contains 93 lines of code and it has a cyclomatic complexity of 8. It takes 4 parameters, represented as [375.0] and does not return any value..
pytorch_ao
public
public
0
0
update_mask
def update_mask(self, module, tensor_name, **kwargs):# tensor_name will give you the FQN, all other entries in sparse config is present in kwargsweights = getattr(module, tensor_name)mask = getattr(module.parametrizations, tensor_name)[0].mask# use negative weights so we can use topk (we prune out the smallest)if weigh...
2
14
4
120
0
21
40
21
null
[]
None
null
0
0
0
null
0
null
The function (update_mask) defined within the public class called public.The function start at line 21 and ends at 40. It contains 14 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [21.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__.__init__.with_counter.wrapper
def wrapper(*args, **kwargs):instance = instance_ref()instance._step_count += 1# type: ignore[union-attr]wrapped = func.__get__(instance, cls)return wrapped(*args, **kwargs)
1
5
2
38
0
46
50
46
null
[]
None
null
0
0
0
null
0
null
The function (__init__.__init__.with_counter.wrapper) defined within the public class called public.The function start at line 46 and ends at 50. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [46.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__.with_counter
def with_counter(method):if getattr(method, "_with_counter", False):# `sparsifier.step()` has already been replaced, return.return method# Keep a weak reference to the sparsifier instance to prevent# cyclic references.instance_ref = weakref.ref(method.__self__)# Get the unbound method for the same purpose.func = method...
2
11
1
55
0
32
55
32
null
[]
None
null
0
0
0
null
0
null
The function (__init__.with_counter) defined within the public class called public.The function start at line 32 and ends at 55. It contains 11 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, sparsifier, last_epoch=-1, verbose=False):# Attach sparsifierif not isinstance(sparsifier, BaseSparsifier):raise TypeError(f"{type(sparsifier).__name__} is not an instance of torch.ao.pruning.BaseSparsifier")self.sparsifier = sparsifier# Initialize epoch and base sparsity levelsself.base_sl = [group[...
3
15
4
104
0
16
65
16
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 16 and ends at 65. It contains 15 lines of code and it has a cyclomatic complexity of 3. It takes 4 parameters, represented as [16.0] and does not return any value..
pytorch_ao
public
public
0
0
state_dict
def state_dict(self):"""Returns the state of the scheduler as a :class:`dict`.It contains an entry for every variable in self.__dict__ whichis not the sparsifier."""return {key: value for key, value in self.__dict__.items() if key != "sparsifier"}
3
4
1
28
0
67
75
67
null
[]
None
null
0
0
0
null
0
null
The function (state_dict) defined within the public class called public.The function start at line 67 and ends at 75. It contains 4 lines of code and it has a cyclomatic complexity of 3. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
load_state_dict
def load_state_dict(self, state_dict):"""Loads the schedulers state.Args:state_dict (dict): scheduler state. Should be an object returnedfrom a call to :meth:`state_dict`."""self.__dict__.update(state_dict)
1
2
2
16
0
77
84
77
null
[]
None
null
0
0
0
null
0
null
The function (load_state_dict) defined within the public class called public.The function start at line 77 and ends at 84. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [77.0] and does not return any value..
pytorch_ao
public
public
0
0
get_last_sl
def get_last_sl(self):"""Return last computed sparsity level by current scheduler."""return self._last_sl
1
2
1
10
0
86
88
86
null
[]
None
null
0
0
0
null
0
null
The function (get_last_sl) defined within the public class called public.The function start at line 86 and ends at 88. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
get_sl
def get_sl(self):# Compute sparsity level using chainable form of the scheduler# Note: This method is not intended to be called directly, and is only# used by the ".step" method. Use .get_last_sl() instead.if not self._get_sl_called_within_step:warnings.warn("To get the last sparsity level computed by the scheduler, ""...
2
7
1
20
0
90
99
90
null
[]
None
null
0
0
0
null
0
null
The function (get_sl) defined within the public class called public.The function start at line 90 and ends at 99. It contains 7 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
print_sl
def print_sl(self, is_verbose, group, sl, epoch=None):"""Display the current sparsity level."""if is_verbose:if epoch is None:print(f"Adjusting sparsity level of group {group} to {sl:.4e}.")else:print(f"Epoch {epoch:5d}: adjusting sparsity level of group {group} to {sl:.4e}.")
3
8
5
36
0
101
109
101
null
[]
None
null
0
0
0
null
0
null
The function (print_sl) defined within the public class called public.The function start at line 101 and ends at 109. It contains 8 lines of code and it has a cyclomatic complexity of 3. It takes 5 parameters, represented as [101.0] and does not return any value..
pytorch_ao
public
public
0
0
__repr__
def __repr__(self):format_string = self.__class__.__name__ + " ("format_string += "\n"format_string += f"Sparsifier {self.sparsifier}\n"format_string += f"base_sl: {self.base_sl}\n"format_string += ")"return format_string
1
7
1
30
0
111
117
111
null
[]
None
null
0
0
0
null
0
null
The function (__repr__) defined within the public class called public.The function start at line 111 and ends at 117. It contains 7 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
step.__init__
def __init__(self, o):self.o = o
1
2
2
12
0
142
143
142
null
[]
None
null
0
0
0
null
0
null
The function (step.__init__) defined within the public class called public.The function start at line 142 and ends at 143. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [142.0] and does not return any value..
pytorch_ao
public
public
0
0
step.__enter__
def __enter__(self):self.o._get_sl_called_within_step = Truereturn self
1
3
1
14
0
145
147
145
null
[]
None
null
0
0
0
null
0
null
The function (step.__enter__) defined within the public class called public.The function start at line 145 and ends at 147. It contains 3 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
step.__exit__
def __exit__(self, type, value, traceback):self.o._get_sl_called_within_step = False
1
2
4
18
0
149
150
149
null
[]
None
null
0
0
0
null
0
null
The function (step.__exit__) defined within the public class called public.The function start at line 149 and ends at 150. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [149.0] and does not return any value..
pytorch_ao
public
public
0
0
step
def step(self, epoch=None):# Raise warning if trying to call scheduler step before the sparsifier.# https://github.com/pytorch/pytorch/issues/20124if self._step_count == 1:if not hasattr(self.sparsifier.step, "_with_counter"):warnings.warn("Seems like `sparsifier.step()` has been overridden after sparsity scheduler ""i...
6
30
2
161
0
119
162
119
null
[]
None
null
0
0
0
null
0
null
The function (step) defined within the public class called public.The function start at line 119 and ends at 162. It contains 30 lines of code and it has a cyclomatic complexity of 6. It takes 2 parameters, represented as [119.0] and does not return any value..
pytorch_ao
public
public
0
0
_make_sure_a_list
def _make_sure_a_list(self, var):r"""Utility that extends it to the same length as the .groups, ensuring it is a list"""n = len(self.sparsifier.groups)if not isinstance(var, (list, tuple)):return [var] * nelse:if len(var) != n:raise ValueError(f"Expected variable of length {n}, but got {len(var)}")return list(var)# We ...
3
8
2
59
0
164
172
164
null
[]
None
null
0
0
0
null
0
null
The function (_make_sure_a_list) defined within the public class called public.The function start at line 164 and ends at 172. It contains 8 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [164.0] and does not return any value..
pytorch_ao
public
public
0
0
_clamp
def _clamp(x, lo, hi):return max(lo, min(hi, x))
1
2
3
21
0
13
14
13
null
[]
None
null
0
0
0
null
0
null
The function (_clamp) defined within the public class called public.The function start at line 13 and ends at 14. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [13.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,sparsifier,init_sl=0.0,init_t=0,delta_t=10,total_t=100,initially_zero=False,last_epoch=-1,verbose=False,):self.sparsifier = sparsifierself.init_sl = self._make_sure_a_list(init_sl)self.init_t = self._make_sure_a_list(init_t)self.delta_t = self._make_sure_a_list(delta_t)self.total_t = self._make_sure_a...
1
18
9
106
0
45
65
45
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 45 and ends at 65. It contains 18 lines of code and it has a cyclomatic complexity of 1. It takes 9 parameters, represented as [45.0] and does not return any value..
pytorch_ao
public
public
0
0
sparsity_compute_fn
def sparsity_compute_fn(s_0, s_f, t, t_0, dt, n, initially_zero=False):r""" "Computes the current level of sparsity.Based on https://arxiv.org/pdf/1710.01878.pdfArgs:s_0: Initial level of sparsity, :math:`s_i`s_f: Target level of sparsity, :math:`s_f`t: Current step, :math:`t`t_0: Initial step, :math:`t_0`dt: Pruning f...
3
6
7
71
0
68
90
68
null
[]
None
null
0
0
0
null
0
null
The function (sparsity_compute_fn) defined within the public class called public.The function start at line 68 and ends at 90. It contains 6 lines of code and it has a cyclomatic complexity of 3. It takes 7 parameters, represented as [68.0] and does not return any value..
pytorch_ao
public
public
0
0
get_sl
def get_sl(self):if not self._get_sl_called_within_step:warnings.warn("To get the last sparsity level computed by the scheduler, ""please use `get_last_sl()`.")return [self.sparsity_compute_fn(s_0=initial_sparsity,s_f=final_sparsity,t=self.last_epoch,t_0=initial_epoch,dt=delta_epoch,n=interval_epochs,initially_zero=ini...
3
25
1
96
0
92
116
92
null
[]
None
null
0
0
0
null
0
null
The function (get_sl) defined within the public class called public.The function start at line 92 and ends at 116. It contains 25 lines of code and it has a cyclomatic complexity of 3. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, sparsifier, sl_lambda, last_epoch=-1, verbose=False):self.sparsifier = sparsifierif not isinstance(sl_lambda, list) and not isinstance(sl_lambda, tuple):self.sl_lambdas = [sl_lambda] * len(sparsifier.groups)else:if len(sl_lambda) != len(sparsifier.groups):raise ValueError(f"Expected {len(sparsifier.g...
4
11
5
95
0
36
47
36
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 36 and ends at 47. It contains 11 lines of code and it has a cyclomatic complexity of 4. It takes 5 parameters, represented as [36.0] and does not return any value..
pytorch_ao
public
public
0
0
get_sl
def get_sl(self):if not self._get_sl_called_within_step:warnings.warn("To get the last sparsity level computed by the scheduler, ""please use `get_last_sl()`.")return [base_sl * lmbda(self.last_epoch)for lmbda, base_sl in zip(self.sl_lambdas, self.base_sl)]
3
10
1
44
0
49
58
49
null
[]
None
null
0
0
0
null
0
null
The function (get_sl) defined within the public class called public.The function start at line 49 and ends at 58. It contains 10 lines of code and it has a cyclomatic complexity of 3. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, defaults: Optional[Dict[str, Any]] = None):super().__init__()self.defaults: Dict[str, Any] = defaults or {}self.state: Dict[str, Dict] = defaultdict(dict)self.groups: List[Dict[str, Any]] = []self.enable_mask_update = True
2
6
2
77
0
60
66
60
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 60 and ends at 66. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [60.0] and does not return any value..
pytorch_ao
public
public
0
0
__getstate__
def __getstate__(self) -> Dict[str, Any]:return {"defaults": self.defaults,"state": self.state,"groups": self.groups,}
1
6
1
33
0
68
73
68
null
[]
None
null
0
0
0
null
0
null
The function (__getstate__) defined within the public class called public.The function start at line 68 and ends at 73. It contains 6 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
__setstate__
def __setstate__(self, state: Dict[str, Dict[str, Any]]) -> None:self.__dict__.update(state)
1
2
2
29
0
75
76
75
null
[]
None
null
0
0
0
null
0
null
The function (__setstate__) defined within the public class called public.The function start at line 75 and ends at 76. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [75.0] and does not return any value..
pytorch_ao
public
public
0
0
__repr__
def __repr__(self):format_string = self.__class__.__name__ + " ("for i, sparse_args in enumerate(self.groups):module = sparse_args["module"]format_string += "\n"format_string += f"\tGroup {i}\n"format_string += f"\tmodule: {module}\n"for key in sorted(sparse_args.keys()):if key == "module":continueformat_string += f"\t...
4
13
1
70
0
78
90
78
null
[]
None
null
0
0
0
null
0
null
The function (__repr__) defined within the public class called public.The function start at line 78 and ends at 90. It contains 13 lines of code and it has a cyclomatic complexity of 4. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
state_dict
def state_dict(self) -> Dict[str, Any]:r"""Returns the state of the optimizer as a :class:`dict`.It contains:* state - current state of the sparsification.* groups - a list containing all sparsity configuration groupswith the key 'tensor_fqn' specifying the path to the sparsified tensor within a modelTODO: Need a clean...
2
14
1
70
0
92
116
92
null
[]
None
null
0
0
0
null
0
null
The function (state_dict) defined within the public class called public.The function start at line 92 and ends at 116. It contains 14 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
load_state_dict
def load_state_dict(self, state_dict: Dict[str, Any], strict: bool = True):groups = copy.deepcopy(state_dict["groups"])states = state_dict["state"]for tensor_fqn, s in states.items():arg_info = get_arg_info_from_tensor_fqn(self.model, tensor_fqn)module = arg_info["module"]tensor_name = arg_info["tensor_name"]if strict ...
10
24
3
199
0
118
143
118
null
[]
None
null
0
0
0
null
0
null
The function (load_state_dict) defined within the public class called public.The function start at line 118 and ends at 143. It contains 24 lines of code and it has a cyclomatic complexity of 10. It takes 3 parameters, represented as [118.0] and does not return any value..
pytorch_ao
public
public
0
0
make_config_from_model
def make_config_from_model(self,model: nn.Module,SUPPORTED_MODULES: Set[Type] = SUPPORTED_MODULES,) -> None:self.config = []stack = [model]while stack:module = stack.pop()for name, child in module.named_children():if type(child) in SUPPORTED_MODULES:module_fqn = module_to_fqn(model, child)assert isinstance(module_fqn, ...
4
16
3
100
0
145
160
145
null
[]
None
null
0
0
0
null
0
null
The function (make_config_from_model) defined within the public class called public.The function start at line 145 and ends at 160. It contains 16 lines of code and it has a cyclomatic complexity of 4. It takes 3 parameters, represented as [145.0] and does not return any value..
pytorch_ao
public
public
0
0
prepare
def prepare(self, model, config):r"""Prepares a model, by adding the parametrizations.Note::The model is modified inplace. If you need to preserve the originalmodel, use copy.deepcopy."""self.model = model# TODO: Need to figure out how to load without this.self.config = config# If no config -- try getting all the suppo...
7
33
3
174
0
162
213
162
null
[]
None
null
0
0
0
null
0
null
The function (prepare) defined within the public class called public.The function start at line 162 and ends at 213. It contains 33 lines of code and it has a cyclomatic complexity of 7. It takes 3 parameters, represented as [162.0] and does not return any value..
pytorch_ao
public
public
0
0
_prepare
def _prepare(self, *args, **kwargs):r"""Adds mask parametrization to the layer weight"""for config in self.groups:module = config["module"]tensor_name = config["tensor_name"]parametrization = config.get("parametrization", FakeSparsity)mask = config.get("mask", torch.ones_like(getattr(module, tensor_name)))self.state[co...
2
10
3
89
0
215
225
215
null
[]
None
null
0
0
0
null
0
null
The function (_prepare) defined within the public class called public.The function start at line 215 and ends at 225. It contains 10 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [215.0] and does not return any value..
pytorch_ao
public
public
0
0
squash_mask
def squash_mask(self,params_to_keep: Optional[Tuple[str, ...]] = None,params_to_keep_per_layer: Optional[Dict[str, Tuple[str, ...]]] = None,*args,**kwargs,):r"""Squashes the sparse masks into the appropriate tensors.If either the `params_to_keep` or `params_to_keep_per_layer` is set,the module will have a `sparse_param...
8
24
5
161
0
227
303
227
null
[]
None
null
0
0
0
null
0
null
The function (squash_mask) defined within the public class called public.The function start at line 227 and ends at 303. It contains 24 lines of code and it has a cyclomatic complexity of 8. It takes 5 parameters, represented as [227.0] and does not return any value..
pytorch_ao
public
public
0
0
convert
def convert(self,module: nn.Module,mapping: Optional[Dict[Type[nn.Module], Type[nn.Module]]] = None,inplace: bool = False,parameterization: Type[nn.Module] = FakeSparsity,):r"""Converts submodules in input module to a different module according to `mapping`by calling `from_dense` method on the target module classArgs:m...
7
28
6
167
0
305
347
305
null
[]
None
null
0
0
0
null
0
null
The function (convert) defined within the public class called public.The function start at line 305 and ends at 347. It contains 28 lines of code and it has a cyclomatic complexity of 7. It takes 6 parameters, represented as [305.0] and does not return any value..
pytorch_ao
public
public
0
0
step
def step(self, use_path: bool = True) -> None:if not self.enable_mask_update:returnwith torch.no_grad():for config in self.groups:self.update_mask(**config)
3
6
2
41
0
349
354
349
null
[]
None
null
0
0
0
null
0
null
The function (step) defined within the public class called public.The function start at line 349 and ends at 354. It contains 6 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [349.0] and does not return any value..
pytorch_ao
public
public
0
0
update_mask
def update_mask(self, module: nn.Module, tensor_name: str, **kwargs):pass
1
2
4
19
0
357
358
357
null
[]
None
null
0
0
0
null
0
null
The function (update_mask) defined within the public class called public.The function start at line 357 and ends at 358. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [357.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, nearliness: int = 1):defaults = {"nearliness": nearliness}super().__init__(defaults=defaults)
1
3
2
28
0
36
38
36
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 36 and ends at 38. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [36.0] and does not return any value..
pytorch_ao
public
public
0
0
update_mask
def update_mask(self, module, tensor_name, nearliness, **kwargs):mask = getattr(module.parametrizations, tensor_name)[0].maskmask.data = torch.zeros_like(mask)if nearliness <= 0:returntensor = getattr(module, tensor_name)height, width = tensor.shapeif nearliness % 2 == 0:raise ValueError("nearliness can only be an odd ...
5
18
5
136
0
40
62
40
null
[]
None
null
0
0
0
null
0
null
The function (update_mask) defined within the public class called public.The function start at line 40 and ends at 62. It contains 18 lines of code and it has a cyclomatic complexity of 5. It takes 5 parameters, represented as [40.0] and does not return any value..
pytorch_ao
public
public
0
0
module_contains_param
def module_contains_param(module: nn.Module, parametrization: Type[nn.Module]) -> bool:if is_parametrized(module):# see if any of the module tensors have a parametriztion attached that matches the one passed inreturn any(any(isinstance(param, parametrization) for param in param_list)for key, param_list in module.parame...
4
7
2
57
0
22
29
22
null
[]
None
null
0
0
0
null
0
null
The function (module_contains_param) defined within the public class called public.The function start at line 22 and ends at 29. It contains 7 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [22.0] and does not return any value..
pytorch_ao
public
public
0
0
swap_module
def swap_module(mod: nn.Module, mapping: Dict[Type[nn.Module], Type[nn.Module]]) -> nn.Module:r"""Swaps the module using from_dense according to the mapping passed in.Args:mod: input modulemapping: a dictionary that maps from nn module to sparse nn moduleReturn:The corresponding sparse module of `mod` according to mapp...
7
20
2
162
4
32
68
32
null
['sparse_mod', 'devices', 'device', 'new_mod']
None
null
0
0
0
null
0
null
The function (swap_module) defined within the public class called public.The function start at line 32 and ends at 68. It contains 20 lines of code and it has a cyclomatic complexity of 7. It takes 2 parameters, represented as [32.0] and does not return any value..
pytorch_ao
public
public
0
0
module_to_fqn
def module_to_fqn(model: nn.Module, module: nn.Module, prefix: str = "") -> Optional[str]:"""Returns the fqn for a module or None if module not a descendent of model."""if module is model:return ""for name, child in model.named_children():fqn = module_to_fqn(child, module, ".")if isinstance(fqn, str):return prefix + na...
4
10
3
71
1
71
83
71
null
['fqn']
None
null
0
0
0
null
0
null
The function (module_to_fqn) defined within the public class called public.The function start at line 71 and ends at 83. It contains 10 lines of code and it has a cyclomatic complexity of 4. It takes 3 parameters, represented as [71.0] and does not return any value..
pytorch_ao
public
public
0
0
fqn_to_module
def fqn_to_module(model: Optional[nn.Module], path: str) -> Optional[nn.Module]:"""Given an fqn, returns the corresponding module or tensor or None if the fqn given by `path`doesn't correspond to anything. Similar to model.get_submodule(path) but works for tensors."""if path != "":for name in path.split("."):model = ge...
3
5
2
51
1
86
94
86
null
['model']
None
null
0
0
0
null
0
null
The function (fqn_to_module) defined within the public class called public.The function start at line 86 and ends at 94. It contains 5 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [86.0] and does not return any value..
pytorch_ao
public
public
0
0
get_arg_info_from_tensor_fqn
def get_arg_info_from_tensor_fqn(model: nn.Module, tensor_fqn: str) -> Dict[str, Any]:"""Uses tensor_fqn to obtain a dict containing module_fqn, module and tensor_name"""# string manip to split tensor_fqn into module_fqn and tensor_name# if tensor_fqn is 'weight' then module_fqn and tensor_name are '' and 'weight'# if ...
1
10
2
77
3
97
114
97
null
['module', 'tensor_name', 'module_fqn']
None
null
0
0
0
null
0
null
The function (get_arg_info_from_tensor_fqn) defined within the public class called public.The function start at line 97 and ends at 114. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [97.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, mask):super().__init__()self.register_buffer("mask", mask)
1
3
2
22
0
129
131
129
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 129 and ends at 131. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [129.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, x):assert self.mask.shape == x.shapereturn self.mask * x
1
3
2
23
0
133
135
133
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 133 and ends at 135. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [133.0] and does not return any value..
pytorch_ao
public
public
0
0
_flat_idx_to_2d
def _flat_idx_to_2d(idx, shape):rows = idx // shape[1]cols = idx % shape[1]return rows, cols
1
4
2
23
2
18
21
18
null
['rows', 'cols']
None
null
0
0
0
null
0
null
The function (_flat_idx_to_2d) defined within the public class called public.The function start at line 18 and ends at 21. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [18.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,sparsity_level: float = 0.5,sparse_block_shape: Tuple[int, int] = (1, 4),zeros_per_block: Optional[int] = None,norm: Optional[Union[Callable, int]] = None,):if zeros_per_block is None:zeros_per_block = reduce(operator.mul, sparse_block_shape)defaults = {"sparsity_level": sparsity_level,"sparse_block_s...
6
25
4
152
0
62
86
62
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 62 and ends at 86. It contains 25 lines of code and it has a cyclomatic complexity of 6. It takes 4 parameters, represented as [62.0] and does not return any value..
pytorch_ao
public
public
0
0
_scatter_fold_block_mask
def _scatter_fold_block_mask(self,output_shape,dim,indices,block_shape,mask=None,input_shape=None,device=None,):r"""Creates patches of size `block_shape` after scattering the indices."""if mask is None:assert input_shape is not Nonemask = torch.ones(input_shape, device=device)mask.scatter_(dim=dim, index=indices, value...
2
18
8
90
0
88
106
88
null
[]
None
null
0
0
0
null
0
null
The function (_scatter_fold_block_mask) defined within the public class called public.The function start at line 88 and ends at 106. It contains 18 lines of code and it has a cyclomatic complexity of 2. It takes 8 parameters, represented as [88.0] and does not return any value..
pytorch_ao
public
public
0
0
_make_tensor_mask
def _make_tensor_mask(self, data, input_shape, sparsity_level, sparse_block_shape, mask=None):r"""Creates a tensor-level mask.Tensor-level mask is described as a mask, where the granularity of sparsification of thesmallest patch is the sparse_block_shape. That means, that for a given mask and asparse_block_shape, the s...
5
39
6
309
0
108
162
108
null
[]
None
null
0
0
0
null
0
null
The function (_make_tensor_mask) defined within the public class called public.The function start at line 108 and ends at 162. It contains 39 lines of code and it has a cyclomatic complexity of 5. It takes 6 parameters, represented as [108.0] and does not return any value..
pytorch_ao
public
public
0
0
_make_block_mask
def _make_block_mask(self, data, sparse_block_shape, zeros_per_block, mask=None):r"""Creates a block-level mask.Block-level mask is described as a mask, where the granularity of sparsification of thelargest patch is the sparse_block_shape. That means that for a given mask and asparse_block_shape, the sparsity is comput...
3
32
5
259
0
164
212
164
null
[]
None
null
0
0
0
null
0
null
The function (_make_block_mask) defined within the public class called public.The function start at line 164 and ends at 212. It contains 32 lines of code and it has a cyclomatic complexity of 3. It takes 5 parameters, represented as [164.0] and does not return any value..
pytorch_ao
public
public
0
0
update_mask
def update_mask(self,module,tensor_name,sparsity_level,sparse_block_shape,zeros_per_block,**kwargs,):values_per_block = reduce(operator.mul, sparse_block_shape)if zeros_per_block > values_per_block:raise ValueError("Number of zeros per block cannot be more than the total number of elements in that block.")if zeros_per_...
8
37
7
185
0
214
251
214
null
[]
None
null
0
0
0
null
0
null
The function (update_mask) defined within the public class called public.The function start at line 214 and ends at 251. It contains 37 lines of code and it has a cyclomatic complexity of 8. It takes 7 parameters, represented as [214.0] and does not return any value..
pytorch_ao
public
public
0
0
get_had12
def get_had12():return torch.FloatTensor([[+1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],[+1, +1, -1, +1, -1, -1, -1, +1, +1, +1, -1, +1],[+1, +1, +1, -1, +1, -1, -1, -1, +1, +1, +1, -1],[+1, -1, +1, +1, -1, +1, -1, -1, -1, +1, +1, +1],[+1, +1, -1, +1, +1, -1, +1, -1, -1, -1, +1, +1],[+1, +1, +1, -1, +1, +1, -1, +1, ...
1
17
0
468
0
12
28
12
null
[]
None
null
0
0
0
null
0
null
The function (get_had12) defined within the public class called public.The function start at line 12 and ends at 28. It contains 17 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
get_had44
def get_had44():return torch.FloatTensor([[1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,],[1,1,-1,1,1,-1,1,-1,1,1,-1,-1,-1,1,-1,-1,-1,-1,-1,1,1,1,-1,1,-1,-1,-1,1,1,1,1,1,-1,1,1,1,-1,-1,1,-1,1,-1,-1,1,],[1,1,1,-1,1,1,-1,1,-1,1,1,-1,-1,...
1
2,029
0
4,962
0
31
2,059
31
null
[]
None
null
0
0
0
null
0
null
The function (get_had44) defined within the public class called public.The function start at line 31 and ends at 2059. It contains 2029 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
get_had40
def get_had40():return torch.FloatTensor([[+1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,+1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,],[+1,+1,-1,+1,+1,-1,-1,-1,-1,+1,-1,+1,-1,+1,+1,+1,+1,-1,-1,+1,+1,+1,-1,+1,+1,-1,-1,-1,-1,+1,-1,+1,-1,+1,+1,+1,+1,-1,-1,+1,],[+1,+1,+1,-1,+1,+1,-1,-1,-1,-1,+...
1
1,685
0
4,932
0
2,062
3,746
2,062
null
[]
None
null
0
0
0
null
0
null
The function (get_had40) defined within the public class called public.The function start at line 2062 and ends at 3746. It contains 1685 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
get_had20
def get_had20():return torch.FloatTensor([[+1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,],[+1,+1,-1,+1,+1,-1,-1,-1,-1,+1,-1,+1,-1,+1,+1,+1,+1,-1,-1,+1,],[+1,+1,+1,-1,+1,+1,-1,-1,-1,-1,+1,-1,+1,-1,+1,+1,+1,+1,-1,-1,],[+1,-1,+1,+1,-1,+1,+1,-1,-1,-1,-1,+1,-1,+1,-1,+1,+1,+1,+1,-1,],[+1,-1,-1,+1,+1,-1,+1,+1,-...
1
445
0
1,272
0
3,749
4,193
3,749
null
[]
None
null
0
0
0
null
0
null
The function (get_had20) defined within the public class called public.The function start at line 3749 and ends at 4193. It contains 445 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
get_had28
def get_had28():return torch.FloatTensor([[+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,-1,+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,],[+1,+1,+1,-1,+1,+1,-1,-1,-1,-1,+1,+1,-1,+1,+1,-1,+1,-1,+1,+1,-1,-1,-1,-1,+1,+1,-1,+1,],[+1,+1,+1,+1,-1,+1,+1,-1,-1,-1,-1,+1,+1,-1,+1,+1,-1,+1,-1,+1,+1,-1,-1,-1,-1,+1,+1,-1,],[+1,-1,+1,+1,+1,-...
1
845
0
2,448
0
4,196
5,040
4,196
null
[]
None
null
0
0
0
null
0
null
The function (get_had28) defined within the public class called public.The function start at line 4196 and ends at 5040. It contains 845 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
get_had36
def get_had36():return torch.FloatTensor([[+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,-1,+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,+1,],[+1,+1,+1,+1,-1,+1,-1,-1,-1,+1,+1,-1,-1,-1,+1,-1,+1,+1,+1,-1,+1,+1,-1,+1,-1,-1,-1,+1,+1,-1,-1,-1,+1,-1,+1,+1,],[+1,+1,+1,+1,+1,-1,+1,-1,-1,-1,+1,+1,-1,-1,-1,+1,-1,+1,+...
1
1,373
0
4,008
0
5,043
6,415
5,043
null
[]
None
null
0
0
0
null
0
null
The function (get_had36) defined within the public class called public.The function start at line 5043 and ends at 6415. It contains 1373 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
get_had60
def get_had60():return torch.FloatTensor([[+1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,],[+1,+1,-1,+1,-1,-1,-1,+1,-1,+1,-1,+1,+1,-1,+1,+1,-1,-1,-1,+1,-1,-1,-1,-1,+1,+1,-1,-1,-1,-1,-1,+...
1
3,725
0
10,992
0
6,418
10,142
6,418
null
[]
None
null
0
0
0
null
0
null
The function (get_had60) defined within the public class called public.The function start at line 6418 and ends at 10142. It contains 3725 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
get_had52
def get_had52():return torch.FloatTensor([[+1,-1,+1,-1,-1,+1,+1,+1,+1,-1,-1,+1,-1,+1,-1,-1,-1,+1,+1,+1,+1,+1,+1,-1,-1,-1,+1,+1,-1,+1,-1,-1,+1,+1,-1,-1,+1,-1,+1,+1,-1,-1,-1,-1,+1,-1,-1,+1,-1,-1,-1,-1,],[-1,+1,-1,+1,-1,-1,+1,+1,+1,+1,-1,-1,+1,-1,+1,-1,-1,-1,+1,+1,+1,+1,+1,+1,-1,-1,+1,+1,+1,-1,+1,-1,-1,+1,+1,-1,-1,+1,-1,-...
1
2,813
0
8,280
0
10,145
12,957
10,145
null
[]
None
null
0
0
0
null
0
null
The function (get_had52) defined within the public class called public.The function start at line 10145 and ends at 12957. It contains 2813 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
get_had108
def get_had108():return torch.FloatTensor([[+1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,...
1
11,885
0
35,328
0
12,960
24,844
12,960
null
[]
None
null
0
0
0
null
0
null
The function (get_had108) defined within the public class called public.The function start at line 12960 and ends at 24844. It contains 11885 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
get_had140
def get_had140():return torch.FloatTensor([[+1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,...
1
19,885
0
59,232
0
24,847
44,731
24,847
null
[]
None
null
0
0
0
null
0
null
The function (get_had140) defined within the public class called public.The function start at line 24847 and ends at 44731. It contains 19885 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
get_had156
def get_had156():return torch.FloatTensor([[+1,+1,+1,-1,-1,+1,-1,+1,-1,-1,-1,-1,-1,+1,-1,-1,+1,+1,-1,-1,-1,-1,+1,+1,-1,-1,+1,-1,-1,-1,-1,-1,+1,-1,+1,-1,-1,+1,+1,+1,+1,+1,+1,-1,-1,-1,+1,-1,-1,+1,+1,-1,-1,-1,-1,+1,-1,+1,-1,-1,+1,-1,+1,-1,-1,-1,-1,+1,+1,-1,-1,+1,-1,-1,-1,+1,+1,+1,+1,+1,+1,-1,-1,+1,+1,-1,+1,-1,-1,-1,+1,-1,...
1
24,653
0
73,488
0
44,734
69,386
44,734
null
[]
None
null
0
0
0
null
0
null
The function (get_had156) defined within the public class called public.The function start at line 44734 and ends at 69386. It contains 24653 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
get_had172
def get_had172():return torch.FloatTensor([[+1,-1,-1,-1,+1,+1,-1,-1,+1,+1,+1,+1,-1,+1,-1,+1,+1,+1,-1,+1,+1,-1,-1,+1,+1,-1,+1,+1,+1,-1,+1,-1,+1,+1,+1,+1,-1,-1,+1,+1,-1,-1,-1,+1,+1,-1,+1,+1,+1,+1,+1,+1,-1,-1,-1,-1,+1,-1,+1,-1,-1,+1,+1,-1,+1,+1,-1,+1,+1,-1,-1,+1,-1,+1,-1,-1,-1,-1,+1,+1,+1,+1,+1,+1,-1,+1,+1,+1,+1,-1,+1,-1,...
1
29,933
0
89,280
0
69,389
99,321
69,389
null
[]
None
null
0
0
0
null
0
null
The function (get_had172) defined within the public class called public.The function start at line 69389 and ends at 99321. It contains 29933 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
matmul_hadU
def matmul_hadU(X, hadK, K):if X.is_cuda:return matmul_hadU_fast(X, hadK, K)else:return matmul_hadU_slow(X, hadK, K)
2
5
3
34
0
32
36
32
null
[]
None
null
0
0
0
null
0
null
The function (matmul_hadU) defined within the public class called public.The function start at line 32 and ends at 36. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [32.0] and does not return any value..
pytorch_ao
public
public
0
0
matmul_hadU
def matmul_hadU(X, hadK, K):return matmul_hadU_slow(X, hadK, K)
1
2
3
18
0
45
46
45
null
[]
None
null
0
0
0
null
0
null
The function (matmul_hadU) defined within the public class called public.The function start at line 45 and ends at 46. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [45.0] and does not return any value..
pytorch_ao
public
public
0
0
register_custom_op_impl.decorator
def decorator(func):return torch.library.custom_op(f"{name}", mutates_args=())(func)
1
2
1
23
0
50
51
50
null
[]
None
null
0
0
0
null
0
null
The function (register_custom_op_impl.decorator) defined within the public class called public.The function start at line 50 and ends at 51. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
register_custom_op_impl
def register_custom_op_impl(name):def decorator(func):return torch.library.custom_op(f"{name}", mutates_args=())(func)return decorator
1
3
1
9
0
49
53
49
null
[]
None
null
0
0
0
null
0
null
The function (register_custom_op_impl) defined within the public class called public.The function start at line 49 and ends at 53. It contains 3 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
register_custom_op_abstract.decorator
def decorator(func):return torch.library.register_fake(f"{name}")(func)
1
2
1
18
0
57
58
57
null
[]
None
null
0
0
0
null
0
null
The function (register_custom_op_abstract.decorator) defined within the public class called public.The function start at line 57 and ends at 58. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
register_custom_op_abstract
def register_custom_op_abstract(name):def decorator(func):return torch.library.register_fake(f"{name}")(func)return decorator
1
3
1
9
0
56
60
56
null
[]
None
null
0
0
0
null
0
null
The function (register_custom_op_abstract) defined within the public class called public.The function start at line 56 and ends at 60. It contains 3 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
hadamard_transform
def hadamard_transform(x: torch.Tensor, scale: float = 1.0) -> torch.Tensor:"""Arguments:x: (..., dim)scale: float. Multiply the output by this number.Returns:out: (..., dim)Multiply each row of x by the Hadamard transform matrix.Equivalent to F.linear(x, torch.tensor(scipy.linalg.hadamard(dim))) * scale.If dim is not ...
1
2
2
29
0
64
78
64
null
[]
None
null
0
0
0
null
0
null
The function (hadamard_transform) defined within the public class called public.The function start at line 64 and ends at 78. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [64.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(x: torch.Tensor, scale: float = 1.0) -> torch.Tensor:torch._check(x.dim() >= 1, lambda: f"input should be at least a 1D tensor, got {x.dim()}D")return torch.empty_like(x)
1
5
2
45
0
82
86
82
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 82 and ends at 86. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [82.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(ctx, u):return _fast_hadamard_transform(u)
1
2
2
12
0
93
94
93
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 93 and ends at 94. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [93.0] and does not return any value..
pytorch_ao
public
public
0
0
backward
def backward(ctx, grad):return _fast_hadamard_transform(grad)
1
2
2
12
0
97
98
97
null
[]
None
null
0
0
0
null
0
null
The function (backward) defined within the public class called public.The function start at line 97 and ends at 98. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [97.0] and does not return any value..
pytorch_ao
public
public
0
0
is_pow2
def is_pow2(n):return (n & (n - 1) == 0) and (n > 0)
2
2
1
23
0
101
102
101
null
[]
None
null
0
0
0
null
0
null
The function (is_pow2) defined within the public class called public.The function start at line 101 and ends at 102. It contains 2 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
get_hadK
def get_hadK(n, transpose=False):hadK, K = None, Noneif n % 172 == 0:# llama-2-7b upassert is_pow2(n // 172)K = 172hadK = get_had172().T if transpose else get_had172()elif n % 156 == 0:# llama-1-30b 3x hiddenassert is_pow2(n // 156)K = 156hadK = get_had156().T if transpose else get_had156()elif n % 140 == 0:# llama-1-3...
25
55
2
378
2
105
172
105
null
['K', 'hadK']
None
null
0
0
0
null
0
null
The function (get_hadK) defined within the public class called public.The function start at line 105 and ends at 172. It contains 55 lines of code and it has a cyclomatic complexity of 25. It takes 2 parameters, represented as [105.0] and does not return any value..
pytorch_ao
public
public
0
0
matmul_hadU_slow
def matmul_hadU_slow(X, hadK, K):n = X.shape[-1]input = X.clone().view(-1, n, 1)output = input.clone()while input.shape[1] > K:input = input.view(input.shape[0], input.shape[1] // 2, 2, input.shape[2])output = output.view(input.shape)output[:, :, 0, :] = input[:, :, 0, :] + input[:, :, 1, :]output[:, :, 1, :] = input[:...
3
15
3
226
3
175
195
175
null
['n', 'input', 'output']
None
null
0
0
0
null
0
null
The function (matmul_hadU_slow) defined within the public class called public.The function start at line 175 and ends at 195. It contains 15 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [175.0] and does not return any value..
pytorch_ao
public
public
0
0
matmul_hadU_fast
def matmul_hadU_fast(X, hadK, K):n = X.shape[-1]if K == 1:return (torch.ops.torchao.hadamard_transform.default(X.contiguous())/ torch.tensor(n).sqrt())input = X.view(-1, K, n // K)input = (torch.ops.torchao.hadamard_transform.default(input.contiguous())/ torch.tensor(n).sqrt())input = hadK.to(input.device).to(input.dty...
2
14
3
125
2
198
211
198
null
['n', 'input']
None
null
0
0
0
null
0
null
The function (matmul_hadU_fast) defined within the public class called public.The function start at line 198 and ends at 211. It contains 14 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [198.0] and does not return any value..
pytorch_ao
public
public
0
0
random_hadamard_matrix
def random_hadamard_matrix(size, device, seed=0):# See https://cornell-relaxml.github.io/quip-sharp/ , Section "Randomized Hadamard Transformation"gen = torch.Generator(device=device)gen.manual_seed(seed)Q = torch.randint(low=0, high=2, size=(size,), generator=gen).to(torch.float64)Q = Q * 2 - 1Q = torch.diag(Q)hadK, K...
1
8
3
96
2
214
222
214
null
['Q', 'gen']
None
null
0
0
0
null
0
null
The function (random_hadamard_matrix) defined within the public class called public.The function start at line 214 and ends at 222. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [214.0] and does not return any value..
pytorch_ao
public
public
0
0
hadamard_matrix
def hadamard_matrix(size, device):# See https://cornell-relaxml.github.io/quip-sharp/ , Section "Randomized Hadamard Transformation"Q = torch.eye(size)hadK, K = get_hadK(size)return matmul_hadU_slow(Q, hadK, K).to(device)
1
4
2
37
1
225
229
225
null
['Q']
None
null
0
0
0
null
0
null
The function (hadamard_matrix) defined within the public class called public.The function start at line 225 and ends at 229. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [225.0] and does not return any value..
pytorch_ao
public
public
0
0
apply_exact_had_to_linear
def apply_exact_had_to_linear(module, had_dim=-1, output=False, R2=None):assert isinstance(module, torch.nn.Linear)in_features, out_features = module.in_features, module.out_featuresif had_dim != -1:assert is_pow2(had_dim), "Hadamard dimension must be a power of 2!"W = module.weight.dataif output and module.bias is not...
17
44
4
405
7
232
282
232
null
['temp', 'hadK', 'B', 'shape', 'dtype_orig', 'W', 'bias_dtype_orig']
None
null
0
0
0
null
0
null
The function (apply_exact_had_to_linear) defined within the public class called public.The function start at line 232 and ends at 282. It contains 44 lines of code and it has a cyclomatic complexity of 17. It takes 4 parameters, represented as [232.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, had_K, K, use_fp32=False):super().__init__()assert had_K is not None, "had_K must be provided"self.register_buffer("had_K", had_K)self.K = Kself.use_fp32 = use_fp32
1
6
4
45
0
30
35
30
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 30 and ends at 35. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [30.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, x):if self.use_fp32:x = matmul_hadU(x.float(), self.had_K, self.K).to(x.dtype)else:x = matmul_hadU(x, self.had_K, self.K)return x
2
6
2
55
0
37
42
37
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 37 and ends at 42. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [37.0] and does not return any value..
pytorch_ao
public
public
0
0
apply_spinquant
def apply_spinquant(model: Transformer,use_r1=False,use_r2=False,use_r4=True,pretrained_rotation_path=None,qkv_split=False,):"""Apply SpinQuant to a Transformer model: https://arxiv.org/abs/2405.16406Currently, the R1, R2, and R4 rotation matrices are implemented, and can be used independentlyfrom each other. For R1 an...
6
24
6
141
2
45
86
45
null
['device', 'original_device']
None
null
0
0
0
null
0
null
The function (apply_spinquant) defined within the public class called public.The function start at line 45 and ends at 86. It contains 24 lines of code and it has a cyclomatic complexity of 6. It takes 6 parameters, represented as [45.0] and does not return any value..