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
teardown_method
def teardown_method(self, method):"""Clean up after each test method."""torch.cuda.empty_cache()import gcgc.collect()
1
4
2
22
0
131
136
131
null
[]
None
null
0
0
0
null
0
null
The function (teardown_method) defined within the public class called public.The function start at line 131 and ends at 136. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [131.0] and does not return any value..
pytorch_ao
public
public
0
0
set_seed
def set_seed(seed):"""Set random seeds for reproducibility."""random.seed(seed)np.random.seed(seed)torch.manual_seed(seed)torch.cuda.manual_seed_all(seed)
1
5
1
34
0
139
144
139
null
[]
None
null
0
0
0
null
0
null
The function (set_seed) defined within the public class called public.The function start at line 139 and ends at 144. It contains 5 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
quantize_and_save_model
def quantize_and_save_model(self,model_name: str,quantization_config: TorchAoConfig,output_dir: Path,):"""Quantize a model and save it to disk."""# Load and quantize modelquantized_model = AutoModelForCausalLM.from_pretrained(model_name,dtype="bfloat16",device_map="cuda",quantization_config=quantization_config,)tokeniz...
1
18
4
75
0
146
169
146
null
[]
None
null
0
0
0
null
0
null
The function (quantize_and_save_model) defined within the public class called public.The function start at line 146 and ends at 169. It contains 18 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [146.0] and does not return any value..
pytorch_ao
public
public
0
0
cleanup_model_directory
def cleanup_model_directory(self, model_path: Path):"""Clean up the model directory safely."""try:if model_path.exists() and model_path.is_dir():shutil.rmtree(model_path)except (OSError, PermissionError) as e:# Log the error but don't fail the testprint(f"Warning: Failed to clean up {model_path}: {e}")
4
6
2
45
0
171
178
171
null
[]
None
null
0
0
0
null
0
null
The function (cleanup_model_directory) defined within the public class called public.The function start at line 171 and ends at 178. It contains 6 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [171.0] and does not return any value..
pytorch_ao
public
public
0
0
test_vllm_smoke_test
def test_vllm_smoke_test(self, tmp_path, quantization_config, compile, tp_size):"""Test vLLM generation with quantized models."""# Skip per_row tests if not supportedtorch._dynamo.reset()# Use a small model for testingbase_model = "facebook/opt-125m"# Create a descriptive name for the output directoryconfig_name = str(...
5
42
5
229
0
189
255
189
null
[]
None
null
0
0
0
null
0
null
The function (test_vllm_smoke_test) defined within the public class called public.The function start at line 189 and ends at 255. It contains 42 lines of code and it has a cyclomatic complexity of 5. It takes 5 parameters, represented as [189.0] and does not return any value..
pytorch_ao
public
public
0
0
setUp
def setUp(self):os.environ["TORCHAO_AUTOTUNER_ENABLE"] = "1"
1
2
1
13
0
22
23
22
null
[]
None
null
0
0
0
null
0
null
The function (setUp) defined within the public class called public.The function start at line 22 and ends at 23. 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
tearDown
def tearDown(self):del os.environ["TORCHAO_AUTOTUNER_ENABLE"]
1
2
1
12
0
25
26
25
null
[]
None
null
0
0
0
null
0
null
The function (tearDown) defined within the public class called public.The function start at line 25 and ends at 26. 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_int_mm
def test_int_mm(self, device, dtype):from torchao.kernel import intmmdtype = torch.bfloat16m, k, n = (128, 64, 16)x = torch.randn(m, k, dtype=dtype, device=device)w = torch.randn(n, k, dtype=dtype, device=device).t()x_int = x.to(dtype=torch.int8)w_int = w.to(dtype=torch.int8)out32_1 = intmm.safe_int_mm(x_int, w_int)ass...
1
13
3
143
0
37
50
37
null
[]
None
null
0
0
0
null
0
null
The function (test_int_mm) defined within the public class called public.The function start at line 37 and ends at 50. It contains 13 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [37.0] and does not return any value..
pytorch_ao
public
public
0
0
test_int_mm_float8
def test_int_mm_float8(self, device, dtype):from torchao.kernel import intmmdtype = torch.bfloat16m, k, n = (128, 64, 16)x = torch.randn(m, k, dtype=dtype, device=device)w = torch.randn(n, k, dtype=dtype, device=device).t()x_float8 = x.to(dtype=torch.float8_e4m3fn)w_float8 = w.to(dtype=torch.float8_e4m3fn)out32_1 = int...
1
10
3
115
0
59
69
59
null
[]
None
null
0
0
0
null
0
null
The function (test_int_mm_float8) defined within the public class called public.The function start at line 59 and ends at 69. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [59.0] and does not return any value..
pytorch_ao
public
public
0
0
test_int_scaled_mm
def test_int_scaled_mm(self, device, dtype):if device == "cuda" and not torch.cuda.is_available():self.skipTest(f"{device} not available")from torchao.kernel import intmmdtype = torch.bfloat16m, k, n = (128, 64, 16)x = torch.randn(m, k, dtype=dtype, device=device)scales = x.sum(-1, keepdim=True)w = torch.randn(n, k, dt...
3
16
3
181
0
79
96
79
null
[]
None
null
0
0
0
null
0
null
The function (test_int_scaled_mm) defined within the public class called public.The function start at line 79 and ends at 96. It contains 16 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [79.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, in_features=64, out_features=128):super().__init__()self.linear1 = torch.nn.Linear(in_features, out_features)self.linear2 = torch.nn.Linear(in_features, out_features)
1
4
3
48
0
34
37
34
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 34 and ends at 37. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [34.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, x, y):x = self.linear1(x)y = self.linear2(y)return x + y
1
4
3
29
0
39
42
39
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 39 and ends at 42. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [39.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self):super().__init__()self.two_linear1 = TwoLinear()self.two_linear2 = TwoLinear(128, 256)
1
4
1
29
0
46
49
46
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 46 and ends at 49. It contains 4 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
forward
def forward(self, x, y):x1 = self.two_linear1(x, y)x2 = self.two_linear2(x1, x1)return x2
1
4
3
31
0
51
54
51
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 51 and ends at 54. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [51.0] and does not return any value..
pytorch_ao
public
public
0
0
_is_two_linear
def _is_two_linear(mod, fqn):return isinstance(mod, TwoLinear)
1
2
2
14
0
57
58
57
null
[]
None
null
0
0
0
null
0
null
The function (_is_two_linear) 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. It takes 2 parameters, represented as [57.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, DIM=128):super().__init__()self.lin = torch.nn.Linear(DIM, DIM)self.register_buffer("other", torch.zeros(DIM, DIM))
1
4
2
45
0
62
65
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 65. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [62.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, x, y):x = self.linear1(x)y = self.linear2(y)return x + y
1
4
3
29
0
67
71
39
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 67 and ends at 71. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [39.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, DIM=128):super().__init__()self.m1 = ModelWithInplaceOp(DIM)self.m2 = ModelWithInplaceOp(DIM)
1
4
2
32
0
75
78
75
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 75 and ends at 78. It contains 4 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
forward
def forward(self, x, y):x1 = self.two_linear1(x, y)x2 = self.two_linear2(x1, x1)return x2
1
4
3
31
0
80
83
51
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 80 and ends at 83. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [51.0] and does not return any value..
pytorch_ao
public
public
0
0
_check_params_and_buffers_type
def _check_params_and_buffers_type(module, check_fun):return [check_fun(p) for p in module.parameters()] + [check_fun(b) for b in module.buffers()]
3
4
2
37
0
86
89
86
null
[]
None
null
0
0
0
null
0
null
The function (_check_params_and_buffers_type) defined within the public class called public.The function start at line 86 and ends at 89. It contains 4 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
test_auto_round
def test_auto_round(self, device: str):example_inputs = (torch.randn(32, 64).to(device),torch.randn(32, 64).to(device),)m = M().eval().to(device)m(*example_inputs)prepare_model_for_applying_auto_round_(m,is_target_module=_is_two_linear,bits=7,group_size=32,iters=20,device=device,)assert all(_check_params_and_buffers_ty...
4
36
2
266
0
96
132
96
null
[]
None
null
0
0
0
null
0
null
The function (test_auto_round) defined within the public class called public.The function start at line 96 and ends at 132. It contains 36 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [96.0] and does not return any value..
pytorch_ao
public
public
0
0
test_wrap_model_with_multi_tensor
def test_wrap_model_with_multi_tensor(self, device: str):_is_model_with_inplace_op = lambda mod, fqn: isinstance(mod, ModelWithInplaceOp)DIM = 128m = M2(DIM).eval().to(device)prepare_model_for_applying_auto_round_(m,is_target_module=_is_model_with_inplace_op,bits=7,group_size=32,iters=20,device=device,)assert all(_chec...
4
33
2
264
0
137
171
137
null
[]
None
null
0
0
0
null
0
null
The function (test_wrap_model_with_multi_tensor) defined within the public class called public.The function start at line 137 and ends at 171. It contains 33 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [137.0] 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
23
27
23
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 23 and ends at 27. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [23.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"):return [torch.randn(1, sequence_length, self.linear1.in_features, dtype=dtype, device=device)for j in range(batch_size)]
2
9
5
53
0
29
37
29
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 29 and ends at 37. It contains 9 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [29.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
39
43
39
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 39 and ends at 43. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [39.0] and does not return any value..
pytorch_ao
public
public
0
0
test_awq_config
def test_awq_config(self):base_config = Int4WeightOnlyConfig()AWQConfig(base_config, step=AWQStep.PREPARE)AWQConfig(base_config, step=AWQStep.PREPARE_FOR_LOADING)AWQConfig(base_config, step=AWQStep.CONVERT)AWQConfig(base_config, step="prepare")AWQConfig(base_config, step="prepare_for_loading")AWQConfig(base_config, ste...
1
10
1
82
0
71
82
71
null
[]
None
null
0
0
0
null
0
null
The function (test_awq_config) defined within the public class called public.The function start at line 71 and ends at 82. 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_awq_functionality
def test_awq_functionality(self, device):dataset_size = 10l1, l2, l3 = 512, 256, 128original_dtype = torch.bfloat16# tinygemm kernel only uses bfloat16 inputssequence_length = 5assert device in device_to_base_configs, "Unsupported device: {}".format(device)base_configs = device_to_base_configs[device]for base_config in...
3
31
2
233
0
85
132
85
null
[]
None
null
0
0
0
null
0
null
The function (test_awq_functionality) defined within the public class called public.The function start at line 85 and ends at 132. It contains 31 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [85.0] and does not return any value..
pytorch_ao
public
public
0
0
test_awq_loading
def test_awq_loading(self, device):dataset_size = 10l1, l2, l3 = 512, 256, 128original_dtype = torch.bfloat16# tinygemm kernel only uses bfloat16 inputssequence_length = 5assert device in device_to_base_configs, "Unsupported device: {}".format(device)base_configs = device_to_base_configs[device]for base_config in base_...
3
38
2
289
0
135
187
135
null
[]
None
null
0
0
0
null
0
null
The function (test_awq_loading) defined within the public class called public.The function start at line 135 and ends at 187. It contains 38 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [135.0] and does not return any value..
pytorch_ao
public
public
0
0
test_awq_loading_vllm
def test_awq_loading_vllm(self, device):"""Simulate weight loading in vllm:* prepare model weight to the same format (awq weight)* use weight.copy_(state_dict["weight"]) to copy over the quantized weights from checkpointThere is also a slicing op that is ommitted here, overall e2e is tested in tests in vllm repo"""data...
3
42
2
337
0
190
252
190
null
[]
None
null
0
0
0
null
0
null
The function (test_awq_loading_vllm) defined within the public class called public.The function start at line 190 and ends at 252. It contains 42 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [190.0] and does not return any value..
pytorch_ao
public
public
0
0
test_blockwise_quant_dequant
def test_blockwise_quant_dequant(_, N, K, dtype):x = torch.randn(N, K).cuda()qx, s = fp8_blockwise_weight_quant(x, dtype=dtype)x_reconstructed = fp8_blockwise_weight_dequant(qx, s)error = torch.linalg.vector_norm(x - x_reconstructed) / torch.linalg.vector_norm(x)print(f"Relative Error: {error.item():.6f}")assert error ...
1
7
4
79
3
40
47
40
null
['x', 'error', 'x_reconstructed']
None
null
0
0
0
null
0
null
The function (test_blockwise_quant_dequant) defined within the public class called public.The function start at line 40 and ends at 47. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [40.0] and does not return any value..
pytorch_ao
public
public
0
0
test_blockwise_fp8_gemm
def test_blockwise_fp8_gemm(M, N, K, dtype):A = torch.randn(M, K).cuda()B = torch.randn(N, K).cuda()C = A @ B.TA_q, A_s = fp8_blockwise_act_quant(A, dtype=dtype)B_q, B_s = fp8_blockwise_weight_quant(B, dtype=dtype)C_q = blockwise_fp8_gemm(A_q, A_s, B_q, B_s)error = torch.linalg.vector_norm(C - C_q) / torch.linalg.vecto...
1
10
4
116
5
62
72
62
null
['B', 'C', 'C_q', 'A', 'error']
None
null
0
0
0
null
0
null
The function (test_blockwise_fp8_gemm) defined within the public class called public.The function start at line 62 and ends at 72. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [62.0] and does not return any value..
pytorch_ao
public
public
0
0
setUp
def setUp(self):torch.manual_seed(123)self.input = torch.randn(100, 256, dtype=torch.float32)self.code_dtype = torch.uint8self.block_size = [-1, 4]self.nbits = 8
1
6
1
51
0
24
29
24
null
[]
None
null
0
0
0
null
0
null
The function (setUp) defined within the public class called public.The function start at line 24 and ends at 29. 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
test_choose_qparams_codebook
def test_choose_qparams_codebook(self):codebook, wq = choose_qparams_and_quantize_codebook_coreml(self.input,self.code_dtype,self.block_size,)group_size = self.block_size[-1]self.assertEqual(codebook.shape, (1, 256 // group_size, 2**self.nbits, 1))self.assertEqual(wq.shape, (100, 256))self.assertFalse(torch.isnan(codeb...
1
11
1
90
0
31
42
31
null
[]
None
null
0
0
0
null
0
null
The function (test_choose_qparams_codebook) defined within the public class called public.The function start at line 31 and ends at 42. It contains 11 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_codebook_quantized_tensor_from_float
def test_codebook_quantized_tensor_from_float(self):cqt = CodebookQuantizedTensor.from_float(self.input,self.code_dtype,self.block_size,)dequant = cqt.dequantize()sqnr = compute_error(dequant, self.input)self.assertGreater(sqnr, 30)
1
9
1
49
0
44
53
44
null
[]
None
null
0
0
0
null
0
null
The function (test_codebook_quantized_tensor_from_float) defined within the public class called public.The function start at line 44 and ends at 53. 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
test_codebook_quantized_tensor_from_float2
def test_codebook_quantized_tensor_from_float2(self):block_size = [-1, 16]code_dtype = torch.uint4cqt = CodebookQuantizedTensor.from_float(self.input,code_dtype,block_size,)dequant = cqt.dequantize()sqnr = compute_error(dequant, self.input)self.assertGreater(sqnr, 18)
1
11
1
58
0
55
68
55
null
[]
None
null
0
0
0
null
0
null
The function (test_codebook_quantized_tensor_from_float2) defined within the public class called public.The function start at line 55 and ends at 68. It contains 11 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_quantize_api
def test_quantize_api(self):m = torch.nn.Sequential(torch.nn.Linear(64, 64))quantize_(m,CodebookWeightOnlyConfig(dtype=self.code_dtype, block_size=self.block_size),)assert type(m[0].weight) == CodebookQuantizedTensor
1
7
1
56
0
70
76
70
null
[]
None
null
0
0
0
null
0
null
The function (test_quantize_api) defined within the public class called public.The function start at line 70 and ends at 76. 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_choose_qparams_codebook_row_grouping
def test_choose_qparams_codebook_row_grouping(self):# Test with a block_size that forces row-wise grouping: [10, 256]# Input tensor is (100, 256)row_grouped_block_size = [10, -1]num_row_groups = (self.input.shape[0] // row_grouped_block_size[0])# 100 // 10 = 10codebook, wq = choose_qparams_and_quantize_codebook_coreml(...
1
14
1
109
0
78
97
78
null
[]
None
null
0
0
0
null
0
null
The function (test_choose_qparams_codebook_row_grouping) defined within the public class called public.The function start at line 78 and ends at 97. It contains 14 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_codebook_quantized_tensor_from_float_row_grouping
def test_codebook_quantized_tensor_from_float_row_grouping(self):# Test end-to-end quantization/dequantization with row groupingrow_grouped_block_size = [20, -1]# 100 is divisible by 20cqt = CodebookQuantizedTensor.from_float(self.input,self.code_dtype,row_grouped_block_size,)dequant = cqt.dequantize()# The SQNR will b...
1
10
1
55
0
99
111
99
null
[]
None
null
0
0
0
null
0
null
The function (test_codebook_quantized_tensor_from_float_row_grouping) defined within the public class called public.The function start at line 99 and ends at 111. 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_export
def test_export(self):m = torch.nn.Sequential(torch.nn.Linear(128, 64)).to(torch.float32)quantize_(m, CodebookWeightOnlyConfig(self.code_dtype, self.block_size))example_inputs = (torch.randn(1, 128, dtype=torch.float32),)m = torch.export.export(m, example_inputs).module()targets = [n.target for n in m.graph.nodes]self....
2
7
1
112
0
113
119
113
null
[]
None
null
0
0
0
null
0
null
The function (test_export) defined within the public class called public.The function start at line 113 and ends at 119. 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
setUp
def setUp(self):torch.manual_seed(123)self.input = torch.randn(100, 256, dtype=torch.float32)self.block_size = (1, 1)self.scale_block_size = 64self.code_dtype = torch.uint8self.chunk_size = 1024
1
7
1
55
0
20
26
20
null
[]
None
null
0
0
0
null
0
null
The function (setUp) defined within the public class called public.The function start at line 20 and ends at 26. 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_choose_qparams_codebook
def test_choose_qparams_codebook(self):codebook, scales = choose_qparams_codebook(self.input,block_size=self.block_size,scale_block_size=self.scale_block_size,code_dtype=self.code_dtype,)self.assertEqual(codebook.dim(), len(self.block_size) + 1)self.assertFalse(torch.isnan(codebook).any())self.assertFalse(torch.isnan(s...
1
10
1
83
0
28
38
28
null
[]
None
null
0
0
0
null
0
null
The function (test_choose_qparams_codebook) defined within the public class called public.The function start at line 28 and ends at 38. 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_codebook_quantized_tensor_from_float
def test_codebook_quantized_tensor_from_float(self):cqt = CodebookQuantizedTensor.from_float(self.input,block_size=self.block_size,code_dtype=self.code_dtype,scale_block_size=self.scale_block_size,chunk_size=self.chunk_size,)dequant = cqt.dequantize()sqnr = compute_error(dequant, self.input)self.assertGreater(sqnr, 30)
1
11
1
65
0
40
52
40
null
[]
None
null
0
0
0
null
0
null
The function (test_codebook_quantized_tensor_from_float) defined within the public class called public.The function start at line 40 and ends at 52. It contains 11 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_codebook_quantized_tensor_from_float2
def test_codebook_quantized_tensor_from_float2(self):block_size = (1, 16)code_dtype = torch.int32scale_block_size = self.input.shape[1]cqt = CodebookQuantizedTensor.from_float(self.input,block_size=block_size,code_dtype=code_dtype,scale_block_size=scale_block_size,chunk_size=self.chunk_size,)dequant = cqt.dequantize()s...
1
14
1
81
0
54
70
54
null
[]
None
null
0
0
0
null
0
null
The function (test_codebook_quantized_tensor_from_float2) defined within the public class called public.The function start at line 54 and ends at 70. It contains 14 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_quantize_api
def test_quantize_api(self):m = torch.nn.Sequential(torch.nn.Linear(64, 64))quantize_(m, codebook_weight_only())assert type(m[0].weight) == CodebookQuantizedTensor
1
4
1
44
0
72
75
72
null
[]
None
null
0
0
0
null
0
null
The function (test_quantize_api) defined within the public class called public.The function start at line 72 and ends at 75. It contains 4 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_accuracy
def test_accuracy(self):granularity = PerGroup(128)embedding_dim = 4096num_embeddings = 131model = torch.nn.Sequential(*[torch.nn.Embedding(num_embeddings, embedding_dim)])indices = torch.randint(0, num_embeddings, (7,), dtype=torch.int32)for weight_dtype, granularity, mapping_type in zip(list(getattr(torch, f"int{x}")...
3
36
1
224
0
40
77
40
null
[]
None
null
0
0
0
null
0
null
The function (test_accuracy) defined within the public class called public.The function start at line 40 and ends at 77. It contains 36 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_export_compile_aoti
def test_export_compile_aoti(self):weight_dtype = torch.int4granularity = PerAxis(0)weight_mapping_type = MappingType.ASYMMETRICembedding_dim = 4096num_embeddings = 131model = torch.nn.Sequential(*[torch.nn.Embedding(num_embeddings, embedding_dim)])indices = torch.randint(0, num_embeddings, (42,), dtype=torch.int32)pri...
1
41
1
262
0
79
123
79
null
[]
None
null
0
0
0
null
0
null
The function (test_export_compile_aoti) defined within the public class called public.The function start at line 79 and ends at 123. It contains 41 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_shared_embedding
def test_shared_embedding(self):weight_dtype = torch.int4weight_mapping_type = MappingType.ASYMMETRICembedding_dim = 4096num_embeddings = 131embedding = torch.nn.Embedding(num_embeddings, embedding_dim)unembedding = torch.nn.Linear(embedding_dim, num_embeddings)unembedding.weight = copy.deepcopy(embedding.weight)model ...
2
57
1
336
0
125
192
125
null
[]
None
null
0
0
0
null
0
null
The function (test_shared_embedding) defined within the public class called public.The function start at line 125 and ends at 192. It contains 57 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_identical_to_IntxWeightOnlyConfig
def test_identical_to_IntxWeightOnlyConfig(self, weight_dtype, granularity, mapping_type, model_dtype):embedding_dim = 4096num_embeddings = 131model = torch.nn.Sequential(*[torch.nn.Embedding(num_embeddings, embedding_dim)])model = model.to(model_dtype)indices = torch.randint(0, num_embeddings, (7,), dtype=torch.int32)...
1
31
5
177
0
209
241
209
null
[]
None
null
0
0
0
null
0
null
The function (test_identical_to_IntxWeightOnlyConfig) defined within the public class called public.The function start at line 209 and ends at 241. It contains 31 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [209.0] and does not return any value..
pytorch_ao
public
public
0
0
test_identical_to_IntXQuantizationAwareTrainingConfig
def test_identical_to_IntXQuantizationAwareTrainingConfig(self, weight_dtype, granularity, mapping_type, scale_dtype, model_dtype):# ASYMMETRIC in QAT is very different that PTQ configsif mapping_type == MappingType.ASYMMETRIC:returnembedding_dim = 4096num_embeddings = 131model = torch.nn.Sequential(*[torch.nn.Embeddin...
4
47
6
234
0
260
314
260
null
[]
None
null
0
0
0
null
0
null
The function (test_identical_to_IntXQuantizationAwareTrainingConfig) defined within the public class called public.The function start at line 260 and ends at 314. It contains 47 lines of code and it has a cyclomatic complexity of 4. It takes 6 parameters, represented as [260.0] and does not return any value..
pytorch_ao
public
public
0
0
test_identical_to_Int4WeightOnlyEmbeddingQATQuantizer
def test_identical_to_Int4WeightOnlyEmbeddingQATQuantizer(self, granularity, scale_dtype, model_dtype):embedding_dim = 4096num_embeddings = 131model = torch.nn.Sequential(*[torch.nn.Embedding(num_embeddings, embedding_dim)])model = model.to(model_dtype)indices = torch.randint(0, num_embeddings, (7,), dtype=torch.int32)...
2
42
4
247
0
329
377
329
null
[]
None
null
0
0
0
null
0
null
The function (test_identical_to_Int4WeightOnlyEmbeddingQATQuantizer) defined within the public class called public.The function start at line 329 and ends at 377. It contains 42 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [329.0] and does not return any value..
pytorch_ao
public
public
0
0
setUp
def setUp(self):torch.manual_seed(123)self.input = torch.randn(2, 256, dtype=torch.float32)self.n_blocks_per_superblock = 8self.block_size = (1, 32)self.dtype = torch.uint4
1
6
1
50
0
21
26
21
null
[]
None
null
0
0
0
null
0
null
The function (setUp) defined within the public class called public.The function start at line 21 and ends at 26. 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
test_choose_qparams_gguf
def test_choose_qparams_gguf(self):(super_block_scale_scale,super_block_min_scale,quantized_block_scale,quantized_block_min,) = _choose_qparams_gguf(self.input, self.block_size, self.dtype)assert super_block_scale_scale.shape, (2, 8)assert super_block_min_scale.shape, (2, 8)assert quantized_block_scale.shape, (2, 32)
1
10
1
60
0
28
38
28
null
[]
None
null
0
0
0
null
0
null
The function (test_choose_qparams_gguf) defined within the public class called public.The function start at line 28 and ends at 38. 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_gguf_quantized_tensor_from_float
def test_gguf_quantized_tensor_from_float(self):gqt = GGUFQuantizedTensor.from_float(self.input,self.n_blocks_per_superblock,self.dtype,)dequant = gqt.dequantize()sqnr = compute_error(dequant, self.input)self.assertGreater(sqnr, 30)
1
9
1
49
0
40
50
40
null
[]
None
null
0
0
0
null
0
null
The function (test_gguf_quantized_tensor_from_float) defined within the public class called public.The function start at line 40 and ends at 50. 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
test_quantize_api
def test_quantize_api(self):m = torch.nn.Sequential(torch.nn.Linear(256, 64))quantize_(m, GGUFWeightOnlyConfig())assert type(m[0].weight) == GGUFQuantizedTensor
1
4
1
44
0
52
55
52
null
[]
None
null
0
0
0
null
0
null
The function (test_quantize_api) defined within the public class called public.The function start at line 52 and ends at 55. It contains 4 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_e2e_accuracy_vs_reference
def test_e2e_accuracy_vs_reference(self,code_dtype,lut_group_size,weight_dtype,has_bias,):"""Tests the numerical accuracy of the full quantized model against a reference.This now uses the `use_qdq_reference` flag instead of layout objects."""m, k, n = 3, 64, 32activations = torch.randn(m, k, dtype=weight_dtype)model = ...
1
36
5
203
0
52
98
52
null
[]
None
null
0
0
0
null
0
null
The function (test_e2e_accuracy_vs_reference) defined within the public class called public.The function start at line 52 and ends at 98. It contains 36 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [52.0] and does not return any value..
pytorch_ao
public
public
0
0
tearDown
def tearDown(self):"""Clear the TorchDynamo cache after each test case to preventrecompilation errors in parameterized tests."""super().tearDown()torch._dynamo.reset()
1
3
1
20
0
100
106
100
null
[]
None
null
0
0
0
null
0
null
The function (tearDown) defined within the public class called public.The function start at line 100 and ends at 106. 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_export_compile_aoti
def test_export_compile_aoti(self,code_dtype,lut_group_size,weight_dtype,has_bias,):"""Tests that the quantized model can be exported and compiled."""k, n = 64, 32activations = torch.randn(2, k, dtype=weight_dtype)model = (nn.Sequential(nn.Linear(k, n, bias=has_bias)).to(dtype=weight_dtype).eval())lut_block_shape = gro...
1
45
5
290
0
112
170
112
null
[]
None
null
0
0
0
null
0
null
The function (test_export_compile_aoti) defined within the public class called public.The function start at line 112 and ends at 170. It contains 45 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [112.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, d1=512, d2=256, d3=128, d4=8):super().__init__()self.linear1 = torch.nn.Linear(d1, d2, bias=False)self.linear2 = torch.nn.Linear(d2, d3, bias=True)self.linear3 = torch.nn.Linear(d3, d4, bias=False)
1
5
5
82
0
26
30
26
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 26 and ends at 30. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [26.0] and does not return any value..
pytorch_ao
public
public
0
0
example_inputs
def example_inputs(self,lead_dim=(1,),dtype=torch.bfloat16,):return torch.randn(*lead_dim, self.linear1.in_features, dtype=dtype, device="cpu")
1
8
2
41
0
32
39
32
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 32 and ends at 39. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [32.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
41
45
41
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 41 and ends at 45. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [41.0] and does not return any value..
pytorch_ao
public
public
0
0
run_before_and_after_tests
def run_before_and_after_tests():yieldtorch._dynamo.reset()# reset cache between tests
1
3
0
12
0
49
51
49
null
[]
None
null
0
0
0
null
0
null
The function (run_before_and_after_tests) defined within the public class called public.The function start at line 49 and ends at 51. 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_parq_conversion
def test_parq_conversion(dtype, granularity, bit_width, lead_dim):torch.manual_seed(0)quantizer = StretchedUnifTorchaoQuantizer(bit_width)config = StretchedIntxWeightConfig(b=bit_width,quant_min=quantizer.quant_min,quant_max=quantizer.quant_max,granularity=granularity,activation_quantization="int8_asym_per_token",)parq...
3
24
4
167
8
61
90
61
null
['config', 'parq_out', 'quantizer', 'activations', 'parq_model', 'sqnr', 'lut_model', 'lut_out']
None
null
0
0
0
null
0
null
The function (test_parq_conversion) defined within the public class called public.The function start at line 61 and ends at 90. It contains 24 lines of code and it has a cyclomatic complexity of 3. It takes 4 parameters, represented as [61.0] and does not return any value..
pytorch_ao
public
public
0
0
test_export
def test_export(dtype, granularity, bit_width, lead_dim):quantizer = StretchedUnifTorchaoQuantizer(bit_width)config = StretchedIntxWeightConfig(b=bit_width,quant_min=quantizer.quant_min,quant_max=quantizer.quant_max,granularity=granularity,activation_quantization="int8_asym_per_token",)parq_model = ToyLinearModel(128, ...
1
18
4
109
5
100
121
100
null
['config', 'quantizer', 'activations', 'parq_model', 'ep']
None
null
0
0
0
null
0
null
The function (test_export) defined within the public class called public.The function start at line 100 and ends at 121. It contains 18 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [100.0] and does not return any value..
pytorch_ao
public
public
0
0
test_quantization_intNwo
def test_quantization_intNwo(self):# skip test int4wo for now since it is under development in torchaofor quantization_bit in [2, 3, 5, 6]:for symmetric in [False, True]:with self.subTest(quantization_bit=quantization_bit, symmetric=symmetric):for x_shape in [[64, 32], [80, 80, 80, 32], [16, 64, 32]]:x = torch.randn(*x...
4
22
1
170
0
19
43
19
null
[]
None
null
0
0
0
null
0
null
The function (test_quantization_intNwo) defined within the public class called public.The function start at line 19 and ends at 43. It contains 22 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
__init__
def __init__(self, bias=True):super().__init__()self.linear = nn.Linear(16, 16, bias=bias)self.seq = nn.Sequential(nn.Linear(16, 16, bias=bias), nn.Linear(16, 16, bias=bias))# Make sure the weights are not randomself.linear.weight = nn.Parameter(torch.zeros_like(self.linear.weight) + 1.0)self.seq[0].weight = nn.Paramet...
2
13
2
237
0
22
36
22
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 22 and ends at 36. It contains 13 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [22.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, x):x = self.linear(x)x = self.seq(x)return x
1
4
2
25
0
38
41
38
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 38 and ends at 41. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [38.0] and does not return any value..
pytorch_ao
public
public
0
0
test_masking_logic
def test_masking_logic(self):model = nn.Linear(16, 16, bias=False)model.weight = nn.Parameter(torch.eye(16))x = torch.randn(3, 16)self.assertEqual(torch.mm(x, torch.eye(16)), model(x))mask = torch.zeros(16, 16)sparsity = utils.FakeSparsity(mask)parametrize.register_parametrization(model, "weight", sparsity)x = torch.ra...
1
10
1
123
0
45
56
45
null
[]
None
null
0
0
0
null
0
null
The function (test_masking_logic) defined within the public class called public.The function start at line 45 and ends at 56. 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_weights_parametrized
def test_weights_parametrized(self):model = ModelUnderTest(bias=False)assert not hasattr(model.linear, "parametrizations")assert not hasattr(model.seq[0], "parametrizations")assert not hasattr(model.seq[1], "parametrizations")mask = torch.eye(16)parametrize.register_parametrization(model.linear, "weight", utils.FakeSpa...
1
23
1
196
0
58
82
58
null
[]
None
null
0
0
0
null
0
null
The function (test_weights_parametrized) defined within the public class called public.The function start at line 58 and ends at 82. It contains 23 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_preserved
def test_state_dict_preserved(self):model_save = ModelUnderTest(bias=False)mask = torch.eye(16)parametrize.register_parametrization(model_save.linear, "weight", utils.FakeSparsity(mask))mask = torch.eye(16)parametrize.register_parametrization(model_save.seq[0], "weight", utils.FakeSparsity(mask))mask = torch.eye(16)par...
1
59
1
494
0
84
150
84
null
[]
None
null
0
0
0
null
0
null
The function (test_state_dict_preserved) defined within the public class called public.The function start at line 84 and ends at 150. It contains 59 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_jit_trace
def test_jit_trace(self):model = ModelUnderTest(bias=False)mask = torch.eye(16)parametrize.register_parametrization(model.linear, "weight", utils.FakeSparsity(mask))mask = torch.eye(16)parametrize.register_parametrization(model.seq[0], "weight", utils.FakeSparsity(mask))mask = torch.eye(16)parametrize.register_parametr...
1
20
1
150
0
152
175
152
null
[]
None
null
0
0
0
null
0
null
The function (test_jit_trace) defined within the public class called public.The function start at line 152 and ends at 175. It contains 20 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
__init__
def __init__(self):super().__init__()self.linear = torch.nn.Linear(256, 256, bias=False).to(torch.float32)
1
3
1
37
0
19
21
19
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 19 and ends at 21. 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
forward
def forward(self, x):return self.linear(x)
1
2
2
14
0
23
24
23
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 23 and ends at 24. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [23.0] and does not return any value..
pytorch_ao
public
public
0
0
test_quantized_linear
def test_quantized_linear(self):m = M()example_inputs = torch.randn(1, 256).to(torch.float32)for w_bits in [0, 1, 2, 3, 4, 16]:m.linear = QuantizeLinear(m.linear.in_features,m.linear.out_features,bias=False,w_bits=w_bits,)m(example_inputs)
2
11
1
75
0
28
38
28
null
[]
None
null
0
0
0
null
0
null
The function (test_quantized_linear) defined within the public class called public.The function start at line 28 and ends at 38. 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
test_quantize_functions
def test_quantize_functions(self):x = torch.randn(256, 256).to(torch.float32)alpha = torch.Tensor(256, 1)for layerwise in [True, False]:LsqBinaryTernaryExtension.apply(x, alpha, 1, layerwise)LsqBinaryTernaryExtension.apply(x, alpha, 3, layerwise)LsqBinaryTernaryExtension.apply(x, alpha, 4, layerwise)StretchedElasticQua...
2
9
1
101
0
40
48
40
null
[]
None
null
0
0
0
null
0
null
The function (test_quantize_functions) defined within the public class called public.The function start at line 40 and ends at 48. 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__
def __init__(self, m=256, n=128, k=16, bias=False, embedding=True, tied_weights=False):nn.Module.__init__(self)self.embed_tokens = nn.Embedding(k, m) if embedding else nn.Identity()self.linear1 = nn.Linear(m, n, bias=bias)self.linear2 = nn.Linear(n, k, bias=bias)self.relu = nn.ReLU()self.sigmoid = nn.Sigmoid()if embedd...
4
13
7
141
0
60
73
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 73. It contains 13 lines of code and it has a cyclomatic complexity of 4. It takes 7 parameters, represented as [60.0] and does not return any value..
pytorch_ao
public
public
0
0
tie_weights
def tie_weights(self):self.linear2.weight = self.embed_tokens.weight
1
2
1
16
0
75
76
75
null
[]
None
null
0
0
0
null
0
null
The function (tie_weights) 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. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
example_inputs
def example_inputs(self, device=None):if isinstance(self.embed_tokens, nn.Identity):inputs = torch.randn(1, self.linear1.in_features, device=device)else:k = self.embed_tokens.num_embeddingsinputs = torch.randint(1, k, (1, self.linear1.in_features), device=device)return inputs
2
7
2
74
0
78
84
78
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 78 and ends at 84. It contains 7 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [78.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, x):x = self.embed_tokens(x)x = self.relu(self.linear1(x))x = self.sigmoid(self.linear2(x))return x
1
5
2
43
0
86
90
86
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 86 and ends at 90. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [86.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,m=256,n=128,k=16,bias=False,embedding=True,tied_weights=False,**kwargs,):super().__init__(**kwargs)self.m = mself.n = nself.k = kself.bias = biasself.embedding = embeddingself.tied_weights = tied_weights
1
17
8
72
0
97
113
97
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 97 and ends at 113. It contains 17 lines of code and it has a cyclomatic complexity of 1. It takes 8 parameters, represented as [97.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, config: MConfig):PreTrainedModel.__init__(self, config)M.__init__(self,m=config.m,n=config.n,k=config.k,bias=config.bias,embedding=config.embedding,tied_weights=config.tied_weights,)
1
11
2
60
0
119
129
119
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 119 and ends at 129. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [119.0] and does not return any value..
pytorch_ao
public
public
0
0
get_input_embeddings
def get_input_embeddings(self) -> nn.Module:return self.embed_tokens
1
2
1
13
0
131
132
131
null
[]
None
null
0
0
0
null
0
null
The function (get_input_embeddings) defined within the public class called public.The function start at line 131 and ends at 132. 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
split_param_groups.get_param_groups
def get_param_groups(model):seen_data_ptrs = set()# avoid duplicates in case of tied weightsfor module in model.children():is_linear = _is_linear(module)for n, p in module.named_parameters():if n == "weight":data_ptr = p.data_ptr()if data_ptr in seen_data_ptrs:continueseen_data_ptrs.add(data_ptr)if is_linear and n == "...
9
16
1
101
0
138
154
138
null
[]
None
null
0
0
0
null
0
null
The function (split_param_groups.get_param_groups) defined within the public class called public.The function start at line 138 and ends at 154. It contains 16 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
split_param_groups
def split_param_groups(model) -> tuple[list, list, list]:params_quant, params_embed, params_no_quant = [], [], []def get_param_groups(model):seen_data_ptrs = set()# avoid duplicates in case of tied weightsfor module in model.children():is_linear = _is_linear(module)for n, p in module.named_parameters():if n == "weight"...
1
5
1
40
3
135
157
135
null
['is_linear', 'data_ptr', 'seen_data_ptrs']
None
null
0
0
0
null
0
null
The function (split_param_groups) defined within the public class called public.The function start at line 135 and ends at 157. It contains 5 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
build_param_groups
def build_param_groups(model,b: int = 2,group_size: Optional[int] = None,embed_b: int = 4,):params_quant, params_embed, params_no_quant = split_param_groups(model)quant_kwargs = {}if group_size:quant_kwargs["quant_block_size"] = group_sizeparam_groups = [{"params": params_quant, "quant_bits": b, **quant_kwargs},{"param...
3
17
4
92
2
160
176
160
null
['param_groups', 'quant_kwargs']
None
null
0
0
0
null
0
null
The function (build_param_groups) defined within the public class called public.The function start at line 160 and ends at 176. It contains 17 lines of code and it has a cyclomatic complexity of 3. It takes 4 parameters, represented as [160.0] and does not return any value..
pytorch_ao
public
public
0
0
get_optim_kwargs
def get_optim_kwargs(model, base_optimizer, embedding=True, quant_cls=UnifTorchaoQuantizer):optim_kwargs = {}if embedding:embed_data_ptrs = set((m.weight.data_ptr()for m in model.modules()if isinstance(m, nn.Embedding)))group_idx = -1for i, group in enumerate(base_optimizer.param_groups):if all(p.data_ptr() in embed_da...
7
20
4
111
3
179
198
179
null
['embed_data_ptrs', 'group_idx', 'optim_kwargs']
None
null
0
0
0
null
0
null
The function (get_optim_kwargs) defined within the public class called public.The function start at line 179 and ends at 198. It contains 20 lines of code and it has a cyclomatic complexity of 7. It takes 4 parameters, represented as [179.0] and does not return any value..
pytorch_ao
public
public
0
0
compare_quantized_models
def compare_quantized_models(model: nn.Module,m_ref: nn.Module,quantizer: UnifTorchaoQuantizer,b: int,group_size: int,):for n, module in model.named_children():if not _is_linear(module):continue# simulate grouping from QuantOptimizer.stepp = module.weightoriginal_shape = p.shapep = p.view(-1, group_size)q, Q = quantize...
3
17
5
127
4
201
222
201
null
['ref', 'q', 'original_shape', 'p']
None
null
0
0
0
null
0
null
The function (compare_quantized_models) defined within the public class called public.The function start at line 201 and ends at 222. It contains 17 lines of code and it has a cyclomatic complexity of 3. It takes 5 parameters, represented as [201.0] and does not return any value..
pytorch_ao
public
public
0
0
compare_parq_convert
def compare_parq_convert(model: nn.Module,m_ref: nn.Module,optimizer: QuantOptimizer,weight_only: bool = False,):# do not update model weights, just quantizeoptimizer.zero_grad()optimizer.step()orig_model = copy.deepcopy(model)# save copy of PARQ quantized model# equivalent to torchao's convert stepoptimizer.torchao_co...
3
20
4
172
5
225
252
225
null
['p_ref', 'inputs', 'p_orig', 'orig_model', 'p']
None
null
0
0
0
null
0
null
The function (compare_parq_convert) defined within the public class called public.The function start at line 225 and ends at 252. It contains 20 lines of code and it has a cyclomatic complexity of 3. It takes 4 parameters, represented as [225.0] and does not return any value..
pytorch_ao
public
public
0
0
check_torchao_tensor_subclass
def check_torchao_tensor_subclass(test_case: common_utils.TestCase, model: nn.Module, weight_only: bool = False):for name, module in model.named_modules():if not hasattr(module, "weight") or f"{name}.weight" in getattr(model, "_tied_weights_keys", []):continueif not weight_only and _is_linear(module):test_case.assertTr...
9
16
3
131
0
255
271
255
null
[]
None
null
0
0
0
null
0
null
The function (check_torchao_tensor_subclass) defined within the public class called public.The function start at line 255 and ends at 271. It contains 16 lines of code and it has a cyclomatic complexity of 9. It takes 3 parameters, represented as [255.0] and does not return any value..
pytorch_ao
public
public
0
0
apply_activation_quantization
def apply_activation_quantization(model: nn.Module, optimizer: torch.optim.Optimizer, model_dtype: torch.dtype):# apply torchao quantized activations on topactivation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False, scale_precision=model_dtype)qat_config = QATConfig(activation_config=activat...
4
13
3
89
2
274
287
274
null
['qat_config', 'activation_config']
None
null
0
0
0
null
0
null
The function (apply_activation_quantization) defined within the public class called public.The function start at line 274 and ends at 287. It contains 13 lines of code and it has a cyclomatic complexity of 4. It takes 3 parameters, represented as [274.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
291
292
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 291 and ends at 292. 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_parq_train_loop
def test_parq_train_loop(self, b: int = 2, unif_quant=True, hard_prox=True, per_group_quantizer=False):model = M(bias=True).to(_DEVICE)if unif_quant:quantizer = TernaryUnifQuantizer() if b == 0 else UnifQuantizer()else:quantizer = LSBQuantizer()param_groups = build_param_groups(model, b, embed_b=b)base_optimizer = torc...
7
27
5
213
0
298
326
298
null
[]
None
null
0
0
0
null
0
null
The function (test_parq_train_loop) defined within the public class called public.The function start at line 298 and ends at 326. It contains 27 lines of code and it has a cyclomatic complexity of 7. It takes 5 parameters, represented as [298.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
330
331
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 330 and ends at 331. 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_int4_weight_only
def test_int4_weight_only(self, group_size: int = 32):model = M(m=512, n=512).to(_DEVICE, dtype=torch.bfloat16)m_ref = copy.deepcopy(model).eval().to(_DEVICE)config = Int4WeightOnlyConfig(group_size=group_size)if check_cpu_version(_DEVICE):config.layout = Int4CPULayout()config.version = 1quantize_(m_ref, config)b = 4co...
2
12
2
100
0
339
352
339
null
[]
None
null
0
0
0
null
0
null
The function (test_int4_weight_only) defined within the public class called public.The function start at line 339 and ends at 352. It contains 12 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [339.0] and does not return any value..
pytorch_ao
public
public
0
0
test_intx_weight_only
def test_intx_weight_only(self, b: int = 2, group_size: int = 32):model = M(m=512, n=512).to(_DEVICE)m_ref = copy.deepcopy(model).eval().to(_DEVICE)quantize_(m_ref,IntxWeightOnlyConfig(weight_dtype=_BIT_WIDTH_TO_DTYPE[b], granularity=PerGroup(group_size)),)quantizer = UnifTorchaoQuantizer()compare_quantized_models(mode...
1
11
3
90
0
356
368
356
null
[]
None
null
0
0
0
null
0
null
The function (test_intx_weight_only) defined within the public class called public.The function start at line 356 and ends at 368. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [356.0] and does not return any value..
pytorch_ao
public
public
0
0
test_int4_weight_only_e2e
def test_int4_weight_only_e2e(self, group_size: int = 32):model = M(m=512, n=512, embedding=False).to(torch.bfloat16).to(_DEVICE)m_ref = copy.deepcopy(model).eval().to(_DEVICE)config = Int4WeightOnlyConfig(group_size=group_size)quantize_(m_ref, config)b = 4base_optimizer = torch.optim.AdamW(build_param_groups(model, b,...
1
16
2
136
0
375
392
375
null
[]
None
null
0
0
0
null
0
null
The function (test_int4_weight_only_e2e) defined within the public class called public.The function start at line 375 and ends at 392. It contains 16 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [375.0] and does not return any value..
pytorch_ao
public
public
0
0
test_intx_weight_only_e2e
def test_intx_weight_only_e2e(self, b: int = 2, group_size: int = 32):model = M(m=512, n=512, embedding=False).to(_DEVICE)m_ref = copy.deepcopy(model).eval().to(_DEVICE)config = IntxWeightOnlyConfig(weight_dtype=_BIT_WIDTH_TO_DTYPE[b], granularity=PerGroup(group_size))quantize_(m_ref, config)base_optimizer = torch.opti...
1
18
3
152
0
396
415
396
null
[]
None
null
0
0
0
null
0
null
The function (test_intx_weight_only_e2e) defined within the public class called public.The function start at line 396 and ends at 415. It contains 18 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [396.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
419
420
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 419 and ends at 420. 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_intx_weight_only_parq_equivalent
def test_intx_weight_only_parq_equivalent(self, b: int = 2, group_size: int = 32):model = M(m=512, n=512).to(_DEVICE)quantizer_ref = UnifQuantizer()quantizer = StretchedUnifTorchaoQuantizer(b)for module in model.children():if not _is_linear(module):continue# simulate grouping from QuantOptimizer.stepp = module.weightp ...
3
13
3
152
0
424
442
424
null
[]
None
null
0
0
0
null
0
null
The function (test_intx_weight_only_parq_equivalent) defined within the public class called public.The function start at line 424 and ends at 442. It contains 13 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [424.0] and does not return any value..
pytorch_ao
public
public
0
0
test_intx_weight_only
def test_intx_weight_only(self, b: int = 2, group_size: int = 32):model = M(m=512, n=512).to(_DEVICE)quantizer = StretchedUnifTorchaoQuantizer(b)m_ref = copy.deepcopy(model).eval().to(_DEVICE)quantize_(m_ref,StretchedIntxWeightConfig(b=b,quant_min=quantizer.quant_min,quant_max=quantizer.quant_max,granularity=PerGroup(g...
1
15
3
105
0
446
463
446
null
[]
None
null
0
0
0
null
0
null
The function (test_intx_weight_only) defined within the public class called public.The function start at line 446 and ends at 463. It contains 15 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [446.0] and does not return any value..
pytorch_ao
public
public
0
0
test_intx_weight_only_e2e
def test_intx_weight_only_e2e(self, b: int = 2, group_size: int = 32):model = M(m=512, n=512, embedding=False).to(_DEVICE)quantizer = StretchedUnifTorchaoQuantizer(b)m_ref = copy.deepcopy(model).eval().to(_DEVICE)config = StretchedIntxWeightConfig(b=b,quant_min=quantizer.quant_min,quant_max=quantizer.quant_max,granular...
1
23
3
174
0
467
492
467
null
[]
None
null
0
0
0
null
0
null
The function (test_intx_weight_only_e2e) defined within the public class called public.The function start at line 467 and ends at 492. It contains 23 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [467.0] and does not return any value..