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
__init__
def __init__(self, int_data: Tensor, scale: Tensor):assert int_data.dtype is torch.int8assert scale.shape == ()self.int_data = int_dataself.scale = scale
1
5
3
38
0
300
304
300
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 300 and ends at 304. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [300.0] and does not return any value..
pytorch_ao
public
public
0
0
__tensor_flatten__
def __tensor_flatten__(self):return ["int_data", "scale"], []
1
2
1
14
0
306
307
306
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 306 and ends at 307. 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):return cls(tensor_data_dict["int_data"], tensor_data_dict["scale"], *tensor_attributes)
1
6
5
33
0
310
315
310
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 310 and ends at 315. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [310.0] and does not return any value..
pytorch_ao
public
public
0
0
__repr__
def __repr__(self):return f"{self.__class__.__name__}(data={self._data})"
1
2
1
8
0
317
318
76
null
[]
None
null
0
0
0
null
0
null
The function (__repr__) defined within the public class called public.The function start at line 317 and ends at 318. 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, out_dtype=None):out = _unpack_i2_in_i8(self.int_data) * self.scaleif out_dtype is not None:out = out.to(out_dtype)return out
2
5
2
37
0
320
324
320
null
[]
None
null
0
0
0
null
0
null
The function (dequantize) defined within the public class called public.The function start at line 320 and ends at 324. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [320.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return _BitNetPacked2bitLinear.apply(*args, **kwargs)
1
2
4
22
0
328
329
328
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 328 and ends at 329. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [328.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return BitNetPacked2bitLinearWeight(func(args[0].int_data, *args[1:], **kwargs),func(args[0].scale, *args[1:], **kwargs),)
1
5
4
55
0
338
342
338
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 338 and ends at 342. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [338.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return BitNetPacked2bitLinearWeight(args[0].int_data, args[0].scale)
1
2
4
28
0
348
349
348
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 348 and ends at 349. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [348.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(ctx,input: Tensor,weight: BitNetPacked2bitLinearWeight,bias: Optional[Tensor] = None,):batch_dims = input.shape[:-1]input = input.view(-1, weight.shape[1])# https://github.com/microsoft/unilm/blob/master/bitnet/The-Era-of-1-bit-LLMs__Training_Tips_Code_FAQ.pdf# Figure 3input_i8, row_scale = quantize_int8_ro...
2
18
4
144
0
354
379
354
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 354 and ends at 379. It contains 18 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [354.0] and does not return any value..
pytorch_ao
public
public
0
0
backward
def backward(ctx, grad_output):input_i8, row_scale, weight_i2, tensor_scale = ctx.saved_tensorsweight_i8 = _unpack_i2_in_i8(weight_i2)grad_input = grad_weight = grad_bias = Nonebatch_dims = grad_output.shape[:-1]grad_output = grad_output.view(-1, weight_i8.shape[0])# NOTE: we can potentially speedup training by also qu...
4
14
2
146
0
382
404
382
null
[]
None
null
0
0
0
null
0
null
The function (backward) defined within the public class called public.The function start at line 382 and ends at 404. It contains 14 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [382.0] and does not return any value..
pytorch_ao
public
public
0
0
quantize_int8_rowwise
def quantize_int8_rowwise(tensor: Tensor, stochastic_rounding: bool = False, eps: float = 1e-12):"""Normal rounding will always round down small changes in weight update. To tackle this problem,stochastic rounding can be used, which has a low chance, but not zero, of rounding up. Theprobability of rounding up is equal ...
2
14
3
119
3
24
52
24
null
['scale', 'tensor', 'inv_scale']
None
null
0
0
0
null
0
null
The function (quantize_int8_rowwise) defined within the public class called public.The function start at line 24 and ends at 52. It contains 14 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [24.0] and does not return any value..
pytorch_ao
public
public
0
0
__new__
def __new__(cls, int_data: Tensor, scale: Tensor):return Tensor._make_wrapper_subclass(cls,int_data.shape,dtype=scale.dtype,device=int_data.device,)
1
7
3
37
0
67
73
67
null
[]
None
null
0
0
0
null
0
null
The function (__new__) defined within the public class called public.The function start at line 67 and ends at 73. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [67.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, int_data: Tensor, scale: Tensor):"""Create a symmetric quantized INT8 weight. This tensor will appear to have the same dtypeas `scale.dtype`. All in-place update ops will perform stochastic rounding."""# NOTE: should scale always be FP32?assert int_data.dtype is torch.int8assert int_data.ndim == 2ass...
1
6
3
44
0
76
85
76
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 76 and ends at 85. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [76.0] and does not return any value..
pytorch_ao
public
public
0
0
__tensor_flatten__
def __tensor_flatten__(self):return ["int_data", "scale"], []
1
2
1
14
0
87
88
87
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 87 and ends at 88. 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):return cls(tensor_data_dict["int_data"], tensor_data_dict["scale"], *tensor_attributes)
1
6
5
33
0
91
96
91
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 91 and ends at 96. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [91.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls, tensor: Tensor):"""Convert a float tensor into INT8 quantized weight. No stochastic rounding is performed.This function is not differentiable."""int_data, scale = quantize_int8_rowwise(tensor.detach())out = cls(int_data, scale)out.requires_grad_(tensor.requires_grad)return out
1
5
2
40
0
99
106
99
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 99 and ends at 106. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [99.0] and does not return any value..
pytorch_ao
public
public
0
0
dequantize
def dequantize(self):return self.int_data * self.scale.view(-1, 1)
1
2
1
21
0
108
109
108
null
[]
None
null
0
0
0
null
0
null
The function (dequantize) defined within the public class called public.The function start at line 108 and ends at 109. 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
__repr__
def __repr__(self):return (f"{self.__class__.__name__}(shape={tuple(self.shape)}, dtype={self.dtype}, device={self.device}, "f"requires_grad={self.requires_grad})")
1
5
1
12
0
111
115
111
null
[]
None
null
0
0
0
null
0
null
The function (__repr__) defined within the public class called public.The function start at line 111 and ends at 115. 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
fsdp_pre_all_gather
def fsdp_pre_all_gather(self,mesh,outer_size=None,outer_stride=None,module=None,mp_policy=None,):scale = self.scaleif mp_policy is not None:scale = scale.to(mp_policy.param_dtype)return (self.int_data, scale), None
2
12
6
55
0
120
132
120
null
[]
None
null
0
0
0
null
0
null
The function (fsdp_pre_all_gather) defined within the public class called public.The function start at line 120 and ends at 132. It contains 12 lines of code and it has a cyclomatic complexity of 2. It takes 6 parameters, represented as [120.0] and does not return any value..
pytorch_ao
public
public
0
0
fsdp_post_all_gather
def fsdp_post_all_gather(self,all_gather_outputs: Tuple[Tensor, ...],metadata: Any,param_dtype: torch.dtype,*,out: Optional[Tensor] = None,):int_data, scale = all_gather_outputsreturn Int8QuantizedTrainingLinearWeight(int_data, scale), all_gather_outputs
1
10
5
50
0
134
143
134
null
[]
None
null
0
0
0
null
0
null
The function (fsdp_post_all_gather) defined within the public class called public.The function start at line 134 and ends at 143. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [134.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(ctx,input: Tensor,weight: Int8QuantizedTrainingLinearWeight,bias: Optional[Tensor] = None,):ctx.save_for_backward(input, weight)ctx.bias = bias is not None# NOTE: we have to .T before .to(input.dtype) for torch.compile() mixed matmul to workout = (input @ weight.int_data.T.to(input.dtype)) * weight.scaleout...
2
11
4
75
0
148
160
148
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 148 and ends at 160. It contains 11 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [148.0] and does not return any value..
pytorch_ao
public
public
0
0
backward
def backward(ctx, grad_output):input, weight = ctx.saved_tensorsgrad_input = (grad_output * weight.scale) @ weight.int_data.to(grad_output.dtype)grad_weight = grad_output.view(-1, weight.shape[0]).T @ input.view(-1, weight.shape[1])grad_bias = grad_output.view(-1, weight.shape[0]).sum(0) if ctx.bias else Nonereturn gra...
2
10
2
100
0
163
173
163
null
[]
None
null
0
0
0
null
0
null
The function (backward) defined within the public class called public.The function start at line 163 and ends at 173. It contains 10 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [163.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return _Int8WeightOnlyLinear.apply(*args, **kwargs)
1
2
4
22
0
180
181
180
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 180 and ends at 181. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [180.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):# will error out if try to slice 2nd dimout = Int8QuantizedTrainingLinearWeight(func(args[0].int_data, *args[1:], **kwargs),func(args[0].scale, *args[1:], **kwargs),)return return_and_correct_aliasing(func, args, kwargs, out)
1
6
4
67
1
196
202
196
null
['out']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 196 and ends at 202. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [196.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):# only perform dtype casting on scale, which determines the appearance dtype# TODO: handle non_blocking kwarg?device = kwargs.get("device", None)dtype = kwargs.get("dtype", None)out = Int8QuantizedTrainingLinearWeight(args[0].int_data.to(device=device),args[0].scale.to(device=device, dt...
1
8
4
79
3
206
215
206
null
['out', 'dtype', 'device']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 206 and ends at 215. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [206.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):dtype = kwargs.get("dtype", args[0].dtype)device = kwargs.get("device", args[0].device)return torch.zeros(args[0].shape, dtype=dtype, device=device)
1
4
4
61
2
220
223
220
null
['dtype', 'device']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 220 and ends at 223. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [220.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):args = [x.dequantize() if isinstance(x, Int8QuantizedTrainingLinearWeight) else xfor x in args]return func(*args, **kwargs)
3
6
4
42
1
228
233
228
null
['args']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 228 and ends at 233. It contains 6 lines of code and it has a cyclomatic complexity of 3. It takes 4 parameters, represented as [228.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):if isinstance(args[0], Int8QuantizedTrainingLinearWeight) and isinstance(args[1], Int8QuantizedTrainingLinearWeight):args[0].int_data.copy_(args[1].int_data, **kwargs)args[0].scale.copy_(args[1].scale, **kwargs)elif isinstance(args[0], Int8QuantizedTrainingLinearWeight):int_data, scale ...
4
13
4
150
0
237
252
237
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 237 and ends at 252. It contains 13 lines of code and it has a cyclomatic complexity of 4. It takes 4 parameters, represented as [237.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):original = args[0]out = func(args[0].dequantize(), *args[1:], **kwargs)return original.copy_(out)
1
4
4
47
2
256
259
256
null
['out', 'original']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 256 and ends at 259. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [256.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):if len(args) == 3 and args[2] != 0:raise NotImplementedError("Int8QTLinearWeight only supports split at dim=0")int8_weight: Int8QuantizedTrainingLinearWeight = args[0]int_data_list = func(int8_weight.int_data, *args[1:], **kwargs)scale_list = func(int8_weight.scale, *args[1:], **kwargs)...
4
11
4
98
3
264
276
264
null
['out', 'scale_list', 'int_data_list']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 264 and ends at 276. It contains 11 lines of code and it has a cyclomatic complexity of 4. It takes 4 parameters, represented as [264.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):size = args[1]if len(size) != 2:raise NotImplementedError# TODO: handle pin_memory kwarg?device = kwargs.get("device", args[0].device)dtype = kwargs.get("dtype", args[0].dtype)int_data = torch.zeros(size, device=device, dtype=torch.int8)scale = torch.zeros(size[0], device=device, dtype=...
2
9
4
101
5
280
290
280
null
['int_data', 'device', 'scale', 'dtype', 'size']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 280 and ends at 290. It contains 9 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [280.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):out = Int8QuantizedTrainingLinearWeight(args[0].int_data, args[0].scale)return return_and_correct_aliasing(func, args, kwargs, out)
1
3
4
40
1
299
301
299
null
['out']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 299 and ends at 301. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [299.0] and does not return any value..
pytorch_ao
public
public
0
0
_int8_weight_only_quantized_training_transform
def _int8_weight_only_quantized_training_transform(module: torch.nn.Module,config: Int8WeightOnlyQuantizedTrainingConfig,) -> torch.nn.Module:new_weight = Int8QuantizedTrainingLinearWeight.from_float(module.weight)module.weight = torch.nn.Parameter(new_weight, requires_grad=True)return module
1
7
2
50
1
313
319
313
null
['new_weight']
None
null
0
0
0
null
0
null
The function (_int8_weight_only_quantized_training_transform) defined within the public class called public.The function start at line 313 and ends at 319. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [313.0] and does not return any value..
pytorch_ao
public
public
0
0
scaled_int8_mm
def scaled_int8_mm(A: Tensor, B: Tensor, row_scale: Tensor, col_scale: Tensor) -> Tensor:return torch._int_mm(A, B) * col_scale.view(-1) * row_scale.view(-1, 1)
1
4
4
48
0
29
32
29
null
[]
None
null
0
0
0
null
0
null
The function (scaled_int8_mm) defined within the public class called public.The function start at line 29 and ends at 32. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [29.0] and does not return any value..
pytorch_ao
public
public
0
0
__new__
def __new__(cls, data: Tensor, config: Int8MixedPrecisionTrainingConfig):return Tensor._make_wrapper_subclass(cls,data.shape,data.stride(),data.storage_offset(),dtype=data.dtype,device=data.device,)
1
9
3
49
0
61
69
61
null
[]
None
null
0
0
0
null
0
null
The function (__new__) defined within the public class called public.The function start at line 61 and ends at 69. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [61.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, data: Tensor, config: Int8MixedPrecisionTrainingConfig):self._data = dataself.config = config
1
3
3
23
0
72
74
72
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 72 and ends at 74. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [72.0] and does not return any value..
pytorch_ao
public
public
0
0
__tensor_flatten__
def __tensor_flatten__(self):return ["_data"], [self.config]
1
2
1
15
0
76
77
76
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 76 and ends at 77. 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):return cls(tensor_data_dict["_data"], *tensor_attributes)
1
4
5
28
0
80
83
80
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 80 and ends at 83. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [80.0] and does not return any value..
pytorch_ao
public
public
0
0
__repr__
def __repr__(self):return f"{self.__class__.__name__}(data={self._data}, config={self.config})"
1
2
1
8
0
85
86
85
null
[]
None
null
0
0
0
null
0
null
The function (__repr__) 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
to_original
def to_original(self):return self._data.clone()
1
2
1
13
0
88
89
88
null
[]
None
null
0
0
0
null
0
null
The function (to_original) 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
__torch_dispatch__.unwrap
def unwrap(x):nonlocal configif config is None:config = x.configelse:assert x.config == configreturn x._data
2
7
1
29
0
96
102
96
null
[]
None
null
0
0
0
null
0
null
The function (__torch_dispatch__.unwrap) defined within the public class called public.The function start at line 96 and ends at 102. 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
__torch_dispatch__
def __torch_dispatch__(cls, func, types, args, kwargs):config = Nonedef unwrap(x):nonlocal configif config is None:config = x.configelse:assert x.config == configreturn x._dataout = func(*pytree.tree_map_only(cls, unwrap, args),**pytree.tree_map_only(cls, unwrap, kwargs),)if func is aten.copy_.default:# return original...
3
25
5
156
0
93
129
93
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 93 and ends at 129. It contains 25 lines of code and it has a cyclomatic complexity of 3. It takes 5 parameters, represented as [93.0] and does not return any value..
pytorch_ao
public
public
0
0
fsdp_pre_all_gather
def fsdp_pre_all_gather(self,mesh,outer_size=None,outer_stride=None,module=None,mp_policy=None,):# TODO: pre-quantize weight here -> reduce comm bandwidth.# we will need another tensor subclass to hold the quantized weight.data = self._dataif mp_policy is not None:data = data.to(mp_policy.param_dtype)return (data,), (s...
2
12
6
57
0
134
148
134
null
[]
None
null
0
0
0
null
0
null
The function (fsdp_pre_all_gather) defined within the public class called public.The function start at line 134 and ends at 148. It contains 12 lines of code and it has a cyclomatic complexity of 2. It takes 6 parameters, represented as [134.0] and does not return any value..
pytorch_ao
public
public
0
0
fsdp_post_all_gather
def fsdp_post_all_gather(self,all_gather_outputs: Tuple[Tensor, ...],metadata: Any,param_dtype: torch.dtype,*,out: Optional[Tensor] = None,):(data,) = all_gather_outputs(config,) = metadataif out is not None:assert isinstance(out, Int8MixedPrecisionTrainingLinearWeight)assert out.config == configreturnreturn Int8MixedP...
2
15
5
77
0
150
164
150
null
[]
None
null
0
0
0
null
0
null
The function (fsdp_post_all_gather) defined within the public class called public.The function start at line 150 and ends at 164. It contains 15 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [150.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):if torch.is_autocast_enabled("cuda"):dtype = torch.get_autocast_gpu_dtype()args = tuple(x.to(dtype) if x is not None else x for x in args)return _Int8MixedPrecisionTrainingLinearFunction.apply(*args, **kwargs)
4
5
4
59
2
168
172
168
null
['args', 'dtype']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 168 and ends at 172. It contains 5 lines of code and it has a cyclomatic complexity of 4. It takes 4 parameters, represented as [168.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, *args, config: Int8MixedPrecisionTrainingConfig, **kwargs) -> None:super().__init__(*args, **kwargs)self.config = config
1
5
4
34
0
176
180
176
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 176 and ends at 180. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [176.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, input: Tensor) -> Tensor:return _Int8MixedPrecisionTrainingLinearFunction.apply(input, self.weight, self.bias, self.config)
1
4
2
30
0
182
185
182
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 182 and ends at 185. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [182.0] and does not return any value..
pytorch_ao
public
public
0
0
_dynamic_int8_mm
def _dynamic_int8_mm(A: Tensor, B: Tensor) -> Tensor:"""Dynamically quantize A and B to perform INT8 matmul, then scale the results back to original precision.To fuse scaling to matmul output, we use row-wise scaling for A and column-wise scaling for B.We transpose B before quantization for 2 reasons:- INT8 matmul is t...
1
10
2
100
1
188
215
188
null
['out']
None
null
0
0
0
null
0
null
The function (_dynamic_int8_mm) defined within the public class called public.The function start at line 188 and ends at 215. It contains 10 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
forward
def forward(ctx,input: Tensor,weight: Union[Int8MixedPrecisionTrainingLinearWeight, Tensor],bias: Optional[Tensor],config: Optional[Int8MixedPrecisionTrainingConfig] = None,):# unpack tensor subclass and dequant if necessary.# NOTE: we have to do this inside autograd.Function so that autograd works correctly.if isinsta...
4
20
5
122
0
221
251
221
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 221 and ends at 251. It contains 20 lines of code and it has a cyclomatic complexity of 4. It takes 5 parameters, represented as [221.0] and does not return any value..
pytorch_ao
public
public
0
0
backward
def backward(ctx, grad_output):input, weight = ctx.saved_tensorsweight = weight.to(input.dtype)# dequant NF4grad_input = grad_weight = grad_bias = Noneif ctx.needs_input_grad[0]:if ctx.config.grad_input:grad_input = _dynamic_int8_mm(grad_output, weight)else:grad_input = grad_output @ weightif ctx.needs_input_grad[1]:gr...
7
21
2
157
0
254
280
254
null
[]
None
null
0
0
0
null
0
null
The function (backward) defined within the public class called public.The function start at line 254 and ends at 280. It contains 21 lines of code and it has a cyclomatic complexity of 7. It takes 2 parameters, represented as [254.0] and does not return any value..
pytorch_ao
public
public
0
0
_int8_mixed_precision_training_transform
def _int8_mixed_precision_training_transform(module: torch.nn.Module,config: Int8MixedPrecisionTrainingConfig,):module_swap = config.module_swap# TODO: skip small layers that don't have perf gain.if module_swap:# module swap implementationmodule.__class__ = Int8MixedPrecisionTrainingLinearmodule.config = configreturn m...
2
13
2
66
2
284
302
284
null
['module_swap', 'new_weight']
None
null
0
0
0
null
0
null
The function (_int8_mixed_precision_training_transform) defined within the public class called public.The function start at line 284 and ends at 302. It contains 13 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [284.0] and does not return any value..
pytorch_ao
public
public
0
0
_scaled_int8_mm_kernel
def _scaled_int8_mm_kernel(A_ptr,B_ptr,C_ptr,row_scale_ptr,col_scale_ptr,M,N,K,stride_am,stride_ak,stride_bk,stride_bn,stride_cm,stride_cn,BLOCK_M: tl.constexpr,BLOCK_N: tl.constexpr,BLOCK_K: tl.constexpr,GROUP_M: tl.constexpr = 8,EVEN_K: tl.constexpr = True,COL_SCALE_SCALAR: tl.constexpr = False,):# based on triton.op...
4
61
20
553
24
64
135
64
null
['width', 'mask', 'pid_m', 'rm', 'rbn', 'idx_n', 'grid_n', 'acc', 'B', 'pid', 'row_scale', 'a', 'b', 'A', 'pid_n', 'xindex', 'ram', 'rk', 'idx_m', 'group_id', 'group_size', 'rn', 'col_scale', 'grid_m']
None
null
0
0
0
null
0
null
The function (_scaled_int8_mm_kernel) defined within the public class called public.The function start at line 64 and ends at 135. It contains 61 lines of code and it has a cyclomatic complexity of 4. It takes 20 parameters, represented as [64.0] and does not return any value..
pytorch_ao
public
public
0
0
scaled_int8_mm
def scaled_int8_mm(A: Tensor, B: Tensor, row_scale: Tensor, col_scale: Tensor) -> Tensor:"""Compute `(A @ B) * row_scale * col_scale`, where `A` and `B` are INT8 to utilizeINT8 tensor cores. `col_scale` can be a scalar."""assert A.dtype is torch.int8 and B.dtype is torch.int8assert row_scale.dtype is col_scale.dtypeass...
2
11
4
130
0
143
156
143
null
[]
None
null
0
0
0
null
0
null
The function (scaled_int8_mm) defined within the public class called public.The function start at line 143 and ends at 156. It contains 11 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [143.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(A: Tensor, B: Tensor, row_scale: Tensor, col_scale: Tensor):return torch.empty((A.shape[0], B.shape[1]), device=A.device, dtype=row_scale.dtype)
1
2
4
52
0
160
161
160
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 160 and ends at 161. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [160.0] and does not return any value..
pytorch_ao
public
public
0
0
scaled_int8_mm_cuda
def scaled_int8_mm_cuda(A: Tensor, B: Tensor, row_scale: Tensor, col_scale: Tensor):M, K = A.shape_, N = B.shapeC = torch.empty(M, N, device=A.device, dtype=row_scale.dtype)grid = lambda meta: (triton.cdiv(meta["M"], meta["BLOCK_M"])* triton.cdiv(meta["N"], meta["BLOCK_N"]),)_scaled_int8_mm_kernel[grid](A,B,C,row_scale...
1
23
4
147
2
165
187
165
null
['C', 'grid']
None
null
0
0
0
null
0
null
The function (scaled_int8_mm_cuda) defined within the public class called public.The function start at line 165 and ends at 187. It contains 23 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [165.0] and does not return any value..
pytorch_ao
public
public
0
0
unflatten_tensor_state_dict
def unflatten_tensor_state_dict(tensors_data_dict: Dict[str, Any],metadata: Dict[str, Any],):"""Reconstructs tensor subclass state dict from provided torch.Tensor data and metadata dictionaryThe naming of metadata is so that it is consistent with safetensors naming to avoid confusionThis function is used after loading ...
7
24
2
174
6
16
88
16
null
['combined_data', 'tensor_names', 'tensor_tensors', 'tensor_type', 'tensor_metadata', 'result']
None
null
0
0
0
null
0
null
The function (unflatten_tensor_state_dict) defined within the public class called public.The function start at line 16 and ends at 88. It contains 24 lines of code and it has a cyclomatic complexity of 7. It takes 2 parameters, represented as [16.0] and does not return any value..
pytorch_ao
public
public
0
0
flatten_tensor_state_dict
def flatten_tensor_state_dict(tensors_dict: Dict[str, Dict[str, torch.Tensor]],):"""Flattens a dictionary of tensor subclasses so that it is compatible with safetensors.save_fileWe disconstruct tensor subclass structure into torch.Tensor data and metadata dictionaryThe naming of metadata is so that it is consistent wit...
9
30
1
227
6
91
173
91
null
['metadata', 'tensors_data_dict', 'tensor_metadata', 'tensor_dict', 'all_tensor_data', 'prefixed_tensors_dict']
None
null
0
0
0
null
0
null
The function (flatten_tensor_state_dict) defined within the public class called public.The function start at line 91 and ends at 173. It contains 30 lines of code and it has a cyclomatic complexity of 9. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
default
def default(self, o):if o.__class__.__name__ in ALLOWED_TENSORS_SUBCLASSES:tensor_attr_dict = {}optional_tensor_attributes = (o.optional_tensor_attribute_namesif hasattr(o, "optional_tensor_attribute_names")else [])all_tensor_attributes = (optional_tensor_attributes + o.tensor_attribute_names)for tensor_attribute_name ...
16
42
2
325
0
45
102
45
null
[]
None
null
0
0
0
null
0
null
The function (default) defined within the public class called public.The function start at line 45 and ends at 102. It contains 42 lines of code and it has a cyclomatic complexity of 16. It takes 2 parameters, represented as [45.0] and does not return any value..
pytorch_ao
public
public
0
0
encode_value
def encode_value(self, value):"""Helper method to recursively encode a value"""# Try to use default for custom typetry:# This will handle all our special cases and raise TypeError# if it can't handle the typeresult = self.default(value)return resultexcept TypeError:pass# Default case - return as is# (This will be proce...
2
7
2
26
0
104
117
104
null
[]
None
null
0
0
0
null
0
null
The function (encode_value) defined within the public class called public.The function start at line 104 and ends at 117. It contains 7 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [104.0] and does not return any value..
pytorch_ao
public
public
0
0
object_from_dict
def object_from_dict(data: Dict[str, Any]):if not isinstance(data, dict):raise TypeError(f"Expected dictionary, got {type(data)}")if "_type" not in data or "_data" not in data:raise ValueError("Input dictionary missing required '_type' or '_data' fields")type_path = data["_type"]obj_data = data["_data"]if type_path == ...
25
52
1
303
5
120
188
120
null
['obj_data', 'allowed_modules_str', 'cls', 'processed_data', 'type_path']
None
null
0
0
0
null
0
null
The function (object_from_dict) defined within the public class called public.The function start at line 120 and ends at 188. It contains 52 lines of code and it has a cyclomatic complexity of 25. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
is_metadata_torchao
def is_metadata_torchao(metadata: Dict[str, Any]):if not metadata or "tensor_names" not in metadata:return Falsetry:all_tensor_names = json.loads(metadata["tensor_names"])except (TypeError, json.JSONDecodeError, UnicodeDecodeError):return Falseif not all_tensor_names or not isinstance(all_tensor_names, list):return Fal...
12
20
1
135
3
191
215
191
null
['tensor_dict', 'all_tensor_names', 'tensor_type']
None
null
0
0
0
null
0
null
The function (is_metadata_torchao) defined within the public class called public.The function start at line 191 and ends at 215. It contains 20 lines of code and it has a cyclomatic complexity of 12. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
__post_init__
def __post_init__(self):self.step = self.step.lower() if isinstance(self.step, str) else self.step.valueall_step_values = [s.value for s in SmoothQuantStep]if self.step not in all_step_values:raise ValueError(f"{self.step} is not one of {all_step_values}")
4
5
1
56
0
52
56
52
null
[]
None
null
0
0
0
null
0
null
The function (__post_init__) defined within the public class called public.The function start at line 52 and ends at 56. It contains 5 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
_smooth_quant_transform
def _smooth_quant_transform(module: torch.nn.Module,config: SmoothQuantConfig,) -> torch.nn.Module:step = config.stepbase_config = config.base_configif step == SmoothQuantStep.PREPARE:observer = SmoothQuantObserver(weight=module.weight,alpha=config.alpha,)return SmoothQuantObservedLinear.from_float(module, observer)if ...
5
54
2
317
12
60
126
60
null
['observed_linear', 'base_config', 'linear', 'dummy_mod', 'example_input', 'step', 'qw', 'quant_mod', 'smoothing_factor', 'observer', 'base_config_handler', 'weight']
None
null
0
0
0
null
0
null
The function (_smooth_quant_transform) defined within the public class called public.The function start at line 60 and ends at 126. It contains 54 lines of code and it has a cyclomatic complexity of 5. It takes 2 parameters, represented as [60.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,weight: torch.Tensor,alpha: Optional[float] = 0.5,):"""A custom observer for smoothing factor, main concept of SmoothQuant.Args:weight: The weight tensor to be observed.alpha: The alpha value to determine smoothing factor, normally between 0 and 1."""super().__init__()assert weight.ndim == 2self.weigh...
1
11
3
60
0
20
37
20
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 20 and ends at 37. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [20.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, input: torch.Tensor):self.inputs.append(input.to("cpu"))return input
1
3
2
26
0
40
42
40
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 40 and ends at 42. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [40.0] and does not return any value..
pytorch_ao
public
public
0
0
calculate_qparams
def calculate_qparams(self):assert self.inputs and len(self.inputs) > 0, ("calibrate observer first by running model on exemplar data")inputs = [inp.to(self.device) for inp in self.inputs]acc = torch.cat(inputs, dim=0)# Reshape if needed: [batch, seq, features] -> [batch*seq, features]if acc.ndim > 2:acc = acc.view(-1,...
5
16
1
172
0
44
65
44
null
[]
None
null
0
0
0
null
0
null
The function (calculate_qparams) defined within the public class called public.The function start at line 44 and ends at 65. It contains 16 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
__init__
def __init__(self,in_features: int,out_features: int,obs: SmoothQuantObserver,is_bias: bool = False,device=None,dtype=None,):super().__init__(in_features, out_features, bias=is_bias, device=device, dtype=dtype)self.obs = obs
1
13
7
59
0
69
81
69
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 69 and ends at 81. It contains 13 lines of code and it has a cyclomatic complexity of 1. It takes 7 parameters, represented as [69.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, input: torch.Tensor):input = self.obs(input)return F.linear(input, self.weight)
1
3
2
30
0
83
85
83
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 83 and ends at 85. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [83.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls, float_linear: torch.nn.Linear, obs: SmoothQuantObserver):with torch.device("meta"):observed_linear = cls(float_linear.in_features,float_linear.out_features,obs,is_bias=float_linear.bias is not None,device=float_linear.weight.device,dtype=float_linear.weight.dtype,)observed_linear.weight = float_line...
1
13
3
81
0
88
100
88
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 88 and ends at 100. It contains 13 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [88.0] and does not return any value..
pytorch_ao
public
public
0
0
benchmark
def benchmark(model, tokenizer, max_seq_length=512, tasks=["PPL"], device="cuda"):"""Benchmark model with perplexity calculation on WikiText-2"""# Load WikiText-2 test setdataset = load_dataset("wikitext", "wikitext-2-raw-v1", split="test")# Prepare text data and truncate if necessarytext = "\n\n".join(dataset["text"])...
4
33
5
261
16
24
73
24
null
['outputs', 'seq_len', 'inference_time', 'neg_log_likelihood', 'nlls', 'end_loc', 'ppl', 'input_ids', 'target_ids', 'encodings', 'text', 'dataset', 'model_max_length', 'trg_len', 'start_time', 'prev_end_loc']
None
null
0
0
0
null
0
null
The function (benchmark) defined within the public class called public.The function start at line 24 and ends at 73. It contains 33 lines of code and it has a cyclomatic complexity of 4. It takes 5 parameters, represented as [24.0] and does not return any value..
pytorch_ao
public
public
0
0
quantize_and_eval
def quantize_and_eval(model_id: str,alpha: float,tasks: list[str],max_seq_length: int,calibration_limit: int,device: str,model_save_path: str,model_save_hf_hub_path: str,):print(f"Loading model on {device}...")torch.manual_seed(34)t0 = time.time()tokenizer = AutoTokenizer.from_pretrained(model_id)model = (AutoModelForC...
4
51
8
288
5
76
138
76
null
['t0', 'tokenizer', 'model', 'calibration_data', 'quant_config']
None
null
0
0
0
null
0
null
The function (quantize_and_eval) defined within the public class called public.The function start at line 76 and ends at 138. It contains 51 lines of code and it has a cyclomatic complexity of 4. It takes 8 parameters, represented as [76.0] and does not return any value..
pytorch_ao
public
public
0
0
compare_models
def compare_models(model_id: str,alpha: float,tasks: list[str],max_seq_length: int,calibration_limit: int,device: str,model_save_path: str,model_save_hf_hub_path: str,):"""Compare perplexity and speed for behchmarking SmoothQuant"""# Case 1: Base model without quantizationprint("Benchmarking base model...")torch.manual...
1
85
8
331
10
141
238
141
null
['w8a8_model', 'w8a8_results', 'smoothquant_ppl_change', 'w8a8_speed_change', 'tokenizer', 'model', 'w8a8_ppl_change', 'smoothquant_results', 'base_results', 'smoothquant_speed_change']
None
null
0
0
0
null
0
null
The function (compare_models) defined within the public class called public.The function start at line 141 and ends at 238. It contains 85 lines of code and it has a cyclomatic complexity of 1. It takes 8 parameters, represented as [141.0] and does not return any value..
pytorch_ao
public
public
0
0
create_parser
def create_parser() -> argparse.ArgumentParser:parser = argparse.ArgumentParser(description="Evaluate a model with SmoothQuant quantization.")parser.add_argument("--model", type=str, required=True, help="Model ID from Huggingface hub.")parser.add_argument("--alpha",type=float,default=0.5,help="The alpha hyperparameter ...
1
51
0
179
1
241
293
241
null
['parser']
None
null
0
0
0
null
0
null
The function (create_parser) defined within the public class called public.The function start at line 241 and ends at 293. It contains 51 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
_float8_dynamic_activation_float8_semi_sparse_weight_transform
def _float8_dynamic_activation_float8_semi_sparse_weight_transform(module: torch.nn.Module,config: SRELUFloat8SemiSparseDynamicActivationFloat8WeightConfig,):return FP8SemiSparseActivationLinear.from_dense(module, config)
1
5
2
25
0
35
39
35
null
[]
None
null
0
0
0
null
0
null
The function (_float8_dynamic_activation_float8_semi_sparse_weight_transform) defined within the public class called public.The function start at line 35 and ends at 39. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [35.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, weight, config) -> None:super().__init__()self.config = configW_aqt = _float8_cutlass_quant(weight, self.config.weight_dtype)self.Wq = W_aqt.tensor_impl.float8_dataself.W_scale = W_aqt.tensor_impl.scale
1
6
3
53
0
47
53
47
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 47 and ends at 53. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [47.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, x):X_scale = torch.empty([x.shape[0], 1], device=x.device, dtype=torch.float32)Xq_sparse, X_meta = torch.ops.torchao.sparse24_sm90_sparsify(x,"cutlass","srelu","largest",dtype=self.config.activation_dtype,scale=X_scale,)result = rowwise_scaled_linear_sparse_cutlass_f8f8(self.Wq,self.W_scale,Xq_sparse,...
1
20
2
104
0
55
76
55
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 55 and ends at 76. It contains 20 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [55.0] and does not return any value..
pytorch_ao
public
public
0
0
from_dense
def from_dense(cls, linear, config: SRELUFloat8SemiSparseDynamicActivationFloat8WeightConfig):if linear.bias is not None:raise NotImplementedError("bias is not supported")if linear.weight.dtype != torch.bfloat16:raise NotImplementedError("weight dtype must be bf16")return cls(linear.weight.data, config)
3
8
3
51
0
79
87
79
null
[]
None
null
0
0
0
null
0
null
The function (from_dense) defined within the public class called public.The function start at line 79 and ends at 87. It contains 8 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [79.0] and does not return any value..
pytorch_ao
public
public
0
0
_dump_metadata_format_cutlass
def _dump_metadata_format_cutlass(rows=128, cols=256, device=torch.device("cuda"), dtype=torch.float8_e4m3fn):"""This is a helper function to dump the metadata packing format for 2:4 sparse GEMMS.We create a 2:4 sparse tensor by tiling the same pattern and then changing a singular 1x4 strip of the metadata at a time.Th...
5
39
3
246
6
10
64
10
null
['dense_reference_tensor_c', 'probe_pattern', 'indicies', 'dense_reference_tensor', 'metadata_list', 'num_per_tb']
None
null
0
0
0
null
0
null
The function (_dump_metadata_format_cutlass) defined within the public class called public.The function start at line 10 and ends at 64. It contains 39 lines of code and it has a cyclomatic complexity of 5. It takes 3 parameters, represented as [10.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self):super().__init__()
1
2
1
12
0
68
69
68
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 68 and ends at 69. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, x):return F.relu(x) ** 2
1
2
2
16
0
71
72
71
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 71 and ends at 72. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [71.0] and does not return any value..
pytorch_ao
public
public
0
0
profiler_runner
def profiler_runner(path, fn, *args, **kwargs):if path is None:path = os.path.join(os.path.expanduser("~/traces"),f"{datetime.now().strftime('%Y-%m-%d-%H-%M-%S')}.json.gz",)with torch.profiler.profile(activities=[torch.profiler.ProfilerActivity.CPU,torch.profiler.ProfilerActivity.CUDA,],record_shapes=True,) as prof:res...
2
17
4
98
2
75
91
75
null
['result', 'path']
None
null
0
0
0
null
0
null
The function (profiler_runner) defined within the public class called public.The function start at line 75 and ends at 91. It contains 17 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [75.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, sparsity_level: float = 0.5, dist: Optional[Union[Callable, int]] = None):defaults = {"sparsity_level": sparsity_level,}if dist is None:dist = 2if callable(dist):self.dist_fn = distelif dist == 1:self.dist_fn = lambda x: torch.cdist(x, x, p=1)elif dist == 2:self.dist_fn = lambda x: torch.cdist(x, x, ...
5
17
3
119
0
33
51
33
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 33 and ends at 51. It contains 17 lines of code and it has a cyclomatic complexity of 5. It takes 3 parameters, represented as [33.0] and does not return any value..
pytorch_ao
public
public
0
0
_compute_distance
def _compute_distance(self, t):r"""Compute distance across all entries in tensor `t` along all dimensionexcept for the one identified by dim.Args:t (torch.Tensor): tensor representing the parameter to pruneReturns:distance (torch.Tensor): distance computed across filtters"""dim = 0# prune filter (row)size = t.size(dim)...
2
12
2
114
0
53
79
53
null
[]
None
null
0
0
0
null
0
null
The function (_compute_distance) defined within the public class called public.The function start at line 53 and ends at 79. It contains 12 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [53.0] and does not return any value..
pytorch_ao
public
public
0
0
update_mask
def update_mask(self, module, tensor_name, sparsity_level, **kwargs):tensor_weight = getattr(module, tensor_name)mask = getattr(module.parametrizations, tensor_name)[0].maskif sparsity_level <= 0:mask.data = torch.ones_like(mask).bool()elif sparsity_level >= 1.0:mask.data = torch.zeros_like(mask).bool()else:distance = ...
3
16
5
140
0
81
98
81
null
[]
None
null
0
0
0
null
0
null
The function (update_mask) defined within the public class called public.The function start at line 81 and ends at 98. It contains 16 lines of code and it has a cyclomatic complexity of 3. It takes 5 parameters, represented as [81.0] and does not return any value..
pytorch_ao
public
public
0
0
_get_supported_structured_pruning_modules
def _get_supported_structured_pruning_modules():SUPPORTED_STRUCTURED_PRUNING_MODULES = {# added to config if None givennn.Linear,nn.Conv2d,nn.LSTM,}return SUPPORTED_STRUCTURED_PRUNING_MODULES
1
7
0
22
1
35
41
35
null
['SUPPORTED_STRUCTURED_PRUNING_MODULES']
None
null
0
0
0
null
0
null
The function (_get_supported_structured_pruning_modules) defined within the public class called public.The function start at line 35 and ends at 41. 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_supported_activation_functions
def _get_supported_activation_functions():SUPPORTED_ACTIVATION_FUNCTIONS = {F.relu,F.rrelu,F.hardtanh,F.relu6,F.sigmoid,F.hardsigmoid,F.tanh,F.silu,F.mish,F.hardswish,F.elu,F.celu,F.selu,F.hardshrink,F.leaky_relu,F.logsigmoid,F.softplus,F.prelu,F.softsign,F.tanhshrink,F.gelu,F.dropout,}return SUPPORTED_ACTIVATION_FUNCT...
1
26
0
98
1
44
69
44
null
['SUPPORTED_ACTIVATION_FUNCTIONS']
None
null
0
0
0
null
0
null
The function (_get_supported_activation_functions) defined within the public class called public.The function start at line 44 and ends at 69. It contains 26 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_get_supported_activation_modules
def _get_supported_activation_modules():SUPPORTED_ACTIVATION_MODULES = {nn.ReLU,nn.RReLU,nn.Hardtanh,nn.ReLU6,nn.Sigmoid,nn.Hardsigmoid,nn.Tanh,nn.SiLU,nn.Mish,nn.Hardswish,nn.ELU,nn.CELU,nn.SELU,nn.Hardshrink,nn.LeakyReLU,nn.LogSigmoid,nn.Softplus,nn.PReLU,nn.Softsign,nn.Tanhshrink,nn.GELU,nn.Dropout,}return SUPPORTED...
1
26
0
98
1
72
97
72
null
['SUPPORTED_ACTIVATION_MODULES']
None
null
0
0
0
null
0
null
The function (_get_supported_activation_modules) defined within the public class called public.The function start at line 72 and ends at 97. It contains 26 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_get_default_structured_pruning_patterns
def _get_default_structured_pruning_patterns() -> Dict[Tuple[Union[Type[nn.Module], Callable, MatchAllNode, str], ...],Callable[..., None],
1
3
0
34
0
100
102
100
null
[]
None
null
0
0
0
null
0
null
The function (_get_default_structured_pruning_patterns) defined within the public class called public.The function start at line 100 and ends at 102. 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
__init__
def __init__(self, defaults, patterns=None):super().__init__(defaults)if patterns is None:patterns = _get_default_structured_pruning_patterns()self.patterns = patterns
2
5
3
34
0
228
232
228
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 228 and ends at 232. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [228.0] and does not return any value..
pytorch_ao
public
public
0
0
make_config_from_model
def make_config_from_model(self,model: nn.Module,SUPPORTED_MODULES: Optional[Set[Type]] = None,) -> None:if SUPPORTED_MODULES is None:SUPPORTED_MODULES = _get_supported_structured_pruning_modules()super().make_config_from_model(model, SUPPORTED_MODULES=SUPPORTED_MODULES)
2
8
3
48
0
234
241
234
null
[]
None
null
0
0
0
null
0
null
The function (make_config_from_model) defined within the public class called public.The function start at line 234 and ends at 241. It contains 8 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [234.0] and does not return any value..
pytorch_ao
public
public
0
0
_prepare
def _prepare(self, *args, **kwargs) -> None:r"""This function will attach the FakeStructuredSparsity parameterizationsand BiasHooks at the appropriate points in the model."""for config in self.groups:module = config["module"]tensor_name = config["tensor_name"]parametrization = config.get("parametrization", FakeStructur...
4
25
3
193
0
243
274
243
null
[]
None
null
0
0
0
null
0
null
The function (_prepare) defined within the public class called public.The function start at line 243 and ends at 274. It contains 25 lines of code and it has a cyclomatic complexity of 4. It takes 3 parameters, represented as [243.0] and does not return any value..
pytorch_ao
public
public
0
0
prune
def prune(self) -> None:r"""This function will FX symbolically trace the model and then find instances of the patternsdefined in self.patterns (by default SUPPORTED_STRUCTURED_PRUNING_PATTERNS ).For each pattern, it will apply to corresponding conversion function, which will modify the outputand input size expected by ...
12
29
1
200
0
276
319
276
null
[]
None
null
0
0
0
null
0
null
The function (prune) defined within the public class called public.The function start at line 276 and ends at 319. It contains 29 lines of code and it has a cyclomatic complexity of 12. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
update_mask
def update_mask(self, module, tensor_name, **kwargs):weights = getattr(module, tensor_name)for p in getattr(module.parametrizations, tensor_name):if isinstance(p, FakeStructuredSparsity):mask = cast(torch.Tensor, p.mask)# select weights based on magnitudeif weights.dim() <= 1:raise Exception("Structured pruning can onl...
5
18
4
178
0
32
57
32
null
[]
None
null
0
0
0
null
0
null
The function (update_mask) defined within the public class called public.The function start at line 32 and ends at 57. It contains 18 lines of code and it has a cyclomatic complexity of 5. It takes 4 parameters, represented as [32.0] and does not return any value..
pytorch_ao
public
public
0
0
_match
def _match(modules: Dict[str, nn.ModuleDict], node: Node, current: Union[nn.Module, Any]) -> bool:r"""checks to see if a single node of a pattern matches"""if isinstance(current, type) and issubclass(current, MatchAllNode):return Trueif not isinstance(node, Node):return Falseif isinstance(current, type) and issubclass(...
10
18
3
136
0
21
41
21
null
[]
None
null
0
0
0
null
0
null
The function (_match) defined within the public class called public.The function start at line 21 and ends at 41. It contains 18 lines of code and it has a cyclomatic complexity of 10. It takes 3 parameters, represented as [21.0] and does not return any value..
pytorch_ao
public
public
0
0
apply_match
def apply_match(modules: Dict[str, nn.ModuleDict],pattern: Union[Tuple[Any], Any],node: Node,matched_node_pattern: List[Node],) -> Optional[List[Node]]:r"""This function will return the matched nodes if the pattern matches the node givenIf there is no match, it will return None"""if isinstance(pattern, tuple):if len(pa...
8
21
4
151
0
44
70
44
null
[]
None
null
0
0
0
null
0
null
The function (apply_match) defined within the public class called public.The function start at line 44 and ends at 70. It contains 21 lines of code and it has a cyclomatic complexity of 8. It takes 4 parameters, represented as [44.0] and does not return any value..
pytorch_ao
public
public
0
0
module_contains_param
def module_contains_param(module, parametrization):if is_parametrized(module):# see if any of the module tensors have a parametriztion attached that matches the one passed inreturn any(any(isinstance(param, parametrization) for param in param_list)for key, param_list in module.parametrizations.items())return False
4
7
2
44
0
11
18
11
null
[]
None
null
0
0
0
null
0
null
The function (module_contains_param) defined within the public class called public.The function start at line 11 and ends at 18. It contains 7 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [11.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, mask):super().__init__()self.register_buffer("mask", mask)
1
3
2
22
0
30
32
30
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 30 and ends at 32. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [30.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, x):assert isinstance(self.mask, torch.Tensor)assert self.mask.shape[0] == x.shape[0]shape = [1] * len(x.shape)shape[0] = -1return self.mask.reshape(shape) * x
1
6
2
64
0
34
39
34
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 34 and ends at 39. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [34.0] and does not return any value..
pytorch_ao
public
public
0
0
state_dict
def state_dict(self, *args, **kwargs):# avoid double saving masksreturn {}
1
2
3
14
0
41
43
41
null
[]
None
null
0
0
0
null
0
null
The function (state_dict) defined within the public class called public.The function start at line 41 and ends at 43. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [41.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, parametrization, prune_bias):self.param = parametrizationself.prune_bias = prune_bias
1
3
3
19
0
47
49
47
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 47 and ends at 49. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [47.0] and does not return any value..