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
maybe_adjust_model_bsz
def maybe_adjust_model_bsz(m, extracted_bsz, target_bsz):"""Makes guesses on how to adjust the model graph to account for thefact that we changed the batch size. Note: this is very brittle"""for n in m.graph.nodes:if n.op == "call_method" and n.target == "view":new_args = []for arg in n.args:if arg == extracted_bsz:new...
6
11
3
75
1
149
164
149
null
['new_args']
None
null
0
0
0
null
0
null
The function (maybe_adjust_model_bsz) defined within the public class called public.The function start at line 149 and ends at 164. It contains 11 lines of code and it has a cyclomatic complexity of 6. It takes 3 parameters, represented as [149.0] and does not return any value..
pytorch_ao
public
public
0
0
__new__
def __new__(cls,weight,qtensor_class_list,*args,mode=["relu", None],model=None,fqn=None,example_inputs=None,fqn_to_submodule=None,batch_size=None,**kwargs,):kwargs["device"] = weight.devicekwargs["layout"] = (kwargs.get("layout") if kwargs.get("layout", False) else weight.layout)kwargs["dtype"] = (kwargs.get("dtype") i...
3
23
11
136
0
183
205
183
null
[]
None
null
0
0
0
null
0
null
The function (__new__) defined within the public class called public.The function start at line 183 and ends at 205. It contains 23 lines of code and it has a cyclomatic complexity of 3. It takes 11 parameters, represented as [183.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,weight,qtensor_class_list,*args,mode=["relu", None],model=None,fqn=None,example_inputs=None,fqn_to_submodule=None,batch_size=None,**kwargs,):self.weight = weightself.qtensor_class_list = qtensor_class_listself.logged_data = {}self.mode = modeself.model = modelself.fqn = fqnself.example_inputs = exampl...
1
22
11
90
0
207
228
207
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 207 and ends at 228. It contains 22 lines of code and it has a cyclomatic complexity of 1. It takes 11 parameters, represented as [207.0] and does not return any value..
pytorch_ao
public
public
0
0
__repr__
def __repr__(self):return (f"{self.__class__.__name__}(data={self.weight}, shape={self.shape}, "f"device={self.device}, dtype={self.dtype}, qtensor_class_list={self.qtensor_class_list})")
1
5
1
12
0
230
234
230
null
[]
None
null
0
0
0
null
0
null
The function (__repr__) defined within the public class called public.The function start at line 230 and ends at 234. 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
log_shape
def log_shape(act_mat, w_autoquant, bias):act_mat = act_mat.reshape(-1, act_mat.shape[-1])logged_dtype = act_mat.dtypelogged_shapes = (act_mat.shape,w_autoquant.shape,None if bias is None else bias.shape,)shapes_and_dtype = logged_shapes + (logged_dtype,)w_autoquant.logged_data[shapes_and_dtype] = 1 + w_autoquant.logge...
2
12
3
80
0
237
248
237
null
[]
None
null
0
0
0
null
0
null
The function (log_shape) defined within the public class called public.The function start at line 237 and ends at 248. It contains 12 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [237.0] and does not return any value..
pytorch_ao
public
public
0
0
tune_autoquant2
def tune_autoquant2(self, fqn, m, batch_size, inputs, q_cls, shapes_and_dtype, time_for_best_shape):act_shape, w_shape, bias_shape, act_dtype = shapes_and_dtypewith torch.no_grad():try:m_copy = copy.deepcopy(m)for name, module in m_copy.named_modules():if isinstance(module, torch.nn.Linear):linear_module = moduleweight...
7
34
8
235
0
250
286
250
null
[]
None
null
0
0
0
null
0
null
The function (tune_autoquant2) defined within the public class called public.The function start at line 250 and ends at 286. It contains 34 lines of code and it has a cyclomatic complexity of 7. It takes 8 parameters, represented as [250.0] and does not return any value..
pytorch_ao
public
public
0
0
to_quantized.count_shapes
def count_shapes(self, do_print=True):differe_shape_count = 0for shapes_and_dtype, times_seen in self.logged_data.items():differe_shape_count += 1if do_print:act_shape, weight_shape, bias_shape, dtype = shapes_and_dtypeprint(f"activation_shapes: {act_shape}, times_seen: {times_seen}")if do_print:print(f"weight_shape: {...
4
12
2
55
0
304
315
304
null
[]
None
null
0
0
0
null
0
null
The function (to_quantized.count_shapes) defined within the public class called public.The function start at line 304 and ends at 315. It contains 12 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [304.0] and does not return any value..
pytorch_ao
public
public
0
0
to_quantized
def to_quantized(self, error_on_unseen, **kwargs):if error_on_unseen and self.logged_data == {}:raise RuntimeError("must run module normally to get shape, dtype info for autoquant")elif (self.logged_data == {}) and not error_on_unseen:# default back to non-quantized weight if not seenself = AQDefaultLinearWeight.from_f...
18
61
3
313
0
289
377
289
null
[]
None
null
0
0
0
null
0
null
The function (to_quantized) defined within the public class called public.The function start at line 289 and ends at 377. It contains 61 lines of code and it has a cyclomatic complexity of 18. It takes 3 parameters, represented as [289.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.weight),self.qtensor_class_list,dtype=self.dtype,mode=self.mode,model=self.model,fqn=self.fqn,example_inputs=self.example_inputs,fqn_to_submodule=self.fqn_to_submodule,batch_size=self.batch_size,)
1
12
2
66
0
379
390
379
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 379 and ends at 390. It contains 12 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [379.0] and does not return any value..
pytorch_ao
public
public
0
0
__tensor_flatten__
def __tensor_flatten__(self):return ["weight"], [self.qtensor_class_list,self.mode,self.model,self.fqn,self.example_inputs,self.fqn_to_submodule,self.batch_size,self.dtype,self.shape,]
1
12
1
48
0
392
403
392
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 392 and ends at 403. It contains 12 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
__tensor_unflatten__
def __tensor_unflatten__(cls, tensor_data_dict, tensor_attributes, outer_size=None, outer_stride=None):weight = tensor_data_dict["weight"](qtensor_class_list,mode,model,fqn,example_inputs,fqn_to_submodule,batch_size,dtype,shape,) = tensor_attributesreturn cls(weight,qtensor_class_list,mode,model=model,fqn=fqn,example_i...
2
28
5
93
0
406
433
406
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 406 and ends at 433. It contains 28 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [406.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls, weight, qtensor_class_list, **kwargs):return cls(weight, qtensor_class_list, **kwargs)
1
2
4
22
0
436
437
436
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 436 and ends at 437. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [436.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_autoquant, bias = (args[0],args[1],args[2] if len(args) > 2 else None,)cls.log_shape(mat1, w_autoquant, bias)return func(mat1, w_autoquant.weight, bias)try:with torch._C....
5
15
4
120
0
440
455
440
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 440 and ends at 455. It contains 15 lines of code and it has a cyclomatic complexity of 5. It takes 4 parameters, represented as [440.0] and does not return any value..
pytorch_ao
public
public
0
0
__torch_dispatch__
def __torch_dispatch__(cls, func, types, args, kwargs):if func is aten.detach.default:return return_and_correct_aliasing(func, args, kwargs, args[0]._apply_fn_to_data(torch.detach))
2
5
5
43
0
458
462
458
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 458 and ends at 462. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [458.0] and does not return any value..
pytorch_ao
public
public
0
0
do_autoquant_bench
def do_autoquant_bench(op, *args, **kwargs):"""runs benchmark op(*args, **kwargs) avoiding torch.compile overhead"""from torch._inductor.runtime.benchmarking import benchmarkerrep = kwargs.pop("rep", 100)warmup = kwargs.pop("warmup", 25)with torch.no_grad():torch.cuda.synchronize()stream = torch.cuda.Stream()stream.wai...
1
20
3
178
5
466
489
466
null
['res', 'graph', 'stream', 'warmup', 'rep']
None
null
0
0
0
null
0
null
The function (do_autoquant_bench) defined within the public class called public.The function start at line 466 and ends at 489. It contains 20 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [466.0] and does not return any value..
pytorch_ao
public
public
0
0
_is_interpolate_mode
def _is_interpolate_mode(mode):if (isinstance(mode, list)and mode[0] == "interpolate"and len(mode) == 2and isinstance(mode[1], float)):return Truereturn False
5
9
1
43
0
492
500
492
null
[]
None
null
0
0
0
null
0
null
The function (_is_interpolate_mode) defined within the public class called public.The function start at line 492 and ends at 500. It contains 9 lines of code and it has a cyclomatic complexity of 5. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_autoquant_test
def _autoquant_test(cls, act_mat, weight, bias, best_time, mode=["relu", None]):w_qtensor = cls.from_float(weight)if _is_interpolate_mode(mode):q_c_op = torch.compile(cls._quantized_linear_op, mode="max-autotune-no-cudagraphs")else:func = lambda a, b, c: F.relu(cls._quantized_linear_op(F.relu(a), b, c))q_c_op = torch.c...
3
17
6
161
0
520
536
520
null
[]
None
null
0
0
0
null
0
null
The function (_autoquant_test) defined within the public class called public.The function start at line 520 and ends at 536. It contains 17 lines of code and it has a cyclomatic complexity of 3. It takes 6 parameters, represented as [520.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float.get_weight_block_size
def get_weight_block_size(x):return (1, x.shape[1])
1
2
1
16
0
558
559
558
null
[]
None
null
0
0
0
null
0
null
The function (from_float.get_weight_block_size) defined within the public class called public.The function start at line 558 and ends at 559. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
from_float.get_per_token_block_size
def get_per_token_block_size(x):block_size = list(x.shape)for i in range(len(block_size) - 1):block_size[i] = 1return block_size
2
5
1
34
0
566
570
566
null
[]
None
null
0
0
0
null
0
null
The function (from_float.get_per_token_block_size) defined within the public class called public.The function start at line 566 and ends at 570. It contains 5 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls, weight):# TODO test if this is valid# in_features = weight.shape[1]# int8 dynamic quantization only has benefit when in_feature > 16# if in_features <= 16:# return weight# avoid circular depfrom torchao.dtypes import to_affine_quantized_intx# weight settingsmapping_type = MappingType.SYMMETRICdef ge...
2
38
2
166
0
545
602
545
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 545 and ends at 602. It contains 38 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [545.0] and does not return any value..
pytorch_ao
public
public
0
0
_autoquant_test
def _autoquant_test(cls, act_mat, weight, bias, best_time, mode=["relu", None]):"""Tests and benchmarks the autoquantization process with special handling for interpolate mode.Args:act_mat (torch.Tensor): The activation matrix.weight (torch.Tensor): The weight tensor.bias (torch.Tensor or None): The bias tensor.best_ti...
3
37
6
237
0
605
661
605
null
[]
None
null
0
0
0
null
0
null
The function (_autoquant_test) defined within the public class called public.The function start at line 605 and ends at 661. It contains 37 lines of code and it has a cyclomatic complexity of 3. It takes 6 parameters, represented as [605.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls, weight):mapping_type = MappingType.SYMMETRICtarget_dtype = torch.int8eps = torch.finfo(torch.float32).epszero_point_dtype = torch.int64block_size = (1, weight.shape[1])return super(AQInt8WeightOnlyQuantizedLinearWeight, cls).from_hp_to_intx(weight,mapping_type,block_size,target_dtype,eps=eps,zero_po...
1
14
2
73
0
670
683
670
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 670 and ends at 683. It contains 14 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [670.0] and does not return any value..
pytorch_ao
public
public
0
0
_quantized_linear_op
def _quantized_linear_op(act_mat, w_qtensor, bias):"""Performs the quantized linear operationsArgs:act_mat (torch.Tensor): The activation matrix.w_qtensor (torch.Tensor): The quantized weight tensor.bias (torch.Tensor or None): The bias tensor.Returns:torch.Tensor: The result of the quantized operation."""orig_dtype = ...
2
9
3
111
0
695
714
695
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 695 and ends at 714. It contains 9 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [695.0] and does not return any value..
pytorch_ao
public
public
0
0
_autoquant_test
def _autoquant_test(cls, act_mat, *args):# if act_mat has batchsize>2 don't use this kernelif act_mat.reshape(-1, act_mat.shape[-1]).shape[0] > 32:return torch.infreturn super()._autoquant_test(act_mat, *args)
2
4
3
50
0
717
721
717
null
[]
None
null
0
0
0
null
0
null
The function (_autoquant_test) defined within the public class called public.The function start at line 717 and ends at 721. It contains 4 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [717.0] and does not return any value..
pytorch_ao
public
public
0
0
_quantized_linear_op
def _quantized_linear_op(act_mat, w_qtensor, bias):orig_shape = act_mat.shapey = torch.mm(act_mat.reshape(-1, orig_shape[-1]),w_qtensor.tensor_impl.int_data.t() * w_qtensor.tensor_impl.scale,)y = y.reshape(*orig_shape[:-1], y.shape[-1])if bias is not None:y += biasreturn y
2
10
3
84
0
733
742
733
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 733 and ends at 742. It contains 10 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [733.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls, weight):group_size = cls.group_size_layout = TensorCoreTiledLayout(inner_k_tiles=8)if weight.shape[-1] % group_size != 0:return weightuse_hqq = Truemapping_type = MappingType.ASYMMETRICblock_size = (1, group_size)target_dtype = torch.int32quant_min = 0quant_max = 15eps = 1e-6preserve_zero = Falsezer...
2
29
2
124
0
753
782
753
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 753 and ends at 782. It contains 29 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [753.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self):super().__init__()
1
2
1
12
0
812
813
812
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 812 and ends at 813. 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(act_mat, w_qtensor, bias):return torch.nn.functional.linear(act_mat, w_qtensor, bias)
1
2
3
24
0
816
817
816
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 816 and ends at 817. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [816.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls, weight):return weight
1
2
2
9
0
820
821
820
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 820 and ends at 821. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [820.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, weight):self.weight = weight.to(torch.float32)
1
2
2
19
0
827
828
827
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 827 and ends at 828. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [827.0] and does not return any value..
pytorch_ao
public
public
0
0
_quantized_linear_op
def _quantized_linear_op(act_mat, w_qtensor, bias):_DTYPE = torch.float32orig_dtype = act_mat.dtypereturn torch.nn.functional.linear(act_mat.to(_DTYPE),w_qtensor.weight,bias.to(_DTYPE) if bias is not None else bias,).to(dtype=orig_dtype)
2
8
3
61
0
831
838
831
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 831 and ends at 838. It contains 8 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [831.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.weight),)
1
4
2
20
0
840
843
840
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 840 and ends at 843. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [840.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls, weight):return cls(weight)
1
2
2
12
0
846
847
846
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 846 and ends at 847. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [846.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,)return weight_tensor._quantized_linear_op(input_tensor, weight_tensor, bias)
2
7
4
54
0
851
857
851
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 851 and ends at 857. It contains 7 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [851.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
861
864
861
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 861 and ends at 864. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [861.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
868
871
861
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 868 and ends at 871. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [861.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
875
881
875
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 875 and ends at 881. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [875.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, weight):self.weight = weight.to(torch.float32)
1
2
2
19
0
885
886
827
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 885 and ends at 886. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [827.0] and does not return any value..
pytorch_ao
public
public
0
0
_quantized_linear_op
def _quantized_linear_op(act_mat, w_qtensor, bias):_DTYPE = torch.float32orig_dtype = act_mat.dtypereturn torch.nn.functional.linear(act_mat.to(_DTYPE),w_qtensor.weight,bias.to(_DTYPE) if bias is not None else bias,).to(dtype=orig_dtype)
2
8
3
61
0
889
896
831
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 889 and ends at 896. It contains 8 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [831.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, weight):self.weight = weight.to(torch.float32)
1
2
2
19
0
900
901
827
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 900 and ends at 901. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [827.0] and does not return any value..
pytorch_ao
public
public
0
0
_quantized_linear_op
def _quantized_linear_op(act_mat, w_qtensor, bias):_DTYPE = torch.float32orig_dtype = act_mat.dtypereturn torch.nn.functional.linear(act_mat.to(_DTYPE),w_qtensor.weight,bias.to(_DTYPE) if bias is not None else bias,).to(dtype=orig_dtype)
2
8
3
61
0
904
911
831
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 904 and ends at 911. It contains 8 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [831.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls, weight):return super(AQFloat32LinearWeight, cls).from_float(weight)
1
2
2
19
0
923
924
923
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 923 and ends at 924. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [923.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls, weight):return super(AQFloat32LinearWeight, cls).from_float(weight)
1
2
2
19
0
936
937
923
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 936 and ends at 937. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [923.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls, weight):return super(AQFloat32LinearWeight, cls).from_float(weight)
1
2
2
19
0
949
950
923
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 949 and ends at 950. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [923.0] and does not return any value..
pytorch_ao
public
public
0
0
_quantized_linear_op
def _quantized_linear_op(act_mat, w_qtensor, bias):return torch.nn.functional.linear(act_mat, w_qtensor.dequantize(), bias)
1
2
3
28
0
961
962
961
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 961 and ends at 962. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [961.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls, weight):block_size = (1, weight.shape[1])return super(AQFloat8WeightOnlyQuantizedLinearWeight, cls).from_hp_to_floatx(weight, block_size, target_dtype=cls.target_dtype, _layout=Float8Layout())
1
5
2
45
0
965
969
965
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 965 and ends at 969. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [965.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float.get_weight_block_size
def get_weight_block_size(x):return (1, x.shape[1])
1
2
1
16
0
988
989
558
null
[]
None
null
0
0
0
null
0
null
The function (from_float.get_weight_block_size) defined within the public class called public.The function start at line 988 and ends at 989. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
from_float.get_per_token_block_size
def get_per_token_block_size(x):block_size = list(x.shape)for i in range(len(block_size) - 1):block_size[i] = 1return block_size
2
5
1
34
0
994
998
566
null
[]
None
null
0
0
0
null
0
null
The function (from_float.get_per_token_block_size) defined within the public class called public.The function start at line 994 and ends at 998. It contains 5 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls, weight):# avoid circular depfrom torchao.dtypes import to_affine_quantized_floatxfrom torchao.quantization.quant_api import _input_activation_quant_func_fp8# weight settingsdef get_weight_block_size(x):return (1, x.shape[1])target_dtype = torch.float8_e4m3fn# input settingsdef get_per_token_block_si...
1
25
2
120
0
982
1,018
982
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 982 and ends at 1018. It contains 25 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [982.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float.get_weight_block_size
def get_weight_block_size(x):assert x.ndim == 2, "Only works for 2D tensors"return x.shape
1
3
1
17
0
1,037
1,039
1,037
null
[]
None
null
0
0
0
null
0
null
The function (from_float.get_weight_block_size) defined within the public class called public.The function start at line 1037 and ends at 1039. 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
from_float
def from_float(cls, weight):# avoid circular depfrom torchao.dtypes import to_affine_quantized_floatxfrom torchao.quantization.quant_api import _input_activation_quant_func_fp8# weight settingsdef get_weight_block_size(x):assert x.ndim == 2, "Only works for 2D tensors"return x.shapetarget_dtype = torch.float8_e4m3fninp...
1
24
2
118
0
1,031
1,061
1,031
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 1031 and ends at 1061. It contains 24 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [1031.0] 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,) -> 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 model containing modules to be replaced.repl...
6
22
5
121
2
1,109
1,142
1,109
null
['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 1109 and ends at 1142. It contains 22 lines of code and it has a cyclomatic complexity of 6. It takes 5 parameters, represented as [1109.0] and does not return any value..
pytorch_ao
public
public
0
0
dict_union
def dict_union(*args):return dict(chain.from_iterable(d.items() for d in args))
2
2
1
24
0
1,145
1,146
1,145
null
[]
None
null
0
0
0
null
0
null
The function (dict_union) defined within the public class called public.The function start at line 1145 and ends at 1146. 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
_change_linears_to_autoquantizable
def _change_linears_to_autoquantizable(model, example_input, fqn_to_submodule, batch_size, **kwargs):"""Converts all linear weight tensors to theAutoQuantizableLinearWeight tensor subclass. Expectation is that this is followedby running the model and then calling _change_autoquantizable_to_quantized"""# from torchao.qu...
2
23
5
136
2
1,149
1,179
1,149
null
['filter_fn', '_']
None
null
0
0
0
null
0
null
The function (_change_linears_to_autoquantizable) defined within the public class called public.The function start at line 1149 and ends at 1179. It contains 23 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [1149.0] and does not return any value..
pytorch_ao
public
public
0
0
_change_autoquantizable_to_quantized
def _change_autoquantizable_to_quantized(model, supress_autoquant_errors=True, **kwargs):"""Converts AutoQuantizableLinearWeight tensor subclassesto various quantized/non-quantized tensor subclasses dependingon benchmark results. Expectation is that these modules aretorch.compiled afterwards."""hold_automatic_dynamic_s...
4
35
3
185
4
1,182
1,228
1,182
null
['error_on_unseen', 'hold_supress_errors', 'hold_automatic_dynamic_shapes', 'filter_fn']
None
null
0
0
0
null
0
null
The function (_change_autoquantizable_to_quantized) defined within the public class called public.The function start at line 1182 and ends at 1228. It contains 35 lines of code and it has a cyclomatic complexity of 4. It takes 3 parameters, represented as [1182.0] and does not return any value..
pytorch_ao
public
public
0
0
autoquant_v2.autoquant_prehook
def autoquant_prehook(module, args, kwargs):real_model.forward(*args, **kwargs)module.finalize_autoquant()return args, kwargs
1
4
3
28
0
1,405
1,408
1,405
null
[]
None
null
0
0
0
null
0
null
The function (autoquant_v2.autoquant_prehook) defined within the public class called public.The function start at line 1405 and ends at 1408. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [1405.0] and does not return any value..
pytorch_ao
public
public
0
0
autoquant_v2.finalize_autoquant
def finalize_autoquant():_change_autoquantizable_to_quantized(real_model,supress_autoquant_errors,**aq_kwargs,)if hasattr(real_model, "old_forward"):model.forward = real_model.old_forwarddelattr(real_model, "old_forward")if hasattr(real_model, "finalize_autoquant"):delattr(real_model, "finalize_autoquant")if not manual...
4
13
0
58
0
1,418
1,430
1,418
null
[]
None
null
0
0
0
null
0
null
The function (autoquant_v2.finalize_autoquant) defined within the public class called public.The function start at line 1418 and ends at 1430. It contains 13 lines of code and it has a cyclomatic complexity of 4. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
autoquant_v2
def autoquant_v2(model,example_input=None,qtensor_class_list=DEFAULT_AUTOQUANT_CLASS_LIST,filter_fn=None,mode=["interpolate", 0.85],manual=False,set_inductor_config=True,supress_autoquant_errors=True,batch_size=None,**aq_kwargs,):"""Autoquantization is a process which identifies the fastest way to quantize each layer o...
18
100
10
623
16
1,235
1,442
1,235
null
['inputs', 'handle', 'example_input', 'extraction_idxs', 'reader', 'm', 'subgraph_fname', 'model', 'is_compiled', 'fqn', 'real_model', 'summary_rows', 'match', 'fqn_to_submodule', 'summary_filename', 'subgraph_idx']
None
null
0
0
0
null
0
null
The function (autoquant_v2) defined within the public class called public.The function start at line 1235 and ends at 1442. It contains 100 lines of code and it has a cyclomatic complexity of 18. It takes 10 parameters, represented as [1235.0] and does not return any value..
pytorch_ao
public
public
0
0
quantize_codebook
def quantize_codebook(input: torch.Tensor,codebook: torch.Tensor,scales: torch.Tensor,chunk_size: int = 1024,code_dtype: torch.dtype = torch.uint4,) -> torch.Tensor:"""code modified from: https://github.com/Vahe1994/AQLM/blob/main/src/kmeans.pyArgs:input (torch.Tensor): Input tensor to quantize, shape (d1, d2, ..., dN)...
4
51
5
370
16
16
95
16
null
['input', 'distances', 'input_size', 'code_dtype', 'input_reshaped', 'num_scale_blocks', 'block_size', 'k', 'new_shape', 'codebook_flat', 'input_chunk', 'block_grid_shape', 'input_flat', 'codes', 'D', 'chunk_end']
None
null
0
0
0
null
0
null
The function (quantize_codebook) defined within the public class called public.The function start at line 16 and ends at 95. It contains 51 lines of code and it has a cyclomatic complexity of 4. It takes 5 parameters, represented as [16.0] and does not return any value..
pytorch_ao
public
public
0
0
dequantize_codebook
def dequantize_codebook(codes: torch.Tensor,codebook: torch.Tensor,scales: torch.Tensor,output_dtype: torch.dtype = torch.float32,) -> torch.Tensor:"""Reconstructs the original tensor from codes and the codebook.Args:codes (torch.Tensor): Indices of codebook entries for each block,shape (d1//b1, d2//b2, ..., dN//bN).co...
2
29
4
198
7
98
149
98
null
['original_shape', 'num_scale_blocks', 'block_size', 'new_shape', 'block_grid_shape', 'D', 'dequant']
None
null
0
0
0
null
0
null
The function (dequantize_codebook) defined within the public class called public.The function start at line 98 and ends at 149. It contains 29 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [98.0] and does not return any value..
pytorch_ao
public
public
0
0
choose_qparams_codebook
def choose_qparams_codebook(input_tensor: torch.Tensor,block_size: Tuple[int, ...],scale_block_size: int,code_dtype: torch.dtype,max_iter: int = 200,devices: Optional[List[torch.device]] = None,) -> torch.Tensor:"""Initialize the codebook using k-means clustering on blocks of the input tensor.Args:input_tensor (torch.T...
4
45
6
289
7
153
221
153
null
['input', 'input_size', 'codebook_size', 'scales', 'num_scale_blocks', 'new_shape', 'D']
None
null
0
0
0
null
0
null
The function (choose_qparams_codebook) defined within the public class called public.The function start at line 153 and ends at 221. It contains 45 lines of code and it has a cyclomatic complexity of 4. It takes 6 parameters, represented as [153.0] and does not return any value..
pytorch_ao
public
public
0
0
_kmeans_greedy_init
def _kmeans_greedy_init(data: torch.Tensor, k: int) -> torch.Tensor:# code modified from: https://github.com/Vahe1994/AQLM/blob/main/src/kmeans.py not sure if I should modify forclusters = torch.zeros(k, data.shape[1], device=data.device)running_min_distances = torch.full((data.shape[0],), torch.inf, device=data.device...
2
17
2
155
4
225
243
225
null
['clusters', 'running_min_distances', 'distances_to_cluster_i', 'data_norm_squared']
None
null
0
0
0
null
0
null
The function (_kmeans_greedy_init) defined within the public class called public.The function start at line 225 and ends at 243. It contains 17 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [225.0] and does not return any value..
pytorch_ao
public
public
0
0
fit_kmeans
def fit_kmeans(data: torch.Tensor,k: int,max_iter: int = 200,check_every: int = 10,rtol: float = 1e-06,atol: float = 1e-08,greedy_init: bool = True,block_size_vals: int = 2**30,devices: Optional[List[torch.device]] = None,):"""code modified from: https://github.com/Vahe1994/AQLM/blob/main/src/kmeans.py not sure if I sh...
19
93
9
794
10
247
359
247
null
['nearest_indices', 'new_clusters', 'block_size', 'shard_size', 'cluster_counts', 'reconstructed_data', 'cluster_sums', 'clusters', 'data', 'devices']
None
null
0
0
0
null
0
null
The function (fit_kmeans) defined within the public class called public.The function start at line 247 and ends at 359. It contains 93 lines of code and it has a cyclomatic complexity of 19. It takes 9 parameters, represented as [247.0] and does not return any value..
pytorch_ao
public
public
0
0
_reshape_into_blocks
def _reshape_into_blocks(input: torch.Tensor, block_size: Tuple[int, ...]) -> torch.Tensor:"""Reshape an N-D input tensor into a 2D tensor where each row corresponds to one block."""assert len(block_size) == input.dim(), (f"block_size {block_size} must match the input dimension {input.dim()}")input_size = input.shape# ...
4
30
2
187
10
362
401
362
null
['num_blocks', 'perm_order', 'input_size', 'input_reshaped', 'block_dims', 'grid_dims', 'block_vector_size', 'input_flat', 'D', 'reshaped_dims']
None
null
0
0
0
null
0
null
The function (_reshape_into_blocks) defined within the public class called public.The function start at line 362 and ends at 401. It contains 30 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [362.0] and does not return any value..
pytorch_ao
public
public
0
0
_reshape_from_blocks
def _reshape_from_blocks(blocks: torch.Tensor, block_size: Tuple[int, ...], original_shape: Tuple[int, ...]) -> torch.Tensor:"""Reshape from the 2D block form (num_blocks, block_vector_size) back to the original N-D shape."""D = len(block_size)reshaped_dims = []num_blocks = 1for i in range(D):reshaped_dims.extend([orig...
8
32
3
212
9
404
445
404
null
['num_blocks', 'perm_order', 'blocks_permuted', 'input_permuted_shape', 'perm_inverse', 'block_vector_size', 'blocks_unpermuted', 'D', 'reshaped_dims']
None
null
0
0
0
null
0
null
The function (_reshape_from_blocks) defined within the public class called public.The function start at line 404 and ends at 445. It contains 32 lines of code and it has a cyclomatic complexity of 8. It takes 3 parameters, represented as [404.0] and does not return any value..
pytorch_ao
public
public
0
0
__new__
def __new__(cls,codes: torch.Tensor,codebook: torch.Tensor,block_size: Tuple[int, ...],scales: torch.Tensor,shape: torch.Size,dtype=None,strides=None,):kwargs = {}kwargs["device"] = codes.devicekwargs["layout"] = (kwargs.get("layout") if kwargs.get("layout", False) else codes.layout)kwargs["dtype"] = dtypeif strides is...
3
20
8
123
0
45
64
45
null
[]
None
null
0
0
0
null
0
null
The function (__new__) defined within the public class called public.The function start at line 45 and ends at 64. It contains 20 lines of code and it has a cyclomatic complexity of 3. It takes 8 parameters, represented as [45.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,codes: torch.Tensor,codebook: torch.Tensor,block_size: Tuple[int, ...],scales: torch.Tensor,shape: torch.Size,dtype=None,strides=None,):self.codes = codesself.codebook = codebookself.block_size = block_sizeself.scales = scalesself._dtype = dtype# not sure this is right
1
15
8
72
0
66
80
66
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 66 and ends at 80. It contains 15 lines of code and it has a cyclomatic complexity of 1. It takes 8 parameters, represented as [66.0] and does not return any value..
pytorch_ao
public
public
0
0
__repr__
def __repr__(self):return (f"{self.__class__.__name__}(codes={self.codes}, codebook={self.codebook}, block_size={self.block_size}, scales={self.scales}, "f"shape={self.shape}, device={self.device}, dtype={self.dtype}, requires_grad={self.requires_grad})")
1
5
1
12
0
82
86
82
null
[]
None
null
0
0
0
null
0
null
The function (__repr__) defined within the public class called public.The function start at line 82 and ends at 86. 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
_quantization_type
def _quantization_type(self):return f"shape={self.shape}, block_size={self.block_size}, codebook_size={self.codebook.size(0)}, device={self.device}, code_dtype={self.codes.dtype}"
1
2
1
8
0
88
89
88
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 88 and ends at 89. 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
dequantize
def dequantize(self, output_dtype: Optional[torch.dtype] = None) -> torch.Tensor:if output_dtype is None:output_dtype = self.dtypeif isinstance(self.codes, UintxTensor):codes = self.codes.get_plain()else:codes = self.codesif codes.dtype != torch.int32:# TODO: Investigate and support not casting to torch.int32 for index...
4
15
2
93
0
91
107
91
null
[]
None
null
0
0
0
null
0
null
The function (dequantize) defined within the public class called public.The function start at line 91 and ends at 107. It contains 15 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [91.0] and does not return any value..
pytorch_ao
public
public
0
0
__tensor_flatten__
def __tensor_flatten__(self):return ["codes", "codebook", "scales"], [self.block_size,self.shape,self.dtype,]
1
6
1
28
0
109
114
109
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 109 and ends at 114. It contains 6 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
__tensor_unflatten__
def __tensor_unflatten__(cls, tensor_data_dict, tensor_attributes, outer_size, outer_stride):codes = tensor_data_dict["codes"]codebook = tensor_data_dict["codebook"]scales = tensor_data_dict["scales"]block_size, shape, dtype = tensor_attributesreturn cls(codes,codebook,block_size,scales,shape if outer_size is None else...
2
16
5
66
0
117
132
117
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 117 and ends at 132. It contains 16 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [117.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls,input_tensor: torch.Tensor,block_size: Tuple[int, ...],code_dtype: torch.dtype,scale_block_size: int,chunk_size: int = 1024,):"""Creates a CodebookQuantizedTensor from a floating-point tensor by performing codebook quantization.Args:input_tensor (torch.Tensor): The input floating-point tensor to quan...
2
26
6
139
0
135
173
135
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 135 and ends at 173. It contains 26 lines of code and it has a cyclomatic complexity of 2. It takes 6 parameters, represented as [135.0] and does not return any value..
pytorch_ao
public
public
0
0
to
def to(self, *args, **kwargs):# I'm not sure if this is rightkwargs = self._get_to_kwargs(*args, **kwargs)device = kwargs.pop("device")return self.__class__(self.codes.to(device),self.codebook.to(device),self.block_size,self.scales.to(device),self.shape,**kwargs,)
1
11
3
75
0
175
186
175
null
[]
None
null
0
0
0
null
0
null
The function (to) defined within the public class called public.The function start at line 175 and ends at 186. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [175.0] and does not return any value..
pytorch_ao
public
public
0
0
_apply_fn_to_data
def _apply_fn_to_data(self, fn):# Apply function to only codes?return self.__class__(fn(self.codes),self.codebook,self.block_size,self.scales,self.shape,dtype=self.dtype,)
1
9
2
42
0
188
197
188
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 188 and ends at 197. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [188.0] and does not return any value..
pytorch_ao
public
public
0
0
__torch_function__
def __torch_function__(cls, func, types, args=(), kwargs=None):if kwargs is None:kwargs = {}if func in CODEBOOK_TORCH_FUNCTIONS:return CODEBOOK_TORCH_FUNCTIONS[func](*args, **kwargs)if any(isinstance(arg, cls) for arg in args):# Dequantize all instances of CodebookQuantizedTensor in argsnew_args = tuple(arg.dequantize(...
7
12
4
95
0
200
215
200
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 200 and ends at 215. It contains 12 lines of code and it has a cyclomatic complexity of 7. It takes 4 parameters, represented as [200.0] and does not return any value..
pytorch_ao
public
public
0
0
detach
def detach(self):"""Returns a new `CodebookQuantizedTensor`."""return self.__class__(self.codes.detach(),self.codebook.detach(),self.block_size,self.scales.detach(),self.shape,dtype=self.dtype,)
1
9
1
50
0
217
228
217
null
[]
None
null
0
0
0
null
0
null
The function (detach) defined within the public class called public.The function start at line 217 and ends at 228. 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
requires_grad_
def requires_grad_(self, requires_grad=True):"""Modifies the tensor's `requires_grad` status in-place."""self.codes.requires_grad_(requires_grad)self.codebook.requires_grad_(requires_grad)self.scales.requires_grad_(requires_grad)return self
1
5
2
36
0
230
237
230
null
[]
None
null
0
0
0
null
0
null
The function (requires_grad_) defined within the public class called public.The function start at line 230 and ends at 237. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [230.0] and does not return any value..
pytorch_ao
public
public
0
0
dtype
def dtype(self):# Hacky way to avoid recursion with __torch_function__return self._dtype
1
2
1
9
0
240
242
240
null
[]
None
null
0
0
0
null
0
null
The function (dtype) defined within the public class called public.The function start at line 240 and ends at 242. 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
implements_torch_function.decorator
def decorator(func):CODEBOOK_TORCH_FUNCTIONS[torch_function] = funcreturn func
1
3
1
13
0
249
251
249
null
[]
None
null
0
0
0
null
0
null
The function (implements_torch_function.decorator) defined within the public class called public.The function start at line 249 and ends at 251. 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
implements_torch_function
def implements_torch_function(torch_function):def decorator(func):CODEBOOK_TORCH_FUNCTIONS[torch_function] = funcreturn funcreturn decorator
1
3
1
9
0
248
253
248
null
[]
None
null
0
0
0
null
0
null
The function (implements_torch_function) defined within the public class called public.The function start at line 248 and ends at 253. 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
function_detach
def function_detach(tensor, *args, **kwargs):return tensor.detach()
1
2
3
17
0
257
258
257
null
[]
None
null
0
0
0
null
0
null
The function (function_detach) defined within the public class called public.The function start at line 257 and ends at 258. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [257.0] and does not return any value..
pytorch_ao
public
public
0
0
function_requires_grad_
def function_requires_grad_(tensor, *args, **kwargs):return tensor.requires_grad_(*args, **kwargs)
1
2
3
22
0
262
263
262
null
[]
None
null
0
0
0
null
0
null
The function (function_requires_grad_) defined within the public class called public.The function start at line 262 and ends at 263. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [262.0] and does not return any value..
pytorch_ao
public
public
0
0
_codebook_weight_only_transform
def _codebook_weight_only_transform(module: torch.nn.Module,config: CodebookWeightOnlyConfig,):"""Applies codebook weight-only quantization to linear layers.Args:dtype: torch.uint1 to torch.uint8, torch.int32 supported.block_size: Tuple of (out_features, in_features) to control quantization granularity.scale_block_size...
3
20
2
102
5
278
308
278
null
['scale_block_size', 'block_size', 'dtype', 'quantized_weight', 'weight']
None
null
0
0
0
null
0
null
The function (_codebook_weight_only_transform) defined within the public class called public.The function start at line 278 and ends at 308. It contains 20 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [278.0] and does not return any value..
pytorch_ao
public
public
0
0
_codebook_weight_only_transform
def _codebook_weight_only_transform(module: torch.nn.Module,config: CodebookWeightOnlyConfig,):"""Applies codebook weight-only quantization to linear layers.Args:dtype: torch.uint1 to torch.uint8, torch.int32 supported.Returns:Callable for quantization transformation."""if not is_package_at_least("coremltools", "8.3.0"...
2
15
2
74
3
29
53
29
null
['quantized_weight', 'dtype', 'weight']
None
null
0
0
0
null
0
null
The function (_codebook_weight_only_transform) defined within the public class called public.The function start at line 29 and ends at 53. It contains 15 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [29.0] and does not return any value..
pytorch_ao
public
public
0
0
choose_qparams_and_quantize_codebook_coreml
def choose_qparams_and_quantize_codebook_coreml(input_tensor: torch.Tensor,code_dtype: torch.dtype,block_size: List[int],force_kmeans1d: bool = False,cluster_dim: int = 1,vector_axis: Optional[int] = None,) -> Tuple[torch.Tensor, torch.Tensor]:"""Initialize the codebook using k-means clustering on blocks of the input t...
8
66
6
492
13
23
136
23
null
['is_col_grouping', 'res_codes', 'processed_block_size', 'reshaped_tensor', 'final_luts', 'input_tensor', 'num_luts', 'block_to_quantize', 'nbits', 'res_lut_list', 'final_luts_stacked', 'final_codes', 'original_shape']
None
null
0
0
0
null
0
null
The function (choose_qparams_and_quantize_codebook_coreml) defined within the public class called public.The function start at line 23 and ends at 136. It contains 66 lines of code and it has a cyclomatic complexity of 8. It takes 6 parameters, represented as [23.0] and does not return any value..
pytorch_ao
public
public
0
0
dequantize_codebook
def dequantize_codebook(codes: torch.Tensor,codebook: torch.Tensor,nbits: int,block_size: List[int],output_dtype: torch.dtype = torch.float32,) -> torch.Tensor:"""Reconstructs the original tensor from codes and the codebook.Args:codes (torch.Tensor): Indices of codebook entries for each elementGeneral shape: (d0, d1, d...
8
52
5
382
14
140
235
140
null
['quant_levels', 'ndim', 'flat_codes', 'group_index_tensor', 'flat_groups', 'shape', 'gathered', 'block_size', 'code_shape', 'vec_dim', 'group_indices', 'idx', 'dequant', 'codebook_shape']
None
null
0
0
0
null
0
null
The function (dequantize_codebook) defined within the public class called public.The function start at line 140 and ends at 235. It contains 52 lines of code and it has a cyclomatic complexity of 8. It takes 5 parameters, represented as [140.0] and does not return any value..
pytorch_ao
public
public
0
0
__new__
def __new__(cls,codes: torch.Tensor,codebook: torch.Tensor,code_dtype: torch.dtype,block_size: List[int],shape: torch.Size,dtype=None,):kwargs = {}kwargs["device"] = codes.devicekwargs["layout"] = (kwargs.get("layout") if kwargs.get("layout", False) else codes.layout)kwargs["dtype"] = dtypekwargs["requires_grad"] = Fal...
2
17
7
105
0
47
63
47
null
[]
None
null
0
0
0
null
0
null
The function (__new__) defined within the public class called public.The function start at line 47 and ends at 63. It contains 17 lines of code and it has a cyclomatic complexity of 2. It takes 7 parameters, represented as [47.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,codes: torch.Tensor,codebook: torch.Tensor,code_dtype: torch.dtype,block_size: List[int],shape: torch.Size,dtype=None,):self.codes = codesself.codebook = codebookself.code_dtype = code_dtypeself.block_size = block_size
1
13
7
61
0
65
77
65
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 65 and ends at 77. It contains 13 lines of code and it has a cyclomatic complexity of 1. It takes 7 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__}(codes={self.codes}, codebook={self.codebook}, code_dtype={self.code_dtype}, block_size={self.block_size} "f"shape={self.shape}, device={self.device}, dtype={self.dtype}, requires_grad={self.requires_grad})")
1
5
1
12
0
79
83
79
null
[]
None
null
0
0
0
null
0
null
The function (__repr__) defined within the public class called public.The function start at line 79 and ends at 83. 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
_quantization_type
def _quantization_type(self):return f"shape={self.shape}, codebook_shape={self.codebook.shape}, code_dtype={self.code_dtype}, block_size={self.block_size}, device={self.device}"
1
2
1
8
0
85
86
85
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 85 and ends at 86. 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
dequantize
def dequantize(self, output_dtype: Optional[torch.dtype] = None) -> torch.Tensor:if output_dtype is None:output_dtype = self.dtypecodes = self.codesif codes.dtype != torch.int32:# TODO: Investigate and support not casting to torch.int32 for indexing to improve performancecodes = codes.to(torch.int32)# Note: code_dtype ...
3
13
2
79
0
88
104
88
null
[]
None
null
0
0
0
null
0
null
The function (dequantize) defined within the public class called public.The function start at line 88 and ends at 104. It contains 13 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [88.0] and does not return any value..
pytorch_ao
public
public
0
0
__tensor_flatten__
def __tensor_flatten__(self):return self.tensor_data_attrs, [getattr(self, attr) for attr in self.tensor_attributes]
2
4
1
24
0
106
109
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 109. It contains 4 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
__tensor_unflatten__
def __tensor_unflatten__(cls, tensor_data_dict, tensor_attributes, outer_size, outer_stride):return cls(*[tensor_data_dict[name] for name in cls.tensor_data_attrs],*tensor_attributes,)
2
7
5
34
0
112
118
112
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 112 and ends at 118. It contains 7 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [112.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(getattr(self, attr)) for attr in self.tensor_data_attrs],*[getattr(self, attr) for attr in self.tensor_attributes],)
3
5
2
48
0
120
124
120
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 120 and ends at 124. It contains 5 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [120.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls,input_tensor: torch.Tensor,code_dtype: torch.dtype,block_size: List[int],):"""Creates a CodebookQuantizedTensor from a floating-point tensor by performing codebook quantization.Args:input_tensor (torch.Tensor): The input floating-point tensor to quantize.code_dtype (torch.dtype): The dtype of the cod...
1
18
4
70
0
127
154
127
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 127 and ends at 154. It contains 18 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [127.0] and does not return any value..
pytorch_ao
public
public
0
0
to
def to(self, *args, **kwargs):kwargs = self._get_to_kwargs(*args, **kwargs)device = kwargs.pop("device")return self.__class__(*[getattr(self, attr).to(device) for attr in self.tensor_data_attrs],*[getattr(self, attr) for attr in self.tensor_attributes],**kwargs,)
3
8
3
77
0
156
163
156
null
[]
None
null
0
0
0
null
0
null
The function (to) defined within the public class called public.The function start at line 156 and ends at 163. It contains 8 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [156.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,)weight_tensor = weight_tensor.dequantize()return func(input_tensor, weight_tensor, bias)
2
8
4
59
1
170
177
170
null
['weight_tensor']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 170 and ends at 177. It contains 8 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [170.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):assert len(args) == 2indices, weight_tensor = (args[0],args[1],)weight_tensor = weight_tensor.dequantize()return func(indices, weight_tensor, **kwargs)
1
8
4
51
1
181
188
181
null
['weight_tensor']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 181 and ends at 188. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [181.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
192
195
192
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 192 and ends at 195. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [192.0] and does not return any value..