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
_
def _(func, types, args, kwargs):input_tensor = kwargs.get("input", args[0] if len(args) > 0 else None)weight_tensor = kwargs.get("weight", args[1] if len(args) > 1 else None)bias = kwargs.get("bias", args[2] if len(args) > 2 else None)assert input_tensor is not None, "input tensor must not be None"assert weight_tensor...
5
11
4
115
3
135
148
135
null
['weight_tensor', 'input_tensor', 'bias']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 135 and ends at 148. It contains 11 lines of code and it has a cyclomatic complexity of 5. It takes 4 parameters, represented as [135.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):if not args[0].is_floating_point():raise NotImplementedError("LinearActivationQuantizedTensor: expecting a floating point input")if func == aten.addmm.default:assert args[1].shape[-1] == args[2].shape[0], (f"need mat1 shape: {args[1].shape} final"f"dim to match mat2 shape: {args[2].shap...
3
32
4
191
3
152
185
152
null
['qtensor', 'original_weight_tensor', 'input_quant_func']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 152 and ends at 185. It contains 32 lines of code and it has a cyclomatic complexity of 3. It takes 4 parameters, represented as [152.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return return_and_correct_aliasing(func, args, kwargs, args[0]._apply_fn_to_data(func))
1
4
4
30
0
189
192
189
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 189 and ends at 192. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [189.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return return_and_correct_aliasing(func, args, kwargs, args[0]._apply_fn_to_data(torch.clone))
1
4
4
32
0
196
199
196
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 196 and ends at 199. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [196.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return return_and_correct_aliasing(func,args,kwargs,args[0].to(*args[1:], **kwargs)._apply_fn_to_data(torch.clone),)
1
7
4
46
0
203
209
203
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 203 and ends at 209. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [203.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):self = args[0]src = args[1]if _same_metadata(self, src):self_tensors = self.__tensor_flatten__()[0]for tensor_name in self_tensors:getattr(self, tensor_name).copy_(getattr(src, tensor_name))returnelif type(self) is torch.Tensor and type(src) is LinearActivationQuantizedTensor:new_src = ...
5
15
4
111
4
213
228
213
null
['self_tensors', 'src', 'new_src', 'self']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 213 and ends at 228. It contains 15 lines of code and it has a cyclomatic complexity of 5. It takes 4 parameters, represented as [213.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return return_and_correct_aliasing(func, args, kwargs, args[0]._apply_fn_to_data(torch.clone))
1
4
4
32
0
232
235
196
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 232 and ends at 235. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [196.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return return_and_correct_aliasing(func,args,kwargs,LinearActivationQuantizedTensor(func(args[0].original_weight_tensor, *args[1:]),args[0].input_quant_func,args[0].quant_kwargs,),)
1
11
4
56
0
239
249
239
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 239 and ends at 249. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [239.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return return_and_correct_aliasing(func,args,kwargs,LinearActivationQuantizedTensor(func(args[0].original_weight_tensor, *args[1:]),args[0].input_quant_func,args[0].quant_kwargs,),)
1
11
4
56
0
253
263
239
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 253 and ends at 263. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [239.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return return_and_correct_aliasing(func,args,kwargs,LinearActivationQuantizedTensor(func(args[0].original_weight_tensor, *args[1:]),args[0].input_quant_func,args[0].quant_kwargs,),)
1
11
4
56
0
267
277
239
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 267 and ends at 277. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [239.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return return_and_correct_aliasing(func,args,kwargs,LinearActivationQuantizedTensor(func(args[0].original_weight_tensor, *args[1:]),args[0].input_quant_func,args[0].quant_kwargs,),)
1
11
4
56
0
282
292
239
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 282 and ends at 292. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [239.0] and does not return any value..
pytorch_ao
public
public
0
0
__new__
def __new__(cls,original_weight_tensor: torch.Tensor,scale: torch.Tensor,):kwargs = {}dtype = original_weight_tensor.dtypekwargs["dtype"] = dtypekwargs["requires_grad"] = Falsekwargs["device"] = original_weight_tensor.deviceshape = original_weight_tensor.shapereturn torch.Tensor._make_wrapper_subclass(cls, shape, **kwa...
1
12
3
66
0
36
47
36
null
[]
None
null
0
0
0
null
0
null
The function (__new__) defined within the public class called public.The function start at line 36 and ends at 47. It contains 12 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [36.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,original_weight_tensor: torch.Tensor,scale: torch.Tensor,):self.original_weight_tensor = original_weight_tensorself.scale = scale
1
7
3
28
0
49
55
49
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 49 and ends at 55. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [49.0] and does not return any value..
pytorch_ao
public
public
0
0
_quantization_type
def _quantization_type(self):return f"{self.__class__}"
1
2
1
8
0
57
58
57
null
[]
None
null
0
0
0
null
0
null
The function (_quantization_type) defined within the public class called public.The function start at line 57 and ends at 58. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_quantized_linear_op
def _quantized_linear_op(input_tensor: torch.Tensor, weight_tensor: torch.Tensor, bias: torch.Tensor):original_weight_tensor = weight_tensor.original_weight_tensorscale = weight_tensor.scale# Note: we can make this function configurable as wellscaled_input_act = input_tensor / scalereturn torch.nn.functional.linear(sca...
1
9
3
51
0
61
70
61
null
[]
None
null
0
0
0
null
0
null
The function (_quantized_linear_op) defined within the public class called public.The function start at line 61 and ends at 70. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [61.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls,input_float: torch.Tensor,scale: torch.Tensor,):return cls(input_float, scale)
1
6
3
25
0
73
78
73
null
[]
None
null
0
0
0
null
0
null
The function (from_float) defined within the public class called public.The function start at line 73 and ends at 78. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [73.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):input_tensor, weight_tensor, bias = (args[0],args[1],args[2] if len(args) > 2 else None,)if isinstance(weight_tensor, WeightTensorWithLinearActivationScaleMetadata):return weight_tensor._quantized_linear_op(input_tensor, weight_tensor, bias)raise NotImplementedError("LinearActivationQua...
3
11
4
67
0
85
96
85
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 85 and ends at 96. It contains 11 lines of code and it has a cyclomatic complexity of 3. It takes 4 parameters, represented as [85.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):self = args[0]new = self.__class__(func(self.original_weight_tensor, *args[1:], **kwargs), self.scale)return return_and_correct_aliasing(func, args, kwargs, new)
1
6
4
55
2
100
105
100
null
['new', 'self']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 100 and ends at 105. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [100.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return return_and_correct_aliasing(func, args, kwargs, args[0]._apply_fn_to_data(torch.t))
1
4
4
32
0
109
112
109
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 109 and ends at 112. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [109.0] and does not return any value..
pytorch_ao
public
public
0
0
__new__
def __new__(cls,original_weight_tensor: torch.Tensor,input_observer: Optional[AffineQuantizedObserverBase] = None,weight_observer: Optional[AffineQuantizedObserverBase] = None,):kwargs = {}dtype = original_weight_tensor.dtypekwargs["dtype"] = dtypekwargs["requires_grad"] = Falsekwargs["device"] = original_weight_tensor...
1
13
4
78
0
38
50
38
null
[]
None
null
0
0
0
null
0
null
The function (__new__) defined within the public class called public.The function start at line 38 and ends at 50. It contains 13 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [38.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,original_weight_tensor: torch.Tensor,input_observer: Optional[AffineQuantizedObserverBase] = None,weight_observer: Optional[AffineQuantizedObserverBase] = None,):self.original_weight_tensor = original_weight_tensorself.input_observer = input_observerself.weight_observer = weight_observer
1
9
4
45
0
52
60
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 60. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [52.0] and does not return any value..
pytorch_ao
public
public
0
0
__repr__
def __repr__(self):return (f"LinearActivationWeightObservedTensor(\n"f"original_weight={self.original_weight_tensor}\n"f"input_observer={self.input_observer.__class__.__name__ if self.input_observer else None}\n"f"weight_observer={self.weight_observer.__class__.__name__ if self.weight_observer else None}\n)")
1
7
1
16
0
62
68
62
null
[]
None
null
0
0
0
null
0
null
The function (__repr__) defined within the public class called public.The function start at line 62 and ends at 68. 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
__tensor_flatten__
def __tensor_flatten__(self):return ["original_weight_tensor"], [self.input_observer, self.weight_observer]
1
2
1
19
0
70
71
70
null
[]
None
null
0
0
0
null
0
null
The function (__tensor_flatten__) defined within the public class called public.The function start at line 70 and ends at 71. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
__tensor_unflatten__
def __tensor_unflatten__(cls,tensor_data_dict: Dict[str, Tensor],tensor_attributes,outer_size,outer_stride,):original_weight_tensor = tensor_data_dict["original_weight_tensor"](input_observer, weight_observer) = tensor_attributesreturn cls(original_weight_tensor, input_observer, weight_observer)
1
10
5
43
0
74
83
74
null
[]
None
null
0
0
0
null
0
null
The function (__tensor_unflatten__) defined within the public class called public.The function start at line 74 and ends at 83. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [74.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls,original_weight_tensor: Tensor,input_observer: Optional[AffineQuantizedObserverBase] = None,weight_observer: Optional[AffineQuantizedObserverBase] = None,):return cls(original_weight_tensor, input_observer, weight_observer)
1
7
4
37
0
86
92
86
null
[]
None
null
0
0
0
null
0
null
The function (from_float) defined within the public class called public.The function start at line 86 and ends at 92. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [86.0] and does not return any value..
pytorch_ao
public
public
0
0
_apply_fn_to_data
def _apply_fn_to_data(self, fn: Callable):"""Applies a fn to the tensor component of the LinearActivationWeightObservedTensor"""return self.__class__(fn(self.original_weight_tensor),self.input_observer,self.weight_observer,)
1
6
2
31
0
94
100
94
null
[]
None
null
0
0
0
null
0
null
The function (_apply_fn_to_data) defined within the public class called public.The function start at line 94 and ends at 100. It contains 6 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
to
def to(self, *args, **kwargs):kwargs = self._get_to_kwargs(*args, **kwargs)return self._apply_fn_to_data(lambda x: x.to(**kwargs))
1
3
3
39
0
102
104
102
null
[]
None
null
0
0
0
null
0
null
The function (to) defined within the public class called public.The function start at line 102 and ends at 104. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [102.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):input_tensor, weight_tensor, bias = (args[0],args[1],args[2] if len(args) > 2 else None,)if weight_tensor.input_observer is not None:input_tensor = weight_tensor.input_observer(input_tensor)if weight_tensor.weight_observer is not None:weight_tensor = weight_tensor.weight_observer(weight...
4
15
4
99
2
111
126
111
null
['weight_tensor', 'input_tensor']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 111 and ends at 126. It contains 15 lines of code and it has a cyclomatic complexity of 4. It takes 4 parameters, represented as [111.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return return_and_correct_aliasing(func, args, kwargs, args[0]._apply_fn_to_data(torch.detach))
1
4
4
32
0
130
133
130
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 130 and ends at 133. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [130.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return return_and_correct_aliasing(func, args, kwargs, args[0]._apply_fn_to_data(torch.detach))
1
4
4
32
0
137
140
130
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 137 and ends at 140. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [130.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return return_and_correct_aliasing(func,args,kwargs,args[0].to(*args[1:], **kwargs)._apply_fn_to_data(torch.clone),)
1
7
4
46
0
144
150
144
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 144 and ends at 150. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [144.0] and does not return any value..
pytorch_ao
public
public
0
0
_check_linear_int4_k
def _check_linear_int4_k(k, groupsize=1, inner_k_tiles=None):k_divisible_by_groupsize = k % groupsize == 0if inner_k_tiles is not None:k_divisible_by_16_times_inner_k_tiles = k % (inner_k_tiles * 16) == 0return k_divisible_by_groupsize and k_divisible_by_16_times_inner_k_tilesreturn k_divisible_by_groupsize
3
6
3
43
2
41
46
41
null
['k_divisible_by_groupsize', 'k_divisible_by_16_times_inner_k_tiles']
None
null
0
0
0
null
0
null
The function (_check_linear_int4_k) defined within the public class called public.The function start at line 41 and ends at 46. It contains 6 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [41.0] and does not return any value..
pytorch_ao
public
public
0
0
linear_forward_int4
def linear_forward_int4(x: torch.Tensor,weight_int4pack: torch.Tensor,scales_and_zeros: torch.Tensor,out_features: int,groupsize: int,precision: torch.dtype = torch.bfloat16,scales_precision: torch.dtype = torch.bfloat16,):origin_x_size = x.size()x = x.reshape(-1, origin_x_size[-1])if is_device(x.device.type, "cpu"):c ...
2
28
7
185
4
49
76
49
null
['origin_x_size', 'c', 'x', 'new_shape']
None
null
0
0
0
null
0
null
The function (linear_forward_int4) defined within the public class called public.The function start at line 49 and ends at 76. It contains 28 lines of code and it has a cyclomatic complexity of 2. It takes 7 parameters, represented as [49.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,in_features: int,out_features: int,# TODO: remove dtype field, not usedbias=False,device=None,dtype=None,groupsize: int = 128,inner_k_tiles: int = 8,precision: torch.dtype = torch.bfloat16,scales_precision: torch.dtype = torch.bfloat16,) -> None:super().__init__()self.padding = not _check_linear_int4_...
4
66
10
278
0
85
154
85
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 85 and ends at 154. It contains 66 lines of code and it has a cyclomatic complexity of 4. It takes 10 parameters, represented as [85.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, input: torch.Tensor) -> torch.Tensor:if self.padding:input = F.pad(input, pad=(0, self.in_features - self.origin_in_features))return linear_forward_int4(input,self.weight,self.scales_and_zeros,self.out_features,self.groupsize,self.precision,self.scales_precision,)
2
12
2
72
0
156
167
156
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 156 and ends at 167. It contains 12 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [156.0] and does not return any value..
pytorch_ao
public
public
0
0
_replace_linear_int4
def _replace_linear_int4(module: torch.nn.Module,groupsize: int,inner_k_tiles: Optional[int],padding_allowed: bool,skip_layer_func: Optional[Callable] = None,precision: torch.dtype = torch.bfloat16,scales_precision: torch.dtype = torch.bfloat16,linear_class: Type[torch.nn.Module] = WeightOnlyInt4Linear,copy_weights: bo...
10
46
9
229
1
170
220
170
null
['new_linear']
None
null
0
0
0
null
0
null
The function (_replace_linear_int4) defined within the public class called public.The function start at line 170 and ends at 220. It contains 46 lines of code and it has a cyclomatic complexity of 10. It takes 9 parameters, represented as [170.0] and does not return any value..
pytorch_ao
public
public
0
0
replace_linear_int4
def replace_linear_int4(module, groupsize, inner_k_tiles, padding_allowed, skip_layer_func=None):_replace_linear_int4(module,groupsize,inner_k_tiles,padding_allowed,skip_layer_func,linear_class=WeightOnlyInt4Linear,)
1
11
5
32
0
223
233
223
null
[]
None
null
0
0
0
null
0
null
The function (replace_linear_int4) defined within the public class called public.The function start at line 223 and ends at 233. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [223.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,groupsize: int = 256,padding_allowed: bool = True,inner_k_tiles: Optional[int] = 8,device: torch.device = torch.device("cuda"),precision: torch.dtype = torch.bfloat16,) -> None:super().__init__()assert inner_k_tiles in [2, 4, 8]assert groupsize in [32, 64, 128, 256]self.inner_k_tiles = inner_k_tilesse...
1
16
5
118
0
237
254
237
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 237 and ends at 254. It contains 16 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [237.0] and does not return any value..
pytorch_ao
public
public
0
0
_create_quantized_state_dict
def _create_quantized_state_dict(self, model: torch.nn.Module) -> Dict[str, torch.Tensor]:cur_state_dict = model.state_dict()for fqn, mod in model.named_modules():if isinstance(mod, torch.nn.Linear) and mod.bias is None:out_features = mod.out_featuresin_features = mod.in_features# assert out_features % 8 == 0, "require...
7
52
2
281
0
257
313
257
null
[]
None
null
0
0
0
null
0
null
The function (_create_quantized_state_dict) defined within the public class called public.The function start at line 257 and ends at 313. It contains 52 lines of code and it has a cyclomatic complexity of 7. It takes 2 parameters, represented as [257.0] and does not return any value..
pytorch_ao
public
public
0
0
_convert_for_runtime
def _convert_for_runtime(self, model: torch.nn.Module) -> torch.nn.Module:_replace_linear_int4(model,self.groupsize,self.inner_k_tiles,self.padding_allowed,skip_layer_func=None,precision=self.precision,scales_precision=self.precision,)return model
1
11
2
54
0
315
325
315
null
[]
None
null
0
0
0
null
0
null
The function (_convert_for_runtime) defined within the public class called public.The function start at line 315 and ends at 325. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [315.0] and does not return any value..
pytorch_ao
public
public
0
0
quantize
def quantize(self, model: torch.nn.Module, *args: Any, **kwargs: Any) -> torch.nn.Module:state_dict = self._create_quantized_state_dict(model)model = self._convert_for_runtime(model)# TODO: make it strictmodel.load_state_dict(state_dict, strict=False)return model
1
7
4
57
0
327
334
327
null
[]
None
null
0
0
0
null
0
null
The function (quantize) defined within the public class called public.The function start at line 327 and ends at 334. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [327.0] and does not return any value..
pytorch_ao
public
public
0
0
linear_forward_8da4w
def linear_forward_8da4w(x,weight_int8,bias,scales,zeros,out_features,groupsize,output_precision,):# uses fp32 to match torchao.quantization.quant_api._int8_asymm_per_token_quant# and activation_scale_dtype in QAT configs# TODO: in future add ability to specify activation_scale_dtype to PTQ configs# and enable similar ...
1
32
8
128
7
337
387
337
null
['w_dq', 'block_size', 'x', 'n_bit', 'c', 'quant_max', 'quant_min']
None
null
0
0
0
null
0
null
The function (linear_forward_8da4w) defined within the public class called public.The function start at line 337 and ends at 387. It contains 32 lines of code and it has a cyclomatic complexity of 1. It takes 8 parameters, represented as [337.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,in_features: int,out_features: int,bias=True,device=None,# TODO: remove this field, not useddtype=None,groupsize: int = 256,precision: torch.dtype = torch.float32,scales_precision: torch.dtype = torch.float32,) -> None:super().__init__()# always pad if needed since it becomes a noop at runtime if not ...
3
43
9
198
0
407
463
407
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 407 and ends at 463. It contains 43 lines of code and it has a cyclomatic complexity of 3. It takes 9 parameters, represented as [407.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, input: torch.Tensor) -> torch.Tensor:input = input.to(self.precision)# padding is removed for perf# input = F.pad(input, pad=(0, self.in_features - self.origin_in_features))return linear_forward_8da4w(input,self.weight,self.bias,self.scales,self.zeros,self.out_features,self.groupsize,self.precision,)
1
12
2
59
0
465
478
465
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 465 and ends at 478. It contains 12 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [465.0] and does not return any value..
pytorch_ao
public
public
0
0
_replace_linear_8da4w.filter_fn
def filter_fn(child: torch.nn.Module, cur_fqn: str) -> bool:return isinstance(child, nn.Linear) and (_check_linear_int4_k(child.in_features, groupsize) or padding_allowed)
3
4
2
39
0
493
496
493
null
[]
None
null
0
0
0
null
0
null
The function (_replace_linear_8da4w.filter_fn) defined within the public class called public.The function start at line 493 and ends at 496. It contains 4 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [493.0] and does not return any value..
pytorch_ao
public
public
0
0
_replace_linear_8da4w.replacement_fn
def replacement_fn(child: torch.nn.Module) -> torch.nn.Module:new_linear = linear_class(child.in_features,child.out_features,bias=child.bias is not None,device=child.weight.device,groupsize=groupsize,precision=precision,scales_precision=scales_precision,)# In distributed training, the model may be instantiated# on the ...
3
14
1
91
0
498
514
498
null
[]
None
null
0
0
0
null
0
null
The function (_replace_linear_8da4w.replacement_fn) defined within the public class called public.The function start at line 498 and ends at 514. It contains 14 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
_replace_linear_8da4w
def _replace_linear_8da4w(module: torch.nn.Module,groupsize: int,padding_allowed: bool,precision: torch.dtype,scales_precision: torch.dtype,linear_class: Type[torch.nn.Module],copy_weights: bool = False,):# import the util function here to avoid circular dependencyfrom torchao.quantization.quant_api import _replace_wit...
1
13
7
69
1
481
516
481
null
['new_linear']
None
null
0
0
0
null
0
null
The function (_replace_linear_8da4w) defined within the public class called public.The function start at line 481 and ends at 516. It contains 13 lines of code and it has a cyclomatic complexity of 1. It takes 7 parameters, represented as [481.0] and does not return any value..
pytorch_ao
public
public
0
0
replace_linear_8da4w
def replace_linear_8da4w(module: torch.nn.Module,groupsize: int,padding_allowed: bool,precision: torch.dtype,scales_precision: torch.dtype,):_replace_linear_8da4w(module,groupsize,padding_allowed,precision,scales_precision,Int8DynActInt4WeightLinear,)
1
15
5
47
0
519
533
519
null
[]
None
null
0
0
0
null
0
null
The function (replace_linear_8da4w) defined within the public class called public.The function start at line 519 and ends at 533. It contains 15 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [519.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,groupsize: int = 256,padding_allowed: bool = False,precision: torch.dtype = torch.float32,scales_precision: torch.dtype = torch.float32,device: torch.device = torch.device("cpu"),mapping_type: MappingType = MappingType.SYMMETRIC,) -> None:super().__init__()self.groupsize: int = groupsizeself.padding_a...
1
16
6
116
0
537
552
537
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 537 and ends at 552. It contains 16 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [537.0] and does not return any value..
pytorch_ao
public
public
0
0
_create_quantized_state_dict
def _create_quantized_state_dict(self, model: torch.nn.Module) -> Dict[str, torch.Tensor]:cur_state_dict = model.state_dict()for fqn, mod in model.named_modules():if isinstance(mod, torch.nn.Linear):out_features = mod.out_featuresin_features = mod.in_features# assert out_features % 8 == 0, "require out_features % 8 == ...
5
44
2
239
0
555
603
555
null
[]
None
null
0
0
0
null
0
null
The function (_create_quantized_state_dict) defined within the public class called public.The function start at line 555 and ends at 603. It contains 44 lines of code and it has a cyclomatic complexity of 5. It takes 2 parameters, represented as [555.0] and does not return any value..
pytorch_ao
public
public
0
0
_convert_for_runtime
def _convert_for_runtime(self, model: torch.nn.Module) -> torch.nn.Module:replace_linear_8da4w(model,self.groupsize,self.padding_allowed,self.precision,# TODO: this should be self.scales_precision?self.precision,)return model
1
9
2
42
0
605
614
605
null
[]
None
null
0
0
0
null
0
null
The function (_convert_for_runtime) defined within the public class called public.The function start at line 605 and ends at 614. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [605.0] and does not return any value..
pytorch_ao
public
public
0
0
quantize
def quantize(self, model: torch.nn.Module, *args: Any, **kwargs: Any) -> torch.nn.Module:state_dict = self._create_quantized_state_dict(model)model = self._convert_for_runtime(model)# TODO: make it strictmodel.load_state_dict(state_dict, strict=False)return model
1
7
4
57
0
616
623
327
null
[]
None
null
0
0
0
null
0
null
The function (quantize) defined within the public class called public.The function start at line 616 and ends at 623. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [327.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, p):self.p = p
1
2
2
12
0
33
34
33
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 33 and ends at 34. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [33.0] and does not return any value..
pytorch_ao
public
public
0
0
__call__
def __call__(self, *args, **keywords):return self.p(*args, **keywords)
1
2
3
22
0
36
37
36
null
[]
None
null
0
0
0
null
0
null
The function (__call__) defined within the public class called public.The function start at line 36 and ends at 37. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [36.0] and does not return any value..
pytorch_ao
public
public
0
0
__repr__
def __repr__(self):return self.p.__repr__()
1
2
1
13
0
39
40
39
null
[]
None
null
0
0
0
null
0
null
The function (__repr__) defined within the public class called public.The function start at line 39 and ends at 40. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
with_args
def with_args(self, *args, **kwargs):return _with_args(self, *args, **kwargs)
1
2
3
22
0
42
43
42
null
[]
None
null
0
0
0
null
0
null
The function (with_args) defined within the public class called public.The function start at line 42 and ends at 43. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [42.0] and does not return any value..
pytorch_ao
public
public
0
0
_with_args
def _with_args(cls_or_self, *args, **kwargs):r"""Wrapper that allows creation of class factories.This can be useful when there is a need to create classes with the sameconstructor arguments, but different instances.Example::>>> # xdoctest: +SKIP("Undefined vars")>>> Foo.with_args = classmethod(_with_args)>>> foo_builde...
1
3
3
30
1
46
63
46
null
['r']
None
null
0
0
0
null
0
null
The function (_with_args) defined within the public class called public.The function start at line 46 and ends at 63. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [46.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,mapping_type: MappingType,target_dtype: torch.dtype,granularity: Granularity,quant_min: Optional[int] = None,quant_max: Optional[int] = None,eps: Optional[float] = None,scale_dtype: Optional[torch.dtype] = None,zero_point_dtype: Optional[torch.dtype] = None,preserve_zero: bool = True,zero_point_domain...
2
27
11
157
0
81
107
81
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 81 and ends at 107. It contains 27 lines of code and it has a cyclomatic complexity of 2. It takes 11 parameters, represented as [81.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, input: torch.Tensor) -> torch.Tensor:"""forward function should take the input tensorand updates internal stats and return the original input Tensor"""pass
1
2
2
17
0
110
114
110
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 110 and ends at 114. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [110.0] and does not return any value..
pytorch_ao
public
public
0
0
calculate_qparams
def calculate_qparams(self) -> Tuple[torch.Tensor, torch.Tensor]:"""Calculate quantization parameter based on the stats attached to the observer moduleand returns a tuple of scale and zero_point Tensor"""pass
1
2
1
18
0
117
121
117
null
[]
None
null
0
0
0
null
0
null
The function (calculate_qparams) defined within the public class called public.The function start at line 117 and ends at 121. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, input: torch.Tensor):if input.numel() == 0:return inputinput_detached = input.detach()assert self.granularity is not None, "granularity is None"block_size = get_block_size(input_detached.shape, self.granularity)shape_for_reduction, reduction_dims = _get_reduction_params(block_size, input_detached.size...
4
27
2
205
0
125
154
125
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 125 and ends at 154. It contains 27 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [125.0] and does not return any value..
pytorch_ao
public
public
0
0
calculate_qparams
def calculate_qparams(self) -> Tuple[torch.Tensor, torch.Tensor]:assert hasattr(self, "min_val") and hasattr(self, "max_val"), ("Expecting the observer has min_val and max_val, please run the observer before calling calculate_qparams")return choose_qparams_affine_with_min_max(self.min_val,self.max_val,self.mapping_type...
2
18
1
85
0
156
173
156
null
[]
None
null
0
0
0
null
0
null
The function (calculate_qparams) defined within the public class called public.The function start at line 156 and ends at 173. 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
__init__
def __init__(self,mapping_type: MappingType,target_dtype: torch.dtype,granularity: Granularity,quant_min: Optional[int] = None,quant_max: Optional[int] = None,eps: Optional[float] = None,scale_dtype: Optional[torch.dtype] = None,zero_point_dtype: Optional[torch.dtype] = None,preserve_zero: bool = True,zero_point_domain...
3
33
13
188
0
181
213
181
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 181 and ends at 213. It contains 33 lines of code and it has a cyclomatic complexity of 3. It takes 13 parameters, represented as [181.0] and does not return any value..
pytorch_ao
public
public
0
0
set_qparams
def set_qparams(self, scale, zero_point=None):if not zero_point:zero_point = torch.zeros_like(scale)self.scale = scale.to(dtype=self.scale_dtype)self.zero_point = zero_point.to(dtype=self.zero_point_dtype)
2
5
3
51
0
215
219
215
null
[]
None
null
0
0
0
null
0
null
The function (set_qparams) defined within the public class called public.The function start at line 215 and ends at 219. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [215.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, input):return input
1
2
2
9
0
221
222
221
null
[]
None
null
0
0
0
null
0
null
The function (forward) 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 [221.0] and does not return any value..
pytorch_ao
public
public
0
0
calculate_qparams
def calculate_qparams(self):return self.scale, self.zero_point
1
2
1
13
0
224
225
224
null
[]
None
null
0
0
0
null
0
null
The function (calculate_qparams) defined within the public class called public.The function start at line 224 and ends at 225. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,mapping_type: MappingType,target_dtype: torch.dtype,granularity: Granularity,quant_min: Optional[int] = None,quant_max: Optional[int] = None,eps: Optional[float] = None,scale_dtype: Optional[torch.dtype] = None,zero_point_dtype: Optional[torch.dtype] = None,preserve_zero: bool = True,zero_point_domain...
1
30
13
137
0
233
262
233
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 233 and ends at 262. It contains 30 lines of code and it has a cyclomatic complexity of 1. It takes 13 parameters, represented as [233.0] and does not return any value..
pytorch_ao
public
public
0
0
mse
def mse(self, pred, expect, block_size):loss = (pred - expect).abs().pow(2)shape_for_reduction, reduction_dims = _get_reduction_params(block_size, loss.size())loss = loss.view(shape_for_reduction)return torch.mean(loss, dim=reduction_dims, keepdim=False)
1
7
4
64
0
264
270
264
null
[]
None
null
0
0
0
null
0
null
The function (mse) defined within the public class called public.The function start at line 264 and ends at 270. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [264.0] and does not return any value..
pytorch_ao
public
public
0
0
loss_fn
def loss_fn(self, x, new_min, new_max):block_size = get_block_size(x.shape, self.granularity)scale, zero_point = choose_qparams_affine_with_min_max(new_min,new_max,self.mapping_type,[],self.target_dtype,self.quant_min,self.quant_max,self.eps,self.scale_dtype,self.zero_point_dtype,self.preserve_zero,self.zero_point_doma...
1
27
4
113
0
272
298
272
null
[]
None
null
0
0
0
null
0
null
The function (loss_fn) defined within the public class called public.The function start at line 272 and ends at 298. It contains 27 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [272.0] and does not return any value..
pytorch_ao
public
public
0
0
line_search
def line_search(self, input):if input.numel() == 0:return inputinput_detached = input.detach()assert self.granularity is not None, "granularity is None"block_size = get_block_size(input_detached.shape, self.granularity)shape_for_reduction, reduction_dims = _get_reduction_params(block_size, input_detached.size())input_d...
3
21
2
203
0
300
326
300
null
[]
None
null
0
0
0
null
0
null
The function (line_search) defined within the public class called public.The function start at line 300 and ends at 326. It contains 21 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [300.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, input):if not (self.run_once and self.calibrated):self.min_val, self.max_val = self.line_search(input)self.calibrated = Truereturn input
3
5
2
40
0
328
333
328
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 328 and ends at 333. It contains 5 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [328.0] and does not return any value..
pytorch_ao
public
public
0
0
calculate_qparams
def calculate_qparams(self):assert hasattr(self, "min_val") and hasattr(self, "max_val"), ("Expecting the observer has min_val and max_val, please run the observer before calling calculate_qparams")return choose_qparams_affine_with_min_max(self.min_val,self.max_val,self.mapping_type,[],self.target_dtype,self.quant_min,...
2
18
1
74
0
335
352
335
null
[]
None
null
0
0
0
null
0
null
The function (calculate_qparams) defined within the public class called public.The function start at line 335 and ends at 352. 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
_replace_with_custom_fn_if_matches_filter
def _replace_with_custom_fn_if_matches_filter(model,replacement_fn,filter_fn,cur_fqn="",device=None,extra_args: Optional[Tuple[Any, ...]] = (),) -> None:"""Recursively replaces each child module in `model` with the result of `replacement_fn(child)`if `filter_fn(child)` returns `True`.Args:model (torch.nn.Module): The m...
8
35
6
193
4
180
229
180
null
['named_children_list', 'new_module', 'new_child', 'model']
None
null
0
0
0
null
0
null
The function (_replace_with_custom_fn_if_matches_filter) defined within the public class called public.The function start at line 180 and ends at 229. It contains 35 lines of code and it has a cyclomatic complexity of 8. It takes 6 parameters, represented as [180.0] and does not return any value..
pytorch_ao
public
public
0
0
_replace_with_custom_fn_if_matches_filter_with_name
def _replace_with_custom_fn_if_matches_filter_with_name(model,replacement_fn,filter_fn,cur_fqn="",device=None,extra_args: Optional[Tuple[Any, ...]] = (),) -> None:"""A variant of _replace_with_custom_fn_if_matches_filter where replacement_fn takes module name as well...replacement_fn (Callable[[torch.nn.Module, str], t...
7
35
6
195
4
232
275
232
null
['named_children_list', 'new_module', 'new_child', 'model']
None
null
0
0
0
null
0
null
The function (_replace_with_custom_fn_if_matches_filter_with_name) defined within the public class called public.The function start at line 232 and ends at 275. It contains 35 lines of code and it has a cyclomatic complexity of 7. It takes 6 parameters, represented as [232.0] and does not return any value..
pytorch_ao
public
public
0
0
_is_linear
def _is_linear(mod, *args):# avoid circular dependenciesfrom torchao.quantization.qat.affine_fake_quantized_tensor import (_AffineFakeQuantizedTensor,)# adding weight tensor subclass isinstance check to make sure the weight is only quantized once# when it is shared by multiple linear modulesreturn (isinstance(mod, torc...
8
14
2
105
0
278
295
278
null
[]
None
null
0
0
0
null
0
null
The function (_is_linear) defined within the public class called public.The function start at line 278 and ends at 295. It contains 14 lines of code and it has a cyclomatic complexity of 8. It takes 2 parameters, represented as [278.0] and does not return any value..
pytorch_ao
public
public
0
0
_get_subclass_inserter.insert_subclass
def insert_subclass(lin):if enable_parametrization:lin.weight = torch.nn.Parameter(cls.from_float(lin.weight, **kwargs), requires_grad=False)_, args = lin.weight.__tensor_flatten__()parametrize.register_parametrization(lin, "weight", getattr(cls, constructor)(*args))else:lin.weight = torch.nn.Parameter(# cls.from_float...
2
15
1
98
0
312
327
312
null
[]
None
null
0
0
0
null
0
null
The function (_get_subclass_inserter.insert_subclass) defined within the public class called public.The function start at line 312 and ends at 327. It contains 15 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_get_subclass_inserter
def _get_subclass_inserter(cls, enable_parametrization=False, **kwargs):"""Returns a function which inserts the given subclass into all linear modulesin the model. The inserted module will have its weight set to the result of`cls(mod.weight, **kwargs)`. If parametrization is enabled then this will be done usingtorch.nn...
1
5
3
37
2
298
329
298
null
['from_float', 'constructor']
None
null
0
0
0
null
0
null
The function (_get_subclass_inserter) defined within the public class called public.The function start at line 298 and ends at 329. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [298.0] and does not return any value..
pytorch_ao
public
public
0
0
swap_conv2d_1x1_to_linear.__init__
def __init__(self, mod):super().__init__()self.mod = mod
1
3
2
19
0
338
340
338
null
[]
None
null
0
0
0
null
0
null
The function (swap_conv2d_1x1_to_linear.__init__) defined within the public class called public.The function start at line 338 and ends at 340. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [338.0] and does not return any value..
pytorch_ao
public
public
0
0
swap_conv2d_1x1_to_linear.forward
def forward(self, *args):return self.mod(args[0].permute(0, 2, 3, 1)).permute(-0, 3, 1, 2)
1
2
2
41
0
342
343
342
null
[]
None
null
0
0
0
null
0
null
The function (swap_conv2d_1x1_to_linear.forward) defined within the public class called public.The function start at line 342 and ends at 343. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [342.0] and does not return any value..
pytorch_ao
public
public
0
0
swap_conv2d_1x1_to_linear.replace_conv2d_1x1
def replace_conv2d_1x1(conv):assert conv.kernel_size == (1, 1)lin = torch.nn.Linear(conv.in_channels, conv.out_channels, bias=(conv.bias is None))lin.weight = torch.nn.Parameter(conv.weight.squeeze(-1, -2))lin.bias = conv.biasreturn PermuteSandwich(lin)
1
8
1
76
0
345
352
345
null
[]
None
null
0
0
0
null
0
null
The function (swap_conv2d_1x1_to_linear.replace_conv2d_1x1) defined within the public class called public.The function start at line 345 and ends at 352. 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
swap_conv2d_1x1_to_linear
def swap_conv2d_1x1_to_linear(model, filter_fn=None):"""Changes all conv2d 1x1 modules to equivalent linear modules so that they can then be quantized."""class PermuteSandwich(torch.nn.Module):def __init__(self, mod):super().__init__()self.mod = moddef forward(self, *args):return self.mod(args[0].permute(0, 2, 3, 1)).p...
3
12
2
69
2
332
361
332
null
['filter_fn', 'lin']
None
null
0
0
0
null
0
null
The function (swap_conv2d_1x1_to_linear) defined within the public class called public.The function start at line 332 and ends at 361. It contains 12 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [332.0] and does not return any value..
pytorch_ao
public
public
0
0
insert_observers_.convert_to_linear_observer
def convert_to_linear_observer(linear_module: nn.Linear):# Wrap the weight with LinearActivationWeightObservedTensor and then with nn.Parameterlinear_module.weight = nn.Parameter(LinearActivationWeightObservedTensor.from_float(linear_module.weight,input_observer=input_observer,weight_observer=weight_observer,),requires...
1
10
1
46
0
426
436
426
null
[]
None
null
0
0
0
null
0
null
The function (insert_observers_.convert_to_linear_observer) defined within the public class called public.The function start at line 426 and ends at 436. 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
insert_observers_
def insert_observers_(model: nn.Module,input_observer: Optional[AffineQuantizedObserverBase],weight_observer: Optional[AffineQuantizedObserverBase],*,filter_fn: Optional[Callable[[torch.nn.Module, str], bool]] = None,):"""Converts the weight of a linear module to a LinearActivationWeightObservedTensor.This function wra...
2
13
5
66
0
364
442
364
null
[]
None
null
0
0
0
null
0
null
The function (insert_observers_) defined within the public class called public.The function start at line 364 and ends at 442. It contains 13 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [364.0] and does not return any value..
pytorch_ao
public
public
0
0
_quantization_type
def _quantization_type(weight: torch.Tensor):if isinstance(weight, AffineQuantizedTensor):return f"{weight.__class__.__name__}({weight._quantization_type()})"if isinstance(weight, LinearActivationQuantizedTensor):return f"{weight.__class__.__name__}(activation={weight.input_quant_func}, weight={_quantization_type(weigh...
6
10
1
69
0
445
458
445
null
[]
None
null
0
0
0
null
0
null
The function (_quantization_type) defined within the public class called public.The function start at line 445 and ends at 458. It contains 10 lines of code and it has a cyclomatic complexity of 6. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_linear_extra_repr
def _linear_extra_repr(self):return f"in_features={self.weight.shape[1]}, out_features={self.weight.shape[0]}, weight={_quantization_type(self.weight)}"
1
2
1
8
0
461
462
461
null
[]
None
null
0
0
0
null
0
null
The function (_linear_extra_repr) defined within the public class called public.The function start at line 461 and ends at 462. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_embedding_extra_repr
def _embedding_extra_repr(self):return f"num_embeddings={self.weight.shape[0]}, embedding_dim={self.weight.shape[1]}, weight={_quantization_type(self.weight)}"
1
2
1
8
0
465
466
465
null
[]
None
null
0
0
0
null
0
null
The function (_embedding_extra_repr) defined within the public class called public.The function start at line 465 and ends at 466. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_get_linear_subclass_inserter.insert_subclass
def insert_subclass(lin):requires_grad = allow_requires_grad and lin.weight.requires_gradif propagate_bias == True:kwargs["bias"] = lin.biaslin.weight = torch.nn.Parameter(constructor(lin.weight, **kwargs), requires_grad=requires_grad)lin.extra_repr = types.MethodType(_linear_extra_repr, lin)return lin
3
9
1
65
0
476
484
476
null
[]
None
null
0
0
0
null
0
null
The function (_get_linear_subclass_inserter.insert_subclass) defined within the public class called public.The function start at line 476 and ends at 484. It contains 9 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
_get_linear_subclass_inserter
def _get_linear_subclass_inserter(constructor, *, allow_requires_grad=False, propagate_bias=False, **kwargs):"""Helper function to apply the constructor that quantizes the weight Tensor (with additional kwargs)to the weight of linear module"""def insert_subclass(lin):requires_grad = allow_requires_grad and lin.weight.r...
1
5
4
23
1
469
486
469
null
['requires_grad']
None
null
0
0
0
null
0
null
The function (_get_linear_subclass_inserter) defined within the public class called public.The function start at line 469 and ends at 486. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [469.0] and does not return any value..
pytorch_ao
public
public
0
0
quantize_
def quantize_(model: torch.nn.Module,config: AOBaseConfig,filter_fn: Optional[Callable[[torch.nn.Module, str], bool]] = None,device: Optional[torch.types.Device] = None,):"""Convert the weight of linear modules in the model with `config`, model is modified inplaceArgs:model (torch.nn.Module): input modelconfig (AOBaseC...
4
30
5
142
2
489
552
489
null
['filter_fn', 'handler']
None
null
0
0
0
null
0
null
The function (quantize_) defined within the public class called public.The function start at line 489 and ends at 552. It contains 30 lines of code and it has a cyclomatic complexity of 4. It takes 5 parameters, represented as [489.0] and does not return any value..
pytorch_ao
public
public
0
0
_int8_asymm_per_token_quant
def _int8_asymm_per_token_quant(x: torch.Tensor) -> torch.Tensor:"""This is defined here instead of local function to support serialization"""mapping_type = MappingType.ASYMMETRICtarget_dtype = torch.int8scale_dtype = torch.float32eps = torch.finfo(torch.float32).epszero_point_dtype = torch.int8return to_affine_quantiz...
1
15
1
73
5
555
570
555
null
['scale_dtype', 'eps', 'target_dtype', 'mapping_type', 'zero_point_dtype']
None
null
0
0
0
null
0
null
The function (_int8_asymm_per_token_quant) defined within the public class called public.The function start at line 555 and ends at 570. 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
_uint8_asymm_per_token_quant
def _uint8_asymm_per_token_quant(x: torch.Tensor) -> torch.Tensor:mapping_type = MappingType.ASYMMETRICtarget_dtype = torch.uint8scale_dtype = torch.float32eps = torch.finfo(torch.float32).epszero_point_dtype = torch.int32quant_min = 0quant_max = 255out = to_affine_quantized_intx(x,mapping_type,_get_per_token_block_siz...
1
20
1
89
8
573
592
573
null
['scale_dtype', 'out', 'quant_min', 'eps', 'target_dtype', 'quant_max', 'mapping_type', 'zero_point_dtype']
None
null
0
0
0
null
0
null
The function (_uint8_asymm_per_token_quant) defined within the public class called public.The function start at line 573 and ends at 592. 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
_int8_symm_per_token_quant
def _int8_symm_per_token_quant(x: torch.Tensor) -> torch.Tensor:mapping_type = MappingType.SYMMETRICtarget_dtype = torch.int8eps = 1e-5quant_min = -127quant_max = 127return to_affine_quantized_intx(x,mapping_type,_get_per_token_block_size(x),target_dtype,eps=eps,quant_min=quant_min,quant_max=quant_max,scale_dtype=torch...
1
16
1
68
5
595
611
595
null
['mapping_type', 'eps', 'target_dtype', 'quant_max', 'quant_min']
None
null
0
0
0
null
0
null
The function (_int8_symm_per_token_quant) defined within the public class called public.The function start at line 595 and ends at 611. It contains 16 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
__post_init__
def __post_init__(self):torch._C._log_api_usage_once("torchao.quantization.Int8DynamicActivationInt4WeightConfig")
1
4
1
13
0
635
638
635
null
[]
None
null
0
0
0
null
0
null
The function (__post_init__) defined within the public class called public.The function start at line 635 and ends at 638. 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
_int8_dynamic_activation_int4_weight_transform
def _int8_dynamic_activation_int4_weight_transform(module: torch.nn.Module,config: Int8DynamicActivationInt4WeightConfig,*,custom_scale: Optional[torch.Tensor] = None,custom_zero_point: Optional[torch.Tensor] = None,):group_size = config.group_sizelayout = config.layoutmapping_type = config.mapping_typeact_mapping_type...
13
70
4
348
10
648
724
648
null
['quant_min', 'layout', 'group_size', 'block_size', 'act_mapping_type', 'target_dtype', 'quant_max', 'mapping_type', 'weight', 'input_quant_func']
None
null
0
0
0
null
0
null
The function (_int8_dynamic_activation_int4_weight_transform) defined within the public class called public.The function start at line 648 and ends at 724. It contains 70 lines of code and it has a cyclomatic complexity of 13. It takes 4 parameters, represented as [648.0] and does not return any value..
pytorch_ao
public
public
0
0
__post_init__
def __post_init__(self):torch._C._log_api_usage_once("torchao.quantization.Int8DynamicActivationIntxWeightConfig")assert self.weight_dtype in [getattr(torch, f"int{b}") for b in range(1, 9)], (f"weight_dtype must be torch.intx, where 1 <= x <= 8, but got {self.weight_dtype}")assert isinstance(self.weight_granularity, (...
7
43
1
205
0
777
820
777
null
[]
None
null
0
0
0
null
0
null
The function (__post_init__) defined within the public class called public.The function start at line 777 and ends at 820. It contains 43 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
_int8_dynamic_activation_intx_weight_quantize_tensor
def _int8_dynamic_activation_intx_weight_quantize_tensor(weight,bias,config,*,custom_scale: Optional[torch.Tensor] = None,custom_zero_point: Optional[torch.Tensor] = None,):weight_dtype = config.weight_dtypeweight_granularity = config.weight_granularityweight_mapping_type = config.weight_mapping_typeweight_scale_dtype ...
15
120
5
560
22
823
964
823
null
['has_weight_zeros', 'bias', 'act_mapping_type', 'custom_zero_point', 'new_weight', 'weight_dtype', 'opaque_formats', 'intx_packing_format', 'zero_point', 'scale', 'groups_per_row', 'weight_granularity', 'weight_scale_dtype', 'block_size', 'activation_quant_func', 'new_bias', 'preserve_zero', 'layout', 'weight_mapping_...
None
null
0
0
0
null
0
null
The function (_int8_dynamic_activation_intx_weight_quantize_tensor) defined within the public class called public.The function start at line 823 and ends at 964. It contains 120 lines of code and it has a cyclomatic complexity of 15. It takes 5 parameters, represented as [823.0] and does not return any value..
pytorch_ao
public
public
0
0
_int8_dynamic_activation_intx_weight_transform
def _int8_dynamic_activation_intx_weight_transform(module: torch.nn.Module,config: Int8DynamicActivationIntxWeightConfig,*,custom_scale: Optional[torch.Tensor] = None,custom_zero_point: Optional[torch.Tensor] = None,) -> torch.nn.Module:new_weight, new_bias = _int8_dynamic_activation_intx_weight_quantize_tensor(module....
3
20
4
121
0
968
987
968
null
[]
None
null
0
0
0
null
0
null
The function (_int8_dynamic_activation_intx_weight_transform) defined within the public class called public.The function start at line 968 and ends at 987. It contains 20 lines of code and it has a cyclomatic complexity of 3. It takes 4 parameters, represented as [968.0] and does not return any value..
pytorch_ao
public
public
0
0
__post_init__
def __post_init__(self):torch._C._log_api_usage_once("torchao.quantization.Int8DynamicActivationInt4WeightConfig")
1
4
1
13
0
1,006
1,009
635
null
[]
None
null
0
0
0
null
0
null
The function (__post_init__) defined within the public class called public.The function start at line 1006 and ends at 1009. 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
_int4_dynamic_activation_int4_weight_transform
def _int4_dynamic_activation_int4_weight_transform(module: torch.nn.Module, config: Int4DynamicActivationInt4WeightConfig) -> torch.nn.Module:weight = module.weightlayout = config.layoutmapping_type = config.mapping_typeact_mapping_type = config.act_mapping_typeif config.set_inductor_config:torchao.quantization.utils.r...
5
25
2
139
4
1,019
1,045
1,019
null
['layout', 'act_mapping_type', 'weight', 'mapping_type']
None
null
0
0
0
null
0
null
The function (_int4_dynamic_activation_int4_weight_transform) defined within the public class called public.The function start at line 1019 and ends at 1045. It contains 25 lines of code and it has a cyclomatic complexity of 5. It takes 2 parameters, represented as [1019.0] and does not return any value..
pytorch_ao
public
public
0
0
__post_init__
def __post_init__(self):torch._C._log_api_usage_once("torchao.quantization.Int8DynamicActivationInt4WeightConfig")
1
4
1
13
0
1,069
1,072
635
null
[]
None
null
0
0
0
null
0
null
The function (__post_init__) defined within the public class called public.The function start at line 1069 and ends at 1072. 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..