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_print_arg_types
def test_print_arg_types(self):class MyTensor(TorchAOBaseTensor):def __new__(cls, data):shape = data.shapereturn torch.Tensor._make_wrapper_subclass(cls, shape)# type: ignore[attr-defined]def __init__(self, data):self.data = datal = torch.nn.Linear(10, 10)# since we did not define `tensor_data_names` and `tensor_attrib...
1
7
1
54
0
90
106
90
null
[]
None
null
0
0
0
null
0
null
The function (test_print_arg_types) defined within the public class called public.The function start at line 90 and ends at 106. It contains 7 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_test_default_impls_helper
def _test_default_impls_helper(self, lp_tensor, lp_tensor_for_copy):# get `all_tensor_data_names` and `all_tensor_attribute_names`all_tensor_data_names = lp_tensor.tensor_data_names.copy()if hasattr(lp_tensor, "optional_tensor_data_names"):for tensor_data_name in lp_tensor.optional_tensor_data_names:if getattr(lp_tenso...
18
90
3
605
0
108
235
108
null
[]
None
null
0
0
0
null
0
null
The function (_test_default_impls_helper) defined within the public class called public.The function start at line 108 and ends at 235. It contains 90 lines of code and it has a cyclomatic complexity of 18. It takes 3 parameters, represented as [108.0] and does not return any value..
pytorch_ao
public
public
0
0
test_default_impls.__new__
def __new__(cls, qdata, attr, device):shape = qdata.shapeif device is None:device = qdata.devicekwargs = {"device": device}return torch.Tensor._make_wrapper_subclass(cls, shape, **kwargs)# type: ignore[attr-defined]
2
6
4
47
0
247
252
247
null
[]
None
null
0
0
0
null
0
null
The function (test_default_impls.__new__) defined within the public class called public.The function start at line 247 and ends at 252. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [247.0] and does not return any value..
pytorch_ao
public
public
0
0
test_default_impls.__init__
def __init__(self, qdata, attr, device):self.qdata = qdataself.attr = attr
1
3
4
21
0
254
256
254
null
[]
None
null
0
0
0
null
0
null
The function (test_default_impls.__init__) defined within the public class called public.The function start at line 254 and ends at 256. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [254.0] and does not return any value..
pytorch_ao
public
public
0
0
test_default_impls
def test_default_impls(self):"""Making sure some common functions has default implementations, such as__tensor_unflatten__, __tensor_flatten__, _apply_fn_to_data, __repr__, to"""class MyTensor(TorchAOBaseTensor):tensor_data_names = ["qdata"]tensor_attribute_names = ["attr", "device"]def __new__(cls, qdata, attr, device...
1
12
1
98
0
238
265
238
null
[]
None
null
0
0
0
null
0
null
The function (test_default_impls) defined within the public class called public.The function start at line 238 and ends at 265. 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_default_impls_with_optional_data.__new__
def __new__(cls, qdata, attr, device, zero_point=None):shape = qdata.shapeif device is None:device = qdata.devicekwargs = {"device": device}return torch.Tensor._make_wrapper_subclass(cls, shape, **kwargs)# type: ignore[attr-defined]
2
6
5
51
0
274
279
274
null
[]
None
null
0
0
0
null
0
null
The function (test_default_impls_with_optional_data.__new__) defined within the public class called public.The function start at line 274 and ends at 279. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [274.0] and does not return any value..
pytorch_ao
public
public
0
0
test_default_impls_with_optional_data.__init__
def __init__(self, qdata, attr, device, zero_point=None):self.qdata = qdataself.attr = attrself.zero_point = zero_point
1
4
5
30
0
281
284
281
null
[]
None
null
0
0
0
null
0
null
The function (test_default_impls_with_optional_data.__init__) defined within the public class called public.The function start at line 281 and ends at 284. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [281.0] and does not return any value..
pytorch_ao
public
public
0
0
test_default_impls_with_optional_data
def test_default_impls_with_optional_data(self):class MyTensorWithOptionalData(TorchAOBaseTensor):tensor_data_names = ["qdata"]tensor_attribute_names = ["attr", "device"]optional_tensor_data_names = ["zero_point"]def __new__(cls, qdata, attr, device, zero_point=None):shape = qdata.shapeif device is None:device = qdata....
1
21
1
166
0
268
302
268
null
[]
None
null
0
0
0
null
0
null
The function (test_default_impls_with_optional_data) defined within the public class called public.The function start at line 268 and ends at 302. 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_default_impls_with_optional_attr.__new__
def __new__(cls, qdata, attr, device, zero_point=None, optional_attr=None):shape = qdata.shapeif device is None:device = qdata.devicekwargs = {"device": device}return torch.Tensor._make_wrapper_subclass(cls, shape, **kwargs)# type: ignore[attr-defined]
2
6
6
55
0
312
317
312
null
[]
None
null
0
0
0
null
0
null
The function (test_default_impls_with_optional_attr.__new__) defined within the public class called public.The function start at line 312 and ends at 317. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 6 parameters, represented as [312.0] and does not return any value..
pytorch_ao
public
public
0
0
test_default_impls_with_optional_attr.__init__
def __init__(self, qdata, attr, device, zero_point=None, optional_attr=None):self.qdata = qdataself.attr = attrself.zero_point = zero_pointself.optional_attr = optional_attr
1
7
6
39
0
319
325
319
null
[]
None
null
0
0
0
null
0
null
The function (test_default_impls_with_optional_attr.__init__) defined within the public class called public.The function start at line 319 and ends at 325. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [319.0] and does not return any value..
pytorch_ao
public
public
0
0
test_default_impls_with_optional_attr
def test_default_impls_with_optional_attr(self):class MyTensorWithOptionalData(TorchAOBaseTensor):tensor_data_names = ["qdata"]tensor_attribute_names = ["attr", "device"]optional_tensor_data_names = ["zero_point"]optional_tensor_attribute_names = ["optional_attr"]def __new__(cls, qdata, attr, device, zero_point=None, o...
1
24
1
173
0
305
345
305
null
[]
None
null
0
0
0
null
0
null
The function (test_default_impls_with_optional_attr) defined within the public class called public.The function start at line 305 and ends at 345. It contains 24 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_config_ids
def get_config_ids(configs):if not isinstance(configs, list):configs = [configs]return [config.__class__.__name__ for config in configs]
3
4
1
31
1
98
101
98
null
['configs']
None
null
0
0
0
null
0
null
The function (get_config_ids) defined within the public class called public.The function start at line 98 and ends at 101. It contains 4 lines of code and it has a cyclomatic complexity of 3. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_reconstructable_dict_file_round_trip
def test_reconstructable_dict_file_round_trip(config):"""Test saving and loading reconstructable dicts to/from JSON files."""# Get a reconstructable dictreconstructable = config_to_dict(config)# Create a temporary file to save the JSONwith tempfile.NamedTemporaryFile(mode="w+", suffix=".json", delete=False) as temp_fil...
7
30
1
172
6
105
151
105
null
['reconstructed_value', 'loaded_dict', 'original_value', 'reconstructable', 'temp_file_path', 'reconstructed']
None
null
0
0
0
null
0
null
The function (test_reconstructable_dict_file_round_trip) defined within the public class called public.The function start at line 105 and ends at 151. It contains 30 lines of code and it has a cyclomatic complexity of 7. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_disallowed_modules
def test_disallowed_modules():"""Test that configs from non-allowed modules are rejected during reconstruction."""# Create a config from a non-allowed moduledummy_config = DummyNonAllowedConfig()reconstructable = config_to_dict(dummy_config)with pytest.raises(ValueError,match="Failed to find class DummyNonAllowedConfig...
1
13
0
70
3
163
180
163
null
['dummy_config', 'reconstructed', 'reconstructable']
None
null
0
0
0
null
0
null
The function (test_disallowed_modules) defined within the public class called public.The function start at line 163 and ends at 180. 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_version_mismatch
def test_version_mismatch():"""Test that version mismatch prints a warning during reconstruction."""# Create a configdummy_config = DummyNonAllowedConfig()reconstructable = config_to_dict(dummy_config)# Modify the version in the dict to create a mismatchreconstructable["_version"] = 1# Patch to allow the module but sho...
2
12
0
68
2
183
200
183
null
['dummy_config', 'reconstructable']
None
null
0
0
0
null
0
null
The function (test_version_mismatch) defined within the public class called public.The function start at line 183 and ends at 200. 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_default_version
def test_default_version():"""Making sure the default version for a new config inheriting from AOBaseConfig is always 1because it's the default version that all children has when they haven't explicitlydefined a version class variable"""@dataclassclass DummyConfig(AOBaseConfig):passconfig = DummyConfig()assert config.v...
1
6
0
27
1
203
214
203
null
['config']
None
null
0
0
0
null
0
null
The function (test_default_version) defined within the public class called public.The function start at line 203 and ends at 214. 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
get_quantization_functions
def get_quantization_functions(do_sparse: bool, do_int4: bool, device: str = "cuda", int4_zp_int: bool = False):base_functions = [Int8WeightOnlyConfig(),Int8DynamicActivationInt4WeightConfig(),Int8DynamicActivationInt8WeightConfig(),Int8DynamicActivationInt8WeightConfig(act_mapping_type=MappingType.ASYMMETRIC),]if do_i...
10
46
4
236
1
52
100
52
null
['base_functions']
None
null
0
0
0
null
0
null
The function (get_quantization_functions) defined within the public class called public.The function start at line 52 and ends at 100. It contains 46 lines of code and it has a cyclomatic complexity of 10. It takes 4 parameters, represented as [52.0] and does not return any value..
pytorch_ao
public
public
0
0
test_tensor_core_layout_transpose
def test_tensor_core_layout_transpose(self):linear = torch.nn.Linear(128, 256, dtype=torch.bfloat16, device="cuda")t = linear.weightshape = t.shapeapply_int4_weight_only_quant = Int4WeightOnlyConfig(group_size=32, version=1)quantize_(linear, apply_int4_weight_only_quant)ql = linearaqt = ql.weightaqt_shape = aqt.shapese...
2
16
1
116
0
109
126
109
null
[]
None
null
0
0
0
null
0
null
The function (test_tensor_core_layout_transpose) defined within the public class called public.The function start at line 109 and ends at 126. It contains 16 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_weights_only
def test_weights_only(self):for device in self.GPU_DEVICES:apply_quant_list = get_quantization_functions(is_cusparselt_available, True, device, True)for apply_quant in apply_quant_list:linear = torch.nn.Linear(128, 256, dtype=torch.bfloat16, device=device)if isinstance(apply_quant, AOBaseConfig):quantize_(linear, apply...
4
16
1
115
0
129
145
129
null
[]
None
null
0
0
0
null
0
null
The function (test_weights_only) defined within the public class called public.The function start at line 129 and ends at 145. It contains 16 lines of code and it has a cyclomatic complexity of 4. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_to_device._apply
def _apply(module, config_or_subclass_inserter):if isinstance(config_or_subclass_inserter, AOBaseConfig):quantize_(module, config_or_subclass_inserter)else:# TODO(#1690): delete this once config migration is donemodule = config_or_subclass_inserter(module)return module
2
6
2
31
0
152
158
152
null
[]
None
null
0
0
0
null
0
null
The function (test_to_device._apply) defined within the public class called public.The function start at line 152 and ends at 158. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [152.0] and does not return any value..
pytorch_ao
public
public
0
0
test_to_device
def test_to_device(self, apply_quant):for device in self.GPU_DEVICES:def _apply(module, config_or_subclass_inserter):if isinstance(config_or_subclass_inserter, AOBaseConfig):quantize_(module, config_or_subclass_inserter)else:# TODO(#1690): delete this once config migration is donemodule = config_or_subclass_inserter(mo...
2
12
2
114
0
149
170
149
null
[]
None
null
0
0
0
null
0
null
The function (test_to_device) defined within the public class called public.The function start at line 149 and ends at 170. It contains 12 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [149.0] and does not return any value..
pytorch_ao
public
public
0
0
test_register_new_dispatch.dispatch_condition
def dispatch_condition(input_tensor, weight_tensor, bias):return (isinstance(weight_tensor, AffineQuantizedTensor)and weight_tensor.quant_min == 0and weight_tensor.quant_max == 2**6 - 1)
3
6
3
34
0
181
186
181
null
[]
None
null
0
0
0
null
0
null
The function (test_register_new_dispatch.dispatch_condition) defined within the public class called public.The function start at line 181 and ends at 186. It contains 6 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [181.0] and does not return any value..
pytorch_ao
public
public
0
0
test_register_new_dispatch.impl
def impl(input_tensor, weight_tensor, bias):# this is just for testing, normally people will call into uint6 weight only# quantized linear operator hereassert False, "dispatching to my impl for uint6 weight only quant"
1
2
3
13
0
188
191
188
null
[]
None
null
0
0
0
null
0
null
The function (test_register_new_dispatch.impl) defined within the public class called public.The function start at line 188 and ends at 191. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [188.0] and does not return any value..
pytorch_ao
public
public
0
0
test_register_new_dispatch.apply_uint6_weight_only_quant
def apply_uint6_weight_only_quant(linear):linear.weight = torch.nn.Parameter(to_affine_quantized_intx(linear.weight,MappingType.ASYMMETRIC,(1, linear.weight.shape[-1]),torch.uint8,0,2**6 - 1,),requires_grad=False,)return linear
1
13
1
60
0
195
207
195
null
[]
None
null
0
0
0
null
0
null
The function (test_register_new_dispatch.apply_uint6_weight_only_quant) defined within the public class called public.The function start at line 195 and ends at 207. 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_register_new_dispatch
def test_register_new_dispatch(self):from torchao.dtypes import AffineQuantizedTensorfrom torchao.dtypes.affine_quantized_tensor_ops import (deregister_aqt_quantized_linear_dispatch,register_aqt_quantized_linear_dispatch,)from torchao.quantization.quant_primitives import MappingTypedef dispatch_condition(input_tensor, ...
1
19
1
108
0
173
218
173
null
[]
None
null
0
0
0
null
0
null
The function (test_register_new_dispatch) defined within the public class called public.The function start at line 173 and ends at 218. 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_print_quantized_module
def test_print_quantized_module(self):for device in self.GPU_DEVICES:apply_quant_list = get_quantization_functions(True, True, device, True)for apply_quant in apply_quant_list:linear = torch.nn.Linear(128, 256, dtype=torch.bfloat16, device=device)if isinstance(apply_quant, AOBaseConfig):quantize_(linear, apply_quant)ql...
4
11
1
83
0
222
233
222
null
[]
None
null
0
0
0
null
0
null
The function (test_print_quantized_module) defined within the public class called public.The function start at line 222 and ends at 233. 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
test_test_copy__apply
def test_test_copy__apply(self, apply_quant):linear = torch.nn.Linear(128, 256, dtype=torch.bfloat16, device="cuda")linear2 = torch.nn.Linear(128, 256, dtype=torch.bfloat16, device="cuda")if isinstance(apply_quant, AOBaseConfig):quantize_(linear, apply_quant)ql = linearquantize_(linear2, apply_quant)ql2 = linear2else:q...
2
17
2
148
0
239
257
239
null
[]
None
null
0
0
0
null
0
null
The function (test_test_copy__apply) defined within the public class called public.The function start at line 239 and ends at 257. It contains 17 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [239.0] and does not return any value..
pytorch_ao
public
public
0
0
test_copy__mismatch_metadata
def test_copy__mismatch_metadata(self, apply_quant):linear = torch.nn.Linear(128, 256, dtype=torch.bfloat16, device="cuda")linear2 = torch.nn.Linear(128, 512, dtype=torch.bfloat16, device="cuda")if isinstance(apply_quant, AOBaseConfig):quantize_(linear, apply_quant)ql = linearquantize_(linear2, apply_quant)ql2 = linear...
2
15
2
111
0
263
280
263
null
[]
None
null
0
0
0
null
0
null
The function (test_copy__mismatch_metadata) defined within the public class called public.The function start at line 263 and ends at 280. It contains 15 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [263.0] and does not return any value..
pytorch_ao
public
public
0
0
test_to_affine_quantized_intx_static
def test_to_affine_quantized_intx_static(self):to_affine_quantized_intx_static(torch.randn(2, 3),scale=torch.randn(1),zero_point=torch.zeros(1),block_size=(2, 3),target_dtype=torch.int8,_layout=PlainLayout(),)
1
9
1
55
0
282
290
282
null
[]
None
null
0
0
0
null
0
null
The function (test_to_affine_quantized_intx_static) defined within the public class called public.The function start at line 282 and ends at 290. 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_flatten_unflatten
def test_flatten_unflatten(self, device, dtype):if device == "cuda" and dtype == torch.bfloat16 and is_fbcode():raise unittest.SkipTest("TODO: Failing for cuda + bfloat16 in fbcode")apply_quant_list = get_quantization_functions(False, True, device)for apply_quant in apply_quant_list:linear = torch.nn.Linear(128, 256, d...
7
26
3
211
0
304
330
304
null
[]
None
null
0
0
0
null
0
null
The function (test_flatten_unflatten) defined within the public class called public.The function start at line 304 and ends at 330. It contains 26 lines of code and it has a cyclomatic complexity of 7. It takes 3 parameters, represented as [304.0] and does not return any value..
pytorch_ao
public
public
0
0
test_alias
def test_alias(self, device, dtype):dummy = nn.Linear(128, 256, dtype=dtype, device=device)quantize_(dummy, Int8DynamicActivationInt8WeightConfig())_ = dummy.weight[...]
1
4
3
43
0
334
337
334
null
[]
None
null
0
0
0
null
0
null
The function (test_alias) defined within the public class called public.The function start at line 334 and ends at 337. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [334.0] and does not return any value..
pytorch_ao
public
public
0
0
test_slice_int4wo
def test_slice_int4wo(self, device, dtype):# in_feature not divisible by 1024# out_feature not divisible by 8# to test slice + padding for int4 weight only quantizationdummy = nn.Linear(256, 321, dtype=dtype, device=device)quantize_(dummy, Int4WeightOnlyConfig(version=1))# make sure these run without error_ = dummy.wei...
1
5
3
66
0
343
351
343
null
[]
None
null
0
0
0
null
0
null
The function (test_slice_int4wo) defined within the public class called public.The function start at line 343 and ends at 351. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [343.0] and does not return any value..
pytorch_ao
public
public
0
0
test_slice_gemlite.dequant
def dequant(input_layer, in_features, orig_shape):int_data = input_layer.tensor_impl.packed_weightscale = input_layer.tensor_impl.scalezero_point = input_layer.tensor_impl.zero_pointW_q = (gemlite.bitpack.unpack_over_rows(int_data,W_nbits=bit_width,num_output_rows=in_features,dtype=torch.uint8,).T.contiguous().view([-1...
2
21
3
150
0
379
403
379
null
[]
None
null
0
0
0
null
0
null
The function (test_slice_gemlite.dequant) defined within the public class called public.The function start at line 379 and ends at 403. It contains 21 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [379.0] and does not return any value..
pytorch_ao
public
public
0
0
test_slice_gemlite
def test_slice_gemlite(self, device, dtype):# in_feature not divisible by 1024# out_feature not divisible by 8# to test slice + padding for int4 weight only quantizationin_features, out_features, group_size, bit_width = 256, 512, 64, 4orig_shape = [out_features, in_features]dummy = nn.Linear(in_features, out_features, ...
4
40
3
293
0
357
434
357
null
[]
None
null
0
0
0
null
0
null
The function (test_slice_gemlite) defined within the public class called public.The function start at line 357 and ends at 434. It contains 40 lines of code and it has a cyclomatic complexity of 4. It takes 3 parameters, represented as [357.0] and does not return any value..
pytorch_ao
public
public
0
0
test_matmul
def test_matmul(self, device, dtype):x = torch.randn(53, 2048)w = torch.randn(53, 2048)w = to_affine_quantized_intx(w,mapping_type=MappingType.SYMMETRIC,block_size=(1, 32),target_dtype=torch.int8,quant_min=-8,quant_max=7,eps=torch.finfo(torch.float32).eps,)# make sure it runstorch.matmul(x, w.t())
1
13
3
90
0
438
451
438
null
[]
None
null
0
0
0
null
0
null
The function (test_matmul) defined within the public class called public.The function start at line 438 and ends at 451. It contains 13 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [438.0] and does not return any value..
pytorch_ao
public
public
0
0
test_slice_and_copy_int4wo
def test_slice_and_copy_int4wo(self, device, dtype):l = torch.nn.Linear(1024, 1024).to("cuda").to(torch.bfloat16)l.weight = torch.nn.Parameter(torch.zeros(1024, 1024, dtype=torch.bfloat16, device="cuda"))quantize_(l, Int4WeightOnlyConfig(version=1))param = l.weightparam_data = param.dataparam_data = param_data.narrow(0...
1
24
3
233
0
457
485
457
null
[]
None
null
0
0
0
null
0
null
The function (test_slice_and_copy_int4wo) defined within the public class called public.The function start at line 457 and ends at 485. It contains 24 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [457.0] and does not return any value..
pytorch_ao
public
public
0
0
test_mm_int4wo
def test_mm_int4wo(self, device, dtype):weight = torch.randn(512, 1024).to(device).to(dtype)weight = weight.t()l = torch.nn.Linear(512, 1024).to(device).to(dtype)l.weight = torch.nn.Parameter(weight)quantize_(l, Int4WeightOnlyConfig(version=1))# weight shape: 1024 x 512weight = l.weightinput = torch.randn(1, 512, devic...
1
9
3
116
0
491
503
491
null
[]
None
null
0
0
0
null
0
null
The function (test_mm_int4wo) defined within the public class called public.The function start at line 491 and ends at 503. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [491.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, in_features, out_features):super().__init__()self.linear1 = torch.nn.Linear(in_features, out_features, bias=False)self.linear2 = torch.nn.Linear(out_features, in_features, bias=False)
1
4
3
52
0
52
55
52
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 52 and ends at 55. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [52.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
57
60
57
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 57 and ends at 60. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [57.0] and does not return any value..
pytorch_ao
public
public
0
0
test_fp8_linear_variants
def test_fp8_linear_variants(self, dtype: torch.dtype, mode: str, compile: bool, sizes: Tuple, granularity):error_message = Noneif isinstance(granularity, PerRow):if mode == "dynamic" and dtype != torch.bfloat16:error_message = "PerRow quantization only works for bfloat16 precision"elif mode == "static":error_message =...
7
51
6
276
0
80
140
80
null
[]
None
null
0
0
0
null
0
null
The function (test_fp8_linear_variants) defined within the public class called public.The function start at line 80 and ends at 140. It contains 51 lines of code and it has a cyclomatic complexity of 7. It takes 6 parameters, represented as [80.0] and does not return any value..
pytorch_ao
public
public
0
0
test_invalid_granularity
def test_invalid_granularity(self):with pytest.raises(ValueError, match="Invalid granularity specification"):Float8DynamicActivationFloat8WeightConfig(granularity="invalid")
1
3
1
23
0
145
147
145
null
[]
None
null
0
0
0
null
0
null
The function (test_invalid_granularity) defined within the public class called public.The function start at line 145 and ends at 147. It contains 3 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_mismatched_granularity
def test_mismatched_granularity(self):with pytest.raises(ValueError,match="Different granularities for activation and weight are not supported",):Float8DynamicActivationFloat8WeightConfig(granularity=(PerTensor(), PerRow()))
1
8
1
32
0
152
159
152
null
[]
None
null
0
0
0
null
0
null
The function (test_mismatched_granularity) defined within the public class called public.The function start at line 152 and ends at 159. 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_unsupported_granularity
def test_unsupported_granularity(self):class UnsupportedGranularity:passwith pytest.raises(ValueError, match="Invalid granularity types"):Float8DynamicActivationFloat8WeightConfig(granularity=(UnsupportedGranularity(), UnsupportedGranularity()),)
1
7
1
36
0
164
171
164
null
[]
None
null
0
0
0
null
0
null
The function (test_unsupported_granularity) defined within the public class called public.The function start at line 164 and ends at 171. It contains 7 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_per_row_with_float32
def test_per_row_with_float32(self):with pytest.raises(AssertionError,match="PerRow quantization only works for bfloat16 precision",):model = ToyLinearModel(64, 64).eval().to(torch.float32).to("cuda")quantize_(model,Float8DynamicActivationFloat8WeightConfig(granularity=PerRow()),)
1
10
1
56
0
177
186
177
null
[]
None
null
0
0
0
null
0
null
The function (test_per_row_with_float32) defined within the public class called public.The function start at line 177 and ends at 186. 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_serialization
def test_serialization(self, mode: str):# Create and quantize the modelmodel = ToyLinearModel(16, 32).to(device="cuda")mode_map = {"dynamic": partial(Float8DynamicActivationFloat8WeightConfig,granularity=PerTensor(),version=1,),"weight-only": partial(Float8WeightOnlyConfig, version=1),"static": partial(Float8StaticActi...
5
51
2
329
0
193
261
193
null
[]
None
null
0
0
0
null
0
null
The function (test_serialization) defined within the public class called public.The function start at line 193 and ends at 261. It contains 51 lines of code and it has a cyclomatic complexity of 5. It takes 2 parameters, represented as [193.0] and does not return any value..
pytorch_ao
public
public
0
0
test_fp8_weight_dimension_warning
def test_fp8_weight_dimension_warning(self):# Create model with incompatible dimensions (not multiples of 16)model = ToyLinearModel(10, 25).cuda()# 10x25 and 25x10 weights# Set up logging capturewith self.assertLogs("torchao.quantization.quant_api", level="INFO") as log_context:quantize_(model,Float8DynamicActivationFl...
5
25
1
113
0
267
299
267
null
[]
None
null
0
0
0
null
0
null
The function (test_fp8_weight_dimension_warning) defined within the public class called public.The function start at line 267 and ends at 299. It contains 25 lines of code and it has a cyclomatic complexity of 5. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_mm_float8dq_per_row
def test_mm_float8dq_per_row(self, in_features, out_features, leading_shape, bias: bool):device = "cuda"dtype = torch.bfloat16input_shape = leading_shape + (in_features,)ref_linear = (torch.nn.Linear(in_features, out_features, bias=bias).to(device).to(dtype))test_linear = copy.deepcopy(ref_linear)quantize_(test_linear,...
1
32
5
260
0
312
354
312
null
[]
None
null
0
0
0
null
0
null
The function (test_mm_float8dq_per_row) defined within the public class called public.The function start at line 312 and ends at 354. It contains 32 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [312.0] and does not return any value..
pytorch_ao
public
public
0
0
test_choose_scale_float8_bounds
def test_choose_scale_float8_bounds(self, float8_dtype, output_dtype):block_size = ()device = "cuda"input_tensor = torch.randn(8, 64, device=device, dtype=torch.float32)# testing upper boundsinput_tensor[0][0] = 2000scale_ref = _choose_scale_float8(input_tensor, float8_dtype=float8_dtype, block_size=block_size)hp_value...
1
28
3
159
0
362
397
362
null
[]
None
null
0
0
0
null
0
null
The function (test_choose_scale_float8_bounds) defined within the public class called public.The function start at line 362 and ends at 397. It contains 28 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [362.0] and does not return any value..
pytorch_ao
public
public
0
0
test_dequantize_affine_float8
def test_dequantize_affine_float8(self, float8_dtype, output_dtype, block_size):"""Test _dequantize_affine_float8 with various configurations"""device = "cuda"input_tensor = torch.randn(8, 64, device=device, dtype=torch.float32)# Choose quantization parametersscale = _choose_scale_float8(input_tensor, float8_dtype=floa...
1
13
4
134
0
406
430
406
null
[]
None
null
0
0
0
null
0
null
The function (test_dequantize_affine_float8) defined within the public class called public.The function start at line 406 and ends at 430. It contains 13 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [406.0] and does not return any value..
pytorch_ao
public
public
0
0
test_dequantize_affine_float8_scale_broadcasting
def test_dequantize_affine_float8_scale_broadcasting(self):"""Test that scale broadcasting works correctly for block-wise quantization"""device = "cuda"# Create input tensor with known block structureinput_tensor = torch.randn(4, 32, device=device, dtype=torch.float32)block_size = (2, 16)# 2x2 blocks in first dim, 2x16...
1
15
1
116
0
436
462
436
null
[]
None
null
0
0
0
null
0
null
The function (test_dequantize_affine_float8_scale_broadcasting) defined within the public class called public.The function start at line 436 and ends at 462. 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_float8_tensor_slicing_basic
def test_float8_tensor_slicing_basic(self, granularity):"""Test basic slicing operations on Float8 tensors"""device = "cuda"dtype = torch.bfloat16# Create and quantize a modelmodel = torch.nn.Linear(64, 32, bias=False).to(device).to(dtype)quantize_(model,Float8DynamicActivationFloat8WeightConfig(granularity=granularity...
1
20
2
172
0
469
500
469
null
[]
None
null
0
0
0
null
0
null
The function (test_float8_tensor_slicing_basic) defined within the public class called public.The function start at line 469 and ends at 500. It contains 20 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [469.0] and does not return any value..
pytorch_ao
public
public
0
0
test_float8_tensor_slicing_per_tensor
def test_float8_tensor_slicing_per_tensor(self):"""Test slicing with per-tensor quantization (scale should not change)"""device = "cuda"dtype = torch.bfloat16# Create and quantize with per-tensor granularitymodel = torch.nn.Linear(64, 32, bias=False).to(device).to(dtype)quantize_(model,Float8DynamicActivationFloat8Weig...
1
17
1
123
0
506
530
506
null
[]
None
null
0
0
0
null
0
null
The function (test_float8_tensor_slicing_per_tensor) defined within the public class called public.The function start at line 506 and ends at 530. 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_float8_tensor_slicing_per_row
def test_float8_tensor_slicing_per_row(self):"""Test slicing with per-row quantization (scale should be sliced appropriately)"""device = "cuda"dtype = torch.bfloat16# Create and quantize with per-row granularitymodel = torch.nn.Linear(64, 32, bias=False).to(device).to(dtype)quantize_(model,Float8DynamicActivationFloat8...
1
20
1
177
0
540
573
540
null
[]
None
null
0
0
0
null
0
null
The function (test_float8_tensor_slicing_per_row) defined within the public class called public.The function start at line 540 and ends at 573. It contains 20 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_float8_tensor_slicing_edge_cases
def test_float8_tensor_slicing_edge_cases(self):"""Test edge cases in slicing"""device = "cuda"dtype = torch.bfloat16# Create and quantize a modelmodel = torch.nn.Linear(64, 32, bias=False).to(device).to(dtype)quantize_(model,Float8DynamicActivationFloat8WeightConfig(granularity=PerTensor(), version=1),)original_weight...
1
17
1
128
0
579
605
579
null
[]
None
null
0
0
0
null
0
null
The function (test_float8_tensor_slicing_edge_cases) defined within the public class called public.The function start at line 579 and ends at 605. 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_float8_tensor_slicing_functional_correctness
def test_float8_tensor_slicing_functional_correctness(self, granularity):"""Test that sliced tensors produce correct results in computations"""device = "cuda"dtype = torch.bfloat16# Create reference and quantized models with dimensions that are multiples of 16ref_model = (torch.nn.Linear(64, 48, bias=False).to(device)....
2
46
2
402
0
616
689
616
null
[]
None
null
0
0
0
null
0
null
The function (test_float8_tensor_slicing_functional_correctness) defined within the public class called public.The function start at line 616 and ends at 689. It contains 46 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [616.0] and does not return any value..
pytorch_ao
public
public
0
0
test_preprocess_scale_3d_reshape
def test_preprocess_scale_3d_reshape(self):"""Test that preprocess_scale correctly handles 3D scale tensors"""device = "cpu"# Use CPU for basic functionality test# Test 1: PerTensor scale (scalar) - should reshape to (1, 1)per_tensor_scale = torch.tensor(0.5, device=device)result = preprocess_scale(per_tensor_scale, (2...
1
30
1
290
0
691
734
691
null
[]
None
null
0
0
0
null
0
null
The function (test_preprocess_scale_3d_reshape) defined within the public class called public.The function start at line 691 and ends at 734. It contains 30 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_dequantize_fp8_inductor
def test_quantize_dequantize_fp8_inductor(self, float8_dtype, hp_dtype):quantize_affine_float8 = torch.ops.torchao.quantize_affine_float8_non_decomposeddequantize_affine_float8 = (torch.ops.torchao.dequantize_affine_float8_non_decomposed)input = torch.randn(10, 10)with torch.no_grad():torch._dynamo.reset()expected_scal...
1
39
3
205
0
738
776
738
null
[]
None
null
0
0
0
null
0
null
The function (test_quantize_dequantize_fp8_inductor) defined within the public class called public.The function start at line 738 and ends at 776. It contains 39 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [738.0] and does not return any value..
pytorch_ao
public
public
0
0
test_expected_kernels_on_gpu
def test_expected_kernels_on_gpu(self, granularity, float8_config_version):"""Verify that float8 quantization + torch.compile results in theexpected number of kernels in the GPU trace."""torch.compiler.reset()M, K, N = 128, 256, 512m = torch.nn.Sequential(torch.nn.Linear(K, N, device="cuda", dtype=torch.bfloat16))if fl...
3
39
3
269
0
785
841
785
null
[]
None
null
0
0
0
null
0
null
The function (test_expected_kernels_on_gpu) defined within the public class called public.The function start at line 785 and ends at 841. It contains 39 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [785.0] and does not return any value..
pytorch_ao
public
public
0
0
colwise_shard
def colwise_shard(m: torch.nn.Module, mesh: DeviceMesh) -> torch.nn.Module:"""Shard linear layer of the model in column-wise fashion"""# Column-wise is wrt to A^T, so for A it is row-wise.# Number of rows per rankorig_weight = m.linear.weightn_local_rows = orig_weight.size(0) // mesh.size()rank = mesh.get_local_rank()l...
1
8
2
100
0
49
63
49
null
[]
None
null
0
0
0
null
0
null
The function (colwise_shard) defined within the public class called public.The function start at line 49 and ends at 63. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [49.0] and does not return any value..
pytorch_ao
public
public
0
0
rowwise_shard
def rowwise_shard(m: torch.nn.Module, mesh: DeviceMesh) -> torch.nn.Module:"""Shard linear layer of the model in row-wise fashion"""# Row-wise is wrt to A^T, so for A it is column-wise.# Number of rows per rankorig_weight = m.linear.weightn_local_cols = orig_weight.size(1) // mesh.size()rank = mesh.get_local_rank()loca...
1
8
2
104
0
66
80
66
null
[]
None
null
0
0
0
null
0
null
The function (rowwise_shard) defined within the public class called public.The function start at line 66 and ends at 80. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [66.0] and does not return any value..
pytorch_ao
public
public
0
0
quantize
def quantize(self, m: torch.nn.Module) -> torch.nn.Module:"""Quantize the model"""quantize_(m, self.QUANT_METHOD_FN(**self.QUANT_METHOD_KWARGS))return m
1
3
2
36
0
82
87
82
null
[]
None
null
0
0
0
null
0
null
The function (quantize) defined within the public class called public.The function start at line 82 and ends at 87. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [82.0] and does not return any value..
pytorch_ao
public
public
0
0
_test_tp.__init__
def __init__(self, in_features, out_features, **kwargs) -> None:super().__init__(**kwargs)self.linear = torch.nn.Linear(in_features, out_features, bias=False, device="cuda")
1
5
4
45
0
95
99
95
null
[]
None
null
0
0
0
null
0
null
The function (_test_tp.__init__) defined within the public class called public.The function start at line 95 and ends at 99. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [95.0] and does not return any value..
pytorch_ao
public
public
0
0
_test_tp.forward
def forward(self, x: torch.Tensor) -> torch.Tensor:return self.linear(x)
1
2
2
22
0
101
102
101
null
[]
None
null
0
0
0
null
0
null
The function (_test_tp.forward) defined within the public class called public.The function start at line 101 and ends at 102. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [101.0] and does not return any value..
pytorch_ao
public
public
0
0
_test_tp
def _test_tp(self, dtype):device = "cuda"# To make sure different ranks create the same moduletorch.manual_seed(5)class M(torch.nn.Module):def __init__(self, in_features, out_features, **kwargs) -> None:super().__init__(**kwargs)self.linear = torch.nn.Linear(in_features, out_features, bias=False, device="cuda")def forw...
1
24
2
206
0
89
132
89
null
[]
None
null
0
0
0
null
0
null
The function (_test_tp) defined within the public class called public.The function start at line 89 and ends at 132. It contains 24 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [89.0] and does not return any value..
pytorch_ao
public
public
0
0
test_tp
def test_tp(self, dtype):return self._test_tp(dtype)
1
2
2
14
0
142
143
142
null
[]
None
null
0
0
0
null
0
null
The function (test_tp) defined within the public class called public.The function start at line 142 and ends at 143. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [142.0] and does not return any value..
pytorch_ao
public
public
0
0
test_tp
def test_tp(self, dtype):return self._test_tp(dtype)
1
2
2
14
0
158
159
142
null
[]
None
null
0
0
0
null
0
null
The function (test_tp) defined within the public class called public.The function start at line 158 and ends at 159. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [142.0] and does not return any value..
pytorch_ao
public
public
0
0
test_tp_gemlite
def test_tp_gemlite(self, dtype):from torchao.quantization import GemliteUIntXWeightOnlyConfigfor packing_bitwidth in [32, 8]:for bit_width in [4, 8]:for group_size in [64, 32, None] if bit_width == 4 else [None]:api = lambda: GemliteUIntXWeightOnlyConfig(group_size, bit_width, packing_bitwidth)self.QUANT_METHOD_FN = s...
5
10
2
77
0
169
179
169
null
[]
None
null
0
0
0
null
0
null
The function (test_tp_gemlite) defined within the public class called public.The function start at line 169 and ends at 179. It contains 10 lines of code and it has a cyclomatic complexity of 5. It takes 2 parameters, represented as [169.0] and does not return any value..
pytorch_ao
public
public
0
0
test_tp
def test_tp(self, dtype):return self._test_tp(dtype)
1
2
2
14
0
189
190
142
null
[]
None
null
0
0
0
null
0
null
The function (test_tp) defined within the public class called public.The function start at line 189 and ends at 190. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [142.0] and does not return any value..
pytorch_ao
public
public
0
0
test_tp
def test_tp(self, dtype):return self._test_tp(dtype)
1
2
2
14
0
208
209
142
null
[]
None
null
0
0
0
null
0
null
The function (test_tp) defined within the public class called public.The function start at line 208 and ends at 209. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [142.0] and does not return any value..
pytorch_ao
public
public
0
0
test_tp
def test_tp(self, dtype):return self._test_tp(dtype)
1
2
2
14
0
221
222
142
null
[]
None
null
0
0
0
null
0
null
The function (test_tp) defined within the public class called public.The function start at line 221 and ends at 222. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [142.0] and does not return any value..
pytorch_ao
public
public
0
0
test_tp
def test_tp(self, dtype):return self._test_tp(dtype)
1
2
2
14
0
234
235
142
null
[]
None
null
0
0
0
null
0
null
The function (test_tp) defined within the public class called public.The function start at line 234 and ends at 235. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [142.0] and does not return any value..
pytorch_ao
public
public
0
0
run_before_and_after_tests
def run_before_and_after_tests():yieldtorch._dynamo.reset()# reset cache between tests
1
3
0
12
0
17
19
17
null
[]
None
null
0
0
0
null
0
null
The function (run_before_and_after_tests) defined within the public class called public.The function start at line 17 and ends at 19. 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_CPU
def test_CPU(bit_width, dim):test_tensor = torch.randint(0, 2**bit_width, (32, 32, 32), dtype=torch.uint8, device="cpu")packed = pack_cpu(test_tensor, bit_width, dim=dim)unpacked = unpack_cpu(packed, bit_width, dim=dim)assert unpacked.allclose(test_tensor)
1
7
2
68
3
24
30
24
null
['unpacked', 'packed', 'test_tensor']
None
null
0
0
0
null
0
null
The function (test_CPU) defined within the public class called public.The function start at line 24 and ends at 30. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [24.0] and does not return any value..
pytorch_ao
public
public
0
0
test_GPU
def test_GPU(bit_width, dim):test_tensor = torch.randint(0, 2**bit_width, (32, 32, 32), dtype=torch.uint8).cuda()packed = pack(test_tensor, bit_width, dim=dim)unpacked = unpack(packed, bit_width, dim=dim)assert unpacked.allclose(test_tensor)
1
5
2
68
3
36
40
36
null
['unpacked', 'packed', 'test_tensor']
None
null
0
0
0
null
0
null
The function (test_GPU) defined within the public class called public.The function start at line 36 and ends at 40. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [36.0] and does not return any value..
pytorch_ao
public
public
0
0
test_compile
def test_compile(bit_width, dim):torch._dynamo.config.specialize_int = Truetorch.compile(pack, fullgraph=True)torch.compile(unpack, fullgraph=True)test_tensor = torch.randint(0, 2**bit_width, (32, 32, 32), dtype=torch.uint8).cuda()packed = pack(test_tensor, bit_width, dim=dim)unpacked = unpack(packed, bit_width, dim=di...
1
8
2
97
3
47
54
47
null
['unpacked', 'packed', 'test_tensor']
None
null
0
0
0
null
0
null
The function (test_compile) defined within the public class called public.The function start at line 47 and ends at 54. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [47.0] and does not return any value..
pytorch_ao
public
public
0
0
test_pack_example
def test_pack_example():test_tensor = torch.tensor([0x30, 0x29, 0x17, 0x5, 0x20, 0x16, 0x9, 0x22], dtype=torch.uint8).cuda()shard_4, shard_2 = pack(test_tensor, 6)print(shard_4, shard_2)assert torch.tensor([0, 105, 151, 37], dtype=torch.uint8).cuda().allclose(shard_4)assert torch.tensor([39, 146], dtype=torch.uint8).cu...
1
10
0
129
2
59
68
59
null
['unpacked', 'test_tensor']
None
null
0
0
0
null
0
null
The function (test_pack_example) defined within the public class called public.The function start at line 59 and ends at 68. 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_pack_example_CPU
def test_pack_example_CPU():test_tensor = torch.tensor([0x30, 0x29, 0x17, 0x5, 0x20, 0x16, 0x9, 0x22], dtype=torch.uint8)shard_4, shard_2 = pack(test_tensor, 6)print(shard_4, shard_2)assert torch.tensor([0, 105, 151, 37], dtype=torch.uint8).allclose(shard_4)assert torch.tensor([39, 146], dtype=torch.uint8).allclose(sha...
1
10
0
117
2
71
80
71
null
['unpacked', 'test_tensor']
None
null
0
0
0
null
0
null
The function (test_pack_example_CPU) defined within the public class called public.The function start at line 71 and ends at 80. 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_pack_tc_fp6_correctness
def test_pack_tc_fp6_correctness(self, device):x = torch.randint(256, size=(256, 64), dtype=torch.uint8, device=device)expected = _pack_tc_floatx(x, 6)actual = _pack_tc_fp6(x)torch.testing.assert_close(actual, expected)
1
5
2
57
0
44
49
44
null
[]
None
null
0
0
0
null
0
null
The function (test_pack_tc_fp6_correctness) defined within the public class called public.The function start at line 44 and ends at 49. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [44.0] and does not return any value..
pytorch_ao
public
public
0
0
test_to_scaled_tc_floatx_compile
def test_to_scaled_tc_floatx_compile(self, ebits, mbits, device):x = torch.randn(256, 64, device=device)expected = to_scaled_tc_floatx(x, ebits, mbits)actual = torch.compile(to_scaled_tc_floatx, fullgraph=True)(x, ebits, mbits)torch.testing.assert_close(actual, expected)
1
5
4
64
0
53
58
53
null
[]
None
null
0
0
0
null
0
null
The function (test_to_scaled_tc_floatx_compile) defined within the public class called public.The function start at line 53 and ends at 58. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [53.0] and does not return any value..
pytorch_ao
public
public
0
0
test_from_tc_floatx_correctness
def test_from_tc_floatx_correctness(self, ebits, mbits, device):x = torch.randn(256, 64, device=device) * 100# quantize and dequantize so that the values are exactly representable in Floatxx = _floatx_unpacked_to_f32(_f32_to_floatx_unpacked(x, ebits, mbits), ebits, mbits)tc_floatx, scale = to_scaled_tc_floatx(x, ebits,...
1
8
4
80
0
62
72
62
null
[]
None
null
0
0
0
null
0
null
The function (test_from_tc_floatx_correctness) defined within the public class called public.The function start at line 62 and ends at 72. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [62.0] and does not return any value..
pytorch_ao
public
public
0
0
test_from_scaled_tc_floatx_compile
def test_from_scaled_tc_floatx_compile(self, ebits, mbits, device):M, N = 256, 64nbits = 1 + ebits + mbitsx = torch.randint(256, size=(M, N // 8 * nbits), dtype=torch.uint8, device=device)scale = torch.randn(M, device=device)expected = from_scaled_tc_floatx(x, ebits, mbits, scale)actual = torch.compile(from_scaled_tc_f...
1
12
4
96
0
76
88
76
null
[]
None
null
0
0
0
null
0
null
The function (test_from_scaled_tc_floatx_compile) defined within the public class called public.The function start at line 76 and ends at 88. It contains 12 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [76.0] and does not return any value..
pytorch_ao
public
public
0
0
test_to_copy_device
def test_to_copy_device(self, ebits, mbits):from torchao.quantization.quant_primitives import (_choose_qparams_affine_floatx,_quantize_affine_floatx,)x = torch.randn(256, 64)scale = _choose_qparams_affine_floatx(x, ebits, mbits)x = _quantize_affine_floatx(x, scale, ebits, mbits)_layout = FloatxTensorCoreLayout(ebits, m...
1
15
3
103
0
92
107
92
null
[]
None
null
0
0
0
null
0
null
The function (test_to_copy_device) defined within the public class called public.The function start at line 92 and ends at 107. It contains 15 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [92.0] and does not return any value..
pytorch_ao
public
public
0
0
test_fpx_weight_only
def test_fpx_weight_only(self, ebits, mbits, bias, dtype):N, OC, IC = 4, 256, 64device = "cuda"linear = torch.nn.Linear(IC, OC, bias=bias, device=device, dtype=dtype)fpx_linear = copy.deepcopy(linear)quantize_(fpx_linear, FPXWeightOnlyConfig(ebits, mbits))x = torch.randn(N, IC, device=device, dtype=dtype)expected = fpx...
1
10
5
119
0
115
127
115
null
[]
None
null
0
0
0
null
0
null
The function (test_fpx_weight_only) defined within the public class called public.The function start at line 115 and ends at 127. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [115.0] and does not return any value..
pytorch_ao
public
public
0
0
_build_input_weight
def _build_input_weight(embed_dim: int, device: torch.device, dtype: torch.dtype):torch.manual_seed(0)input_weight = torch.empty(embed_dim, embed_dim, device=device, dtype=dtype)input_weight.normal_(0, 1)return input_weight
1
5
3
53
1
62
66
62
null
['input_weight']
None
null
0
0
0
null
0
null
The function (_build_input_weight) defined within the public class called public.The function start at line 62 and ends at 66. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [62.0] and does not return any value..
pytorch_ao
public
public
0
0
_build_bnb_linear
def _build_bnb_linear(input_weight, device):assert bnb_available, "Needs bitsandbytes support"param = bnb.nn.Params4bit(input_weight, requires_grad=False, quant_type="nf4").cuda(device)bnb_linear = bnb.nn.LinearNF4(input_weight.size(0), input_weight.size(1), bias=False)bnb_linear.weight = parambnb_linear.to(device)retu...
1
11
2
73
2
69
79
69
null
['bnb_linear', 'param']
None
null
0
0
0
null
0
null
The function (_build_bnb_linear) defined within the public class called public.The function start at line 69 and ends at 79. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [69.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, tensor, block_size, scaler_block_size):super().__init__()self.param = torch.nn.Parameter(to_nf4(tensor, block_size, scaler_block_size))
1
5
4
37
0
84
88
84
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 84 and ends at 88. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [84.0] and does not return any value..
pytorch_ao
public
public
0
0
save_state_dict_to_buffer
def save_state_dict_to_buffer(self, state_dict: OrderedDict):buffer = io.BytesIO()torch.save(state_dict, buffer)buffer.seek(0)return buffer
1
5
2
32
0
90
94
90
null
[]
None
null
0
0
0
null
0
null
The function (save_state_dict_to_buffer) defined within the public class called public.The function start at line 90 and ends at 94. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [90.0] and does not return any value..
pytorch_ao
public
public
0
0
test_register_nf4_as_param
def test_register_nf4_as_param(self, dtype: torch.dtype):nf4_tensor = to_nf4(torch.randn(512, 512, dtype=dtype))# Would raise if nn.Parameter registration fails, such as no detach()# impl when calling __torch_dispatch__param = torch.nn.Parameter(nf4_tensor, requires_grad=False)assert not param.requires_grad
1
4
2
47
0
97
103
97
null
[]
None
null
0
0
0
null
0
null
The function (test_register_nf4_as_param) defined within the public class called public.The function start at line 97 and ends at 103. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [97.0] and does not return any value..
pytorch_ao
public
public
0
0
test_output_dtype_match
def test_output_dtype_match(self, dtype: torch.dtype):# Test to ensure W4 A16 produces A16inp = torch.randn(2, 512, dtype=dtype, requires_grad=True)nf4_tensor = to_nf4(torch.randn(512, 512, dtype=dtype))out = linear_nf4(input=inp, weight=nf4_tensor)assert out.dtype == dtype
1
5
2
64
0
106
111
106
null
[]
None
null
0
0
0
null
0
null
The function (test_output_dtype_match) defined within the public class called public.The function start at line 106 and ends at 111. It contains 5 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
test_backward_dtype_match
def test_backward_dtype_match(self, dtype: torch.dtype):# Test to ensure backward pass gives activation a bf16 gradient and no gradient# to the linear's weight, as it is frozen.nf4_tensor = to_nf4(torch.randn(512, 512, dtype=dtype))inp = torch.randn(2, 512, dtype=dtype, requires_grad=True)linear_nf4(inp, nf4_tensor).su...
2
6
2
81
0
114
121
114
null
[]
None
null
0
0
0
null
0
null
The function (test_backward_dtype_match) defined within the public class called public.The function start at line 114 and ends at 121. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [114.0] and does not return any value..
pytorch_ao
public
public
0
0
test_reconstruction_qlora_vs_bnb
def test_reconstruction_qlora_vs_bnb(self, dtype: torch.dtype):# From https://github.com/drisspg/transformer_nuggets/blob/f05afad68ad9086d342268f46a7f344617a02314/test/test_qlora.py#L65C1-L81C47torch.manual_seed(0)device = "cuda"embed_dim = 512input_weight = _build_input_weight(embed_dim, device, dtype)nf4_weight = to_...
1
15
2
126
0
130
147
130
null
[]
None
null
0
0
0
null
0
null
The function (test_reconstruction_qlora_vs_bnb) defined within the public class called public.The function start at line 130 and ends at 147. It contains 15 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [130.0] and does not return any value..
pytorch_ao
public
public
0
0
test_nf4_bnb_linear
def test_nf4_bnb_linear(self, dtype: torch.dtype):"""This test ensures that nf4_linear is "no worse" than BNB by ensuring theerror compared to a bf16 linear is not more than BNB's implementation."""torch.manual_seed(0)dim = 512device = "cuda"input_weight = _build_input_weight(dim, device, dtype)nf4_weight = to_nf4(inpu...
1
15
2
148
0
156
177
156
null
[]
None
null
0
0
0
null
0
null
The function (test_nf4_bnb_linear) defined within the public class called public.The function start at line 156 and ends at 177. It contains 15 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [156.0] and does not return any value..
pytorch_ao
public
public
0
0
test_load_from_state_dicts
def test_load_from_state_dicts(self, dtype: torch.dtype):"""Tests loading to and from different module state dicts"""input_tensor = torch.rand(64, device="cuda", dtype=dtype)base_mod = self.TestMod(input_tensor, 32, 2)dummy_dict = {"param": input_tensor}base_mod.load_state_dict(dummy_dict)assert base_mod.param.block_si...
1
7
2
69
0
181
190
181
null
[]
None
null
0
0
0
null
0
null
The function (test_load_from_state_dicts) defined within the public class called public.The function start at line 181 and ends at 190. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [181.0] and does not return any value..
pytorch_ao
public
public
0
0
test_load_from_nf4_same_meta
def test_load_from_nf4_same_meta(self, dtype: torch.dtype):"""Tests loading to and from different module state dicts"""input_tensor = torch.rand(64, dtype=dtype)base_mod = self.TestMod(input_tensor, 32, 2)state_dict = base_mod.state_dict()saved_state_dict = self.save_state_dict_to_buffer(state_dict)other_mod = self.Tes...
1
9
2
90
0
193
203
193
null
[]
None
null
0
0
0
null
0
null
The function (test_load_from_nf4_same_meta) defined within the public class called public.The function start at line 193 and ends at 203. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [193.0] and does not return any value..
pytorch_ao
public
public
0
0
test_load_from_nf4_diff_meta
def test_load_from_nf4_diff_meta(self, dtype: torch.dtype):"""Tests loading to and from different module state dicts"""input_tensor = torch.rand(128, dtype=dtype)base_mod = self.TestMod(input_tensor, 32, 2)state_dict = base_mod.state_dict()saved_state_dict = self.save_state_dict_to_buffer(state_dict)other_mod = self.Te...
1
9
2
90
0
206
216
206
null
[]
None
null
0
0
0
null
0
null
The function (test_load_from_nf4_diff_meta) defined within the public class called public.The function start at line 206 and ends at 216. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [206.0] and does not return any value..
pytorch_ao
public
public
0
0
test_to_copy
def test_to_copy(self, dtype: torch.dtype):input_tensor = torch.rand(128, device="cpu")input_tensor_nf4 = to_nf4(input_tensor, 32, 2)nf4_to_dtype = input_tensor_nf4.to(dtype)torch.testing.assert_allclose(input_tensor, nf4_to_dtype, atol=0.13, rtol=0.13)if torch.cuda.is_available():input_tensor = torch.rand(128, device=...
2
12
2
124
0
219
231
219
null
[]
None
null
0
0
0
null
0
null
The function (test_to_copy) defined within the public class called public.The function start at line 219 and ends at 231. It contains 12 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [219.0] and does not return any value..
pytorch_ao
public
public
0
0
test_to_copy_device
def test_to_copy_device(self):input_tensor = torch.rand(128, device="cpu")t = to_nf4(input_tensor, 32, 2)assert t.device == torch.device("cpu")z = t.cuda()assert z.device.type == "cuda"# Because the device could be cuda:0x = z.cpu()assert x.device == torch.device("cpu")input_tensor = torch.rand(128, device="cuda")t = t...
1
11
1
101
0
234
245
234
null
[]
None
null
0
0
0
null
0
null
The function (test_to_copy_device) defined within the public class called public.The function start at line 234 and ends at 245. 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_to_dtype
def test_to_dtype(self, dtype: torch.dtype):input_tensor = torch.rand(128, dtype=dtype)input_tensor_nf4 = to_nf4(input_tensor, 32, 2)assert type(input_tensor_nf4) is not torch.Tensorassert type(input_tensor_nf4.to(dtype)) is torch.Tensorassert input_tensor_nf4.to(dtype).dtype is dtype
1
6
2
68
0
248
253
248
null
[]
None
null
0
0
0
null
0
null
The function (test_to_dtype) defined within the public class called public.The function start at line 248 and ends at 253. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [248.0] and does not return any value..
pytorch_ao
public
public
0
0
test_smoketest_linear
def test_smoketest_linear(self, dtype: torch.dtype):a = torch.randn(32, 32, dtype=dtype, device="cuda")a_nf4 = torchao.dtypes.to_nf4(a, 16, 2)inp = torch.randn(2, 32, 32, dtype=a.dtype, device=a.device)_ = torch.nn.functional.linear(inp, a)_ = torch.nn.functional.linear(inp, a_nf4)
1
6
2
95
0
257
262
257
null
[]
None
null
0
0
0
null
0
null
The function (test_smoketest_linear) defined within the public class called public.The function start at line 257 and ends at 262. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [257.0] and does not return any value..
pytorch_ao
public
public
0
0
test_smoketest_linear_compile
def test_smoketest_linear_compile(self, dtype: torch.dtype):if (torch.cuda.is_available()and torch.cuda.get_device_capability() < (8, 0)and dtype == torch.bfloat16):self.skipTest("test requires SM capability of at least (8, 0).")if version.parse(torch.__version__) < version.parse("2.3.0"):self.skipTest("test requires 2...
5
13
2
150
0
266
278
266
null
[]
None
null
0
0
0
null
0
null
The function (test_smoketest_linear_compile) defined within the public class called public.The function start at line 266 and ends at 278. It contains 13 lines of code and it has a cyclomatic complexity of 5. It takes 2 parameters, represented as [266.0] and does not return any value..