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
setUp
def setUp(self):"""Set up test fixtures before each test method."""# This is a bit hacked since it makes all tests pass# purpose of these tests is to catch no wild regressions and 1e-1# is ok for nowtorch.manual_seed(78)
1
2
1
12
0
25
30
25
null
[]
None
null
0
0
0
null
0
null
The function (setUp) defined within the public class called public.The function start at line 25 and ends at 30. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_get_default_quantization_params
def _get_default_quantization_params(self):"""Get default quantization parameters."""return {"x_eps": torch.finfo(torch.float32).eps,}
1
4
1
22
0
32
36
32
null
[]
None
null
0
0
0
null
0
null
The function (_get_default_quantization_params) defined within the public class called public.The function start at line 32 and ends at 36. 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
_create_test_tensors
def _create_test_tensors(self, batch_size, in_features, out_features, group_size, bias=True):"""Create test tensors for the given dimensions."""# Create input activationx_fp32 = torch.randn(batch_size, in_features, dtype=torch.float32)# Create 4-bit quantized weight (stored as int8 with values in [-8, 7])weight_i4 = to...
2
20
6
144
0
38
67
38
null
[]
None
null
0
0
0
null
0
null
The function (_create_test_tensors) defined within the public class called public.The function start at line 38 and ends at 67. It contains 20 lines of code and it has a cyclomatic complexity of 2. It takes 6 parameters, represented as [38.0] and does not return any value..
pytorch_ao
public
public
0
0
_run_qdq_implementation
def _run_qdq_implementation(self, tensors, quant_params, group_size):"""Run the QDQ implementation with given tensors and parameters."""return _qdq_dynamic_quantized_linear_4bit_groupwise(x_fp32=tensors["x_fp32"],x_eps=quant_params["x_eps"],weight_i4=tensors["weight_i4"],weight_scale=tensors["weight_scale"],weight_zero...
1
10
4
62
0
69
79
69
null
[]
None
null
0
0
0
null
0
null
The function (_run_qdq_implementation) defined within the public class called public.The function start at line 69 and ends at 79. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [69.0] and does not return any value..
pytorch_ao
public
public
0
0
_run_reference_implementation
def _run_reference_implementation(self, tensors, quant_params, group_size):"""Run the reference implementation with given tensors and parameters."""return _reference_dynamic_quantized_linear_4bit_groupwise(x_fp32=tensors["x_fp32"],x_eps=quant_params["x_eps"],weight_i4=tensors["weight_i4"],weight_scale=tensors["weight_s...
1
10
4
62
0
81
91
81
null
[]
None
null
0
0
0
null
0
null
The function (_run_reference_implementation) defined within the public class called public.The function start at line 81 and ends at 91. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [81.0] and does not return any value..
pytorch_ao
public
public
0
0
_assert_basic_properties
def _assert_basic_properties(self, result, expected_shape):"""Assert basic properties of the result tensor."""self.assertEqual(result.shape, expected_shape)self.assertEqual(result.dtype, torch.float32)
1
3
3
32
0
93
96
93
null
[]
None
null
0
0
0
null
0
null
The function (_assert_basic_properties) defined within the public class called public.The function start at line 93 and ends at 96. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [93.0] and does not return any value..
pytorch_ao
public
public
0
0
_assert_implementations_close
def _assert_implementations_close(self, qdq_result, ref_result, atol=1e-1, rtol=1e-1, msg_suffix=""):"""Assert that QDQ and reference implementations produce similar results."""torch.testing.assert_close(qdq_result,ref_result,atol=atol,rtol=rtol,msg=f"QDQ and reference results differ significantly{msg_suffix}",)
1
10
6
50
0
98
108
98
null
[]
None
null
0
0
0
null
0
null
The function (_assert_implementations_close) defined within the public class called public.The function start at line 98 and ends at 108. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [98.0] and does not return any value..
pytorch_ao
public
public
0
0
test_qdq_dynamic_quantized_linear_4bit_groupwise_basic
def test_qdq_dynamic_quantized_linear_4bit_groupwise_basic(self):"""Test that QDQ implementation runs without errors and produces reasonable output."""# Test-specific parametersbatch_size, in_features, out_features, group_size = 2, 32, 8, 8quant_params = self._get_default_quantization_params()tensors = self._create_tes...
1
8
1
66
0
110
121
110
null
[]
None
null
0
0
0
null
0
null
The function (test_qdq_dynamic_quantized_linear_4bit_groupwise_basic) defined within the public class called public.The function start at line 110 and ends at 121. 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_reference_dynamic_quantized_linear_4bit_groupwise_basic
def test_reference_dynamic_quantized_linear_4bit_groupwise_basic(self):"""Test that reference implementation runs without errors and produces reasonable output."""# Test-specific parametersbatch_size, in_features, out_features, group_size = 2, 32, 8, 8quant_params = self._get_default_quantization_params()tensors = self...
1
8
1
66
0
123
134
123
null
[]
None
null
0
0
0
null
0
null
The function (test_reference_dynamic_quantized_linear_4bit_groupwise_basic) defined within the public class called public.The function start at line 123 and ends at 134. 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_both_implementations_no_bias
def test_both_implementations_no_bias(self):"""Test both implementations without bias."""# Test-specific parametersbatch_size, in_features, out_features, group_size = 1, 16, 4, 8quant_params = self._get_default_quantization_params()tensors = self._create_test_tensors(batch_size, in_features, out_features, group_size, b...
1
15
1
106
0
136
155
136
null
[]
None
null
0
0
0
null
0
null
The function (test_both_implementations_no_bias) defined within the public class called public.The function start at line 136 and ends at 155. It contains 15 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_edge_cases_group_size_validation
def test_edge_cases_group_size_validation(self):"""Test edge cases and error conditions."""# Test-specific parametersbatch_size, in_features, out_features = 1, 32, 8quant_params = self._get_default_quantization_params()tensors = self._create_test_tensors(batch_size, in_features, out_features, 8)# Valid group size for t...
1
12
1
74
0
157
175
157
null
[]
None
null
0
0
0
null
0
null
The function (test_edge_cases_group_size_validation) defined within the public class called public.The function start at line 157 and ends at 175. It contains 12 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_weight_dimension_validation
def test_weight_dimension_validation(self):"""Test weight dimension validation."""# Test-specific parametersbatch_size, in_features, out_features, group_size = 1, 32, 8, 8quant_params = self._get_default_quantization_params()tensors = self._create_test_tensors(batch_size, in_features, out_features, group_size)# Create ...
1
9
1
89
0
177
191
177
null
[]
None
null
0
0
0
null
0
null
The function (test_weight_dimension_validation) defined within the public class called public.The function start at line 177 and ends at 191. 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_different_group_sizes
def test_different_group_sizes(self):"""Test with different valid group sizes."""# Test-specific parametersbatch_size, in_features, out_features = 2, 64, 16group_sizes = [8, 16, 32]quant_params = self._get_default_quantization_params()for group_size in group_sizes:with self.subTest(group_size=group_size):tensors = self...
2
20
1
123
0
193
218
193
null
[]
None
null
0
0
0
null
0
null
The function (test_different_group_sizes) defined within the public class called public.The function start at line 193 and ends at 218. It contains 20 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_qdq_vs_reference_implementation_comparison
def test_qdq_vs_reference_implementation_comparison(self):"""Test that QDQ and reference implementations produce similar results with various configurations."""# Test-specific parameterstest_cases = [(1, 32, 8, 8),(2, 64, 16, 16),(4, 128, 32, 32),]quant_params = self._get_default_quantization_params()for batch_size, in...
2
52
1
221
0
220
283
220
null
[]
None
null
0
0
0
null
0
null
The function (test_qdq_vs_reference_implementation_comparison) defined within the public class called public.The function start at line 220 and ends at 283. It contains 52 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, input_size=128, hidden_size=64, output_size=32):super().__init__()self.linear1 = nn.Linear(input_size, hidden_size)self.relu = nn.ReLU()self.linear2 = nn.Linear(hidden_size, output_size)
1
5
4
57
0
289
293
289
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 289 and ends at 293. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [289.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, x):x = self.linear1(x)x = self.relu(x)x = self.linear2(x)return x
1
5
2
33
0
295
299
295
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 295 and ends at 299. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [295.0] and does not return any value..
pytorch_ao
public
public
0
0
setUp
def setUp(self):"""Set up test fixtures before each test method."""# This is a bit hacked since it makes all tests pass# purpose of these tests is to catch no wild regressions and 1e-1# is ok for nowtorch.manual_seed(78)
1
2
1
12
0
305
307
25
null
[]
None
null
0
0
0
null
0
null
The function (setUp) defined within the public class called public.The function start at line 305 and ends at 307. 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_export_and_rewrite_workflow
def test_export_and_rewrite_workflow(self):"""Test the complete export and rewrite workflow."""# Create modelmodel = SimpleLinearModel(input_size=64, hidden_size=32, output_size=16)example_input = torch.randn(1, 64)# Apply 8da4w quantizationquantize_(model, Int8DynamicActivationInt4WeightConfig(group_size=32))# Unwrap ...
1
19
1
175
0
309
349
309
null
[]
None
null
0
0
0
null
0
null
The function (test_export_and_rewrite_workflow) defined within the public class called public.The function start at line 309 and ends at 349. 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_different_group_sizes_rewrite
def test_different_group_sizes_rewrite(self):"""Test rewrite functionality with different group sizes."""group_sizes = [16, 32, 64]for group_size in group_sizes:with self.subTest(group_size=group_size):# Create modelmodel = SimpleLinearModel(input_size=64, hidden_size=32, output_size=16)example_input = torch.randn(1, 2...
2
24
1
166
0
351
393
351
null
[]
None
null
0
0
0
null
0
null
The function (test_different_group_sizes_rewrite) defined within the public class called public.The function start at line 351 and ends at 393. It contains 24 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_model_without_bias_rewrite
def test_model_without_bias_rewrite(self):"""Test rewrite functionality with linear layers that have no bias."""# Create model without biasmodel = SimpleLinearModel(input_size=32, hidden_size=16, output_size=8)model.linear1.bias = Nonemodel.linear2.bias = Noneexample_input = torch.randn(1, 32)# Apply quantizationquanti...
1
21
1
153
0
395
434
395
null
[]
None
null
0
0
0
null
0
null
The function (test_model_without_bias_rewrite) defined within the public class called public.The function start at line 395 and ends at 434. 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
forward.apply_fake_quant_fn
def apply_fake_quant_fn(t: torch.Tensor):assert isinstance(t, _AffineFakeQuantizedTensor)qmin, qmax = _get_and_check_qmin_qmax(target_dtype, quant_min, quant_max)if zero_point_domain == ZeroPointDomain.FLOAT and not preserve_zero:scale, zero_point = _choose_qparams_affine_tinygemm(t.original_tensor,mapping_type,block_s...
5
50
1
164
0
50
99
50
null
[]
None
null
0
0
0
null
0
null
The function (forward.apply_fake_quant_fn) defined within the public class called public.The function start at line 50 and ends at 99. It contains 50 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
forward
def forward(ctx: torch.autograd.function.FunctionCtx,original_tensor: torch.Tensor,mapping_type: MappingType,block_size: Tuple[int, ...],target_dtype: torch.dtype,quant_min: Optional[int] = None,quant_max: Optional[int] = None,eps: Optional[float] = None,scale_dtype: Optional[torch.dtype] = None,zero_point_dtype: Optio...
2
22
12
128
0
33
105
33
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 33 and ends at 105. It contains 22 lines of code and it has a cyclomatic complexity of 2. It takes 12 parameters, represented as [33.0] and does not return any value..
pytorch_ao
public
public
0
0
backward
def backward(ctx, gy):return gy, None, None, None, None, None, None, None, None, None, None
1
2
2
29
0
108
109
108
null
[]
None
null
0
0
0
null
0
null
The function (backward) defined within the public class called public.The function start at line 108 and ends at 109. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [108.0] and does not return any value..
pytorch_ao
public
public
0
0
__new__
def __new__(cls,original_tensor: torch.Tensor,apply_fake_quant_fn: Callable,fake_quant_enabled: bool = True,**kwargs,):kwargs.setdefault("dtype", original_tensor.dtype)kwargs.setdefault("device", original_tensor.device)kwargs.setdefault("requires_grad", original_tensor.requires_grad)return torch.Tensor._make_wrapper_su...
1
15
5
72
0
130
144
130
null
[]
None
null
0
0
0
null
0
null
The function (__new__) defined within the public class called public.The function start at line 130 and ends at 144. It contains 15 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [130.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,original_tensor: torch.Tensor,apply_fake_quant_fn: Callable,fake_quant_enabled: bool = True,**kwargs,):self.original_tensor = original_tensorself.apply_fake_quant_fn = apply_fake_quant_fnself.fake_quant_enabled = fake_quant_enabled
1
10
5
40
0
146
155
146
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 146 and ends at 155. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [146.0] and does not return any value..
pytorch_ao
public
public
0
0
__tensor_flatten__
def __tensor_flatten__(self):return ["original_tensor"], [self.apply_fake_quant_fn, self.fake_quant_enabled]
1
2
1
19
0
157
158
157
null
[]
None
null
0
0
0
null
0
null
The function (__tensor_flatten__) defined within the public class called public.The function start at line 157 and ends at 158. 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
__tensor_unflatten__
def __tensor_unflatten__(cls,tensor_data_dict,tensor_attributes,outer_size,outer_stride,):original_tensor = tensor_data_dict["original_tensor"](apply_fake_quant_fn, fake_quant_enabled) = tensor_attributesreturn cls(original_tensor,apply_fake_quant_fn,fake_quant_enabled,)
1
14
5
37
0
161
174
161
null
[]
None
null
0
0
0
null
0
null
The function (__tensor_unflatten__) defined within the public class called public.The function start at line 161 and ends at 174. It contains 14 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [161.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls,original_input: torch.Tensor,mapping_type: MappingType,block_size: Tuple[int, ...],target_dtype: torch.dtype,quant_min: Optional[int] = None,quant_max: Optional[int] = None,eps: Optional[float] = None,scale_dtype: Optional[torch.dtype] = None,zero_point_dtype: Optional[torch.dtype] = None,preserve_ze...
2
29
12
132
0
177
205
177
null
[]
None
null
0
0
0
null
0
null
The function (from_float) defined within the public class called public.The function start at line 177 and ends at 205. It contains 29 lines of code and it has a cyclomatic complexity of 2. It takes 12 parameters, represented as [177.0] and does not return any value..
pytorch_ao
public
public
0
0
get_value
def get_value(self) -> torch.Tensor:if self.fake_quant_enabled:return self.apply_fake_quant_fn(self)else:return self.original_tensor
2
5
1
27
0
207
211
207
null
[]
None
null
0
0
0
null
0
null
The function (get_value) defined within the public class called public.The function start at line 207 and ends at 211. 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
_get_to_kwargs
def _get_to_kwargs(self, *args, **kwargs):device, dtype, _, memory_format = torch._C._nn._parse_to(*args, **kwargs)device = self.device if device is None else devicedtype = self.dtype if dtype is None else dtypememory_format = (memory_format if memory_format is not None else torch.preserve_format)kwargs = {"device": de...
4
14
3
93
0
213
226
213
null
[]
None
null
0
0
0
null
0
null
The function (_get_to_kwargs) defined within the public class called public.The function start at line 213 and ends at 226. It contains 14 lines of code and it has a cyclomatic complexity of 4. It takes 3 parameters, represented as [213.0] and does not return any value..
pytorch_ao
public
public
0
0
to
def to(self, *args, **kwargs):kwargs = self._get_to_kwargs(*args, **kwargs)device = kwargs.pop("device")# not supported yetkwargs.pop("memory_format")return self.__class__(self.original_tensor.to(device),self.apply_fake_quant_fn,self.fake_quant_enabled,**kwargs,)
1
10
3
63
0
228
238
228
null
[]
None
null
0
0
0
null
0
null
The function (to) defined within the public class called public.The function start at line 228 and ends at 238. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [228.0] and does not return any value..
pytorch_ao
public
public
0
0
_apply_fn_to_data
def _apply_fn_to_data(self, fn: Callable):"""Create a new `_AffineFakeQuantizedTensor` with `fn` applied to theoriginal tensor, to be called within __torch_dispatch__."""return self._create_new(fn(self.original_tensor))
1
2
2
22
0
240
245
240
null
[]
None
null
0
0
0
null
0
null
The function (_apply_fn_to_data) defined within the public class called public.The function start at line 240 and ends at 245. It contains 2 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
_create_new
def _create_new(self, new_value: torch.Tensor):"""Create a new `_AffineFakeQuantizedTensor` with a new value,to be called within __torch_dispatch__.Note: `requires_grad` must be False here because tensors createdin `__torch_dispatch__` cannot produce gradients, since autogradwill try to attach autograd metadata to thes...
1
7
2
32
0
247
263
247
null
[]
None
null
0
0
0
null
0
null
The function (_create_new) defined within the public class called public.The function start at line 247 and ends at 263. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [247.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):input_tensor, weight_tensor, bias = (args[0],args[1],args[2] if len(args) > 2 else None,)if isinstance(input_tensor, _AffineFakeQuantizedTensor):input_tensor = input_tensor.get_value()if isinstance(weight_tensor, _AffineFakeQuantizedTensor):weight_tensor = weight_tensor.get_value()retur...
4
11
4
88
2
270
280
270
null
['weight_tensor', 'input_tensor']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 270 and ends at 280. It contains 11 lines of code and it has a cyclomatic complexity of 4. It takes 4 parameters, represented as [270.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):input_tensor = args[0]weight_tensor = args[1]if isinstance(input_tensor, _AffineFakeQuantizedTensor):input_tensor = input_tensor.get_value()if isinstance(weight_tensor, _AffineFakeQuantizedTensor):weight_tensor = weight_tensor.get_value()return func(input_tensor, weight_tensor)
3
8
4
60
2
284
291
284
null
['weight_tensor', 'input_tensor']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 284 and ends at 291. It contains 8 lines of code and it has a cyclomatic complexity of 3. It takes 4 parameters, represented as [284.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):bias = args[0]input_tensor = args[1]weight_tensor = args[2]if isinstance(input_tensor, _AffineFakeQuantizedTensor):input_tensor = input_tensor.get_value()if isinstance(weight_tensor, _AffineFakeQuantizedTensor):weight_tensor = weight_tensor.get_value()return func(bias, input_tensor, wei...
3
9
4
68
3
295
303
295
null
['weight_tensor', 'input_tensor', 'bias']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 295 and ends at 303. It contains 9 lines of code and it has a cyclomatic complexity of 3. It takes 4 parameters, represented as [295.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return return_and_correct_aliasing(func,args,kwargs,args[0]._apply_fn_to_data(torch.detach),)
1
7
4
33
0
307
313
307
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 307 and ends at 313. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [307.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return return_and_correct_aliasing(func,args,kwargs,args[0]._apply_fn_to_data(torch.detach),)
1
7
4
33
0
317
323
307
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 317 and ends at 323. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [307.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return return_and_correct_aliasing(func,args,kwargs,args[0]._apply_fn_to_data(torch.detach),)
1
7
4
33
0
327
333
307
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 327 and ends at 333. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [307.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):assert len(args) == 2, f"dispatched the wrong op to the binary handler: {func}"new_args = pytree.tree_map_only(_AffineFakeQuantizedTensor, lambda x: x.original_tensor, args)first_afq_tensor = (args[0] if isinstance(args[0], _AffineFakeQuantizedTensor) else args[1])new_value = func(*new_...
2
11
4
90
4
344
354
344
null
['out', 'first_afq_tensor', 'new_args', 'new_value']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 344 and ends at 354. It contains 11 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [344.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):out = torch.empty_like(args[0].original_tensor, **kwargs)return return_and_correct_aliasing(func, args, kwargs, out)
1
3
4
38
1
361
363
361
null
['out']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 361 and ends at 363. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [361.0] and does not return any value..
pytorch_ao
public
public
0
0
_.make_new_tensor
def make_new_tensor(value):out = args[0]._create_new(value)return return_and_correct_aliasing(func, args, kwargs, out)
1
3
1
27
0
370
372
370
null
[]
None
null
0
0
0
null
0
null
The function (_.make_new_tensor) defined within the public class called public.The function start at line 370 and ends at 372. 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
_
def _(func, types, args, kwargs):new_values = torch.split(args[0].original_tensor, *args[1:], **kwargs)def make_new_tensor(value):out = args[0]._create_new(value)return return_and_correct_aliasing(func, args, kwargs, out)return list(map(make_new_tensor, new_values))
1
4
4
46
2
367
374
367
null
['out', 'new_values']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 367 and ends at 374. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [367.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):out = args[0].original_tensor.new_zeros(*args[1:], **kwargs)return return_and_correct_aliasing(func, args, kwargs, out)
1
3
4
43
1
378
380
378
null
['out']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 378 and ends at 380. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [378.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,base_config: Optional[AOBaseConfig] = None,activation_config: Optional[FakeQuantizeConfigBase] = None,weight_config: Optional[FakeQuantizeConfigBase] = None,*,step: QATStep = "prepare",):self.base_config = base_configself.activation_config = activation_configself.weight_config = weight_configself.step...
1
13
5
66
0
137
149
137
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 137 and ends at 149. It contains 13 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [137.0] and does not return any value..
pytorch_ao
public
public
0
0
__post_init__
def __post_init__(self):torch._C._log_api_usage_once("torchao.quantization.qat.QATConfig")self.step = self.step.lower()all_step_values = [s.value for s in QATStep]if self.step not in all_step_values:raise ValueError(f"`step` must be one of {all_step_values}")if self.base_config is not None and self.activation_config is...
13
34
1
183
0
151
185
151
null
[]
None
null
0
0
0
null
0
null
The function (__post_init__) defined within the public class called public.The function start at line 151 and ends at 185. It contains 34 lines of code and it has a cyclomatic complexity of 13. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_qat_config_transform
def _qat_config_transform(module: torch.nn.Module,config: QATConfig,) -> torch.nn.Module:"""During the prepare step, perform module swap to apply fake quantization.If the base PTQ config is specified, derive the fake quantization configs from it.During the convert step, first perform module swap to revert all fake quan...
16
74
2
367
7
189
288
189
null
['base_config', 'has_custom_scale_and_zero_point', 'kwargs', 'step', 'act_config', 'weight_config', 'module']
None
null
0
0
0
null
0
null
The function (_qat_config_transform) defined within the public class called public.The function start at line 189 and ends at 288. It contains 74 lines of code and it has a cyclomatic complexity of 16. It takes 2 parameters, represented as [189.0] and does not return any value..
pytorch_ao
public
public
0
0
__post_init__
def __post_init__(self):_log_deprecation_warning(self)
1
2
1
9
0
323
324
323
null
[]
None
null
0
0
0
null
0
null
The function (__post_init__) defined within the public class called public.The function start at line 323 and ends at 324. 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
_intx_quantization_aware_training_transform
def _intx_quantization_aware_training_transform(module: torch.nn.Module,config: IntXQuantizationAwareTrainingConfig,) -> torch.nn.Module:mod = moduleactivation_config = config.activation_configweight_config = config.weight_configif isinstance(mod, torch.nn.Linear):return FakeQuantizedLinear.from_linear(mod,activation_c...
4
21
2
103
3
333
354
333
null
['activation_config', 'mod', 'weight_config']
None
null
0
0
0
null
0
null
The function (_intx_quantization_aware_training_transform) defined within the public class called public.The function start at line 333 and ends at 354. It contains 21 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [333.0] and does not return any value..
pytorch_ao
public
public
0
0
__post_init__
def __post_init__(self):_log_deprecation_warning(self)
1
2
1
9
0
378
379
323
null
[]
None
null
0
0
0
null
0
null
The function (__post_init__) defined within the public class called public.The function start at line 378 and ends at 379. 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
_from_intx_quantization_aware_training_transform
def _from_intx_quantization_aware_training_transform(mod: torch.nn.Module,config: FromIntXQuantizationAwareTrainingConfig,) -> torch.nn.Module:"""If the given module is a fake quantized module, return the originalcorresponding version of the module without fake quantization."""if isinstance(mod, FakeQuantizedLinear):re...
3
10
2
55
0
388
401
388
null
[]
None
null
0
0
0
null
0
null
The function (_from_intx_quantization_aware_training_transform) defined within the public class called public.The function start at line 388 and ends at 401. It contains 10 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [388.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, quantizers: List[TwoStepQuantizer]):torch._C._log_api_usage_once("torchao.quantization.qat.ComposableQATQuantizer")self.quantizers = quantizers
1
3
2
25
0
424
426
424
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 424 and ends at 426. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [424.0] and does not return any value..
pytorch_ao
public
public
0
0
prepare
def prepare(self, model: torch.nn.Module, *args: Any, **kwargs: Any) -> torch.nn.Module:for quantizer in self.quantizers:model = quantizer.prepare(model)return model
2
6
4
46
0
428
433
428
null
[]
None
null
0
0
0
null
0
null
The function (prepare) defined within the public class called public.The function start at line 428 and ends at 433. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [428.0] and does not return any value..
pytorch_ao
public
public
0
0
convert
def convert(self, model: torch.nn.Module, *args: Any, **kwargs: Any) -> torch.nn.Module:for quantizer in self.quantizers:model = quantizer.convert(model)return model
2
6
4
46
0
435
440
435
null
[]
None
null
0
0
0
null
0
null
The function (convert) defined within the public class called public.The function start at line 435 and ends at 440. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [435.0] and does not return any value..
pytorch_ao
public
public
0
0
initialize_fake_quantizers._set_initialized
def _set_initialized(m: torch.nn.Module):if isinstance(m, IntxFakeQuantizer):m._initialized = True
2
3
1
24
0
457
459
457
null
[]
None
null
0
0
0
null
0
null
The function (initialize_fake_quantizers._set_initialized) defined within the public class called public.The function start at line 457 and ends at 459. It contains 3 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
initialize_fake_quantizers
def initialize_fake_quantizers(model: torch.nn.Module,example_inputs: Tuple[Any, ...],) -> None:"""(Prototype) Initialize the scales and zero points on all:class:`~torchao.quantization.qat.fake_quantizer.IntxFakeQuantizerBase`in the model based on the provided example inputs."""torch._C._log_api_usage_once("torchao.qua...
1
9
2
55
0
443
462
443
null
[]
None
null
0
0
0
null
0
null
The function (initialize_fake_quantizers) defined within the public class called public.The function start at line 443 and ends at 462. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [443.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,num_embeddings: int,embedding_dim: int,padding_idx: Optional[int] = None,max_norm: Optional[float] = None,norm_type: float = 2.0,scale_grad_by_freq: bool = False,sparse: bool = False,weight_config: Optional[FakeQuantizeConfigBase] = None,*args,**kwargs,) -> None:super().__init__(num_embeddings,embeddi...
2
29
11
127
0
44
72
44
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 44 and ends at 72. It contains 29 lines of code and it has a cyclomatic complexity of 2. It takes 11 parameters, represented as [44.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, x: torch.Tensor) -> torch.Tensor:if self.weight_fake_quantizer is not None:w = self.weight_fake_quantizer(self.weight)else:w = self.weightreturn F.embedding(x,w,self.padding_idx,self.max_norm,self.norm_type,self.scale_grad_by_freq,self.sparse,)
2
14
2
70
0
74
87
74
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 74 and ends at 87. It contains 14 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [74.0] and does not return any value..
pytorch_ao
public
public
0
0
to_embedding
def to_embedding(self) -> torch.nn.Embedding:new_embedding = torch.nn.Embedding(self.num_embeddings,self.embedding_dim,self.padding_idx,self.max_norm,self.norm_type,self.scale_grad_by_freq,self.sparse,device=self.weight.device,dtype=self.weight.dtype,)# In distributed training, the model may be instantiated# on the met...
2
15
1
87
0
89
106
89
null
[]
None
null
0
0
0
null
0
null
The function (to_embedding) defined within the public class called public.The function start at line 89 and ends at 106. 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
from_embedding
def from_embedding(cls,mod: torch.nn.Embedding,weight_config: Optional[FakeQuantizeConfigBase] = None,):new_embedding = FakeQuantizedEmbedding(mod.num_embeddings,mod.embedding_dim,mod.padding_idx,mod.max_norm,mod.norm_type,mod.scale_grad_by_freq,mod.sparse,weight_config=weight_config,device=mod.weight.device,dtype=mod....
2
20
3
99
0
109
131
109
null
[]
None
null
0
0
0
null
0
null
The function (from_embedding) defined within the public class called public.The function start at line 109 and ends at 131. It contains 20 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [109.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,group_size: int = 256,scale_precision: torch.dtype = torch.float32,zero_point_precision: torch.dtype = torch.int32,) -> None:super().__init__()torch._C._log_api_usage_once("torchao.quantization.qat.Int4WeightOnlyEmbeddingQATQuantizer")self.bit_width = 4self.group_size: int = group_sizeself.scale_preci...
1
14
4
79
0
145
158
145
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 145 and ends at 158. It contains 14 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [145.0] and does not return any value..
pytorch_ao
public
public
0
0
prepare.filter_fn
def filter_fn(child: torch.nn.Module, cur_fqn: str) -> bool:return isinstance(child, torch.nn.Embedding)
1
2
2
28
0
171
172
171
null
[]
None
null
0
0
0
null
0
null
The function (prepare.filter_fn) defined within the public class called public.The function start at line 171 and ends at 172. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [171.0] and does not return any value..
pytorch_ao
public
public
0
0
prepare.replacement_fn
def replacement_fn(child: torch.nn.Module) -> torch.nn.Module:new_embedding = Int4WeightOnlyQATEmbedding(# nn.Embedding argsnum_embeddings=child.num_embeddings,embedding_dim=child.embedding_dim,padding_idx=child.padding_idx,max_norm=child.max_norm,norm_type=child.norm_type,scale_grad_by_freq=child.scale_grad_by_freq,sp...
2
18
1
121
0
174
196
174
null
[]
None
null
0
0
0
null
0
null
The function (prepare.replacement_fn) defined within the public class called public.The function start at line 174 and ends at 196. It contains 18 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
prepare
def prepare(self, model: torch.nn.Module, *args: Any, **kwargs: Any) -> torch.nn.Module:"""Swap `nn.Embedding` modules with `Int4WeightOnlyQATEmbedding`."""# avoid circular importsfrom torchao.quantization.quant_api import (_replace_with_custom_fn_if_matches_filter,)def filter_fn(child: torch.nn.Module, cur_fqn: str) -...
1
10
4
55
0
160
199
160
null
[]
None
null
0
0
0
null
0
null
The function (prepare) defined within the public class called public.The function start at line 160 and ends at 199. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [160.0] and does not return any value..
pytorch_ao
public
public
0
0
convert
def convert(self, model: torch.nn.Module, *args: Any, **kwargs: Any) -> torch.nn.Module:"""Swap all `Int4WeightOnlyQATEmbedding` modules with `Int4WeightOnlyEmbedding`."""self._convert_helper(model)return model
1
5
4
38
0
201
208
201
null
[]
None
null
0
0
0
null
0
null
The function (convert) defined within the public class called public.The function start at line 201 and ends at 208. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [201.0] and does not return any value..
pytorch_ao
public
public
0
0
_convert_helper
def _convert_helper(self, module: torch.nn.Module):"""Helper function to recursively swap `Int4WeightOnlyQATEmbedding`modules with `Int4WeightOnlyEmbedding`"""from torchao._executorch_ops import (_quantized_decomposed_quantize_per_channel_group_wrapper,)for name, child in module.named_children():if isinstance(child, In...
3
48
2
253
0
210
266
210
null
[]
None
null
0
0
0
null
0
null
The function (_convert_helper) defined within the public class called public.The function start at line 210 and ends at 266. It contains 48 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [210.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,num_embeddings: int,embedding_dim: int,padding_idx: Optional[int] = None,max_norm: Optional[float] = None,norm_type: float = 2.0,scale_grad_by_freq: bool = False,sparse: bool = False,group_size: int = 32,scale_precision: torch.dtype = torch.float32,zero_point_precision: torch.dtype = torch.int32,*args...
1
35
13
144
0
280
314
280
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 280 and ends at 314. It contains 35 lines of code and it has a cyclomatic complexity of 1. It takes 13 parameters, represented as [280.0] and does not return any value..
pytorch_ao
public
public
0
0
enable_fake_quant
def enable_fake_quant(self, enabled: bool = True):self.weight_fake_quantizer.enabled = enabled
1
2
2
18
0
316
317
316
null
[]
None
null
0
0
0
null
0
null
The function (enable_fake_quant) defined within the public class called public.The function start at line 316 and ends at 317. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [316.0] and does not return any value..
pytorch_ao
public
public
0
0
disable_fake_quant
def disable_fake_quant(self):self.enable_fake_quant(False)
1
2
1
11
0
319
320
319
null
[]
None
null
0
0
0
null
0
null
The function (disable_fake_quant) defined within the public class called public.The function start at line 319 and ends at 320. 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
__init__
def __init__(self,num_embeddings: int,embedding_dim: int,padding_idx: Optional[int] = None,max_norm: Optional[float] = None,norm_type: float = 2.0,scale_grad_by_freq: bool = False,sparse: bool = False,group_size: int = 32,scale_precision: torch.dtype = torch.float32,zero_point_precision: torch.dtype = torch.int32,devic...
1
50
13
243
0
329
384
329
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 329 and ends at 384. It contains 50 lines of code and it has a cyclomatic complexity of 1. It takes 13 parameters, represented as [329.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, x):from torchao.quantization.quant_primitives import (dequantize_affine,)qmin, qmax = _get_qmin_qmax(self.bit_width)# dequantize_affine casts to output_dtype before scaling# dequantize_per_channel_group scales and then casts to output_dtype# The two do not agree when dtype != torch.float32w_dq = dequa...
1
24
2
97
0
386
414
386
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 386 and ends at 414. It contains 24 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [386.0] and does not return any value..
pytorch_ao
public
public
0
0
__post_init__
def __post_init__(self):"""Verify dtype and granularity are the ones we support."""if not _is_float8_type(self.dtype):raise ValueError(f"{self.dtype} is not a float8 dtype")if isinstance(self.granularity, type):raise ValueError("Please specify the granularity object instead of the class, e.g. PerRow() instead of PerRow...
4
11
1
57
0
65
78
65
null
[]
None
null
0
0
0
null
0
null
The function (__post_init__) defined within the public class called public.The function start at line 65 and ends at 78. It contains 11 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
__post_init__
def __post_init__(self):if self.activation_dtype not in [e4m3_dtype, torch.bfloat16]:raise ValueError(f"Only {e4m3_dtype} or torch.bfloat16 activation are supported")
2
5
1
25
0
97
101
97
null
[]
None
null
0
0
0
null
0
null
The function (__post_init__) defined within the public class called public.The function start at line 97 and ends at 101. 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
__init__
def __init__(self,dtype: Union[torch.dtype, TorchAODType],granularity: Union[Granularity, str, None] = None,mapping_type: Optional[MappingType] = None,scale_precision: torch.dtype = torch.float32,zero_point_precision: torch.dtype = torch.int32,zero_point_domain: ZeroPointDomain = ZeroPointDomain.INT,is_dynamic: bool = ...
5
36
12
246
0
164
204
164
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 164 and ends at 204. It contains 36 lines of code and it has a cyclomatic complexity of 5. It takes 12 parameters, represented as [164.0] and does not return any value..
pytorch_ao
public
public
0
0
__post_init__
def __post_init__(self):"""For deprecation only, can remove after https://github.com/pytorch/ao/issues/2630."""pass
1
2
1
7
0
206
210
206
null
[]
None
null
0
0
0
null
0
null
The function (__post_init__) defined within the public class called public.The function start at line 206 and ends at 210. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_get_granularity
def _get_granularity(self,granularity: Union[Granularity, str, None],group_size: Optional[int],) -> Granularity:"""Parse the `Granularity` represented in the args.Granularity can be specified in one of three ways:1) `Granularity` object: one of PerToken(), PerAxis(), and PerGroup(group_size)2) str: one of 'per_token', ...
15
44
3
203
0
212
270
212
null
[]
None
null
0
0
0
null
0
null
The function (_get_granularity) defined within the public class called public.The function start at line 212 and ends at 270. It contains 44 lines of code and it has a cyclomatic complexity of 15. It takes 3 parameters, represented as [212.0] and does not return any value..
pytorch_ao
public
public
0
0
_get_mapping_type
def _get_mapping_type(self,mapping_type: Optional[MappingType],is_symmetric: Optional[bool],) -> MappingType:"""Parse the `MappingType` represented in the args.Mapping type can be specified in one of two ways:1): `MappingType` object: one of SYMMETRIC or ASYMMETRIC2): is_symmetric bool"""if mapping_type is not None and...
8
18
3
99
0
272
302
272
null
[]
None
null
0
0
0
null
0
null
The function (_get_mapping_type) defined within the public class called public.The function start at line 272 and ends at 302. It contains 18 lines of code and it has a cyclomatic complexity of 8. It takes 3 parameters, represented as [272.0] and does not return any value..
pytorch_ao
public
public
0
0
group_size
def group_size(self) -> int:"""If this is per group granularity, return the group size.Otherwise, throw an error."""if isinstance(self.granularity, PerGroup):return self.granularity.group_sizeelse:raise ValueError("`group_size` is undefined for %s granularity" % self.granularity)
2
7
1
35
0
305
315
305
null
[]
None
null
0
0
0
null
0
null
The function (group_size) defined within the public class called public.The function start at line 305 and ends at 315. 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
is_symmetric
def is_symmetric(self) -> bool:"""Return True if mapping type is symmetric, else False (asymmetric)."""return self.mapping_type == MappingType.SYMMETRIC
1
2
1
16
0
318
322
318
null
[]
None
null
0
0
0
null
0
null
The function (is_symmetric) defined within the public class called public.The function start at line 318 and ends at 322. 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
__setattr__
def __setattr__(self, name: str, value: Any):"""Support setting `group_size` and `is_symmetric`."""if name == "group_size":super().__setattr__("granularity", PerGroup(value))elif name == "is_symmetric":mapping_type = MappingType.SYMMETRIC if value else MappingType.ASYMMETRICsuper().__setattr__("mapping_type", mapping_t...
4
8
3
70
0
324
334
324
null
[]
None
null
0
0
0
null
0
null
The function (__setattr__) defined within the public class called public.The function start at line 324 and ends at 334. It contains 8 lines of code and it has a cyclomatic complexity of 4. It takes 3 parameters, represented as [324.0] and does not return any value..
pytorch_ao
public
public
0
0
__post_init__
def __post_init__(self):_log_deprecation_warning(self)
1
2
1
9
0
343
344
343
null
[]
None
null
0
0
0
null
0
null
The function (__post_init__) defined within the public class called public.The function start at line 343 and ends at 344. 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
_infer_fake_quantize_configs
def _infer_fake_quantize_configs(base_config: AOBaseConfig,) -> Tuple[Optional[FakeQuantizeConfigBase], Optional[FakeQuantizeConfigBase]]:"""Given a base post-training quantization (PTQ) config, infer the corresponding`FakeQuantizeConfigBase`s for both the activations and the weights.This is called during the prepare p...
14
148
1
659
4
347
508
347
null
['zp_domain', 'supported_packing_formats', 'weight_config', 'act_config']
None
null
0
0
0
null
0
null
The function (_infer_fake_quantize_configs) defined within the public class called public.The function start at line 347 and ends at 508. It contains 148 lines of code and it has a cyclomatic complexity of 14. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
__repr__
def __repr__(self) -> str:"""Return a human readable representation of this `FakeQuantizer` with config details."""return "FakeQuantizer(%s)" % self.config
1
2
1
14
0
55
59
55
null
[]
None
null
0
0
0
null
0
null
The function (__repr__) defined within the public class called public.The function start at line 55 and ends at 59. 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
from_config
def from_config(config: FakeQuantizeConfigBase) -> "FakeQuantizerBase":if isinstance(config, IntxFakeQuantizeConfig):return IntxFakeQuantizer(config)elif isinstance(config, Int4WeightFakeQuantizeConfig):return Int4WeightFakeQuantizer(config)elif isinstance(config, Float8FakeQuantizeConfig):return Float8FakeQuantizer(co...
4
9
1
56
0
62
70
62
null
[]
None
null
0
0
0
null
0
null
The function (from_config) defined within the public class called public.The function start at line 62 and ends at 70. It contains 9 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, config: Float8FakeQuantizeConfig):super().__init__()self.config = configtorch._C._log_api_usage_once("torchao.quantization.qat.Float8FakeQuantizer")
1
4
2
29
0
78
81
78
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 78 and ends at 81. It contains 4 lines of code and it has a cyclomatic complexity of 1. 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: torch.Tensor) -> torch.Tensor:original_dtype = x.dtypeblock_size = get_block_size(x.shape, self.config.granularity)scale = _choose_scale_float8(x,block_size,self.config.dtype,hp_value_lb=self.config.hp_value_lb,hp_value_ub=self.config.hp_value_ub,)q = _quantize_affine_float8(x, scale, self.config.d...
1
13
2
91
0
83
95
83
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 83 and ends at 95. It contains 13 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [83.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, config: Float8FakeQuantizeConfig):super().__init__()self.config = configtorch._C._log_api_usage_once("torchao.quantization.qat.Float8FakeQuantizer")
1
4
2
29
0
107
110
78
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 107 and ends at 110. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [78.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, w: torch.Tensor) -> torch.Tensor:if self.config.activation_dtype == torch.float8_e4m3fn:return self._fp8_activations_forward(w)elif self.config.activation_dtype == torch.bfloat16:return self._bf16_activations_forward(w)else:raise ValueError(f"Unknown activation dtype {self.config.activation_dtype}")
3
7
2
59
0
112
118
112
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 112 and ends at 118. It contains 7 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [112.0] and does not return any value..
pytorch_ao
public
public
0
0
_fp8_activations_forward
def _fp8_activations_forward(self, w: torch.Tensor) -> torch.Tensor:"""Apply int4 fake quantization to the weight tensor where the input activationsare expected to be rowwise fp8, using the following as a reference:https://github.com/pytorch/FBGEMM/blob/80cc48c4b2b7fcc579e53211fc8715a8592cbd2c/fbgemm_gpu/experimental/g...
1
29
2
211
0
120
159
120
null
[]
None
null
0
0
0
null
0
null
The function (_fp8_activations_forward) defined within the public class called public.The function start at line 120 and ends at 159. It contains 29 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [120.0] and does not return any value..
pytorch_ao
public
public
0
0
_bf16_activations_forward
def _bf16_activations_forward(self, w: torch.Tensor) -> torch.Tensor:"""Apply int4 fake quantization to the weight tensor where the input activationsare expected to be bf16, using the following as a reference:https://github.com/pytorch/FBGEMM/blob/80cc48c4b2b7fcc579e53211fc8715a8592cbd2c/fbgemm_gpu/experimental/gen_ai/...
1
15
2
184
0
161
181
161
null
[]
None
null
0
0
0
null
0
null
The function (_bf16_activations_forward) defined within the public class called public.The function start at line 161 and ends at 181. It contains 15 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [161.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, config: IntxFakeQuantizeConfig):super().__init__()torch._C._log_api_usage_once("torchao.quantization.qat.IntxFakeQuantizer")self.config = configself.enabled = Trueself.scale: Optional[torch.Tensor] = Noneself.zero_point: Optional[torch.Tensor] = None# For range learning only# TODO: make this configur...
1
9
2
70
0
189
200
189
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 189 and ends at 200. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [189.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, x: torch.Tensor) -> torch.Tensor:"""Apply fake quantization to the tensor based on the bit-width,granularity, symmetry, and other properties specified in the config."""if not self.enabled:return xif (self.config.range_learningand not self._initializedand (self.scale is None or self.zero_point is None)...
8
19
2
114
0
202
226
202
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 202 and ends at 226. It contains 19 lines of code and it has a cyclomatic complexity of 8. It takes 2 parameters, represented as [202.0] and does not return any value..
pytorch_ao
public
public
0
0
_per_token_forward
def _per_token_forward(self, x: torch.Tensor) -> torch.Tensor:"""Perform per token fake quantization on the tensor."""if self.config.is_symmetric:raise NotImplementedError("Symmetric per token is not supported yet")qmin, qmax = _DTYPE_TO_QVALUE_BOUNDS[self.config.dtype]if self._should_compute_qparams():self.scale, self...
3
18
2
135
0
228
248
228
null
[]
None
null
0
0
0
null
0
null
The function (_per_token_forward) defined within the public class called public.The function start at line 228 and ends at 248. It contains 18 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [228.0] and does not return any value..
pytorch_ao
public
public
0
0
_per_channel_or_group_forward
def _per_channel_or_group_forward(self, x: torch.Tensor) -> torch.Tensor:"""Perform per channel or per group fake quantization on the tensor.We express per channel using per group where the group size is the sizeof the last dimension of the tensor."""granularity = self.config.granularityscale_precision = self.config.sc...
5
43
2
229
0
250
303
250
null
[]
None
null
0
0
0
null
0
null
The function (_per_channel_or_group_forward) defined within the public class called public.The function start at line 250 and ends at 303. It contains 43 lines of code and it has a cyclomatic complexity of 5. It takes 2 parameters, represented as [250.0] and does not return any value..
pytorch_ao
public
public
0
0
_should_compute_qparams
def _should_compute_qparams(self) -> bool:"""Return whether we need to compute new scales and zero points."""return self.config.is_dynamic or self.scale is None or self.zero_point is None
3
2
1
26
0
305
309
305
null
[]
None
null
0
0
0
null
0
null
The function (_should_compute_qparams) defined within the public class called public.The function start at line 305 and ends at 309. It contains 2 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
_maybe_update_qparams_for_range_learning
def _maybe_update_qparams_for_range_learning(self) -> None:"""If range learning is enabled, turn scales and zero points into trainable parameters.This function is idempotent and should only be called once."""if (not self.config.range_learningor isinstance(self.scale, torch.nn.Parameter)or isinstance(self.zero_point, to...
5
17
1
150
0
311
332
311
null
[]
None
null
0
0
0
null
0
null
The function (_maybe_update_qparams_for_range_learning) defined within the public class called public.The function start at line 311 and ends at 332. It contains 17 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
__init__
def __init__(self, config: FakeQuantizeConfigBase):super().__init__(config)_log_deprecation_warning(self)
1
3
2
21
0
341
343
341
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 341 and ends at 343. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [341.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,in_features: int,out_features: int,bias: bool = False,activation_config: Optional[FakeQuantizeConfigBase] = None,weight_config: Optional[FakeQuantizeConfigBase] = None,*args,**kwargs,) -> None:super().__init__(in_features,out_features,bias,*args,**kwargs,)torch._C._log_api_usage_once("torchao.quantiza...
7
37
8
164
0
67
106
67
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 67 and ends at 106. It contains 37 lines of code and it has a cyclomatic complexity of 7. It takes 8 parameters, represented as [67.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, x: torch.Tensor) -> torch.Tensor:if self.activation_fake_quantizer is not None:x = self.activation_fake_quantizer(x)if self.weight_fake_quantizer is not None:w = self.weight_fake_quantizer(self.weight)else:w = self.weightreturn F.linear(x, w, self.bias)
3
8
2
69
0
108
115
108
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 108 and ends at 115. It contains 8 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [108.0] and does not return any value..
pytorch_ao
public
public
0
0
to_linear
def to_linear(self) -> torch.nn.Linear:new_linear = torch.nn.Linear(self.in_features,self.out_features,self.bias is not None,device=self.weight.device,dtype=self.weight.dtype,)# In distributed training, the model may be instantiated# on the meta device, in which case there is no need to# copy the weights, and doing so ...
2
12
1
81
0
117
131
117
null
[]
None
null
0
0
0
null
0
null
The function (to_linear) defined within the public class called public.The function start at line 117 and ends at 131. It contains 12 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..