project_name
string
class_name
string
class_modifiers
string
class_implements
int64
class_extends
int64
function_name
string
function_body
string
cyclomatic_complexity
int64
NLOC
int64
num_parameter
int64
num_token
int64
num_variable
int64
start_line
int64
end_line
int64
function_index
int64
function_params
string
function_variable
string
function_return_type
string
function_body_line_type
string
function_num_functions
int64
function_num_lines
int64
outgoing_function_count
int64
outgoing_function_names
string
incoming_function_count
int64
incoming_function_names
string
lexical_representation
string
pytorch_ao
public
public
0
0
test_fake_quantize_config_granularity
def test_fake_quantize_config_granularity(self):"""Test initialization and property setting of `IntxFakeQuantizeConfig`'s granularity."""# per tokenper_token_config1 = IntxFakeQuantizeConfig(torch.int8, PerToken())per_token_config2 = IntxFakeQuantizeConfig(torch.int8, "per_token")self.assertIsInstance(per_token_config1...
1
31
1
295
0
818
858
818
null
[]
None
null
0
0
0
null
0
null
The function (test_fake_quantize_config_granularity) defined within the public class called public.The function start at line 818 and ends at 858. It contains 31 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_fake_quantize_config_granularity_error_cases
def test_fake_quantize_config_granularity_error_cases(self):"""Test incorrect settings of `IntxFakeQuantizeConfig`'s granularity."""# no granularity providedwith self.assertRaisesRegex(ValueError, "`granularity` or `group_size` must be set"):IntxFakeQuantizeConfig(torch.int8)# group_size with conflicting granularitymsg...
1
23
1
194
0
860
892
860
null
[]
None
null
0
0
0
null
0
null
The function (test_fake_quantize_config_granularity_error_cases) defined within the public class called public.The function start at line 860 and ends at 892. 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_fake_quantize_config_mapping_type
def test_fake_quantize_config_mapping_type(self):"""Test initialization and property setting of `IntxFakeQuantizeConfig`'s mapping type."""# symmetricsymmetric_config1 = IntxFakeQuantizeConfig(torch.int8, "per_token")symmetric_config2 = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=True)symmetric_config3...
1
36
1
248
0
894
941
894
null
[]
None
null
0
0
0
null
0
null
The function (test_fake_quantize_config_mapping_type) defined within the public class called public.The function start at line 894 and ends at 941. It contains 36 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_fake_quantize_config_dtype
def test_fake_quantize_config_dtype(self):"""Test that unsupported dtypes are caught in `IntxFakeQuantizeConfig`."""msg = "Unsupported dtype"with self.assertRaisesRegex(ValueError, msg):IntxFakeQuantizeConfig(torch.int16, "per_token")with self.assertRaisesRegex(ValueError, msg):IntxFakeQuantizeConfig(torch.int32, "per_...
1
26
1
209
0
943
972
943
null
[]
None
null
0
0
0
null
0
null
The function (test_fake_quantize_config_dtype) defined within the public class called public.The function start at line 943 and ends at 972. It contains 26 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_fake_quantize_config_dynamic_and_range_learning
def test_fake_quantize_config_dynamic_and_range_learning(self):"""Test that `is_dynamic` and `range_learning` cannot both be set."""IntxFakeQuantizeConfig(torch.int8, "per_channel", is_dynamic=True, range_learning=False)IntxFakeQuantizeConfig(torch.int8, "per_channel", is_dynamic=False, range_learning=True)with self.as...
1
11
1
64
0
974
987
974
null
[]
None
null
0
0
0
null
0
null
The function (test_fake_quantize_config_dynamic_and_range_learning) defined within the public class called public.The function start at line 974 and ends at 987. 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_fake_quantized_linear_8da4w.linear_forward_8da4w
def linear_forward_8da4w(x: torch.Tensor, weight: torch.Tensor) -> torch.Tensor:"""Baseline for int8 dynamic per token asymmetric + int4 per group symmetric quant."""# activations(s, zp) = choose_qparams_affine(x,mapping_type=MappingType.ASYMMETRIC,block_size=_get_per_token_block_size(x),target_dtype=torch.int8,quant_m...
1
20
2
158
0
1,007
1,032
1,007
null
[]
None
null
0
0
0
null
0
null
The function (test_fake_quantized_linear_8da4w.linear_forward_8da4w) defined within the public class called public.The function start at line 1007 and ends at 1032. It contains 20 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [1007.0] and does not return any value..
pytorch_ao
public
public
0
0
test_fake_quantized_linear_8da4w
def test_fake_quantized_linear_8da4w(self):"""Test that we can express int8 dynamic activations + int4 weights with `FakeQuantizedLinear`."""group_size = 128torch.manual_seed(self.SEED)fq_linear = FakeQuantizedLinear(256,688,bias=False,activation_config=IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False...
1
21
1
120
0
989
1,040
989
null
[]
None
null
0
0
0
null
0
null
The function (test_fake_quantized_linear_8da4w) defined within the public class called public.The function start at line 989 and ends at 1040. It contains 21 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_fake_quantized_linear_4w.linear_forward_4w
def linear_forward_4w(x: torch.Tensor, weight: torch.Tensor) -> torch.Tensor:"""Baseline for int4 weight only fake quantization that simulates the tinygemm kernel."""(qmin, qmax) = _get_qmin_qmax(4, symmetric=False)(s, zp) = get_groupwise_affine_qparams(weight, 4, group_size, torch.float32)zp = zp.to(torch.int32)w_fq =...
1
14
2
94
0
1,062
1,078
1,062
null
[]
None
null
0
0
0
null
0
null
The function (test_fake_quantized_linear_4w.linear_forward_4w) defined within the public class called public.The function start at line 1062 and ends at 1078. It contains 14 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [1062.0] and does not return any value..
pytorch_ao
public
public
0
0
test_fake_quantized_linear_4w
def test_fake_quantized_linear_4w(self):"""Test that we can express int4 weight only (tinygemm) with `FakeQuantizedLinear`."""group_size = 128weight_config = IntxFakeQuantizeConfig(dtype=torch.uint4,group_size=group_size,is_symmetric=False,zero_point_domain=ZeroPointDomain.FLOAT,)torch.manual_seed(self.SEED)fq_linear =...
1
23
1
125
0
1,042
1,086
1,042
null
[]
None
null
0
0
0
null
0
null
The function (test_fake_quantized_linear_4w) defined within the public class called public.The function start at line 1042 and ends at 1086. 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_replace_linear_8da4w
def test_replace_linear_8da4w(self):module = torch.nn.ModuleList([torch.nn.Linear(in_features=256, out_features=50, bias=True),torch.nn.Linear(in_features=256, out_features=50, bias=False),])_replace_linear_8da4w(module,256,False,torch.float32,torch.float32,Int8DynActInt4WeightQATLinear,copy_weights=True,)assert isinst...
1
18
1
97
0
1,088
1,105
1,088
null
[]
None
null
0
0
0
null
0
null
The function (test_replace_linear_8da4w) defined within the public class called public.The function start at line 1088 and ends at 1105. It contains 18 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_replace_linear_int4
def test_replace_linear_int4(self):module = torch.nn.ModuleList([torch.nn.Linear(in_features=256, out_features=50, bias=True)])_replace_linear_int4(module,256,8,padding_allowed=True,precision=torch.bfloat16,scales_precision=torch.bfloat16,linear_class=Int4WeightOnlyQATLinear,copy_weights=True,)assert not isinstance(mod...
2
31
1
164
0
1,107
1,137
1,107
null
[]
None
null
0
0
0
null
0
null
The function (test_replace_linear_int4) defined within the public class called public.The function start at line 1107 and ends at 1137. It contains 31 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_fake_quantized_embedding_4w.embedding_forward_4w
def embedding_forward_4w(x: torch.Tensor, weight: torch.Tensor) -> torch.Tensor:"""Baseline for int4 per group symmetric weight only fake quantization."""(s, zp) = get_group_qparams_symmetric(weight, 4, group_size, torch.float32)zp = zp.to(torch.int32)(qmin, qmax) = _get_qmin_qmax(4)w_fq = _fake_quantize_per_channel_gr...
1
8
2
83
0
1,156
1,166
1,156
null
[]
None
null
0
0
0
null
0
null
The function (test_fake_quantized_embedding_4w.embedding_forward_4w) defined within the public class called public.The function start at line 1156 and ends at 1166. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [1156.0] and does not return any value..
pytorch_ao
public
public
0
0
test_fake_quantized_embedding_4w
def test_fake_quantized_embedding_4w(self):"""Test that we can express int4 per group symmetric weight only fake quantizationwith `FakeQuantizedEmbedding`."""num_embeddings = 64embedding_dim = 128group_size = 32torch.manual_seed(self.SEED)fq_embedding = FakeQuantizedEmbedding(num_embeddings,embedding_dim,weight_config=...
1
19
1
111
0
1,139
1,174
1,139
null
[]
None
null
0
0
0
null
0
null
The function (test_fake_quantized_embedding_4w) defined within the public class called public.The function start at line 1139 and ends at 1174. 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_qat_prototype_bc
def test_qat_prototype_bc(self):"""Just to make sure we can import all the old prototype paths.We will remove this test in the near future when we actually break BC."""from torchao.quantization.prototype.qat import (# noqa: F401, F811, I001disable_4w_fake_quant,disable_8da4w_fake_quant,enable_4w_fake_quant,enable_8da4w...
1
48
1
161
0
1,176
1,227
1,176
null
[]
None
null
0
0
0
null
0
null
The function (test_qat_prototype_bc) defined within the public class called public.The function start at line 1176 and ends at 1227. It contains 48 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_qat_config_init
def test_qat_config_init(self):"""Test that the correct errors are thrown if `QATConfig` is not instantiated properly."""base_config = Int8DynamicActivationInt4WeightConfig(group_size=32)fq_config = IntxFakeQuantizeConfig(torch.int8, "per_channel")# OKQATConfig(base_config, step="prepare")QATConfig(base_config, step="c...
1
37
1
275
0
1,229
1,282
1,229
null
[]
None
null
0
0
0
null
0
null
The function (test_qat_config_init) defined within the public class called public.The function start at line 1229 and ends at 1282. It contains 37 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_prepare
def test_quantize_api_prepare(self):"""Test that the following:quantize_(model, QATConfig(...))can produce the same results as `ComposableQATQuantizer`."""from torchao.quantization.qat import (ComposableQATQuantizer,Int4WeightOnlyEmbeddingQATQuantizer,Int8DynActInt4WeightQATQuantizer,)group_size = 16torch.manual_seed(s...
1
33
1
205
0
1,284
1,330
1,284
null
[]
None
null
0
0
0
null
0
null
The function (test_quantize_api_prepare) defined within the public class called public.The function start at line 1284 and ends at 1330. It contains 33 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_errors
def test_quantize_api_errors(self):"""Test that we throw exceptions with helpful error messages if `quantize_`runs into unexpected configurations."""fq_config = IntxFakeQuantizeConfig(torch.int8, group_size=32)qat_config = QATConfig(activation_config=fq_config, weight_config=fq_config)m = M3()# Embedding currently only...
1
10
1
99
0
1,332
1,349
1,332
null
[]
None
null
0
0
0
null
0
null
The function (test_quantize_api_errors) defined within the public class called public.The function start at line 1332 and ends at 1349. 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_quantize_api_e2e
def test_quantize_api_e2e(self):"""Test that the following:quantize_(model, QATConfig(Int8DynamicActivationInt4WeightConfig(), step="prepare"))quantize_(model, QATConfig(Int8DynamicActivationInt4WeightConfig(), step="convert"))can produce the same results as `Int8DynActInt4WeightQATQuantizer` prepare + convert."""from ...
1
26
1
209
0
1,351
1,397
1,351
null
[]
None
null
0
0
0
null
0
null
The function (test_quantize_api_e2e) defined within the public class called public.The function start at line 1351 and ends at 1397. It contains 26 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_fake_quantize_config_torch_intx
def test_fake_quantize_config_torch_intx(self):"""Test that `IntxFakeQuantizeConfig` works with torch.intx."""group_size = 16config1 = IntxFakeQuantizeConfig(TorchAODType.INT4, group_size=group_size)config2 = IntxFakeQuantizeConfig(torch.int4, group_size=group_size)linear1 = FakeQuantizedLinear(32, 64, weight_config=co...
1
13
1
131
0
1,399
1,414
1,399
null
[]
None
null
0
0
0
null
0
null
The function (test_fake_quantize_config_torch_intx) defined within the public class called public.The function start at line 1399 and ends at 1414. It contains 13 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_fake_quantizer_repr
def test_fake_quantizer_repr(self):"""Test that `repr(IntxFakeQuantizer(config))` exposes useful config details."""config = IntxFakeQuantizeConfig(torch.int4, group_size=128)fake_quantizer = IntxFakeQuantizer(config)fake_quantizer_repr = repr(fake_quantizer)self.assertTrue("dtype=torch.int4" in fake_quantizer_repr)self...
1
8
1
62
0
1,416
1,426
1,416
null
[]
None
null
0
0
0
null
0
null
The function (test_fake_quantizer_repr) defined within the public class called public.The function start at line 1416 and ends at 1426. 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_qat_linear_bias
def test_qat_linear_bias(self):"""Test that QAT supports linear bias."""m = ModelWithLinearBias()act_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)weight_config = IntxFakeQuantizeConfig(TorchAODType.INT4, group_size=32)qat_config = QATConfig(activation_config=act_config, weight_config=weig...
1
10
1
67
0
1,428
1,440
1,428
null
[]
None
null
0
0
0
null
0
null
The function (test_qat_linear_bias) defined within the public class called public.The function start at line 1428 and ends at 1440. 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_fake_quantize_per_token_vs_convert
def test_fake_quantize_per_token_vs_convert(self, dtype: torch.dtype):"""Test that the following produce the exact same numerics:1. IntxFakeQuantizer with asymmetric per_token config2. torchao.quantization.utils.per_token_dynamic_quant"""from torchao.quantization.utils import per_token_dynamic_quanttorch.manual_seed(se...
1
9
2
95
0
1,443
1,457
1,443
null
[]
None
null
0
0
0
null
0
null
The function (test_fake_quantize_per_token_vs_convert) defined within the public class called public.The function start at line 1443 and ends at 1457. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [1443.0] and does not return any value..
pytorch_ao
public
public
0
0
test_qat_8da4w_prepare_vs_convert
def test_qat_8da4w_prepare_vs_convert(self, dtype: torch.dtype):"""Test that the prepare and convert steps of Int8DynActInt4QATQuantizer producesnumerics that match exactly over N trials."""from torchao.quantization.qat import Int8DynActInt4WeightQATQuantizernum_trials = 1000group_size = 16non_inf_sqnr = []for seed in ...
4
29
2
194
0
1,460
1,496
1,460
null
[]
None
null
0
0
0
null
0
null
The function (test_qat_8da4w_prepare_vs_convert) defined within the public class called public.The function start at line 1460 and ends at 1496. It contains 29 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [1460.0] and does not return any value..
pytorch_ao
public
public
0
0
test_fake_quantize_config_eps
def test_fake_quantize_config_eps(self):"""Test that users can set arbitrary eps value in `IntxFakeQuantizeConfig`."""eps = 0.00123x = torch.randn(2, 3).to(torch.float32)scale, zp = choose_qparams_affine(x,mapping_type=MappingType.ASYMMETRIC,block_size=(1, 3),target_dtype=torch.int8,quant_min=-128,quant_max=127,eps=eps...
1
22
1
134
0
1,498
1,522
1,498
null
[]
None
null
0
0
0
null
0
null
The function (test_fake_quantize_config_eps) defined within the public class called public.The function start at line 1498 and ends at 1522. It contains 22 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_qat_8da4w_eps
def test_qat_8da4w_eps(self):"""Test that the 8da4w QAT flow uses the expected eps."""from torchao.quantization.qat import Int8DynActInt4WeightQATQuantizerfrom torchao.quantization.utils import per_token_dynamic_quantgroup_size = 16torch.manual_seed(self.SEED)m = M()quantizer = Int8DynActInt4WeightQATQuantizer(groupsiz...
1
37
1
225
0
1,524
1,568
1,524
null
[]
None
null
0
0
0
null
0
null
The function (test_qat_8da4w_eps) defined within the public class called public.The function start at line 1524 and ends at 1568. It contains 37 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_fake_quantizer_range_learning
def test_fake_quantizer_range_learning(self, is_symmetric):"""Test that range learning requires `IntxFakeQuantizer`s to be initialized correctly."""config = IntxFakeQuantizeConfig(torch.int8,"per_channel",is_dynamic=False,range_learning=True,scale_precision=torch.float32,zero_point_precision=torch.float32,is_symmetric=...
2
32
2
209
0
1,571
1,609
1,571
null
[]
None
null
0
0
0
null
0
null
The function (test_fake_quantizer_range_learning) defined within the public class called public.The function start at line 1571 and ends at 1609. It contains 32 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [1571.0] and does not return any value..
pytorch_ao
public
public
0
0
test_qat_range_learning
def test_qat_range_learning(self, is_symmetric):"""Test end-to-end QAT flow with range learning."""config = IntxFakeQuantizeConfig(torch.int8,"per_channel",is_dynamic=False,range_learning=True,scale_precision=torch.float32,zero_point_precision=torch.float32,is_symmetric=is_symmetric,)m = M()example_inputs = m.example_i...
6
58
2
438
0
1,612
1,684
1,612
null
[]
None
null
0
0
0
null
0
null
The function (test_qat_range_learning) defined within the public class called public.The function start at line 1612 and ends at 1684. It contains 58 lines of code and it has a cyclomatic complexity of 6. It takes 2 parameters, represented as [1612.0] and does not return any value..
pytorch_ao
public
public
0
0
test_qat_fp8a4w_quantizer
def test_qat_fp8a4w_quantizer(self):"""Test basic model training with `Float8ActInt4WeightQATQuantizer`."""torch.manual_seed(self.SEED)m = M()qat_quantizer = Float8ActInt4WeightQATQuantizer()qat_model = qat_quantizer.prepare(m)for linear in [m.linear1, m.sub.linear, m.linear2]:self.assertIsInstance(linear, FakeQuantize...
2
28
1
227
0
1,686
1,719
1,686
null
[]
None
null
0
0
0
null
0
null
The function (test_qat_fp8a4w_quantizer) defined within the public class called public.The function start at line 1686 and ends at 1719. It contains 28 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_legacy_quantize_api_e2e
def test_legacy_quantize_api_e2e(self):"""Test that the following two APIs are numerically equivalent:New API:quantize_(model, QATConfig(Int8DynamicActivationInt4WeightConfig(), step="prepare"))quantize_(model, QATConfig(Int8DynamicActivationInt4WeightConfig(), step="convert"))Old API:quantize_(model, IntXQuantizationA...
1
26
1
228
0
1,721
1,770
1,721
null
[]
None
null
0
0
0
null
0
null
The function (test_legacy_quantize_api_e2e) defined within the public class called public.The function start at line 1721 and ends at 1770. It contains 26 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_qat_api_deprecation
def test_qat_api_deprecation(self):"""Test that the appropriate deprecation warning is logged exactly once per class."""from torchao.quantization.qat import (FakeQuantizeConfig,FakeQuantizer,from_intx_quantization_aware_training,intx_quantization_aware_training,)# Reset deprecation warning state, otherwise we won't log...
3
26
1
142
0
1,772
1,808
1,772
null
[]
None
null
0
0
0
null
0
null
The function (test_qat_api_deprecation) defined within the public class called public.The function start at line 1772 and ends at 1808. It contains 26 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_qat_api_convert_no_quantization
def test_qat_api_convert_no_quantization(self):"""Test that `QATConfig(step="convert")` swaps back to nn modules without quantization."""torch.manual_seed(self.SEED)m = M()baseline_model = copy.deepcopy(m)# Prepare swaps to FakeQuantizedLinearquantize_(m, QATConfig(Int8DynamicActivationInt4WeightConfig(), step="prepare...
1
18
1
202
0
1,810
1,836
1,810
null
[]
None
null
0
0
0
null
0
null
The function (test_qat_api_convert_no_quantization) defined within the public class called public.The function start at line 1810 and ends at 1836. It contains 18 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_float8_fake_quantize_config
def test_float8_fake_quantize_config(self):"""Test that the correct errors are thrown if `Float8FakeQuantizeConfig` is not instantiated properly."""# OKFloat8FakeQuantizeConfig(torch.float8_e4m3fn)Float8FakeQuantizeConfig(torch.float8_e4m3fn, PerRow())Float8FakeQuantizeConfig(torch.float8_e4m3fn, PerTensor())with self....
1
14
1
82
0
1,838
1,856
1,838
null
[]
None
null
0
0
0
null
0
null
The function (test_float8_fake_quantize_config) defined within the public class called public.The function start at line 1838 and ends at 1856. 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_float8_fake_quantize
def test_float8_fake_quantize(self, granularity: Granularity):"""Test that `Float8FakeQuantizer` is numerically close to `Float8Tensor`."""dtype = torch.float8_e4m3fnfq_config = Float8FakeQuantizeConfig(dtype, granularity)fake_quantizer = Float8FakeQuantizer(fq_config)torch.manual_seed(self.SEED)x = torch.randn(32, 64)...
1
10
2
85
0
1,859
1,871
1,859
null
[]
None
null
0
0
0
null
0
null
The function (test_float8_fake_quantize) defined within the public class called public.The function start at line 1859 and ends at 1871. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [1859.0] and does not return any value..
pytorch_ao
public
public
0
0
_test_quantize_api_against_ptq
def _test_quantize_api_against_ptq(self,base_config: AOBaseConfig,target_prepare_sqnr: float,target_convert_sqnr: float,dtype: torch.dtype = torch.bfloat16,module_type: str = "linear",):"""Test the following:quantize_(model, QATConfig(base_config, step="prepare"))quantize_(model, QATConfig(base_config, step="convert"))...
3
30
6
261
0
1,873
1,919
1,873
null
[]
None
null
0
0
0
null
0
null
The function (_test_quantize_api_against_ptq) defined within the public class called public.The function start at line 1873 and ends at 1919. It contains 30 lines of code and it has a cyclomatic complexity of 3. It takes 6 parameters, represented as [1873.0] and does not return any value..
pytorch_ao
public
public
0
0
test_quantize_api_fp8_fp8
def test_quantize_api_fp8_fp8(self, granularity: Granularity):"""Test the following:quantize_(model, QATConfig(Float8DynamicActivationFloat8Weight(), step="prepare"))quantize_(model, QATConfig(Float8DynamicActivationFloat8Weight(), step="convert"))"""self._test_quantize_api_against_ptq(Float8DynamicActivationFloat8Weig...
1
6
2
33
0
1,924
1,934
1,924
null
[]
None
null
0
0
0
null
0
null
The function (test_quantize_api_fp8_fp8) defined within the public class called public.The function start at line 1924 and ends at 1934. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [1924.0] and does not return any value..
pytorch_ao
public
public
0
0
test_quantize_api_fp8_int4
def test_quantize_api_fp8_int4(self):"""Test the following:quantize_(model, QATConfig(Float8DynamicActivationInt4WeightConfig(), step="prepare"))quantize_(model, QATConfig(Float8DynamicActivationInt4WeightConfig(), step="convert"))"""self._test_quantize_api_against_ptq(Float8DynamicActivationInt4WeightConfig(),target_p...
1
6
1
26
0
1,941
1,951
1,941
null
[]
None
null
0
0
0
null
0
null
The function (test_quantize_api_fp8_int4) defined within the public class called public.The function start at line 1941 and ends at 1951. 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_quantize_api_int4
def test_quantize_api_int4(self, version: int, packing_format: Int4PackingFormat):"""Test the following:quantize_(model, QATConfig(Int4WeightOnlyConfig(), step="prepare"))quantize_(model, QATConfig(Int4WeightOnlyConfig(), step="convert"))"""self._test_quantize_api_against_ptq(Int4WeightOnlyConfig(version=version, int4_...
2
6
3
47
0
1,962
1,972
1,962
null
[]
None
null
0
0
0
null
0
null
The function (test_quantize_api_int4) defined within the public class called public.The function start at line 1962 and ends at 1972. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [1962.0] and does not return any value..
pytorch_ao
public
public
0
0
test_quantize_api_int8_int4
def test_quantize_api_int8_int4(self):"""Test the following:quantize_(model, QATConfig(Int8DynamicActivationInt4WeightConfig(), step="prepare"))quantize_(model, QATConfig(Int8DynamicActivationInt4WeightConfig(), step="convert"))"""self._test_quantize_api_against_ptq(Int8DynamicActivationInt4WeightConfig(group_size=32),...
1
6
1
29
0
1,975
1,985
1,975
null
[]
None
null
0
0
0
null
0
null
The function (test_quantize_api_int8_int4) defined within the public class called public.The function start at line 1975 and ends at 1985. 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_quantize_api_int8_intx
def test_quantize_api_int8_intx(self, weight_dtype, weight_granularity, dtype):"""Test the following:quantize_(model, QATConfig(Int8DynamicActivationIntxWeightConfig(), step="prepare"))quantize_(model, QATConfig(Int8DynamicActivationIntxWeightConfig(), step="convert"))"""self._test_quantize_api_against_ptq(Int8DynamicA...
1
9
4
46
0
1,997
2,010
1,997
null
[]
None
null
0
0
0
null
0
null
The function (test_quantize_api_int8_intx) defined within the public class called public.The function start at line 1997 and ends at 2010. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [1997.0] and does not return any value..
pytorch_ao
public
public
0
0
test_quantize_api_intx
def test_quantize_api_intx(self, weight_dtype, granularity, dtype, module_type):"""Test the following:quantize_(model, QATConfig(IntxWeightOnlyConfig(), step="prepare"))quantize_(model, QATConfig(IntxWeightOnlyConfig(), step="convert"))"""self._test_quantize_api_against_ptq(IntxWeightOnlyConfig(weight_dtype=weight_dtyp...
1
8
5
52
0
2,023
2,035
2,023
null
[]
None
null
0
0
0
null
0
null
The function (test_quantize_api_intx) defined within the public class called public.The function start at line 2023 and ends at 2035. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [2023.0] and does not return any value..
pytorch_ao
public
public
0
0
test_infer_fp8_int4_config
def test_infer_fp8_int4_config(self):"""Test that fake quantize configs are correctly inferred from`Float8DynamicActivationInt4WeightConfig`."""from torchao.quantization.qat.fake_quantize_config import (_infer_fake_quantize_configs,)base_config = Float8DynamicActivationInt4WeightConfig()(act_config, weight_config) = _i...
1
12
1
90
0
2,037
2,053
2,037
null
[]
None
null
0
0
0
null
0
null
The function (test_infer_fp8_int4_config) defined within the public class called public.The function start at line 2037 and ends at 2053. 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_infer_int4_weight_only_config
def test_infer_int4_weight_only_config(self):"""Test that fake quantize configs are correctly inferred from `Int4WeightOnlyConfig`."""from torchao.quantization.qat.fake_quantize_config import (_infer_fake_quantize_configs,)base_config = Int4WeightOnlyConfig(version=1)(act_config, weight_config) = _infer_fake_quantize_c...
1
17
1
135
0
2,055
2,076
2,055
null
[]
None
null
0
0
0
null
0
null
The function (test_infer_int4_weight_only_config) defined within the public class called public.The function start at line 2055 and ends at 2076. It contains 17 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_quantize_api_nvfp4
def test_quantize_api_nvfp4(self, use_per_tensor_scale: bool):"""Test the following:quantize_(model, QATConfig(NVFP4InferenceConfig(), step="prepare"))quantize_(model, QATConfig(NVFP4InferenceConfig(), step="convert"))"""from torchao.prototype.mx_formats import NVFP4InferenceConfigself._test_quantize_api_against_ptq(NV...
1
7
2
44
0
2,080
2,092
2,080
null
[]
None
null
0
0
0
null
0
null
The function (test_quantize_api_nvfp4) defined within the public class called public.The function start at line 2080 and ends at 2092. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [2080.0] and does not return any value..
pytorch_ao
public
public
0
0
test_qat_nvfp4
def test_qat_nvfp4(self, use_per_tensor_scale: bool):"""Test QAT with `NVFP4FakeQuantizeConfig`."""from torchao.prototype.mx_formats import NVFP4InferenceConfigfrom torchao.prototype.qat import NVFP4FakeQuantizeConfigtorch.manual_seed(self.SEED)m = M().cuda()baseline_model = copy.deepcopy(m)quantize_(baseline_model,NVF...
1
22
2
145
0
2,097
2,124
2,097
null
[]
None
null
0
0
0
null
0
null
The function (test_qat_nvfp4) defined within the public class called public.The function start at line 2097 and ends at 2124. It contains 22 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [2097.0] and does not return any value..
pytorch_ao
public
public
0
0
test_fbgemm_fp8_primitives
def test_fbgemm_fp8_primitives(self):"""Compare numerics between:(1) fbgemm_gpu.experimental.gen_ai.quantize.quantize_fp8_row(2) Our reference QAT version in `Float8FakeQuantizer`"""from fbgemm_gpu.experimental.gen_ai.quantize import quantize_fp8_rowfrom torchao.quantization.quant_primitives import (_choose_scale_float...
1
23
1
179
0
2,131
2,164
2,131
null
[]
None
null
0
0
0
null
0
null
The function (test_fbgemm_fp8_primitives) defined within the public class called public.The function start at line 2131 and ends at 2164. 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_fbgemm_fp8_int4_preshuffled_primitives.shuffle_and_pack
def shuffle_and_pack(t: torch.Tensor, scale: torch.Tensor) -> torch.Tensor:t = pack_int4(t.to(torch.int8))return torch.ops.fbgemm.preshuffle_i4(t, scale.to(torch.float8_e4m3fn))[0]
1
3
2
55
0
2,225
2,227
2,225
null
[]
None
null
0
0
0
null
0
null
The function (test_fbgemm_fp8_int4_preshuffled_primitives.shuffle_and_pack) defined within the public class called public.The function start at line 2225 and ends at 2227. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [2225.0] and does not return any value..
pytorch_ao
public
public
0
0
test_fbgemm_fp8_int4_preshuffled_primitives
def test_fbgemm_fp8_int4_preshuffled_primitives(self):"""Compare numerics between:(1) fbgemm_gpu.experimental.gen_ai.quantize.quantize_int4_preshuffle(2) Our reference QAT version in `Int4WeightFakeQuantizer`"""from fbgemm_gpu.experimental.gen_ai.quantize import (int4_row_quantize,pack_int4,quantize_fp8_row,quantize_in...
1
54
1
399
0
2,171
2,246
2,171
null
[]
None
null
0
0
0
null
0
null
The function (test_fbgemm_fp8_int4_preshuffled_primitives) defined within the public class called public.The function start at line 2171 and ends at 2246. It contains 54 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_fbgemm_int4_weight_only_primitives.shuffle_and_pack
def shuffle_and_pack(t: torch.Tensor, scale: torch.Tensor) -> torch.Tensor:t = pack_int4(t.to(torch.int8))return torch.ops.fbgemm.preshuffle_i4(t, scale.to(torch.bfloat16))[0]
1
3
2
55
0
2,289
2,291
2,289
null
[]
None
null
0
0
0
null
0
null
The function (test_fbgemm_int4_weight_only_primitives.shuffle_and_pack) defined within the public class called public.The function start at line 2289 and ends at 2291. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [2289.0] and does not return any value..
pytorch_ao
public
public
0
0
test_fbgemm_int4_weight_only_primitives
def test_fbgemm_int4_weight_only_primitives(self):"""Compare numerics between:(1) fbgemm_gpu.experimental.gen_ai.quantize.int4_row_quantize_zp(2) Our reference QAT version in `Int4WeightFakeQuantizer`"""from fbgemm_gpu.experimental.gen_ai.quantize import (int4_row_quantize_zp,pack_int4,quantize_int4_preshuffle,)group_s...
1
37
1
360
0
2,253
2,311
2,253
null
[]
None
null
0
0
0
null
0
null
The function (test_fbgemm_int4_weight_only_primitives) defined within the public class called public.The function start at line 2253 and ends at 2311. It contains 37 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_range_learning_convert_pass_qparams
def test_range_learning_convert_pass_qparams(self, base_config_cls: Type[AOBaseConfig]):"""Verify that range learning QAT can pass qparams from the preparedmodel to the convert model."""group_size = 32config = IntxFakeQuantizeConfig(torch.int4,group_size=group_size,is_symmetric=True,is_dynamic=False,range_learning=True...
2
36
2
266
0
2,321
2,362
2,321
null
[]
None
null
0
0
0
null
0
null
The function (test_range_learning_convert_pass_qparams) defined within the public class called public.The function start at line 2321 and ends at 2362. It contains 36 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [2321.0] and does not return any value..
pytorch_ao
public
public
0
0
dynamic_quant
def dynamic_quant(model, example_inputs):m = torch.export.export(model, example_inputs, strict=True).module()quantizer = XNNPACKQuantizer().set_global(get_symmetric_quantization_config(is_dynamic=True))m = prepare_pt2e(m, quantizer)m = convert_pt2e(m)return m
1
8
2
58
2
84
91
84
null
['quantizer', 'm']
None
null
0
0
0
null
0
null
The function (dynamic_quant) defined within the public class called public.The function start at line 84 and ends at 91. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [84.0] and does not return any value..
pytorch_ao
public
public
0
0
capture_and_prepare
def capture_and_prepare(model, example_inputs):m = torch.export.export(model, example_inputs, strict=True)quantizer = XNNPACKQuantizer().set_global(get_symmetric_quantization_config(is_dynamic=True))m = prepare_pt2e(m, quantizer)# TODO: we can run the weight observer in convert_pt2e so that user don't need to run thism...
1
8
2
53
2
94
102
94
null
['quantizer', 'm']
None
null
0
0
0
null
0
null
The function (capture_and_prepare) defined within the public class called public.The function start at line 94 and ends at 102. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [94.0] and does not return any value..
pytorch_ao
public
public
0
0
prepare
def prepare(self, model: torch.nn.Module) -> torch.nn.Module:_replace_with_custom_fn_if_matches_filter(model,lambda linear_mod: capture_and_prepare(linear_mod, (torch.randn(1, linear_mod.in_features))),lambda mod, fqn: isinstance(mod, torch.nn.Linear),)return model
1
9
2
63
0
106
114
106
null
[]
None
null
0
0
0
null
0
null
The function (prepare) defined within the public class called public.The function start at line 106 and ends at 114. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [106.0] and does not return any value..
pytorch_ao
public
public
0
0
convert
def convert(self, model: torch.nn.Module) -> torch.nn.Module:_replace_with_custom_fn_if_matches_filter(model,lambda linear_mod: convert_pt2e(linear_mod),lambda mod, fqn: isinstance(mod, torch.fx.GraphModule),)return model
1
7
2
50
0
116
122
116
null
[]
None
null
0
0
0
null
0
null
The function (convert) defined within the public class called public.The function start at line 116 and ends at 122. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [116.0] and does not return any value..
pytorch_ao
public
public
0
0
quantize
def quantize(self, model: torch.nn.Module) -> torch.nn.Module:quantize_(model, Int8DynamicActivationInt8WeightConfig())return model
1
3
2
29
0
126
128
126
null
[]
None
null
0
0
0
null
0
null
The function (quantize) defined within the public class called public.The function start at line 126 and ends at 128. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [126.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, m=64, n=32, k=64, bias=False):super().__init__()self.linear1 = torch.nn.Linear(m, n, bias=bias).to(torch.float)self.linear2 = torch.nn.Linear(n, k, bias=bias).to(torch.float)
1
4
5
78
0
132
135
132
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 132 and ends at 135. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [132.0] and does not return any value..
pytorch_ao
public
public
0
0
example_inputs
def example_inputs(self, batch_size=1, dtype=torch.float, device="cpu"):return (torch.randn(batch_size, self.linear1.in_features, dtype=dtype, device=device),)
1
6
4
43
0
137
142
137
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 137 and ends at 142. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [137.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)return x
1
4
2
25
0
144
147
144
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 144 and ends at 147. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [144.0] and does not return any value..
pytorch_ao
public
public
0
0
_get_ref_change_linear_weights_to_woqtensors._ref_change_linear_weights_to_woqtensors
def _ref_change_linear_weights_to_woqtensors(model, filter_fn=None, **kwargs):"""The deprecated implementation for weight only quant API, used as a reference fornumerics and performance"""from torchao.quantization.quant_api import _get_subclass_inserter, _is_linearfilter_fn = kwargs.pop("filter_fn", _is_linear)_replace...
1
10
3
52
0
151
166
151
null
[]
None
null
0
0
0
null
0
null
The function (_get_ref_change_linear_weights_to_woqtensors._ref_change_linear_weights_to_woqtensors) defined within the public class called public.The function start at line 151 and ends at 166. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [151.0] and does ...
pytorch_ao
public
public
0
0
_get_ref_change_linear_weights_to_woqtensors
def _get_ref_change_linear_weights_to_woqtensors(deprecated_tenosr_subclass):def _ref_change_linear_weights_to_woqtensors(model, filter_fn=None, **kwargs):"""The deprecated implementation for weight only quant API, used as a reference fornumerics and performance"""from torchao.quantization.quant_api import _get_subclas...
1
3
1
9
1
150
168
150
null
['filter_fn']
None
null
0
0
0
null
0
null
The function (_get_ref_change_linear_weights_to_woqtensors) defined within the public class called public.The function start at line 150 and ends at 168. 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_dynamic_quant_gpu_singleline
def test_dynamic_quant_gpu_singleline(self):m = ToyLinearModel().eval()example_inputs = m.example_inputs()quantize_(m, Int8DynamicActivationInt8WeightConfig())m(*example_inputs)
1
5
1
34
0
184
188
184
null
[]
None
null
0
0
0
null
0
null
The function (test_dynamic_quant_gpu_singleline) defined within the public class called public.The function start at line 184 and ends at 188. 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
test_dynamic_quant_gpu_unified_api_unified_impl
def test_dynamic_quant_gpu_unified_api_unified_impl(self):quantizer = XNNPackDynamicQuantizer()m = ToyLinearModel().eval()example_inputs = m.example_inputs()m = quantizer.prepare(m)m = quantizer.convert(m)quantized = m(*example_inputs)# AssertionError: Expecting input to have dtype torch.float32, but got dtype: torch.f...
1
10
1
86
0
197
209
197
null
[]
None
null
0
0
0
null
0
null
The function (test_dynamic_quant_gpu_unified_api_unified_impl) defined within the public class called public.The function start at line 197 and ends at 209. 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_dynamic_quant_gpu_unified_api_eager_mode_impl
def test_dynamic_quant_gpu_unified_api_eager_mode_impl(self):quantizer = TorchCompileDynamicQuantizer()m = ToyLinearModel().eval()example_inputs = m.example_inputs()m = quantizer.quantize(m)quantized = m(*example_inputs)m = torch.compile(m, mode="max-autotune")compiled = m(*example_inputs)torch.testing.assert_close(qua...
1
9
1
78
0
214
222
214
null
[]
None
null
0
0
0
null
0
null
The function (test_dynamic_quant_gpu_unified_api_eager_mode_impl) defined within the public class called public.The function start at line 214 and ends at 222. 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_int4_wo_quant_save_load.api
def api(model):quantize_(model, Int4WeightOnlyConfig(layout=Int4XPULayout(), version=1))unwrap_tensor_subclass(model)
1
3
1
26
0
229
231
229
null
[]
None
null
0
0
0
null
0
null
The function (test_int4_wo_quant_save_load.api) defined within the public class called public.The function start at line 229 and ends at 231. 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_int4_wo_quant_save_load
def test_int4_wo_quant_save_load(self):m = ToyLinearModel().eval().cpu()def api(model):quantize_(model, Int4WeightOnlyConfig(layout=Int4XPULayout(), version=1))unwrap_tensor_subclass(model)api(m)example_inputs = m.example_inputs()ref = m(*example_inputs)with tempfile.NamedTemporaryFile() as f:torch.save(m.state_dict(),...
1
17
1
142
0
226
250
226
null
[]
None
null
0
0
0
null
0
null
The function (test_int4_wo_quant_save_load) defined within the public class called public.The function start at line 226 and ends at 250. It contains 17 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_int8_wo_quant_save_load.api
def api(model):quantize_(model, Int8WeightOnlyConfig())unwrap_tensor_subclass(model)
1
3
1
17
0
256
258
256
null
[]
None
null
0
0
0
null
0
null
The function (test_int8_wo_quant_save_load.api) defined within the public class called public.The function start at line 256 and ends at 258. It contains 3 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_int8_wo_quant_save_load
def test_int8_wo_quant_save_load(self):m = ToyLinearModel().eval().cpu()def api(model):quantize_(model, Int8WeightOnlyConfig())unwrap_tensor_subclass(model)api(m)example_inputs = m.example_inputs()ref = m(*example_inputs)with tempfile.NamedTemporaryFile() as f:torch.save(m.state_dict(), f)f.seek(0)state_dict = torch.lo...
2
18
1
175
0
253
279
253
null
[]
None
null
0
0
0
null
0
null
The function (test_int8_wo_quant_save_load) defined within the public class called public.The function start at line 253 and ends at 279. 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
test_8da4w_quantizer
def test_8da4w_quantizer(self):from torchao.quantization.linear_quant_modules import Int8DynActInt4WeightLinearfrom torchao.quantization.quant_api import Int8DynActInt4WeightQuantizerquantizer = Int8DynActInt4WeightQuantizer(groupsize=32)m = ToyLinearModel().eval()example_inputs = m.example_inputs()m = quantizer.quanti...
1
10
1
76
0
281
291
281
null
[]
None
null
0
0
0
null
0
null
The function (test_8da4w_quantizer) defined within the public class called public.The function start at line 281 and ends at 291. 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_8da4w_quantizer_linear_bias
def test_8da4w_quantizer_linear_bias(self):from torchao.quantization.linear_quant_modules import Int8DynActInt4WeightLinearfrom torchao.quantization.quant_api import Int8DynActInt4WeightQuantizerquantizer = Int8DynActInt4WeightQuantizer(groupsize=32)m = ToyLinearModel(bias=True).eval()example_inputs = m.example_inputs(...
1
10
1
79
0
293
303
293
null
[]
None
null
0
0
0
null
0
null
The function (test_8da4w_quantizer_linear_bias) defined within the public class called public.The function start at line 293 and ends at 303. 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_quantizer_int4_weight_only
def test_quantizer_int4_weight_only(self):from torchao._models._eval import TransformerEvalWrapperfrom torchao.quantization.linear_quant_modules import Int4WeightOnlyQuantizerprecision = torch.bfloat16device = "cuda"checkpoint_path = Path("../checkpoints/meta-llama/Llama-2-7b-chat-hf/model.pth")model = Transformer.from...
1
35
1
190
0
306
341
306
null
[]
None
null
0
0
0
null
0
null
The function (test_quantizer_int4_weight_only) defined within the public class called public.The function start at line 306 and ends at 341. It contains 35 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_eval_wrapper
def test_eval_wrapper(self):from torchao._models._eval import TransformerEvalWrapperprecision = torch.bfloat16device = "cuda"checkpoint_path = Path("../checkpoints/meta-llama/Llama-2-7b-chat-hf/model.pth")model = Transformer.from_name(checkpoint_path.parent.name)checkpoint = torch.load(str(checkpoint_path), mmap=True, ...
1
29
1
160
0
344
373
344
null
[]
None
null
0
0
0
null
0
null
The function (test_eval_wrapper) defined within the public class called public.The function start at line 344 and ends at 373. It contains 29 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_eval_wrapper_llama3
def test_eval_wrapper_llama3(self):from torchao._models._eval import TransformerEvalWrapperprecision = torch.bfloat16device = "cuda"checkpoint_path = Path(".../gpt-fast/checkpoints/meta-llama/Meta-Llama-3-8B/model.pth")model = Transformer.from_name(checkpoint_path.parent.name)checkpoint = torch.load(str(checkpoint_path...
1
31
1
160
0
377
408
377
null
[]
None
null
0
0
0
null
0
null
The function (test_eval_wrapper_llama3) defined within the public class called public.The function start at line 377 and ends at 408. It contains 31 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_quantized_tensor_subclass_8da4w
def test_quantized_tensor_subclass_8da4w(self, mapping_type):group_size = 32m = ToyLinearModel().eval()m_copy = copy.deepcopy(m)example_inputs = m.example_inputs()quantize_(m,Int8DynamicActivationInt4WeightConfig(group_size=group_size, mapping_type=mapping_type),)assert isinstance(m.linear1.weight, LinearActivationQuan...
1
30
2
179
0
414
448
414
null
[]
None
null
0
0
0
null
0
null
The function (test_quantized_tensor_subclass_8da4w) defined within the public class called public.The function start at line 414 and ends at 448. It contains 30 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [414.0] and does not return any value..
pytorch_ao
public
public
0
0
test_quantized_tensor_subclass_int4
def test_quantized_tensor_subclass_int4(self):for device in self.GPU_DEVICES:# use 1024 so that we don't need paddingm = ToyLinearModel(1024, 1024, 1024).eval().to(torch.bfloat16).to(device)m_copy = copy.deepcopy(m)example_inputs = m.example_inputs(dtype=torch.bfloat16, device=device)group_size = 32if device == "xpu":q...
3
21
1
166
0
451
477
451
null
[]
None
null
0
0
0
null
0
null
The function (test_quantized_tensor_subclass_int4) defined within the public class called public.The function start at line 451 and ends at 477. It contains 21 lines of code and it has a cyclomatic complexity of 3. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_quantized_tensor_subclass_int8_wo
def test_quantized_tensor_subclass_int8_wo(self):m = ToyLinearModel().eval().to(torch.bfloat16)m_copy = copy.deepcopy(m)example_inputs = tuple(map(lambda x: x.to(torch.bfloat16), m.example_inputs()))quantize_(m, Int8WeightOnlyConfig())assert isinstance(m.linear1.weight, AffineQuantizedTensor)assert isinstance(m.linear2...
1
11
1
115
0
480
496
480
null
[]
None
null
0
0
0
null
0
null
The function (test_quantized_tensor_subclass_int8_wo) defined within the public class called public.The function start at line 480 and ends at 496. 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_quantized_tensor_subclass_save_load
def test_quantized_tensor_subclass_save_load(self):m = ToyLinearModel().eval().to(torch.bfloat16)m_copy = copy.deepcopy(m)example_inputs = m.example_inputs(dtype=torch.bfloat16)quantize_(m, Int8WeightOnlyConfig())ref = m(*example_inputs)with tempfile.NamedTemporaryFile() as f:torch.save(m.state_dict(), f)f.seek(0)state...
1
13
1
116
0
499
514
499
null
[]
None
null
0
0
0
null
0
null
The function (test_quantized_tensor_subclass_save_load) defined within the public class called public.The function start at line 499 and ends at 514. It contains 13 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_int8wo_quantized_model_to_device
def test_int8wo_quantized_model_to_device(self):m = ToyLinearModel().eval().to(torch.bfloat16)example_inputs = m.example_inputs(dtype=torch.bfloat16, device="cpu")quantize_(m, Int8WeightOnlyConfig())ref = m(*example_inputs)example_inputs_cuda = (example_inputs[0].to("cuda"),)m.to(device="cuda")cuda_res = m(*example_inp...
1
9
1
93
0
517
527
517
null
[]
None
null
0
0
0
null
0
null
The function (test_int8wo_quantized_model_to_device) defined within the public class called public.The function start at line 517 and ends at 527. 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_quantized_tensor_subclass_save_load_map_location
def test_quantized_tensor_subclass_save_load_map_location(self):m = ToyLinearModel().eval().to(dtype=torch.bfloat16, device="cuda")example_inputs = m.example_inputs(dtype=torch.bfloat16, device="cuda")quantize_(m, Int8WeightOnlyConfig())ref = m(*example_inputs)with tempfile.NamedTemporaryFile() as f:torch.save(m.state_...
1
15
1
159
0
530
548
530
null
[]
None
null
0
0
0
null
0
null
The function (test_quantized_tensor_subclass_save_load_map_location) defined within the public class called public.The function start at line 530 and ends at 548. 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_quantized_model_streaming.reset_memory
def reset_memory():gc.collect()torch.cuda.empty_cache()torch.cuda.reset_peak_memory_stats()
1
4
0
23
0
552
555
552
null
[]
None
null
0
0
0
null
0
null
The function (test_quantized_model_streaming.reset_memory) defined within the public class called public.The function start at line 552 and ends at 555. 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_quantized_model_streaming
def test_quantized_model_streaming(self):def reset_memory():gc.collect()torch.cuda.empty_cache()torch.cuda.reset_peak_memory_stats()reset_memory()m = ToyLinearModel()quantize_(m.to(device="cuda"), Int8WeightOnlyConfig())memory_baseline = torch.cuda.max_memory_allocated()del mreset_memory()m = ToyLinearModel()quantize_(...
2
14
1
91
0
551
570
551
null
[]
None
null
0
0
0
null
0
null
The function (test_quantized_model_streaming) defined within the public class called public.The function start at line 551 and ends at 570. It contains 14 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_int4wo_cpu
def test_int4wo_cpu(self, dtype, x_dim, use_hqq):device = "cpu"m = ToyLinearModel().eval().to(dtype).to(device)example_inputs = m.example_inputs(dtype=dtype, device=device)if x_dim == 3:example_inputs = (example_inputs[0].unsqueeze(0),)with torch.no_grad():quantize_(m,Int4WeightOnlyConfig(group_size=32, layout=Int4CPUL...
2
19
4
145
0
575
595
575
null
[]
None
null
0
0
0
null
0
null
The function (test_int4wo_cpu) defined within the public class called public.The function start at line 575 and ends at 595. It contains 19 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [575.0] and does not return any value..
pytorch_ao
public
public
0
0
test_workflow_e2e_numerics
def test_workflow_e2e_numerics(self, config):"""Simple test of e2e Int4WeightOnlyConfig workflow, comparing numericsto a bfloat16 baseline."""if (isinstance(config,(Float8DynamicActivationFloat8WeightConfig,Float8StaticActivationFloat8WeightConfig,),)and not is_sm_at_least_89()):return unittest.skip("requires CUDA capa...
9
33
2
209
0
616
664
616
null
[]
None
null
0
0
0
null
0
null
The function (test_workflow_e2e_numerics) defined within the public class called public.The function start at line 616 and ends at 664. It contains 33 lines of code and it has a cyclomatic complexity of 9. It takes 2 parameters, represented as [616.0] and does not return any value..
pytorch_ao
public
public
0
0
test_module_fqn_to_config_default
def test_module_fqn_to_config_default(self):config1 = Int4WeightOnlyConfig(group_size=32, version=1)config2 = Int8WeightOnlyConfig()config = ModuleFqnToConfig({"_default": config1, "linear2": config2})model = ToyLinearModel().cuda().to(dtype=torch.bfloat16)example_inputs = model.example_inputs(device="cuda", dtype=torc...
1
12
1
129
0
667
678
667
null
[]
None
null
0
0
0
null
0
null
The function (test_module_fqn_to_config_default) defined within the public class called public.The function start at line 667 and ends at 678. 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_module_fqn_to_config_module_name
def test_module_fqn_to_config_module_name(self):config1 = Int4WeightOnlyConfig(group_size=32, version=1)config2 = Int8WeightOnlyConfig()config = ModuleFqnToConfig({"linear1": config1, "linear2": config2})model = ToyLinearModel().cuda().to(dtype=torch.bfloat16)example_inputs = model.example_inputs(device="cuda", dtype=t...
1
12
1
129
0
681
692
681
null
[]
None
null
0
0
0
null
0
null
The function (test_module_fqn_to_config_module_name) defined within the public class called public.The function start at line 681 and ends at 692. 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_module_fqn_to_config_embedding_linear
def test_module_fqn_to_config_embedding_linear(self):weight_dtype = torch.int8granularity = PerGroup(8)mapping_type = MappingType.SYMMETRICembedding_config = IntxWeightOnlyConfig(weight_dtype=weight_dtype,granularity=granularity,mapping_type=mapping_type,)# example model linear is Linear(16, 8)linear_config = Int8Dynam...
2
28
1
178
0
694
724
694
null
[]
None
null
0
0
0
null
0
null
The function (test_module_fqn_to_config_embedding_linear) defined within the public class called public.The function start at line 694 and ends at 724. It contains 28 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_module_fqn_to_config_skip
def test_module_fqn_to_config_skip(self):config1 = Int4WeightOnlyConfig(group_size=32, version=1)config = ModuleFqnToConfig({"_default": config1, "linear2": None})model = ToyLinearModel().cuda().to(dtype=torch.bfloat16)example_inputs = model.example_inputs(device="cuda", dtype=torch.bfloat16)quantize_(model, config)mod...
1
10
1
112
0
727
736
727
null
[]
None
null
0
0
0
null
0
null
The function (test_module_fqn_to_config_skip) defined within the public class called public.The function start at line 727 and ends at 736. 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_int4wo_cuda_serialization
def test_int4wo_cuda_serialization(self):config = Int4WeightOnlyConfig(group_size=32, version=1)model = ToyLinearModel().cuda().to(dtype=torch.bfloat16)# quantize in cudaquantize_(model, config)example_inputs = model.example_inputs(device="cuda", dtype=torch.bfloat16)model(*example_inputs)with tempfile.NamedTemporaryFi...
2
12
1
133
0
739
755
739
null
[]
None
null
0
0
0
null
0
null
The function (test_int4wo_cuda_serialization) defined within the public class called public.The function start at line 739 and ends at 755. 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..
pytorch_ao
public
public
0
0
test_config_deprecation
def test_config_deprecation(self):"""Test that old config functions like `int4_weight_only` trigger deprecation warnings."""from torchao.quantization import (float8_dynamic_activation_float8_weight,float8_static_activation_float8_weight,float8_weight_only,fpx_weight_only,gemlite_uintx_weight_only,int4_dynamic_activatio...
3
38
1
178
0
757
805
757
null
[]
None
null
0
0
0
null
0
null
The function (test_config_deprecation) defined within the public class called public.The function start at line 757 and ends at 805. It contains 38 lines of code and it has a cyclomatic complexity of 3. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
check_idempotent
def check_idempotent(self, fn, *args, **kwargs):output0 = fn(*args, **kwargs)assert torch.is_tensor(output0)output1 = fn(*args, **kwargs)self.assertTrue(torch.equal(output0, output1), f"Expected given function {fn} to be idempotent.")return output1
1
8
4
58
2
48
55
48
null
['output0', 'output1']
None
null
0
0
0
null
0
null
The function (check_idempotent) defined within the public class called public.The function start at line 48 and ends at 55. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [48.0] and does not return any value..
pytorch_ao
public
public
0
0
_get_groupwise_affine_qparams
def _get_groupwise_affine_qparams(w,n_bit=4,groupsize=128,dtype=torch.bfloat16,zero_point_domain=ZeroPointDomain.FLOAT,zero_point_dtype=torch.bfloat16,):if groupsize > w.shape[-1]:groupsize = w.shape[-1]assert groupsize > 1assert w.shape[-1] % groupsize == 0assert w.dim() == 2to_quant = w.reshape(-1, groupsize)# assert...
3
29
6
267
9
59
90
59
null
['groupsize', 'max_val', 'max_int', 'scales', 'zeros', 'min_val', 'quant_max', 'quant_min', 'to_quant']
None
null
0
0
0
null
0
null
The function (_get_groupwise_affine_qparams) defined within the public class called public.The function start at line 59 and ends at 90. It contains 29 lines of code and it has a cyclomatic complexity of 3. It takes 6 parameters, represented as [59.0] and does not return any value..
pytorch_ao
public
public
0
0
_groupwise_affine_quantize_tensor_from_qparams
def _groupwise_affine_quantize_tensor_from_qparams(w, scales, zeros, n_bit=4, groupsize=128, zero_point_domain=ZeroPointDomain.FLOAT):assert groupsize > 1assert n_bit == 4# needed for GPTQ single column quantizeif groupsize > w.shape[-1] and scales.shape[-1] == 1:groupsize = w.shape[-1]assert w.shape[-1] % groupsize ==...
7
38
6
319
8
93
137
93
null
['groupsize', 'zeros', 'scales', 'max_int', 'min_int', 'w_int4x8', 'min_val', 'to_quant']
None
null
0
0
0
null
0
null
The function (_groupwise_affine_quantize_tensor_from_qparams) defined within the public class called public.The function start at line 93 and ends at 137. It contains 38 lines of code and it has a cyclomatic complexity of 7. It takes 6 parameters, represented as [93.0] and does not return any value..
pytorch_ao
public
public
0
0
_groupwise_affine_dequantize_tensor_from_qparams
def _groupwise_affine_dequantize_tensor_from_qparams(w_int4x8,scales,zeros,n_bit=4,groupsize=128,zero_point_domain=ZeroPointDomain.FLOAT,):assert groupsize > 1# needed for GPTQ single column dequantizeif groupsize > w_int4x8.shape[-1] and scales.shape[-1] == 1:groupsize = w_int4x8.shape[-1]assert w_int4x8.shape[-1] % g...
4
26
6
171
5
140
168
140
null
['w_int4x8_grouped', 'w_dq', 'zeros', 'scales', 'groupsize']
None
null
0
0
0
null
0
null
The function (_groupwise_affine_dequantize_tensor_from_qparams) defined within the public class called public.The function start at line 140 and ends at 168. It contains 26 lines of code and it has a cyclomatic complexity of 4. It takes 6 parameters, represented as [140.0] and does not return any value..
pytorch_ao
public
public
0
0
test_get_group_qparams_symmetric
def test_get_group_qparams_symmetric(self):"""Test that `get_group_qparams_symmetric` produces the exact same scales as`PerChannelMinMaxObserver._calculate_qparams`."""n_bit = 4qmin = -(2 ** (n_bit - 1))qmax = 2 ** (n_bit - 1) - 1groupsize = 256torch.manual_seed(self.SEED)weight = torch.randn(100, 256).to(torch.float16...
1
21
1
168
0
174
204
174
null
[]
None
null
0
0
0
null
0
null
The function (test_get_group_qparams_symmetric) defined within the public class called public.The function start at line 174 and ends at 204. It contains 21 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_choose_qparams_group_sym
def test_choose_qparams_group_sym(self):"""Note: groupwise asymmetric quant is using a different way of computing zero_points, sowe don't include it here. We may just replace it with per block quant"""input = torch.randn(10, 10)mapping_type = MappingType.SYMMETRICdtype = torch.int8block_size = (1, 2)eps = torch.finfo(t...
1
21
1
127
0
206
231
206
null
[]
None
null
0
0
0
null
0
null
The function (test_choose_qparams_group_sym) defined within the public class called public.The function start at line 206 and ends at 231. It contains 21 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_choose_qparams_group_sym_no_clipping_err
def test_choose_qparams_group_sym_no_clipping_err(self):"""Test the added MappingType.SYMMETRIC_NO_CLIPPING_ERR"""input = torch.randn(10, 10)mapping_type = MappingType.SYMMETRIC_NO_CLIPPING_ERRdtype = torch.int8block_size = (1, 2)eps = torch.finfo(torch.float32).epsprecision = torch.float32scale, zero_point = choose_qp...
1
21
1
127
0
233
258
233
null
[]
None
null
0
0
0
null
0
null
The function (test_choose_qparams_group_sym_no_clipping_err) defined within the public class called public.The function start at line 233 and ends at 258. It contains 21 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_choose_qparams_token_asym
def test_choose_qparams_token_asym(self):input = torch.randn(10, 10)mapping_type = MappingType.ASYMMETRICdtype = torch.int8block_size = (1, 10)scale, zero_point = choose_qparams_affine(input,mapping_type,block_size,dtype,eps=torch.finfo(torch.float32).eps,scale_dtype=torch.float64,zero_point_dtype=torch.int64,)scale_re...
1
23
1
139
0
261
284
261
null
[]
None
null
0
0
0
null
0
null
The function (test_choose_qparams_token_asym) defined within the public class called public.The function start at line 261 and ends at 284. 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_choose_qparams_tensor_asym
def test_choose_qparams_tensor_asym(self):input = torch.randn(10, 10)mapping_type = MappingType.ASYMMETRICdtype = torch.int8block_size = (10, 10)eps = torch.finfo(torch.float32).epsscale, zero_point = choose_qparams_affine(input, mapping_type, block_size, dtype, eps=eps)quant_min = -128quant_max = 127scale_ref, zp_ref ...
1
18
1
131
0
287
306
287
null
[]
None
null
0
0
0
null
0
null
The function (test_choose_qparams_tensor_asym) defined within the public class called public.The function start at line 287 and ends at 306. It contains 18 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_choose_qparams_tensor_sym
def test_choose_qparams_tensor_sym(self):input = torch.randn(10, 10)mapping_type = MappingType.SYMMETRICdtype = torch.int8block_size = (10, 10)eps = torch.finfo(torch.float32).epsscale, zero_point = choose_qparams_affine(input, mapping_type, block_size, dtype, eps=eps)quant_min = -128quant_max = 127scale_ref, zp_ref = ...
1
18
1
131
0
309
328
309
null
[]
None
null
0
0
0
null
0
null
The function (test_choose_qparams_tensor_sym) defined within the public class called public.The function start at line 309 and ends at 328. It contains 18 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_quantize_activation_per_token_abs_max
def test_quantize_activation_per_token_abs_max(self):input = torch.randn(10, 10)quantized_ref, scale_ref = _quantize_activation_per_token_absmax(input)mapping_type = MappingType.SYMMETRICblock_size = list(input.shape)for i in range(len(block_size) - 1):block_size[i] = 1dtype = torch.int8eps = 1e-5quant_min = -127quant_...
2
26
1
145
0
330
358
330
null
[]
None
null
0
0
0
null
0
null
The function (test_quantize_activation_per_token_abs_max) defined within the public class called public.The function start at line 330 and ends at 358. It contains 26 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_activation_per_token_abs_max_zero_input
def test_quantize_activation_per_token_abs_max_zero_input(self):input = torch.zeros(10, 10)# make sure it still worksquantized_ref, scale_ref = _quantize_activation_per_token_absmax(input)
1
3
1
23
0
360
363
360
null
[]
None
null
0
0
0
null
0
null
The function (test_quantize_activation_per_token_abs_max_zero_input) defined within the public class called public.The function start at line 360 and ends at 363. 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..