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
test_intx_weight_only_tied_embed_linear
def test_intx_weight_only_tied_embed_linear(self, b: int = 2, model_dtype: torch.dtype = torch.float32):model = M(m=256, n=256, tied_weights=True).to(_DEVICE)quantizer = StretchedUnifTorchaoQuantizer(b)base_optimizer = torch.optim.SGD(build_param_groups(model, b))optim_kwargs = get_optim_kwargs(model, base_optimizer)op...
1
22
3
150
0
498
521
498
null
[]
None
null
0
0
0
null
0
null
The function (test_intx_weight_only_tied_embed_linear) defined within the public class called public.The function start at line 498 and ends at 521. It contains 22 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [498.0] and does not return any value..
pytorch_ao
public
public
0
0
setUp
def setUp(self):torch.manual_seed(123)
1
2
1
11
0
525
526
291
null
[]
None
null
0
0
0
null
0
null
The function (setUp) defined within the public class called public.The function start at line 525 and ends at 526. 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
test_int8_dynamic_activation_intx_e2e
def test_int8_dynamic_activation_intx_e2e(self,b: int = 2,model_dtype: torch.dtype = torch.float32,group_size: int = 32,):config = MConfig(embedding=False, bias=True)model = PreTrainedM(config).to(_DEVICE, dtype=model_dtype)x = model.example_inputs(device=_DEVICE).to(model_dtype)# reference model using native quantizat...
6
52
4
355
0
535
596
535
null
[]
None
null
0
0
0
null
0
null
The function (test_int8_dynamic_activation_intx_e2e) defined within the public class called public.The function start at line 535 and ends at 596. It contains 52 lines of code and it has a cyclomatic complexity of 6. It takes 4 parameters, represented as [535.0] and does not return any value..
pytorch_ao
public
public
0
0
test_tied_weights_quantization
def test_tied_weights_quantization(self, b: int = 4):config = MConfig(m=128, n=128, tied_weights=True)model = PreTrainedM(config).to(_DEVICE)quantizer = StretchedUnifTorchaoQuantizer(b)linear_config = StretchedIntxWeightConfig(b=b,quant_min=quantizer.quant_min,quant_max=quantizer.quant_max,granularity=PerAxis(0),)embed...
1
32
2
255
0
602
639
602
null
[]
None
null
0
0
0
null
0
null
The function (test_tied_weights_quantization) defined within the public class called public.The function start at line 602 and ends at 639. It contains 32 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [602.0] and does not return any value..
pytorch_ao
public
public
0
0
_reset
def _reset():# using TF32 will cause mixed mm to segfault with triton backend# fixed in nightly by https://github.com/pytorch/pytorch/pull/133173# also required for correctness checktorch.set_float32_matmul_precision("highest")torch._dynamo.reset()
1
3
0
17
0
44
49
44
null
[]
None
null
0
0
0
null
0
null
The function (_reset) defined within the public class called public.The function start at line 44 and ends at 49. 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
test_int8_stochastic_rounding
def test_int8_stochastic_rounding(self, device):x = torch.randn(32, device=device)x_samples = x.view(1, -1).repeat(100_000, 1)x_int8, x_scale = quantize_int8_rowwise(x_samples, stochastic_rounding=True)x_dequant_samples = x_int8 * x_scale.view(-1, 1)x_dequant_mean = x_dequant_samples.mean(0)# a more rigorous test would...
1
7
2
92
0
54
64
54
null
[]
None
null
0
0
0
null
0
null
The function (test_int8_stochastic_rounding) defined within the public class called public.The function start at line 54 and ends at 64. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [54.0] and does not return any value..
pytorch_ao
public
public
0
0
_forward_and_backward
def _forward_and_backward(module, input, grad):# clone input, since we want to inspect its gradient laterinput = input.detach().clone().requires_grad_(True)output = module(input)output.backward(grad)return input, output
1
5
3
41
0
67
72
67
null
[]
None
null
0
0
0
null
0
null
The function (_forward_and_backward) defined within the public class called public.The function start at line 67 and ends at 72. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [67.0] and does not return any value..
pytorch_ao
public
public
0
0
test_int8_weight_only_correctness
def test_int8_weight_only_correctness(self, leading_dims, bias, device):_reset()embed_dim = 32linear_fp32 = nn.Linear(embed_dim, embed_dim, bias=bias, device=device)linear_int8 = copy.deepcopy(linear_fp32)quantize_(linear_int8,int8_weight_only_quantized_training(),)linear_fp32.weight.data = linear_int8.weight.data.dequ...
2
19
4
192
0
77
99
77
null
[]
None
null
0
0
0
null
0
null
The function (test_int8_weight_only_correctness) defined within the public class called public.The function start at line 77 and ends at 99. It contains 19 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [77.0] and does not return any value..
pytorch_ao
public
public
0
0
test_int8_weight_only_compile
def test_int8_weight_only_compile(self, leading_dims, bias, device):_reset()embed_dim = 128linear_eager = nn.Linear(embed_dim, embed_dim, bias=bias, device=device)quantize_(linear_eager,int8_weight_only_quantized_training(),)linear_compiled = copy.deepcopy(linear_eager)linear_compiled.compile()input = torch.randn(leadi...
2
25
4
184
0
104
132
104
null
[]
None
null
0
0
0
null
0
null
The function (test_int8_weight_only_compile) defined within the public class called public.The function start at line 104 and ends at 132. It contains 25 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [104.0] and does not return any value..
pytorch_ao
public
public
0
0
test_int8_weight_only_training
def test_int8_weight_only_training(self, compile, device):_reset()bsize = 4embed_dim = 32n_classes = 10model_fp32 = nn.Sequential(nn.Linear(embed_dim, embed_dim * 2, bias=False),nn.GELU(),nn.Linear(embed_dim * 2, n_classes),).to(device)model_int8 = copy.deepcopy(model_fp32)quantize_(model_int8, int8_weight_only_quantiz...
3
30
3
244
0
136
172
136
null
[]
None
null
0
0
0
null
0
null
The function (test_int8_weight_only_training) defined within the public class called public.The function start at line 136 and ends at 172. It contains 30 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [136.0] and does not return any value..
pytorch_ao
public
public
0
0
test_int8_mixed_precision_training.snr
def snr(ref, actual):error = actual - refreturn 20 * torch.log10(torch.linalg.vector_norm(ref) / torch.linalg.vector_norm(error))
1
5
2
37
0
212
216
212
null
[]
None
null
0
0
0
null
0
null
The function (test_int8_mixed_precision_training.snr) defined within the public class called public.The function start at line 212 and ends at 216. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [212.0] and does not return any value..
pytorch_ao
public
public
0
0
test_int8_mixed_precision_training
def test_int8_mixed_precision_training(self, compile, config, module_swap):_reset()bsize = 64embed_dim = 64device = "cuda"linear = nn.Linear(embed_dim, embed_dim, device=device)linear_int8mp = copy.deepcopy(linear)config.module_swap = module_swapapply_func = int8_mixed_precision_training(config)quantize_(linear_int8mp,...
2
25
4
172
0
186
220
186
null
[]
None
null
0
0
0
null
0
null
The function (test_int8_mixed_precision_training) defined within the public class called public.The function start at line 186 and ends at 220. It contains 25 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [186.0] and does not return any value..
pytorch_ao
public
public
0
0
test_bitnet_training.activation_quant
def activation_quant(self, x):scale = 127.0 / x.abs().max(dim=-1, keepdim=True).values.clamp_(min=1e-5)return (x * scale).round().clamp_(-128, 127) / scale
1
5
2
61
0
230
234
230
null
[]
None
null
0
0
0
null
0
null
The function (test_bitnet_training.activation_quant) defined within the public class called public.The function start at line 230 and ends at 234. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [230.0] and does not return any value..
pytorch_ao
public
public
0
0
test_bitnet_training.weight_quant
def weight_quant(self, x):scale = 1.0 / x.abs().mean().clamp_(min=1e-5)return (x * scale).round().clamp_(-1, 1) / scale
1
3
2
51
0
236
238
236
null
[]
None
null
0
0
0
null
0
null
The function (test_bitnet_training.weight_quant) defined within the public class called public.The function start at line 236 and ends at 238. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [236.0] and does not return any value..
pytorch_ao
public
public
0
0
test_bitnet_training.forward
def forward(self, x):w = self.weightx = x + (self.activation_quant(x) - x).detach()w = w + (self.weight_quant(w) - w).detach()return F.linear(x, w, self.bias)
1
5
2
61
0
240
244
240
null
[]
None
null
0
0
0
null
0
null
The function (test_bitnet_training.forward) defined within the public class called public.The function start at line 240 and ends at 244. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [240.0] and does not return any value..
pytorch_ao
public
public
0
0
test_bitnet_training
def test_bitnet_training(self, compile):# reference implementation# https://github.com/microsoft/unilm/blob/master/bitnet/The-Era-of-1-bit-LLMs__Training_Tips_Code_FAQ.pdf# Figure 3class BitLinear(nn.Linear):def activation_quant(self, x):scale = 127.0 / x.abs().max(dim=-1, keepdim=True).values.clamp_(min=1e-5)return (x...
4
37
2
269
0
225
287
225
null
[]
None
null
0
0
0
null
0
null
The function (test_bitnet_training) defined within the public class called public.The function start at line 225 and ends at 287. It contains 37 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [225.0] and does not return any value..
pytorch_ao
public
public
0
0
world_size
def world_size(self) -> int:return _FSDP_WORLD_SIZE
1
2
1
9
0
295
296
295
null
[]
None
null
0
0
0
null
0
null
The function (world_size) defined within the public class called public.The function start at line 295 and ends at 296. 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
test_fsdp2_correctness
def test_fsdp2_correctness(self):mp_policy = MixedPrecisionPolicy()# quantize_fn, mp_policy, tolerancetest_args = [# high tolerance due to stochastic rounding(int8_weight_only_quantized_training(), mp_policy, 0.05),(int8_mixed_precision_training(), mp_policy, 1e-6),(int8_mixed_precision_training(module_swap=True), mp_p...
1
16
1
135
0
299
325
299
null
[]
None
null
0
0
0
null
0
null
The function (test_fsdp2_correctness) defined within the public class called public.The function start at line 299 and ends at 325. It contains 16 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
_run_subtest
def _run_subtest(self, args):quantize_fn, mp_policy, tolerance = argsbatch_size = 3vocab_size = 32seq_len = 64# NOTE: if weight_tying=True and we also quantize LM head, INT8 mixed-precision will fail.model_args = ModelArgs(n_layers=2,n_heads=2,dim=128,vocab_size=vocab_size,max_seq_len=seq_len,dropout_p=0,)torch.manual_...
5
50
2
361
0
327
386
327
null
[]
None
null
0
0
0
null
0
null
The function (_run_subtest) defined within the public class called public.The function start at line 327 and ends at 386. It contains 50 lines of code and it has a cyclomatic complexity of 5. It takes 2 parameters, represented as [327.0] and does not return any value..
pytorch_ao
public
public
0
0
test_precompute_bitnet_scale
def test_precompute_bitnet_scale(self):from torchao.prototype.quantized_training.bitnet import (get_bitnet_scale,precompute_bitnet_scale_for_fsdp,)model = nn.Sequential(nn.Linear(32, 64), nn.GELU(), nn.Linear(64, 32)).cuda()model_fsdp = copy.deepcopy(model)quantize_(model_fsdp, bitnet_training())fully_shard(model_fsdp)...
1
18
1
134
0
389
409
389
null
[]
None
null
0
0
0
null
0
null
The function (test_precompute_bitnet_scale) defined within the public class called public.The function start at line 389 and ends at 409. It contains 18 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):if self.last_epoch > 0:return [group["sparsity_level"] * 0.5 for group in self.sparsifier.groups]else:return list(self.base_sl)
3
5
1
40
0
21
25
21
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 21 and ends at 25. It contains 5 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
test_constructor
def test_constructor(self):model = nn.Sequential(nn.Linear(16, 16))sparsifier = WeightNormSparsifier()sparsifier.prepare(model, config=None)scheduler = ImplementedScheduler(sparsifier)assert scheduler.sparsifier is sparsifierassert scheduler._step_count == 1assert scheduler.base_sl == [sparsifier.groups[0]["sparsity_le...
1
8
1
69
0
29
37
29
null
[]
None
null
0
0
0
null
0
null
The function (test_constructor) defined within the public class called public.The function start at line 29 and ends at 37. It contains 8 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
test_order_of_steps
def test_order_of_steps(self):"""Checks if the warning is thrown if the scheduler step is calledbefore the sparsifier step"""model = nn.Sequential(nn.Linear(16, 16))sparsifier = WeightNormSparsifier()sparsifier.prepare(model, config=None)scheduler = ImplementedScheduler(sparsifier)# Sparsifier step is not calledwith se...
2
14
1
109
0
39
61
39
null
[]
None
null
0
0
0
null
0
null
The function (test_order_of_steps) defined within the public class called public.The function start at line 39 and ends at 61. 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
test_step
def test_step(self):model = nn.Sequential(nn.Linear(16, 16))sparsifier = WeightNormSparsifier()sparsifier.prepare(model, config=None)assert sparsifier.groups[0]["sparsity_level"] == 0.5scheduler = ImplementedScheduler(sparsifier)assert sparsifier.groups[0]["sparsity_level"] == 0.5sparsifier.step()scheduler.step()assert...
1
10
1
93
0
63
73
63
null
[]
None
null
0
0
0
null
0
null
The function (test_step) defined within the public class called public.The function start at line 63 and ends at 73. It contains 10 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
test_lambda_scheduler
def test_lambda_scheduler(self):model = nn.Sequential(nn.Linear(16, 16))sparsifier = WeightNormSparsifier()sparsifier.prepare(model, config=None)assert sparsifier.groups[0]["sparsity_level"] == 0.5scheduler = LambdaSL(sparsifier, lambda epoch: epoch * 10)assert sparsifier.groups[0]["sparsity_level"] == 0.0# Epoch 0sche...
1
9
1
95
0
75
83
75
null
[]
None
null
0
0
0
null
0
null
The function (test_lambda_scheduler) defined within the public class called public.The function start at line 75 and ends at 83. It contains 9 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
setUp
def setUp(self):self.model_sparse_config = [{"tensor_fqn": "0.weight", "sparsity_level": 0.8},{"tensor_fqn": "2.weight", "sparsity_level": 0.4},]self.sorted_sparse_levels = [conf["sparsity_level"] for conf in self.model_sparse_config]self.initial_sparsity = 0.1self.initial_step = 3
2
10
1
63
0
87
96
87
null
[]
None
null
0
0
0
null
0
null
The function (setUp) defined within the public class called public.The function start at line 87 and ends at 96. It contains 10 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
_make_model
def _make_model(self, **kwargs):model = nn.Sequential(nn.Linear(13, 17),nn.Dropout(0.5),nn.Linear(17, 3),)return model
1
7
2
44
0
98
104
98
null
[]
None
null
0
0
0
null
0
null
The function (_make_model) defined within the public class called public.The function start at line 98 and ends at 104. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [98.0] and does not return any value..
pytorch_ao
public
public
0
0
_make_scheduler
def _make_scheduler(self, model, **kwargs):sparsifier = WeightNormSparsifier()sparsifier.prepare(model, config=self.model_sparse_config)scheduler_args = {"init_sl": self.initial_sparsity,"init_t": self.initial_step,}scheduler_args.update(kwargs)scheduler = CubicSL(sparsifier, **scheduler_args)return sparsifier, schedul...
1
10
3
62
0
106
117
106
null
[]
None
null
0
0
0
null
0
null
The function (_make_scheduler) defined within the public class called public.The function start at line 106 and ends at 117. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [106.0] and does not return any value..
pytorch_ao
public
public
0
0
_get_sparsity_levels
def _get_sparsity_levels(sparsifier, precision=32):r"""Gets the current levels of sparsity in a sparsifier."""return [round(group["sparsity_level"], precision) for group in sparsifier.groups]
2
4
2
29
0
120
124
120
null
[]
None
null
0
0
0
null
0
null
The function (_get_sparsity_levels) defined within the public class called public.The function start at line 120 and ends at 124. It contains 4 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [120.0] and does not return any value..
pytorch_ao
public
public
0
0
test_constructor
def test_constructor(self):model = self._make_model()sparsifier, scheduler = self._make_scheduler(model=model, initially_zero=True)self.assertIs(scheduler.sparsifier, sparsifier, msg="Sparsifier is not properly attached")self.assertEqual(scheduler._step_count,1,msg="Scheduler is initialized with incorrect step count",)...
1
28
1
147
0
126
157
126
null
[]
None
null
0
0
0
null
0
null
The function (test_constructor) defined within the public class called public.The function start at line 126 and ends at 157. It contains 28 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
test_step
def test_step(self):# For n=5, dt=2, there will be totally 10 steps between s_0 and s_f, starting from t_0model = self._make_model()sparsifier, scheduler = self._make_scheduler(model=model, initially_zero=True, init_t=3, delta_t=2, total_t=5)scheduler.step()scheduler.step()self.assertEqual(scheduler._step_count,3,msg="...
2
38
1
217
0
159
202
159
null
[]
None
null
0
0
0
null
0
null
The function (test_step) defined within the public class called public.The function start at line 159 and ends at 202. It contains 38 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, m=512, n=256, k=128):super().__init__()self.linear1 = torch.nn.Linear(m, n, bias=False)self.linear2 = torch.nn.Linear(n, k, bias=False)self.linear3 = torch.nn.Linear(k, 64, bias=False)
1
5
4
78
0
30
34
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 34. It contains 5 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
example_inputs
def example_inputs(self,batch_size,sequence_length=10,dtype=torch.bfloat16,device="cuda",):# For SmoothQuant tests, we intentionally insert some outliers to input featuresx = torch.randn(batch_size,sequence_length,self.linear1.in_features,dtype=dtype,device=device,)n_outliers = max(1, int(x.size(-1) * 0.1))# Randomly s...
1
18
5
104
0
36
55
36
null
[]
None
null
0
0
0
null
0
null
The function (example_inputs) defined within the public class called public.The function start at line 36 and ends at 55. It contains 18 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [36.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, x):x = self.linear1(x)x = self.linear2(x)x = self.linear3(x)return x
1
5
2
33
0
57
61
57
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 57 and ends at 61. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [57.0] and does not return any value..
pytorch_ao
public
public
0
0
setUpClass
def setUpClass(cls):"""Set up class-level configuration for tests."""# This test case will trigger recompilation many times, so set a large cache_size_limit heretorch._dynamo.config.cache_size_limit = 128
1
2
1
15
0
72
75
72
null
[]
None
null
0
0
0
null
0
null
The function (setUpClass) defined within the public class called public.The function start at line 72 and ends at 75. 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
test_smoothquant_accuracy
def test_smoothquant_accuracy(self, alpha, base_config, device, input_dtype):"""Test if SmoothQuant achieves lower loss than basic quantization."""# Create linear layerm = ToyLinearModel().eval().to(device).to(input_dtype)x = m.example_inputs(batch_size=16, dtype=input_dtype, device=device)# Reference outputout_ref = m...
1
30
5
215
0
88
131
88
null
[]
None
null
0
0
0
null
0
null
The function (test_smoothquant_accuracy) defined within the public class called public.The function start at line 88 and ends at 131. It contains 30 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [88.0] and does not return any value..
pytorch_ao
public
public
0
0
test_observer_insertion
def test_observer_insertion(self, base_config):"""Test that PREPARE step correctly inserts SmoothQuantObservedLinear."""m = ToyLinearModel().eval()# Before quantization - should be regular Linearself.assertIsInstance(m.linear1, torch.nn.Linear)self.assertNotIsInstance(m.linear1, SmoothQuantObservedLinear)# PREPARE step...
1
17
2
136
0
140
170
140
null
[]
None
null
0
0
0
null
0
null
The function (test_observer_insertion) defined within the public class called public.The function start at line 140 and ends at 170. It contains 17 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [140.0] and does not return any value..
pytorch_ao
public
public
0
0
test_prepare_for_loading
def test_prepare_for_loading(self, base_config):"""Test PREPARE_FOR_LOADING step for loading pre-quantized checkpoints."""m = ToyLinearModel().eval()# Before quantization - should be regular Linearself.assertIsInstance(m.linear1, torch.nn.Linear)self.assertNotIsInstance(m.linear1, SmoothQuantObservedLinear)# PREPARE_FO...
1
24
2
156
0
179
214
179
null
[]
None
null
0
0
0
null
0
null
The function (test_prepare_for_loading) defined within the public class called public.The function start at line 179 and ends at 214. It contains 24 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [179.0] and does not return any value..
pytorch_ao
public
public
0
0
test_constructor
def test_constructor(self):# Cannot instantiate the abstract baseself.assertRaises(TypeError, BaseSparsifier)# Can instantiate the model with no configsmodel = SimpleLinear()sparsifier = ImplementedSparsifier(test=3)sparsifier.prepare(model, config=None)assert len(sparsifier.groups) == 5sparsifier.step()# Can instantia...
1
13
1
114
0
36
51
36
null
[]
None
null
0
0
0
null
0
null
The function (test_constructor) defined within the public class called public.The function start at line 36 and ends at 51. It contains 13 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
test_prepare_config
def test_prepare_config(self):model = SimpleLinear()sparsifier = ImplementedSparsifier(test=3)# Make sure there are no parametrizations before `prepare`assert not hasattr(model.seq[0], "parametrizations")assert not hasattr(model.linear1, "parametrizations")assert not hasattr(model.linear2, "parametrizations")sparsifier...
1
21
1
169
0
53
78
53
null
[]
None
null
0
0
0
null
0
null
The function (test_prepare_config) defined within the public class called public.The function start at line 53 and ends at 78. It contains 21 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
test_step
def test_step(self):model = SimpleLinear()sparsifier = ImplementedSparsifier(test=3)sparsifier.enable_mask_update = Truesparsifier.prepare(model, [{"tensor_fqn": "linear1.weight"}])sparsifier.step()assert torch.all(model.linear1.parametrizations.weight[0].mask[0] == 0)
1
7
1
65
0
80
86
80
null
[]
None
null
0
0
0
null
0
null
The function (test_step) defined within the public class called public.The function start at line 80 and ends at 86. 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
test_state_dict
def test_state_dict(self):step_count = 3model0 = SimpleLinear()sparsifier0 = ImplementedSparsifier(test=3)sparsifier0.prepare(model0, [{"tensor_fqn": "linear1.weight"}])mask = model0.linear1.parametrizations["weight"][0].maskmask.data = torch.arange(mask.shape[0] * mask.shape[1]).reshape(mask.shape)for step in range(st...
9
44
1
396
0
88
144
88
null
[]
None
null
0
0
0
null
0
null
The function (test_state_dict) defined within the public class called public.The function start at line 88 and ends at 144. It contains 44 lines of code and it has a cyclomatic complexity of 9. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_convert
def test_convert(self):model = SimpleLinear()sparsifier = ImplementedSparsifier(test=3)sparsifier.prepare(model, [{"tensor_fqn": "linear1.weight"}])new_model = sparsifier.convert(model, mapping={nn.Linear: MockSparseLinear}, inplace=False)assert isinstance(new_model.linear1, MockSparseLinear)assert isinstance(new_model...
1
10
1
88
0
146
156
146
null
[]
None
null
0
0
0
null
0
null
The function (test_convert) defined within the public class called public.The function start at line 146 and ends at 156. It contains 10 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
test_mask_squash
def test_mask_squash(self):model = SimpleLinear()sparsifier = ImplementedSparsifier(test=3)sparsifier.prepare(model, [{"tensor_fqn": "linear1.weight"}])assert hasattr(model.linear1.parametrizations.weight[0], "mask")assert is_parametrized(model.linear1, "weight")assert not is_parametrized(model.seq[0], "weight")sparsif...
1
10
1
98
0
158
168
158
null
[]
None
null
0
0
0
null
0
null
The function (test_mask_squash) defined within the public class called public.The function start at line 158 and ends at 168. It contains 10 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
test_mask_squash_with_params1
def test_mask_squash_with_params1(self):model = SimpleLinear()sparsifier = ImplementedSparsifier(foo=3, bar=2, baz=1)sparsifier.prepare(model, [{"tensor_fqn": "linear1.weight"}, {"tensor_fqn": "seq.0.weight"}])sparsifier.squash_mask(params_to_keep_per_layer={"linear1": ("foo", "bar"), "seq.0": ("baz",)})assert not is_p...
1
19
1
212
0
170
188
170
null
[]
None
null
0
0
0
null
0
null
The function (test_mask_squash_with_params1) defined within the public class called public.The function start at line 170 and ends at 188. It contains 19 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
test_mask_squash_with_params2
def test_mask_squash_with_params2(self):model = SimpleLinear()sparsifier = ImplementedSparsifier(foo=3, bar=2, baz=1)sparsifier.prepare(model, [{"tensor_fqn": "linear1.weight"}, {"tensor_fqn": "seq.0.weight"}])sparsifier.squash_mask(params_to_keep=("foo", "bar"))assert not is_parametrized(model.seq[0], "weight")assert ...
1
17
1
201
0
190
206
190
null
[]
None
null
0
0
0
null
0
null
The function (test_mask_squash_with_params2) defined within the public class called public.The function start at line 190 and ends at 206. 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
test_mask_squash_with_params3
def test_mask_squash_with_params3(self):model = SimpleLinear()sparsifier = ImplementedSparsifier(foo=3, bar=2, baz=1)sparsifier.prepare(model, [{"tensor_fqn": "linear1.weight"}, {"tensor_fqn": "seq.0.weight"}])sparsifier.squash_mask(params_to_keep=("foo", "bar"), params_to_keep_per_layer={"seq.0": ("baz",)})assert not ...
1
19
1
212
0
208
226
208
null
[]
None
null
0
0
0
null
0
null
The function (test_mask_squash_with_params3) defined within the public class called public.The function start at line 208 and ends at 226. It contains 19 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
test_constructor
def test_constructor(self):model = SimpleLinear()sparsifier = WeightNormSparsifier()sparsifier.prepare(model, config=None)for g in sparsifier.groups:assert isinstance(g["module"], nn.Linear)# The groups are unorderedassert g["module_fqn"] in ("seq.0", "seq.1", "seq.2", "linear1", "linear2")
2
7
1
61
0
230
237
230
null
[]
None
null
0
0
0
null
0
null
The function (test_constructor) defined within the public class called public.The function start at line 230 and ends at 237. 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
test_step
def test_step(self):model = SimpleLinear()sparsifier = WeightNormSparsifier(sparsity_level=0.5)sparsifier.prepare(model, config=[{"tensor_fqn": "linear1.weight"}])for g in sparsifier.groups:# Before stepmodule = g["module"]assert (1.0 - module.parametrizations["weight"][0].mask.mean()) == 0# checking sparsity level is ...
5
30
1
228
0
239
272
239
null
[]
None
null
0
0
0
null
0
null
The function (test_step) defined within the public class called public.The function start at line 239 and ends at 272. It contains 30 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
test_step_2_of_4
def test_step_2_of_4(self):model = SimpleLinear()sparsifier = WeightNormSparsifier(sparsity_level=1.0, sparse_block_shape=(1, 4), zeros_per_block=2)sparsifier.prepare(model, config=[{"tensor_fqn": "linear1.weight"}])sparsifier.step()# make sure the sparsity level is approximately 50%mask = model.linear1.parametrization...
3
19
1
188
0
274
294
274
null
[]
None
null
0
0
0
null
0
null
The function (test_step_2_of_4) defined within the public class called public.The function start at line 274 and ends at 294. It contains 19 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
test_prepare
def test_prepare(self):model = SimpleLinear()sparsifier = WeightNormSparsifier()sparsifier.prepare(model, config=None)for g in sparsifier.groups:module = g["module"]# Check mask existsassert hasattr(module.parametrizations["weight"][0], "mask")# Check parametrization exists and is correctassert is_parametrized(module, ...
2
9
1
74
0
296
306
296
null
[]
None
null
0
0
0
null
0
null
The function (test_prepare) defined within the public class called public.The function start at line 296 and ends at 306. It contains 9 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
test_mask_squash
def test_mask_squash(self):model = SimpleLinear()sparsifier = WeightNormSparsifier()sparsifier.prepare(model, config=None)sparsifier.squash_mask()for g in sparsifier.groups:module = g["module"]assert not is_parametrized(module, "weight")assert not hasattr(module, "mask")
2
9
1
59
0
308
316
308
null
[]
None
null
0
0
0
null
0
null
The function (test_mask_squash) defined within the public class called public.The function start at line 308 and ends at 316. It contains 9 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
test_sparsity_levels
def test_sparsity_levels(self):sparsity_levels = [-1.0, 0.0, 0.5, 1.0, 2.0]sparse_block_shapes = [(1, 1), (1, 4), (2, 2), (4, 1)]zeros_per_blocks = [0, 1, 2, 3, 4]testcases = itertools.tee(itertools.product(sparsity_levels, sparse_block_shapes, zeros_per_blocks))# Create a config and model with all the testcasesmodel =...
6
43
1
357
0
318
370
318
null
[]
None
null
0
0
0
null
0
null
The function (test_sparsity_levels) defined within the public class called public.The function start at line 318 and ends at 370. It contains 43 lines of code and it has a cyclomatic complexity of 6. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_constructor
def test_constructor(self):model = SimpleLinear()sparsifier = NearlyDiagonalSparsifier(nearliness=1)sparsifier.prepare(model, config=None)for g in sparsifier.groups:assert isinstance(g["module"], nn.Linear)# The groups are unorderedassert g["module_fqn"] in ("seq.0", "seq.1", "seq.2", "linear1", "linear2")
2
7
1
64
0
374
381
374
null
[]
None
null
0
0
0
null
0
null
The function (test_constructor) defined within the public class called public.The function start at line 374 and ends at 381. 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
test_step
def test_step(self):model = SimpleLinear()sparsifier = NearlyDiagonalSparsifier(nearliness=1)sparsifier.prepare(model, config=[{"tensor_fqn": "linear1.weight"}])for g in sparsifier.groups:# Before stepmodule = g["module"]assert (1.0 - module.parametrizations["weight"][0].mask.mean()) == 0# checking sparsity level is 0s...
5
28
1
227
0
383
418
383
null
[]
None
null
0
0
0
null
0
null
The function (test_step) defined within the public class called public.The function start at line 383 and ends at 418. It contains 28 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
test_prepare
def test_prepare(self):model = SimpleLinear()sparsifier = NearlyDiagonalSparsifier(nearliness=1)sparsifier.prepare(model, config=None)for g in sparsifier.groups:module = g["module"]# Check mask existsassert hasattr(module.parametrizations["weight"][0], "mask")# Check parametrization exists and is correctassert is_param...
2
9
1
77
0
420
430
420
null
[]
None
null
0
0
0
null
0
null
The function (test_prepare) defined within the public class called public.The function start at line 420 and ends at 430. It contains 9 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
test_mask_squash
def test_mask_squash(self):model = SimpleLinear()sparsifier = NearlyDiagonalSparsifier(nearliness=1)sparsifier.prepare(model, config=None)sparsifier.step()sparsifier.squash_mask()for g in sparsifier.groups:module = g["module"]assert not is_parametrized(module, "weight")assert not hasattr(module, "mask")weights = module...
2
15
1
97
0
432
446
432
null
[]
None
null
0
0
0
null
0
null
The function (test_mask_squash) defined within the public class called public.The function start at line 432 and ends at 446. It contains 15 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
test_sparsity_levels
def test_sparsity_levels(self):nearliness_levels = list(range(-1, 100))model = nn.Sequential()p = re.compile(r"[-\.\s]")for nearliness in nearliness_levels:sparsifier = NearlyDiagonalSparsifier(nearliness=1)layer_name = f"{nearliness}"layer_name = p.sub("_", layer_name)layer = nn.Linear(32, 32, bias=False)layer.weight ...
5
25
1
197
0
448
478
448
null
[]
None
null
0
0
0
null
0
null
The function (test_sparsity_levels) defined within the public class called public.The function start at line 448 and ends at 478. It contains 25 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
_verify_nearliness
def _verify_nearliness(self, mask: torch.Tensor, nearliness: int):if nearliness <= 0:assert torch.all(mask == torch.zeros(mask.shape[0], mask.shape[1]))else:height, width = mask.shapedist_to_diagonal = nearliness // 2for row in range(0, height):for col in range(0, width):if abs(row - col) <= dist_to_diagonal:assert mas...
5
12
3
109
0
481
492
481
null
[]
None
null
0
0
0
null
0
null
The function (_verify_nearliness) defined within the public class called public.The function start at line 481 and ends at 492. It contains 12 lines of code and it has a cyclomatic complexity of 5. It takes 3 parameters, represented as [481.0] and does not return any value..
pytorch_ao
public
public
0
0
test_module_to_fqn
def test_module_to_fqn(self):"""Tests that module_to_fqn works as expected when compared to known goodmodule.get_submodule(fqn) function"""for model_class in model_list:model = model_class()list_of_modules = [m for _, m in model.named_modules()] + [model]for module in list_of_modules:fqn = module_to_fqn(model, module)c...
4
8
1
64
0
43
54
43
null
[]
None
null
0
0
0
null
0
null
The function (test_module_to_fqn) defined within the public class called public.The function start at line 43 and ends at 54. It contains 8 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
test_module_to_fqn_fail
def test_module_to_fqn_fail(self):"""Tests that module_to_fqn returns None when an fqn that doesn'tcorrespond to a path to a node/tensor is given"""for model_class in model_list:model = model_class()fqn = module_to_fqn(model, torch.nn.Linear(3, 3))self.assertEqual(fqn, None)
2
5
1
41
0
56
64
56
null
[]
None
null
0
0
0
null
0
null
The function (test_module_to_fqn_fail) defined within the public class called public.The function start at line 56 and ends at 64. It contains 5 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
test_module_to_fqn_root
def test_module_to_fqn_root(self):"""Tests that module_to_fqn returns '' when model and target module are the same"""for model_class in model_list:model = model_class()fqn = module_to_fqn(model, model)self.assertEqual(fqn, "")
2
5
1
32
0
66
73
66
null
[]
None
null
0
0
0
null
0
null
The function (test_module_to_fqn_root) defined within the public class called public.The function start at line 66 and ends at 73. It contains 5 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
test_fqn_to_module
def test_fqn_to_module(self):"""Tests that fqn_to_module operates as inverseof module_to_fqn"""for model_class in model_list:model = model_class()list_of_modules = [m for _, m in model.named_modules()] + [model]for module in list_of_modules:fqn = module_to_fqn(model, module)check_module = fqn_to_module(model, fqn)self....
4
8
1
64
0
75
86
75
null
[]
None
null
0
0
0
null
0
null
The function (test_fqn_to_module) defined within the public class called public.The function start at line 75 and ends at 86. It contains 8 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
test_fqn_to_module_fail
def test_fqn_to_module_fail(self):"""Tests that fqn_to_module returns None when it tries tofind an fqn of a module outside the model"""for model_class in model_list:model = model_class()fqn = "foo.bar.baz"check_module = fqn_to_module(model, fqn)self.assertEqual(check_module, None)
2
6
1
35
0
88
97
88
null
[]
None
null
0
0
0
null
0
null
The function (test_fqn_to_module_fail) defined within the public class called public.The function start at line 88 and ends at 97. It contains 6 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
test_fqn_to_module_for_tensors
def test_fqn_to_module_for_tensors(self):"""Tests that fqn_to_module works for tensors, actually all parametersof the model. This is tested by identifying a module with a tensor,and generating the tensor_fqn using module_to_fqn on the module +the name of the tensor."""for model_class in model_list:model = model_class()...
6
12
1
95
0
99
116
99
null
[]
None
null
0
0
0
null
0
null
The function (test_fqn_to_module_for_tensors) defined within the public class called public.The function start at line 99 and ends at 116. It contains 12 lines of code and it has a cyclomatic complexity of 6. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_get_arg_info_from_tensor_fqn
def test_get_arg_info_from_tensor_fqn(self):"""Tests that get_arg_info_from_tensor_fqn works for all parameters of the model.Generates a tensor_fqn in the same way as test_fqn_to_module_for_tensors andthen compares with known (parent) module and tensor_name as well as module_fqnfrom module_to_fqn."""for model_class in ...
6
15
1
131
0
118
138
118
null
[]
None
null
0
0
0
null
0
null
The function (test_get_arg_info_from_tensor_fqn) defined within the public class called public.The function start at line 118 and ends at 138. It contains 15 lines of code and it has a cyclomatic complexity of 6. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_get_arg_info_from_tensor_fqn_fail
def test_get_arg_info_from_tensor_fqn_fail(self):"""Tests that get_arg_info_from_tensor_fqn works as expected for invalid tensor_fqninputs. The string outputs still work but the output module is expected to be None."""for model_class in model_list:model = model_class()tensor_fqn = "foo.bar.baz"arg_info = get_arg_info_f...
2
9
1
71
0
140
152
140
null
[]
None
null
0
0
0
null
0
null
The function (test_get_arg_info_from_tensor_fqn_fail) defined within the public class called public.The function start at line 140 and ends at 152. It contains 9 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_model
def _init_model(name="7B", device="cpu", precision=torch.bfloat16):model = Transformer.from_name(name)model.to(device=device, dtype=precision)return model.eval()
1
4
3
43
1
13
16
13
null
['model']
None
null
0
0
0
null
0
null
The function (_init_model) defined within the public class called public.The function start at line 13 and ends at 16. It contains 4 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
test_spinquant_no_quantization
def test_spinquant_no_quantization(device):model = _init_model(device=device)seq_len = 16batch_size = 1is_training = Falseinput_ids = torch.randint(0, 1024, (batch_size, seq_len)).to(device)input_pos = None if is_training else torch.arange(seq_len).to(device)with torch.device(device):model.setup_caches(max_batch_size=b...
2
16
1
133
8
23
42
23
null
['out', 'is_training', 'seq_len', 'input_pos', 'out_spinquant', 'model', 'input_ids', 'batch_size']
None
null
0
0
0
null
0
null
The function (test_spinquant_no_quantization) defined within the public class called public.The function start at line 23 and ends at 42. It contains 16 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
update_mask
def update_mask(self, module, tensor_name, **kwargs):getattr(module.parametrizations, tensor_name)[0].mask[1] = False
1
2
4
30
0
52
53
52
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 52 and ends at 53. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [52.0] and does not return any value..
pytorch_ao
public
public
0
0
update_mask
def update_mask(self, module, tensor_name, **kwargs):"""Prunes 1/3 of the weight output channels, so resulting module has 33.3% pruning"""num_rows = len(module.parametrizations[tensor_name][0].mask)prune = random.sample(list(range(num_rows)), num_rows // 3)module.parametrizations[tensor_name][0].mask[prune] = False
1
4
4
61
0
57
61
57
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 57 and ends at 61. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [57.0] and does not return any value..
pytorch_ao
public
public
0
0
update_mask
def update_mask(self, module, tensor_name, **kwargs):for p in getattr(module.parametrizations, tensor_name):if isinstance(p, FakeStructuredSparsity):mask = p.maskmasks = torch.split(mask, len(mask) // 4)for small in masks:num = len(small)small[num // 2 :] = Falsenew_mask = torch.cat(masks)mask.data = new_mask.data
4
10
4
80
0
70
79
70
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 70 and ends at 79. It contains 10 lines of code and it has a cyclomatic complexity of 4. It takes 4 parameters, represented as [70.0] and does not return any value..
pytorch_ao
public
public
0
0
test_saliency_pruner_update_mask
def test_saliency_pruner_update_mask(self):"""Test that we prune out the row with the lowest saliency (first row)"""model = SimpleLinear()with torch.no_grad():model.linear1.weight = nn.Parameter(torch.Tensor([[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]))pruning_config = [{"tensor_fqn": "linear1.weight", "sp...
1
16
1
190
0
83
102
83
null
[]
None
null
0
0
0
null
0
null
The function (test_saliency_pruner_update_mask) defined within the public class called public.The function start at line 83 and ends at 102. It contains 16 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
test_lstm_saliency_pruner_update_mask
def test_lstm_saliency_pruner_update_mask(self):model = LSTMLinearModel(input_dim=2,hidden_dim=2,output_dim=2,num_layers=1,)manual_weights = torch.Tensor([[1, 1], [2, 2], [2, 2], [1, 1], [-1, -1], [-2, -2], [-2, -2], [-1, -1]])with torch.no_grad():model.lstm.weight_ih_l0 = nn.Parameter(manual_weights)model.lstm.weight_...
2
41
1
453
0
104
154
104
null
[]
None
null
0
0
0
null
0
null
The function (test_lstm_saliency_pruner_update_mask) defined within the public class called public.The function start at line 104 and ends at 154. It contains 41 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
_check_pruner_prepared
def _check_pruner_prepared(self, model, pruner, device):for config in pruner.groups:module = config["module"]assert module.weight.device.type == device.type# Check mask existsassert config["tensor_fqn"] in pruner.state# Check parametrization exists and is correctassert parametrize.is_parametrized(module)assert hasattr(...
2
8
4
73
0
158
168
158
null
[]
None
null
0
0
0
null
0
null
The function (_check_pruner_prepared) defined within the public class called public.The function start at line 158 and ends at 168. It contains 8 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [158.0] and does not return any value..
pytorch_ao
public
public
0
0
_check_pruner_valid_before_step
def _check_pruner_valid_before_step(self, model, pruner, device):for config in pruner.groups:modules = []if type(config["module"]) is tuple:modules.extend(config["module"])else:module = config["module"]modules.append(module)for module in modules:assert module.weight.device.type == device.typeassert module.parametrizati...
4
11
4
90
0
170
180
170
null
[]
None
null
0
0
0
null
0
null
The function (_check_pruner_valid_before_step) defined within the public class called public.The function start at line 170 and ends at 180. It contains 11 lines of code and it has a cyclomatic complexity of 4. It takes 4 parameters, represented as [170.0] and does not return any value..
pytorch_ao
public
public
0
0
_check_pruner_valid_after_step
def _check_pruner_valid_after_step(self, model, pruner, mask, device):for config in pruner.groups:modules = []if type(config["module"]) is tuple:modules.extend(config["module"])else:module = config["module"]modules.append(module)for module in modules:assert module.weight.device.type == device.typetotal = module.paramet...
4
15
5
112
0
182
196
182
null
[]
None
null
0
0
0
null
0
null
The function (_check_pruner_valid_after_step) defined within the public class called public.The function start at line 182 and ends at 196. It contains 15 lines of code and it has a cyclomatic complexity of 4. It takes 5 parameters, represented as [182.0] and does not return any value..
pytorch_ao
public
public
0
0
_test_constructor_on_device
def _test_constructor_on_device(self, model, device):self.assertRaisesRegex(TypeError,"BaseStructuredSparsifier.*update_mask",BaseStructuredSparsifier,)model1 = copy.deepcopy(model).to(device)pruner = SimplePruner(None)pruner.prepare(model1, None)pruner.enable_mask_update = Truefor g in pruner.groups:module = g["module...
2
22
3
170
0
198
220
198
null
[]
None
null
0
0
0
null
0
null
The function (_test_constructor_on_device) defined within the public class called public.The function start at line 198 and ends at 220. It contains 22 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
test_constructor
def test_constructor(self):model = SimpleLinear()for device in DEVICES:self._test_constructor_on_device(model, torch.device(device))
2
4
1
28
0
222
225
222
null
[]
None
null
0
0
0
null
0
null
The function (test_constructor) defined within the public class called public.The function start at line 222 and ends at 225. 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
_test_prepare_linear_on_device
def _test_prepare_linear_on_device(self, model, device):model = copy.deepcopy(model).to(device)x = torch.ones(128, 7, device=device)pruner = SimplePruner(None)pruner.prepare(model, None)self._check_pruner_prepared(model, pruner, device)assert model(x).shape == (128, 10)
1
7
3
73
0
227
233
227
null
[]
None
null
0
0
0
null
0
null
The function (_test_prepare_linear_on_device) defined within the public class called public.The function start at line 227 and ends at 233. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [227.0] and does not return any value..
pytorch_ao
public
public
0
0
test_prepare_linear
def test_prepare_linear(self):models = [SimpleLinear(),LinearBias(),LinearActivation(),LinearActivationFunctional(),]# without and with biasfor device in DEVICES:for model in models:self._test_prepare_linear_on_device(model, torch.device(device))
3
10
1
48
0
235
244
235
null
[]
None
null
0
0
0
null
0
null
The function (test_prepare_linear) defined within the public class called public.The function start at line 235 and ends at 244. 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
_test_prepare_conv2d_on_device
def _test_prepare_conv2d_on_device(self, model, expected_shape, config, device):x = torch.ones((1, 1, 28, 28), device=device)pruner = SimplePruner(None)pruner.prepare(model, config)self._check_pruner_prepared(model, pruner, device)assert model(x).shape == expected_shape
1
6
5
66
0
246
251
246
null
[]
None
null
0
0
0
null
0
null
The function (_test_prepare_conv2d_on_device) defined within the public class called public.The function start at line 246 and ends at 251. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [246.0] and does not return any value..
pytorch_ao
public
public
0
0
test_prepare_conv2d
def test_prepare_conv2d(self):models = [SimpleConv2d(),Conv2dBias(),Conv2dActivation(),Conv2dPadBias(),Conv2dPool(),]shapes = [(1, 52, 20, 20),(1, 52, 18, 18),(1, 52, 18, 18),(1, 52, 24, 24),(1, 52, 3, 3),]configs = [None, None, None, None, None]for device in DEVICES:for model, shape, config in zip(models, shapes, conf...
3
22
1
142
0
253
274
253
null
[]
None
null
0
0
0
null
0
null
The function (test_prepare_conv2d) defined within the public class called public.The function start at line 253 and ends at 274. It contains 22 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
_test_step_linear_on_device
def _test_step_linear_on_device(self, model, device):model = model.to(device)pruner = SimplePruner(None)pruner.prepare(model, None)pruner.enable_mask_update = Trueself._check_pruner_valid_before_step(model, pruner, device)pruner.step()self._check_pruner_valid_after_step(model, pruner, 1, device)
1
8
3
63
0
276
283
276
null
[]
None
null
0
0
0
null
0
null
The function (_test_step_linear_on_device) defined within the public class called public.The function start at line 276 and ends at 283. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [276.0] and does not return any value..
pytorch_ao
public
public
0
0
test_step_linear
def test_step_linear(self):models = [SimpleLinear(),LinearBias(),LinearActivation(),LinearActivationFunctional(),]for device in DEVICES:for model in models:self._test_step_linear_on_device(model, torch.device(device))
3
10
1
48
0
285
294
285
null
[]
None
null
0
0
0
null
0
null
The function (test_step_linear) defined within the public class called public.The function start at line 285 and ends at 294. 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
_test_step_conv2d_on_device
def _test_step_conv2d_on_device(self, model, expected_shape, config, device):model = model.to(device)x = torch.ones((1, 1, 28, 28), device=device)pruner = SimplePruner(None)pruner.prepare(model, config)pruner.enable_mask_update = Trueself._check_pruner_valid_before_step(model, pruner, device)pruner.step()self._check_pr...
1
10
5
96
0
296
305
296
null
[]
None
null
0
0
0
null
0
null
The function (_test_step_conv2d_on_device) defined within the public class called public.The function start at line 296 and ends at 305. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [296.0] and does not return any value..
pytorch_ao
public
public
0
0
test_step_conv2d
def test_step_conv2d(self):models = [SimpleConv2d(),Conv2dBias(),Conv2dActivation(),Conv2dPadBias(),Conv2dPool(),]shapes = [(1, 52, 20, 20),(1, 52, 18, 18),(1, 52, 18, 18),(1, 52, 24, 24),(1, 52, 3, 3),]configs = [None, None, None, None, None]for device in DEVICES:for model, shape, config in zip(models, shapes, configs...
3
21
1
134
0
308
328
308
null
[]
None
null
0
0
0
null
0
null
The function (test_step_conv2d) defined within the public class called public.The function start at line 308 and ends at 328. It contains 21 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
_check_pruner_pruned
def _check_pruner_pruned(self, model, pruner, device):for config in pruner.groups:module = config["module"]assert not hasattr(module, "parametrizations")assert not hasattr(module, "mask")
2
5
4
40
0
330
334
330
null
[]
None
null
0
0
0
null
0
null
The function (_check_pruner_pruned) defined within the public class called public.The function start at line 330 and ends at 334. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [330.0] and does not return any value..
pytorch_ao
public
public
0
0
_test_linear_on_device
def _test_linear_on_device(self, model, config, expected_shape, device, also_prune_bias):model = model.to(device)model.eval()num_original_params = sum(p.numel() for p in model.parameters())x = torch.ones(128, 7, device=device)pruner = ImplementedPruner({"prune_bias": also_prune_bias})pruner.prepare(model, config)pruner...
4
22
6
199
0
336
363
336
null
[]
None
null
0
0
0
null
0
null
The function (_test_linear_on_device) defined within the public class called public.The function start at line 336 and ends at 363. It contains 22 lines of code and it has a cyclomatic complexity of 4. It takes 6 parameters, represented as [336.0] and does not return any value..
pytorch_ao
public
public
0
0
test_prune_linear_linear
def test_prune_linear_linear(self):r"""test pruning linear-> linear modules"""configs, shapes = [], []configs.append([{"tensor_fqn": "seq.0.weight"},{"tensor_fqn": "seq.1.weight"},{"tensor_fqn": "seq.2.weight"},])shapes.append((128, 10))configs.append([{"tensor_fqn": "seq.0.weight"},{"tensor_fqn": "seq.1.weight"},{"ten...
4
36
1
169
0
365
403
365
null
[]
None
null
0
0
0
null
0
null
The function (test_prune_linear_linear) defined within the public class called public.The function start at line 365 and ends at 403. It contains 36 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
test_prune_linear_bias_linear
def test_prune_linear_bias_linear(self):# linear(bias) -> linear(no bias)configs, shapes = [], []configs.append([{"tensor_fqn": "seq.0.weight"},{"tensor_fqn": "seq.1.weight"},])shapes.append((128, 10))# linear(bias) -> linear(bias)configs.append([{"tensor_fqn": "seq.2.weight"},{"tensor_fqn": "seq.3.weight"},])shapes.ap...
4
34
1
155
0
405
444
405
null
[]
None
null
0
0
0
null
0
null
The function (test_prune_linear_bias_linear) defined within the public class called public.The function start at line 405 and ends at 444. It contains 34 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
test_prune_linear_activation_linear
def test_prune_linear_activation_linear(self):config = [{"tensor_fqn": "seq.0.weight"},{"tensor_fqn": "seq.2.weight"},{"tensor_fqn": "seq.4.weight"},{"tensor_fqn": "linear1.weight"},]shape = (128, 10)for device in DEVICES:for also_prune_bias in [True, False]:# test version with nn.Modulesself._test_linear_on_device(Lin...
3
24
1
98
0
446
472
446
null
[]
None
null
0
0
0
null
0
null
The function (test_prune_linear_activation_linear) defined within the public class called public.The function start at line 446 and ends at 472. It contains 24 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
_test_conv2d_on_device
def _test_conv2d_on_device(self, model, config, x, expected_shape, device, also_prune_bias):model = model.to(device)num_original_params = sum(p.numel() for p in model.parameters())model.eval()pruner = ImplementedPruner({"prune_bias": also_prune_bias})pruner.prepare(model, config)pruner.enable_mask_update = Truepruner.s...
4
26
7
187
0
474
507
474
null
[]
None
null
0
0
0
null
0
null
The function (_test_conv2d_on_device) defined within the public class called public.The function start at line 474 and ends at 507. It contains 26 lines of code and it has a cyclomatic complexity of 4. It takes 7 parameters, represented as [474.0] and does not return any value..
pytorch_ao
public
public
0
0
test_prune_conv2d_conv2d
def test_prune_conv2d_conv2d(self):configs, shapes = [], []# all within sequential blocksconfigs.append([{"tensor_fqn": "seq.0.weight"},])shapes.append((1, 52, 20, 20))# prune across sequential blocksconfigs.append([{"tensor_fqn": "seq.0.weight"},{"tensor_fqn": "seq.1.weight"},{"tensor_fqn": "conv2d1.weight"},])shapes....
4
28
1
150
0
509
539
509
null
[]
None
null
0
0
0
null
0
null
The function (test_prune_conv2d_conv2d) defined within the public class called public.The function start at line 509 and ends at 539. It contains 28 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
test_prune_conv2d_bias_conv2d
def test_prune_conv2d_bias_conv2d(self):# Conv2d with Bias and no Activationconfigs, shapes = [], []# conv2d(bias) -> conv2d(bias)configs.append([{"tensor_fqn": "seq.0.weight"},{"tensor_fqn": "seq.1.weight"},])shapes.append((1, 52, 18, 18))# conv2d(no bias) -> conv2d(bias)configs.append([{"tensor_fqn": "seq.0.weight"},...
4
37
1
195
0
541
584
541
null
[]
None
null
0
0
0
null
0
null
The function (test_prune_conv2d_bias_conv2d) defined within the public class called public.The function start at line 541 and ends at 584. It contains 37 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
test_prune_conv2d_activation_conv2d
def test_prune_conv2d_activation_conv2d(self):# Conv2d with Activation and no Biasconfigs, shapes = [], []# conv2d(no bias) -> activation -> conv2d(no bias)configs.append([{"tensor_fqn": "seq.4.weight"},])shapes.append((1, 52, 18, 18))# conv2d(bias) -> activation -> conv2d(bias)configs.append([{"tensor_fqn": "seq.0.wei...
4
40
1
204
0
586
635
586
null
[]
None
null
0
0
0
null
0
null
The function (test_prune_conv2d_activation_conv2d) defined within the public class called public.The function start at line 586 and ends at 635. It contains 40 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
test_prune_conv2d_padding_conv2d
def test_prune_conv2d_padding_conv2d(self):# Conv2d with Padded layers after Bias layersconfigs, shapes = [], []# conv(padded, bias) -> conv(padded, bias)configs.append([{"tensor_fqn": "seq.4.weight"},])shapes.append((1, 52, 24, 24))# conv(no bias, no pad) -> conv(padded, bias)configs.append([{"tensor_fqn": "seq.2.weig...
4
44
1
219
0
637
690
637
null
[]
None
null
0
0
0
null
0
null
The function (test_prune_conv2d_padding_conv2d) defined within the public class called public.The function start at line 637 and ends at 690. It contains 44 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
test_prune_conv2d_pool_conv2d
def test_prune_conv2d_pool_conv2d(self):# Conv2d with Pooling layersconfig = [{"tensor_fqn": "seq.0.weight"},{"tensor_fqn": "seq.3.weight"},{"tensor_fqn": "conv2d1.weight"},{"tensor_fqn": "conv2d2.weight"},]shape = (1, 52, 3, 3)for device in DEVICES:x = torch.ones((1, 1, 28, 28), device=device)for also_prune_bias in [T...
3
19
1
102
0
692
712
692
null
[]
None
null
0
0
0
null
0
null
The function (test_prune_conv2d_pool_conv2d) defined within the public class called public.The function start at line 692 and ends at 712. It contains 19 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
test_complex_conv2d
def test_complex_conv2d(self):"""Test fusion for models that contain Conv2d & Linear modules.Currently supports: Conv2d-Pool2d-Flatten-Linear, Skip-add"""config = [{"tensor_fqn": "seq.0.weight"},{"tensor_fqn": "seq.3.weight"},{"tensor_fqn": "conv2d1.weight"},{"tensor_fqn": "conv2d2.weight"},]shape = (1, 13)for device i...
3
27
1
123
0
715
744
715
null
[]
None
null
0
0
0
null
0
null
The function (test_complex_conv2d) defined within the public class called public.The function start at line 715 and ends at 744. It contains 27 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
test_prune_lstm_linear_multiple_layer
def test_prune_lstm_linear_multiple_layer(self):"""Test fusion support for LSTM(multi-layer) -> Linear"""model = LSTMLinearModel(input_dim=8,hidden_dim=8,output_dim=8,num_layers=2,)config = [{"tensor_fqn": "lstm.weight_ih_l0"},{"tensor_fqn": "lstm.weight_hh_l0"},{"tensor_fqn": "lstm.weight_ih_l1"},{"tensor_fqn": "lstm....
2
29
1
177
0
746
787
746
null
[]
None
null
0
0
0
null
0
null
The function (test_prune_lstm_linear_multiple_layer) defined within the public class called public.The function start at line 746 and ends at 787. It contains 29 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..