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
fold_weight
def fold_weight(self):# note: _W_zps are zeroes and they are ignored# TODO(future PR): set up serialization for thisW_int_repr, self.W_scales, _W_zps = self.get_scaled_quantized_w()# need to store transposed weights to make eager mode matmul# op work in cuBlas, or non-transposed to make it fast in torch.compileif self....
2
7
1
60
0
109
119
109
null
[]
None
null
0
0
0
null
0
null
The function (fold_weight) defined within the public class called public.The function start at line 109 and ends at 119. It contains 7 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
set_debug_x_absmax
def set_debug_x_absmax(self):"""Sets `self.x_running_abs_max` to a value which will lead to smooth scaleof all ones if `alpha=0.5`, to enable performance benchmarking withoutcalibration."""raise NotImplementedError()
1
2
1
10
0
121
127
121
null
[]
None
null
0
0
0
null
0
null
The function (set_debug_x_absmax) defined within the public class called public.The function start at line 121 and ends at 127. 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, *args, **kwargs):alpha = kwargs.pop("alpha")super().__init__(*args, **kwargs)self.init_smoothquant_variables(alpha)
1
4
3
37
0
137
140
137
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 137 and ends at 140. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [137.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, X, *args, **kwargs):if self.calibrating:self.update_x_running_abs_max(X)Y = F.linear(X, self.weight, self.bias)else:if not self.debug_skip_scaling:# Ideally this would be fused into preceding layers# but in practice torch.compile fuses it with other# ops so the slowdown is minimalX = X / self.smooth_s...
4
14
4
96
0
142
158
142
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 142 and ends at 158. It contains 14 lines of code and it has a cyclomatic complexity of 4. It takes 4 parameters, represented as [142.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls, mod, alpha=0.5):"""Converts a `mod` of class `torch.nn.Linear` to the smooth fake quantizedversion of it.Note: requires calibration."""# create the new module with a toy size to ensure initialization is fastfake_in_features, fake_out_features = 8, 8new_mod = cls(fake_in_features, fake_out_features, ...
1
12
3
90
0
161
178
161
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 161 and ends at 178. It contains 12 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [161.0] and does not return any value..
pytorch_ao
public
public
0
0
to_inference
def to_inference(self):"""Calculates the smoothquant scale based on calibrationin preparation for inference"""assert self.x_running_abs_max is not None, "no calibration data found"self.calibrating = Falseself.smooth_scale = get_scale(self.x_running_abs_max,torch.max(torch.abs(self.weight.transpose(0, 1)), dim=1).values...
1
9
1
69
0
180
192
180
null
[]
None
null
0
0
0
null
0
null
The function (to_inference) defined within the public class called public.The function start at line 180 and ends at 192. 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
set_debug_x_absmax
def set_debug_x_absmax(self):w_absmax = torch.max(torch.abs(self.weight.transpose(0, 1)), dim=1).valuesself.x_running_abs_max = w_absmax
1
3
1
38
0
194
196
194
null
[]
None
null
0
0
0
null
0
null
The function (set_debug_x_absmax) defined within the public class called public.The function start at line 194 and ends at 196. 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
swap_linear_with_smooth_fq_linear
def swap_linear_with_smooth_fq_linear(model, skip_fqn_list=None, cur_fqn="", alpha=0.5) -> None:"""Replaces linear layers in the model with their SmoothFakeDynamicallyQuantizedLinear equivalents.Args:model (torch.nn.Module): The model containing linear layers to be replaced.skip_fqn_list (list of str, optional): List o...
6
17
4
127
4
209
238
209
null
['new_fqn', 'target_cls', 'new_child', 'name_to_child']
None
null
0
0
0
null
0
null
The function (swap_linear_with_smooth_fq_linear) defined within the public class called public.The function start at line 209 and ends at 238. It contains 17 lines of code and it has a cyclomatic complexity of 6. It takes 4 parameters, represented as [209.0] and does not return any value..
pytorch_ao
public
public
0
0
smooth_fq_linear_to_inference
def smooth_fq_linear_to_inference(model, debug_skip_calibration=False) -> None:"""Prepares the model for inference by calculating the smoothquant scale for each SmoothFakeDynamicallyQuantizedLinear layer.Args:model (torch.nn.Module): The model containing SmoothFakeDynamicallyQuantizedLinear layers.debug_skip_calibratio...
4
6
2
51
0
241
257
241
null
[]
None
null
0
0
0
null
0
null
The function (smooth_fq_linear_to_inference) defined within the public class called public.The function start at line 241 and ends at 257. It contains 6 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [241.0] and does not return any value..
pytorch_ao
public
public
0
0
set_smooth_fq_attribute
def set_smooth_fq_attribute(model, attribute_name, new_attribute_val):for _, mod in model.named_modules():if isinstance(mod, tuple(source_cls_to_target_cls.values())):if hasattr(mod, attribute_name):setattr(mod, attribute_name, new_attribute_val)
4
5
3
51
0
262
266
262
null
[]
None
null
0
0
0
null
0
null
The function (set_smooth_fq_attribute) defined within the public class called public.The function start at line 262 and ends at 266. It contains 5 lines of code and it has a cyclomatic complexity of 4. It takes 3 parameters, represented as [262.0] and does not return any value..
pytorch_ao
public
public
0
0
__new__
def __new__(cls, int_data, transposed, shape, *args, **kwargs):kwargs["device"] = int_data.devicekwargs["layout"] = (kwargs.get("layout") if kwargs.get("layout", False) else int_data.layout)assert "dtype" in kwargsassert not kwargs.get("requires_grad", False)kwargs["requires_grad"] = Falsereturn torch.Tensor._make_wrap...
2
9
6
85
0
49
57
49
null
[]
None
null
0
0
0
null
0
null
The function (__new__) defined within the public class called public.The function start at line 49 and ends at 57. It contains 9 lines of code and it has a cyclomatic complexity of 2. It takes 6 parameters, represented as [49.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, int_data, transposed, *args, **kwargs):self.int_data = int_dataself.transposed = transposed
1
3
5
25
0
59
62
59
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 59 and ends at 62. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [59.0] and does not return any value..
pytorch_ao
public
public
0
0
_quantized_op
def _quantized_op(act_mat, w_qtensor, bias):pass
1
2
3
10
0
65
66
65
null
[]
None
null
0
0
0
null
0
null
The function (_quantized_op) defined within the public class called public.The function start at line 65 and ends at 66. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [65.0] and does not return any value..
pytorch_ao
public
public
0
0
__repr__
def __repr__(self):return (f"{self.__class__.__name__}(data={self.dequantize()}, shape={self.shape}, "f"device={self.device}, dtype={self.dtype}, requires_grad={self.requires_grad})")
1
5
1
12
0
68
72
68
null
[]
None
null
0
0
0
null
0
null
The function (__repr__) defined within the public class called public.The function start at line 68 and ends at 72. It contains 5 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
dequantize
def dequantize(self):pass
1
2
1
6
0
74
75
74
null
[]
None
null
0
0
0
null
0
null
The function (dequantize) defined within the public class called public.The function start at line 74 and ends at 75. 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
int_repr
def int_repr(self):pass
1
2
1
6
0
77
78
77
null
[]
None
null
0
0
0
null
0
null
The function (int_repr) defined within the public class called public.The function start at line 77 and ends at 78. 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
q_params
def q_params(self):pass
1
2
1
6
0
80
81
80
null
[]
None
null
0
0
0
null
0
null
The function (q_params) defined within the public class called public.The function start at line 80 and ends at 81. 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
half
def half(self):return self.to(torch.float16)
1
2
1
14
0
83
84
83
null
[]
None
null
0
0
0
null
0
null
The function (half) defined within the public class called public.The function start at line 83 and ends at 84. 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_to_kwargs
def _get_to_kwargs(self, *args, **kwargs):device, dtype, _, memory_format = torch._C._nn._parse_to(*args, **kwargs)device = self.device if device is None else devicedtype = self.dtype if dtype is None else dtypememory_format = (memory_format if memory_format is not None else torch.preserve_format)kwargs = {"device": de...
4
13
3
87
0
86
98
86
null
[]
None
null
0
0
0
null
0
null
The function (_get_to_kwargs) defined within the public class called public.The function start at line 86 and ends at 98. It contains 13 lines of code and it has a cyclomatic complexity of 4. It takes 3 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):pass
1
2
2
8
0
100
101
100
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 100 and ends at 101. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [100.0] and does not return any value..
pytorch_ao
public
public
0
0
_change_shape
def _change_shape(self):pass
1
2
1
6
0
103
104
103
null
[]
None
null
0
0
0
null
0
null
The function (_change_shape) defined within the public class called public.The function start at line 103 and ends at 104. 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_flatten__
def __tensor_flatten__(self):pass
1
2
1
6
0
106
107
106
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 106 and ends at 107. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
__tensor_unflatten__
def __tensor_unflatten__(cls, tensor_data_dict, tensor_attributes, outer_size, outer_stride):pass
1
4
5
14
0
110
113
110
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 110 and ends at 113. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [110.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls, input_float):pass
1
2
2
8
0
116
117
116
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 116 and ends at 117. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [116.0] and does not return any value..
pytorch_ao
public
public
0
0
__torch_function__
def __torch_function__(cls, func, types, args=(), kwargs=None):kwargs = {} if kwargs is None else kwargsif func is torch.nn.functional.linear:mat1, w_qtensor, bias = (args[0],args[1],args[2] if len(args) > 2 else None,)assert not w_qtensor.transposedreturn cls._quantized_op(mat1, w_qtensor, bias)try:with torch._C.Disab...
5
15
4
115
0
122
138
122
null
[]
None
null
0
0
0
null
0
null
The function (__torch_function__) defined within the public class called public.The function start at line 122 and ends at 138. It contains 15 lines of code and it has a cyclomatic complexity of 5. It takes 4 parameters, represented as [122.0] and does not return any value..
pytorch_ao
public
public
0
0
__torch_dispatch__
def __torch_dispatch__(cls, func, types, args, kwargs):# two scenarios where we currently fall back to vanilla mm:# 1 - when tensor is on CPU: we are missing qmm for CPU, but we should have a CPU implementation# for consistency and to allow people to test# 2 - we're given non-floats - quantizing long to int8 is crazyif...
10
46
5
340
0
141
196
141
null
[]
None
null
0
0
0
null
0
null
The function (__torch_dispatch__) defined within the public class called public.The function start at line 141 and ends at 196. It contains 46 lines of code and it has a cyclomatic complexity of 10. It takes 5 parameters, represented as [141.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, *args, **kwargs):super().__init__()self.args = argsself.kwargs = kwargs
1
4
3
28
0
200
203
200
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 200 and ends at 203. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [200.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, x):pass
1
2
2
8
0
205
206
205
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 205 and ends at 206. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [205.0] and does not return any value..
pytorch_ao
public
public
0
0
right_inverse
def right_inverse(self, tensor_subclass_instance):fields, _ = tensor_subclass_instance.__tensor_flatten__()return [getattr(tensor_subclass_instance, field) for field in fields]
2
3
2
29
0
208
210
208
null
[]
None
null
0
0
0
null
0
null
The function (right_inverse) defined within the public class called public.The function start at line 208 and ends at 210. It contains 3 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [208.0] and does not return any value..
pytorch_ao
public
public
0
0
from_qtensor_components_int8dyn
def from_qtensor_components_int8dyn(*args, **kwargs):return Int8DynamicallyQuantizedLinearWeight(*args, **kwargs)
1
2
2
18
0
214
215
214
null
[]
None
null
0
0
0
null
0
null
The function (from_qtensor_components_int8dyn) defined within the public class called public.The function start at line 214 and ends at 215. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [214.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, int_data, q_scales):return from_qtensor_components_int8dyn(int_data, q_scales, *self.args, **self.kwargs)
1
4
3
26
0
219
222
219
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 219 and ends at 222. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [219.0] and does not return any value..
pytorch_ao
public
public
0
0
__new__
def __new__(cls, int_data, q_scales, transposed, shape, dtype=None, **kwargs):if dtype is None:dtype = q_scales.dtypekwargs["dtype"] = dtypereturn super().__new__(cls, int_data, transposed, shape, **kwargs)# type: ignore[attr-defined]
2
5
7
54
0
235
239
235
null
[]
None
null
0
0
0
null
0
null
The function (__new__) defined within the public class called public.The function start at line 235 and ends at 239. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 7 parameters, represented as [235.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, int_data, q_scales, transposed, shape, dtype=None, **kwargs):self.q_scales = q_scalessuper().__init__(int_data, transposed)
1
3
7
35
0
241
243
241
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 241 and ends at 243. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 7 parameters, represented as [241.0] and does not return any value..
pytorch_ao
public
public
0
0
_quantized_op
def _quantized_op(act_mat, w_qtensor, bias):return _quant_int8_dynamic_per_token_linear(act_mat, w_qtensor.int_data, w_qtensor.q_scales, bias, act_mat.dtype)
1
4
3
28
0
246
249
246
null
[]
None
null
0
0
0
null
0
null
The function (_quantized_op) defined within the public class called public.The function start at line 246 and ends at 249. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [246.0] and does not return any value..
pytorch_ao
public
public
0
0
dequantize
def dequantize(self, dtype=None):"""Obtain the dequantized version of the quantized tensor subclass"""zero_points = torch.zeros(self.q_scales.shape, device=self.q_scales.device, dtype=self.q_scales.dtype)# zero_points = 0# TODO: fix dtype here? `to(self.dtype)` is not overwritten by `dtype` arg?dq_t = dequantize_per_ch...
3
11
2
87
0
251
267
251
null
[]
None
null
0
0
0
null
0
null
The function (dequantize) defined within the public class called public.The function start at line 251 and ends at 267. It contains 11 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [251.0] and does not return any value..
pytorch_ao
public
public
0
0
int_repr
def int_repr(self):"""Get the internal integer representation of the quantized tensor"""return self.int_data if self.transposed else self.int_data.t()
2
2
1
22
0
269
273
269
null
[]
None
null
0
0
0
null
0
null
The function (int_repr) defined within the public class called public.The function start at line 269 and ends at 273. It contains 2 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
q_params
def q_params(self):"""Get the quantization scales for the quantized tensor"""return {"q_scales": self.q_scales}
1
2
1
14
0
275
279
275
null
[]
None
null
0
0
0
null
0
null
The function (q_params) defined within the public class called public.The function start at line 275 and ends at 279. 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
to
def to(self, *args, **kwargs):kwargs = self._get_to_kwargs(*args, **kwargs)return self.__class__(self.int_data.to(kwargs["device"]),self.q_scales.to(kwargs["device"]),self.transposed,self.shape,**kwargs,)
1
9
3
64
0
281
289
281
null
[]
None
null
0
0
0
null
0
null
The function (to) defined within the public class called public.The function start at line 281 and ends at 289. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [281.0] and does not return any value..
pytorch_ao
public
public
0
0
_apply_fn_to_data
def _apply_fn_to_data(self, fn):return self.__class__(fn(self.int_data),fn(self.q_scales),self.transposed,self.shape,dtype=self.dtype,)
1
8
2
41
0
291
298
291
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 291 and ends at 298. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [291.0] and does not return any value..
pytorch_ao
public
public
0
0
_change_shape
def _change_shape(self, shape):return self.__class__(self.int_data, self.q_scales, self.transposed, shape, dtype=self.dtype)
1
4
2
32
0
302
305
302
null
[]
None
null
0
0
0
null
0
null
The function (_change_shape) defined within the public class called public.The function start at line 302 and ends at 305. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [302.0] and does not return any value..
pytorch_ao
public
public
0
0
__tensor_flatten__
def __tensor_flatten__(self):# note: the order of args must match the order of args in __init__return ["int_data", "q_scales"], [self.transposed, self.shape, self.dtype]
1
2
1
25
0
307
309
307
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 307 and ends at 309. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
__tensor_unflatten__
def __tensor_unflatten__(cls, tensor_data_dict, tensor_attributes, outer_size=None, outer_stride=None):int_data, q_scales = tensor_data_dict["int_data"], tensor_data_dict["q_scales"]transposed, shape, dtype = tensor_attributesreturn cls(int_data,q_scales,transposed,shape if outer_size is None else outer_size,dtype=dtyp...
2
13
5
63
0
312
324
312
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 312 and ends at 324. It contains 13 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [312.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls, input_float, qmin=-128, qmax=127, dtype=None):"""Method used to convert a linear weight tensor to an instance of theInt8DynamicallyQuantizedLinearWeight subclass.Example usage::model.lin_mod.weight = (Int8DynamicallyQuantizedLinearWeight.from_float(model.lin_mod.weight))"""if dtype is None:dtype = i...
3
16
5
94
0
327
359
327
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 327 and ends at 359. It contains 16 lines of code and it has a cyclomatic complexity of 3. It takes 5 parameters, represented as [327.0] and does not return any value..
pytorch_ao
public
public
0
0
from_qtensor_components_int8wo
def from_qtensor_components_int8wo(*args, **kwargs):return Int8WeightOnlyQuantizedLinearWeight(*args, **kwargs)
1
2
2
18
0
363
364
363
null
[]
None
null
0
0
0
null
0
null
The function (from_qtensor_components_int8wo) defined within the public class called public.The function start at line 363 and ends at 364. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [363.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, int_data, q_scales):return from_qtensor_components_int8dyn(int_data, q_scales, *self.args, **self.kwargs)
1
4
3
26
0
368
371
219
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 368 and ends at 371. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [219.0] and does not return any value..
pytorch_ao
public
public
0
0
_quantized_op
def _quantized_op(act_mat, w_qtensor, bias):orig_dtype = act_mat.dtypey = (torch.mm(act_mat.reshape(-1, act_mat.shape[-1]),w_qtensor.int_data.to(act_mat.dtype),)* w_qtensor.q_scales)y = y.reshape(*act_mat.shape[:-1], y.shape[-1])if bias is not None:y += biasreturn y.to(orig_dtype)
2
13
3
94
0
384
396
384
null
[]
None
null
0
0
0
null
0
null
The function (_quantized_op) defined within the public class called public.The function start at line 384 and ends at 396. It contains 13 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [384.0] and does not return any value..
pytorch_ao
public
public
0
0
from_qtensor_components_int4wo
def from_qtensor_components_int4wo(*args, **kwargs):return Int4WeightOnlyQuantizedLinearWeight(*args, **kwargs)
1
2
2
18
0
400
401
400
null
[]
None
null
0
0
0
null
0
null
The function (from_qtensor_components_int4wo) defined within the public class called public.The function start at line 400 and ends at 401. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [400.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, int_data, q_scales):return from_qtensor_components_int8dyn(int_data, q_scales, *self.args, **self.kwargs)
1
4
3
26
0
405
408
219
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 405 and ends at 408. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [219.0] and does not return any value..
pytorch_ao
public
public
0
0
__new__
def __new__(cls,int_data,scales_and_zeros,transposed,shape,groupsize=128,inner_k_tiles=8,zero_point_domain=ZeroPointDomain.FLOAT,preserve_zero=False,dtype=None,**kwargs,):if dtype is None:dtype = scales_and_zeros.dtypekwargs["dtype"] = dtypereturn super().__new__(cls, int_data, transposed, shape, **kwargs)# type: ignor...
2
17
11
73
0
421
437
421
null
[]
None
null
0
0
0
null
0
null
The function (__new__) defined within the public class called public.The function start at line 421 and ends at 437. It contains 17 lines of code and it has a cyclomatic complexity of 2. It takes 11 parameters, represented as [421.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,int_data,scales_and_zeros,transposed,shape,groupsize,inner_k_tiles,zero_point_domain,preserve_zero,dtype,**kwargs,):# the transposed flag tracks whether the tensor subclass has been transposed relative# to how a weight is normally stored in a linear i.e. [out_features, in_features].# tracking both tra...
1
19
11
62
0
439
462
439
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 439 and ends at 462. It contains 19 lines of code and it has a cyclomatic complexity of 1. It takes 11 parameters, represented as [439.0] and does not return any value..
pytorch_ao
public
public
0
0
_quantized_op
def _quantized_op(act_mat, w_qtensor, bias):orig_act_size = act_mat.size()orig_dtype = act_mat.dtype# reshape and pad activationact_mat = act_mat.reshape(-1, act_mat.shape[-1]).to(torch.bfloat16)pad_size = find_multiple(act_mat.shape[-1], 1024)act_mat = torch.nn.functional.pad(act_mat, (0, pad_size - act_mat.shape[-1])...
6
44
3
289
0
465
515
465
null
[]
None
null
0
0
0
null
0
null
The function (_quantized_op) defined within the public class called public.The function start at line 465 and ends at 515. It contains 44 lines of code and it has a cyclomatic complexity of 6. It takes 3 parameters, represented as [465.0] and does not return any value..
pytorch_ao
public
public
0
0
dequantize
def dequantize(self):eye_shape = self.shape[1] if not self.transposed else self.shape[0]w_dq = self._quantized_op(torch.eye(eye_shape, device=self.device, dtype=self.dtype), self, None)# we dequantized using linear with the identity matrix, output has shape [in_channels, out_channels]# so we need to transpose back to g...
3
7
1
76
0
517
525
517
null
[]
None
null
0
0
0
null
0
null
The function (dequantize) defined within the public class called public.The function start at line 517 and ends at 525. It contains 7 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
int_repr
def int_repr(self):return self.int_data
1
2
1
9
0
527
528
527
null
[]
None
null
0
0
0
null
0
null
The function (int_repr) defined within the public class called public.The function start at line 527 and ends at 528. 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
q_params
def q_params(self):scales, zero_points = unpack_tinygemm_scales_and_zeros(self.scales_and_zeros,)return {"q_scales": scales, "q_zero_points": zero_points}
1
5
1
26
0
530
534
530
null
[]
None
null
0
0
0
null
0
null
The function (q_params) defined within the public class called public.The function start at line 530 and ends at 534. It contains 5 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
to
def to(self, *args, **kwargs):kwargs = self._get_to_kwargs(*args, **kwargs)return self.__class__(self.int_data.to(kwargs["device"]),self.scales_and_zeros.to(kwargs["device"]),self.transposed,self.shape,self.groupsize,self.inner_k_tiles,self.zero_point_domain,self.preserve_zero,**kwargs,)
1
13
3
80
0
536
548
536
null
[]
None
null
0
0
0
null
0
null
The function (to) defined within the public class called public.The function start at line 536 and ends at 548. It contains 13 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [536.0] and does not return any value..
pytorch_ao
public
public
0
0
_apply_fn_to_data
def _apply_fn_to_data(self, fn):return self.__class__(fn(self.int_data),fn(self.scales_and_zeros),self.transposed,self.shape,self.groupsize,self.inner_k_tiles,self.zero_point_domain,self.preserve_zero,dtype=self.dtype,)
1
12
2
57
0
550
561
550
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 550 and ends at 561. It contains 12 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [550.0] and does not return any value..
pytorch_ao
public
public
0
0
_change_shape
def _change_shape(self, shape):return self.__class__(self.int_data,self.scales_and_zeros,self.transposed,shape,self.groupsize,self.inner_k_tiles,self.zero_point_domain,self.preserve_zero,dtype=self.dtype,)
1
12
2
49
0
565
576
565
null
[]
None
null
0
0
0
null
0
null
The function (_change_shape) defined within the public class called public.The function start at line 565 and ends at 576. It contains 12 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [565.0] and does not return any value..
pytorch_ao
public
public
0
0
__tensor_flatten__
def __tensor_flatten__(self):return ["int_data", "scales_and_zeros"], (self.transposed,self.shape,self.groupsize,self.inner_k_tiles,self.zero_point_domain,self.preserve_zero,self.dtype,)
1
10
1
42
0
578
587
578
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 578 and ends at 587. 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
__tensor_unflatten__
def __tensor_unflatten__(cls, tensor_data_dict, attributes, outer_size=None, outer_stride=None):int_data, scales_and_zeros = (tensor_data_dict["int_data"],tensor_data_dict["scales_and_zeros"],)(transposed,shape,groupsize,inner_k_tiles,zero_point_domain,preserve_zero,dtype,) = attributesreturn cls(int_data,scales_and_ze...
2
28
5
89
0
593
620
593
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 593 and ends at 620. It contains 28 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [593.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls,input_float,groupsize=128,inner_k_tiles=8,zero_point_domain=ZeroPointDomain.FLOAT,preserve_zero=False,dtype=None,):"""Method used to convert a linear weight tensor to an instance of theInt4WeightOnlyQuantizedLinearWeight subclass.Example usage::model.lin_mod.weight = (Int4WeightOnlyQuantizedLinearWei...
2
31
7
102
0
623
664
623
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 623 and ends at 664. It contains 31 lines of code and it has a cyclomatic complexity of 2. It takes 7 parameters, represented as [623.0] and does not return any value..
pytorch_ao
public
public
0
0
to_qtensor_components
def to_qtensor_components(cls,input_float,groupsize=128,inner_k_tiles=8,zero_point_domain=ZeroPointDomain.FLOAT,preserve_zero=False,):assert groupsize in [256, 128, 64, 32]assert inner_k_tiles in [8, 4, 2]orig_out_features, orig_in_features = input_float.shape# paddingin_features = find_multiple(orig_in_features, 1024)...
2
32
6
165
0
667
702
667
null
[]
None
null
0
0
0
null
0
null
The function (to_qtensor_components) defined within the public class called public.The function start at line 667 and ends at 702. It contains 32 lines of code and it has a cyclomatic complexity of 2. It takes 6 parameters, represented as [667.0] and does not return any value..
pytorch_ao
public
public
0
0
register_quantize_module_handler.decorator
def decorator(func):_QUANTIZE_CONFIG_HANDLER[config_type] = funcreturn func# needed to make the functions usable externally
1
3
1
13
0
48
50
48
null
[]
None
null
0
0
0
null
0
null
The function (register_quantize_module_handler.decorator) defined within the public class called public.The function start at line 48 and ends at 50. 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
register_quantize_module_handler
def register_quantize_module_handler(config_type):"""A decorator to register a transform function to map from a workflowconfiguration (child of `AOBaseConfig`) to a function that transformsa `torch.nn.Module` according to the specified configuration.For example::# user facing codeclass WorkflowFooConfig(AOBaseConfig): ...
1
4
1
17
0
19
52
19
null
[]
None
null
0
0
0
null
0
null
The function (register_quantize_module_handler) defined within the public class called public.The function start at line 19 and ends at 52. 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
quantize
def quantize(self, model: torch.nn.Module, *args: Any, **kwargs: Any) -> torch.nn.Module:pass
1
4
4
30
0
23
26
23
null
[]
None
null
0
0
0
null
0
null
The function (quantize) defined within the public class called public.The function start at line 23 and ends at 26. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [23.0] and does not return any value..
pytorch_ao
public
public
0
0
prepare
def prepare(self, model: torch.nn.Module, *args: Any, **kwargs: Any) -> torch.nn.Module:pass
1
4
4
30
0
32
35
32
null
[]
None
null
0
0
0
null
0
null
The function (prepare) defined within the public class called public.The function start at line 32 and ends at 35. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [32.0] and does not return any value..
pytorch_ao
public
public
0
0
convert
def convert(self, model: torch.nn.Module, *args: Any, **kwargs: Any) -> torch.nn.Module:pass
1
4
4
30
0
38
41
38
null
[]
None
null
0
0
0
null
0
null
The function (convert) defined within the public class called public.The function start at line 38 and ends at 41. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [38.0] and does not return any value..
pytorch_ao
public
public
0
0
compute_error
def compute_error(x, y):Ps = torch.linalg.norm(x)Pn = torch.linalg.norm(x - y)return 20 * torch.log10(Ps / Pn)
1
4
2
40
2
63
66
63
null
['Pn', 'Ps']
None
null
0
0
0
null
0
null
The function (compute_error) defined within the public class called public.The function start at line 63 and ends at 66. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [63.0] and does not return any value..
pytorch_ao
public
public
0
0
_get_logging_hook.forward_hook
def forward_hook(module, input):global _cur_fqn_cur_fqn = fqn
1
3
2
12
0
75
77
75
null
[]
None
null
0
0
0
null
0
null
The function (_get_logging_hook.forward_hook) defined within the public class called public.The function start at line 75 and ends at 77. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [75.0] and does not return any value..
pytorch_ao
public
public
0
0
_get_logging_hook
def _get_logging_hook(fqn):def forward_hook(module, input):global _cur_fqn_cur_fqn = fqnreturn forward_hook
1
3
1
9
1
74
79
74
null
['_cur_fqn']
None
null
0
0
0
null
0
null
The function (_get_logging_hook) defined within the public class called public.The function start at line 74 and ends at 79. 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
_apply_logging_hook
def _apply_logging_hook(model):for name, mod in model.named_modules():mod.register_forward_pre_hook(_get_logging_hook(name))
2
3
1
25
0
82
84
82
null
[]
None
null
0
0
0
null
0
null
The function (_apply_logging_hook) defined within the public class called public.The function start at line 82 and ends at 84. It contains 3 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
__torch_dispatch__
def __torch_dispatch__(self, func, types, args=(), kwargs=None):if kwargs is None:kwargs = {}rs = func(*args, **kwargs)global _cur_fqnop_name: str = f"{func.__module__}.{func.__name__}"shape_str = ""for arg in args:if isinstance(arg, torch.Tensor):shape_str += str(list(arg.shape)) + ", "if shape_str != "":shape_str = s...
8
20
4
159
0
94
115
94
null
[]
None
null
0
0
0
null
0
null
The function (__torch_dispatch__) defined within the public class called public.The function start at line 94 and ends at 115. It contains 20 lines of code and it has a cyclomatic complexity of 8. It takes 4 parameters, represented as [94.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, inputs):self.values = list(inputs)
1
2
2
15
0
119
120
119
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 119 and ends at 120. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [119.0] and does not return any value..
pytorch_ao
public
public
0
0
add_input
def add_input(self, input):self.values.append(input)return self
1
3
2
17
0
122
124
122
null
[]
None
null
0
0
0
null
0
null
The function (add_input) defined within the public class called public.The function start at line 122 and ends at 124. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [122.0] and does not return any value..
pytorch_ao
public
public
0
0
__getitem__
def __getitem__(self, slice):return _MultiInput(self.values[slice])
1
2
2
17
0
126
127
126
null
[]
None
null
0
0
0
null
0
null
The function (__getitem__) defined within the public class called public.The function start at line 126 and ends at 127. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [126.0] and does not return any value..
pytorch_ao
public
public
0
0
cuda
def cuda(self):self.values = [val.cuda() if isinstance(val, torch.Tensor) else val for val in self.values]
3
4
1
33
0
129
132
129
null
[]
None
null
0
0
0
null
0
null
The function (cuda) defined within the public class called public.The function start at line 129 and ends at 132. 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
xpu
def xpu(self):self.values = [val.xpu() if isinstance(val, torch.Tensor) else val for val in self.values]
3
4
1
33
0
134
137
134
null
[]
None
null
0
0
0
null
0
null
The function (xpu) defined within the public class called public.The function start at line 134 and ends at 137. 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
_guard_dtype_size
def _guard_dtype_size(tensor_arg, arg_name, dtype=None, size=None):if dtype is not None and tensor_arg.dtype != dtype:raise ValueError(f"Expected Tensor argument {arg_name} to have dtype {dtype}, but got {tensor_arg.dtype} instead.")if size is not None and tensor_arg.size() != size:raise ValueError(f"Expected Tensor ar...
5
9
4
53
0
140
148
140
null
[]
None
null
0
0
0
null
0
null
The function (_guard_dtype_size) defined within the public class called public.The function start at line 140 and ends at 148. It contains 9 lines of code and it has a cyclomatic complexity of 5. It takes 4 parameters, represented as [140.0] and does not return any value..
pytorch_ao
public
public
0
0
_get_per_token_block_size
def _get_per_token_block_size(x: torch.Tensor) -> List[int]:block_size = []for _ in range(len(x.shape) - 1):block_size.append(1)block_size.append(x.shape[-1])return block_size
2
6
1
53
1
151
156
151
null
['block_size']
None
null
0
0
0
null
0
null
The function (_get_per_token_block_size) defined within the public class called public.The function start at line 151 and ends at 156. It contains 6 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
_quantize_activation_per_token_absmax
def _quantize_activation_per_token_absmax(t):# if the shape of t is [B, N, K], the shape of scales will be [B, N, 1]mapping_type = MappingType.SYMMETRICblock_size = list(t.shape)for i in range(len(block_size) - 1):block_size[i] = 1dtype = torch.int8eps = 1e-5# Note: the original smoothquant does not clamp to qmin/qmax ...
3
24
1
116
8
162
192
162
null
['scale_dtype', 'quantized', 'mapping_type', 'block_size', 'eps', 'dtype', 'quant_max', 'quant_min']
None
null
0
0
0
null
0
null
The function (_quantize_activation_per_token_absmax) defined within the public class called public.The function start at line 162 and ends at 192. It contains 24 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
_quant_int8_dynamic_per_token_linear
def _quant_int8_dynamic_per_token_linear(x,w_vals_int8_t,w_scales,bias,out_dtype,):"""like F.linear, but with int8 dynamic quantization of activation,and a quantized weight"""x_vals_int8, x_scales = _quantize_activation_per_token_absmax(x)mm_out = _quant_int8_per_token_matmul(x_vals_int8, x_scales, w_vals_int8_t, w_sca...
2
14
5
50
1
195
212
195
null
['mm_out']
None
null
0
0
0
null
0
null
The function (_quant_int8_dynamic_per_token_linear) defined within the public class called public.The function start at line 195 and ends at 212. It contains 14 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [195.0] and does not return any value..
pytorch_ao
public
public
0
0
_quant_int8_per_token_matmul
def _quant_int8_per_token_matmul(x_vals_int8,x_scales,w_vals_int8_t,w_scales,output_dtype=torch.float32,):"""Quantized matmul of int8 operands that accumulates to int32 and returnsoutput_dtype. For now, this is written for approximate numericalAssumes that activation and weight quantization are symmetric,i.e. act_zp an...
1
26
5
138
3
215
272
215
null
['tmp', 'y', 'y_dot_scaled']
None
null
0
0
0
null
0
null
The function (_quant_int8_per_token_matmul) defined within the public class called public.The function start at line 215 and ends at 272. It contains 26 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [215.0] and does not return any value..
pytorch_ao
public
public
0
0
dynamically_quantize_per_channel
def dynamically_quantize_per_channel(x, quant_min, quant_max, target_dtype):"""assumes symmetric quantizationassumes axis == 0assumes dense memory formatTODO(future): relax ^ as needed"""assert x.dim() == 2, "only support 2d Tensors"eps = torch.finfo(torch.float32).epsblock_size = (1, x.shape[1])zero_point_dtype = torc...
1
20
4
113
5
275
303
275
null
['block_size', 'eps', 'quant', 'mapping_type', 'zero_point_dtype']
None
null
0
0
0
null
0
null
The function (dynamically_quantize_per_channel) defined within the public class called public.The function start at line 275 and ends at 303. It contains 20 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [275.0] and does not return any value..
pytorch_ao
public
public
0
0
dequantize_per_tensor
def dequantize_per_tensor(int_repr, scale, zero_point, out_dtype=torch.float32):block_size = int_repr.shapeinput_dtype = int_repr.dtypeassert scale.numel() == 1, f"scale size: {scale.numel()}"dequantized = dequantize_affine(int_repr, block_size, scale, zero_point, input_dtype, output_dtype=out_dtype)return dequantized
1
8
4
56
3
307
314
307
null
['dequantized', 'input_dtype', 'block_size']
None
null
0
0
0
null
0
null
The function (dequantize_per_tensor) defined within the public class called public.The function start at line 307 and ends at 314. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [307.0] and does not return any value..
pytorch_ao
public
public
0
0
dequantize_per_channel
def dequantize_per_channel(int_repr, scales, zero_points, out_dtype=torch.float32):assert int_repr.dim() == 2, "only support 2d Tensors"# channel axis == 0# block_size before transpose should be (1, int_repr.shape[1]) for axis == 0 per channel quant# TODO: transpose is for perf reasons for torch.compile, we should sepa...
1
10
4
76
4
318
332
318
null
['dequantized', 'int_repr', 'input_dtype', 'block_size']
None
null
0
0
0
null
0
null
The function (dequantize_per_channel) defined within the public class called public.The function start at line 318 and ends at 332. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [318.0] and does not return any value..
pytorch_ao
public
public
0
0
get_groupwise_affine_qparams
def get_groupwise_affine_qparams(w,n_bit=4,groupsize=128,dtype=torch.bfloat16,zero_point_domain=ZeroPointDomain.FLOAT,preserve_zero=False,eps=None,):if groupsize > w.shape[-1]:groupsize = w.shape[-1]assert groupsize > 1assert w.shape[-1] % groupsize == 0assert w.dim() == 2assert n_bit <= 8, f"only n_bit smaller than 8 ...
8
65
7
293
9
335
402
335
null
['scale_dtype', 'quant_min', 'groupsize', 'block_size', 'eps', 'target_dtype', 'quant_max', 'mapping_type', 'zero_point_dtype']
None
null
0
0
0
null
0
null
The function (get_groupwise_affine_qparams) defined within the public class called public.The function start at line 335 and ends at 402. It contains 65 lines of code and it has a cyclomatic complexity of 8. It takes 7 parameters, represented as [335.0] and does not return any value..
pytorch_ao
public
public
0
0
pack_tinygemm_scales_and_zeros
def pack_tinygemm_scales_and_zeros(scales, zeros, dtype=torch.bfloat16):_guard_dtype_size(scales, "scales", dtype=dtype, size=zeros.size())_guard_dtype_size(zeros, "zeros", dtype=dtype)dim = scales.dim()return (torch.cat([scales.unsqueeze(-1),zeros.unsqueeze(-1),],dim,).transpose(-3, -2).contiguous())
1
15
3
90
1
405
419
405
null
['dim']
None
null
0
0
0
null
0
null
The function (pack_tinygemm_scales_and_zeros) defined within the public class called public.The function start at line 405 and ends at 419. It contains 15 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [405.0] and does not return any value..
pytorch_ao
public
public
0
0
unpack_tinygemm_scales_and_zeros
def unpack_tinygemm_scales_and_zeros(scales_and_zeros):assert scales_and_zeros.shape[-1] == 2return torch.split(scales_and_zeros.transpose(-3, -2), 1, -1)
1
3
1
36
0
422
424
422
null
[]
None
null
0
0
0
null
0
null
The function (unpack_tinygemm_scales_and_zeros) defined within the public class called public.The function start at line 422 and ends at 424. 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
groupwise_affine_quantize_tensor_from_qparams
def groupwise_affine_quantize_tensor_from_qparams(w, scales, zeros, n_bit=4, groupsize=128, zero_point_domain=ZeroPointDomain.FLOAT):assert groupsize > 1# needed for GPTQ single column quantizeif groupsize > w.shape[-1] and scales.shape[-1] == 1:groupsize = w.shape[-1]assert w.shape[-1] % groupsize == 0assert w.dim() =...
10
37
6
262
7
427
468
427
null
['int_data', 'groupsize', '_quantize_affine', 'block_size', 'output_dtype', 'quant_max', 'quant_min']
None
null
0
0
0
null
0
null
The function (groupwise_affine_quantize_tensor_from_qparams) defined within the public class called public.The function start at line 427 and ends at 468. It contains 37 lines of code and it has a cyclomatic complexity of 10. It takes 6 parameters, represented as [427.0] and does not return any value..
pytorch_ao
public
public
0
0
groupwise_affine_dequantize_tensor_from_qparams
def groupwise_affine_dequantize_tensor_from_qparams(w_int4x8,scales,zeros,n_bit=4,groupsize=128,zero_point_domain=ZeroPointDomain.FLOAT,):assert groupsize > 1assert w_int4x8.dim() == 2# need to handle single column case so check for dtype/size from groupwise_affine_quantize_tensor_from_qparams pathif (w_int4x8.dtype ==...
9
52
6
294
10
471
525
471
null
['input_dtype', 'groupsize', 'high_bits', '_dequantize_affine', 'block_size', 'quant_max', 'w_int32', 'quant_min', 'low_bits', 'data']
None
null
0
0
0
null
0
null
The function (groupwise_affine_dequantize_tensor_from_qparams) defined within the public class called public.The function start at line 471 and ends at 525. It contains 52 lines of code and it has a cyclomatic complexity of 9. It takes 6 parameters, represented as [471.0] and does not return any value..
pytorch_ao
public
public
0
0
groupwise_affine_quantize_tensor
def groupwise_affine_quantize_tensor(w,n_bit=4,groupsize=128,dtype=torch.bfloat16,zero_point_domain=ZeroPointDomain.FLOAT,preserve_zero=False,):scales, zeros = get_groupwise_affine_qparams(w,n_bit,groupsize,dtype,zero_point_domain=zero_point_domain,preserve_zero=preserve_zero,)w_int4x8 = groupwise_affine_quantize_tenso...
1
21
6
85
2
528
548
528
null
['w_int4x8', 'scales_and_zeros']
None
null
0
0
0
null
0
null
The function (groupwise_affine_quantize_tensor) defined within the public class called public.The function start at line 528 and ends at 548. It contains 21 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [528.0] and does not return any value..
pytorch_ao
public
public
0
0
groupwise_affine_dequantize_tensor
def groupwise_affine_dequantize_tensor(w_int4x8,scales_and_zeros,n_bit=4,groupsize=128,):scales, zeros = unpack_tinygemm_scales_and_zeros(scales_and_zeros)return groupwise_affine_dequantize_tensor_from_qparams(w_int4x8, scales, zeros, n_bit, groupsize)
1
10
4
37
0
551
560
551
null
[]
None
null
0
0
0
null
0
null
The function (groupwise_affine_dequantize_tensor) defined within the public class called public.The function start at line 551 and ends at 560. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [551.0] and does not return any value..
pytorch_ao
public
public
0
0
get_group_qparams_symmetric
def get_group_qparams_symmetric(w,n_bit=4,groupsize=128,precision=torch.float32,mapping_type=MappingType.SYMMETRIC,eps=None,):# needed for GPTQ with paddingif groupsize > w.shape[-1]:groupsize = w.shape[-1]assert groupsize > 1assert w.shape[-1] % groupsize == 0assert w.dim() == 2assert n_bit <= 8, f"unsupported n_bit: ...
4
34
6
234
4
564
600
564
null
['eps', 'ranges', 'block_size', 'groupsize']
None
null
0
0
0
null
0
null
The function (get_group_qparams_symmetric) defined within the public class called public.The function start at line 564 and ends at 600. It contains 34 lines of code and it has a cyclomatic complexity of 4. It takes 6 parameters, represented as [564.0] and does not return any value..
pytorch_ao
public
public
0
0
group_quantize_tensor_symmetric
def group_quantize_tensor_symmetric(w,n_bit=4,group_size=128,precision=torch.float32,mapping_type=MappingType.SYMMETRIC,):scales, zeros = get_group_qparams_symmetric(w, n_bit, group_size, precision, mapping_type)n_bit = 4max_int = 2 ** (n_bit - 1) - 1min_int = -(2 ** (n_bit - 1))# TODO: currently we don't know how to e...
1
20
5
103
4
603
626
603
null
['max_int', 'n_bit', 'min_int', 'w_int8']
None
null
0
0
0
null
0
null
The function (group_quantize_tensor_symmetric) defined within the public class called public.The function start at line 603 and ends at 626. It contains 20 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [603.0] and does not return any value..
pytorch_ao
public
public
0
0
per_token_dynamic_quant
def per_token_dynamic_quant(input: torch.Tensor,scale_dtype: torch.dtype = torch.float32,zero_point_dtype: torch.dtype = torch.float32,eps: Optional[float] = None,) -> torch.Tensor:mapping_type = MappingType.ASYMMETRICblock_size = _get_per_token_block_size(input)quant_min = -128quant_max = 127quant_dtype = torch.int8ou...
1
43
4
146
8
629
672
629
null
['quant_dtype', 'mapping_type', 'q', 'block_size', 'output_dtype', 'quant_max', 'dq', 'quant_min']
None
null
0
0
0
null
0
null
The function (per_token_dynamic_quant) defined within the public class called public.The function start at line 629 and ends at 672. It contains 43 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [629.0] and does not return any value..
pytorch_ao
public
public
0
0
recommended_inductor_config_setter
def recommended_inductor_config_setter():"""Set inductor config to use the following optimizations which have been showed to improve performance for quantized models:coordinate_descent_tuning = Truecoordinate_descent_check_all_directions = Trueforce_fuse_int_mm_with_mul = Truefx_graph_cache = Truetriton.unique_kernel_n...
1
7
0
58
0
675
690
675
null
[]
None
null
0
0
0
null
0
null
The function (recommended_inductor_config_setter) defined within the public class called public.The function start at line 675 and ends at 690. 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
get_block_size
def get_block_size(input_shape: Tuple[int, ...], granularity: Granularity) -> Tuple[int, ...]:"""Get the block size based on the input shape and granularity type.Args:input_shape: The input tensor shape possibly more than 2 dimensionsgranularity: The granularity type of the quantization"""if isinstance(granularity, Per...
7
27
2
206
1
693
724
693
null
['block_size']
None
null
0
0
0
null
0
null
The function (get_block_size) defined within the public class called public.The function start at line 693 and ends at 724. It contains 27 lines of code and it has a cyclomatic complexity of 7. It takes 2 parameters, represented as [693.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, *args, **kwargs):"""Initializes the WeightOnlyInt8QuantLinear module.Args:*args: Variable length argument list for `torch.nn.Linear`.**kwargs: Arbitrary keyword arguments.Must include 'w_int8' (int8 quantized weights) and 'scales' (scaling factors)."""w_int8 = kwargs.pop("w_int8")scales = kwargs.pop(...
1
6
3
56
0
29
43
29
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 29 and ends at 43. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [29.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, x: torch.Tensor, *args, **kwargs) -> torch.Tensor:"""Performs the forward pass of the quantized linear layer, which consists ofmixed dtype matrix multiplication using int8 symmetric per-channel weight quantization.Args:x (torch.Tensor): The input floating point tensor to the quantized linear layer.*ar...
2
7
4
96
0
45
64
45
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 45 and ends at 64. It contains 7 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [45.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls, mod: torch.nn.Linear):"""Converts a `torch.nn.Linear` module to a `WeightOnlyInt8QuantLinear` module.This method performs the conversion by dynamically quantizing the weights of the originalfloating point linear layer to int8 format and creating a new `WeightOnlyInt8QuantLinear`instance with these q...
1
20
2
124
0
67
100
67
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 67 and ends at 100. It contains 20 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [67.0] and does not return any value..
pytorch_ao
public
public
0
0
__new__
def __new__(cls,original_weight_tensor: torch.Tensor,input_quant_func_static: Callable,scale: torch.Tensor,zero_point: Optional[torch.Tensor],quant_kwargs: Dict[str, Any],):kwargs = {}dtype = original_weight_tensor.dtypekwargs["dtype"] = dtypekwargs["requires_grad"] = Falsekwargs["device"] = original_weight_tensor.devi...
1
15
6
88
0
41
55
41
null
[]
None
null
0
0
0
null
0
null
The function (__new__) defined within the public class called public.The function start at line 41 and ends at 55. It contains 15 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [41.0] and does not return any value..