project_name
string
class_name
string
class_modifiers
string
class_implements
int64
class_extends
int64
function_name
string
function_body
string
cyclomatic_complexity
int64
NLOC
int64
num_parameter
int64
num_token
int64
num_variable
int64
start_line
int64
end_line
int64
function_index
int64
function_params
string
function_variable
string
function_return_type
string
function_body_line_type
string
function_num_functions
int64
function_num_lines
int64
outgoing_function_count
int64
outgoing_function_names
string
incoming_function_count
int64
incoming_function_names
string
lexical_representation
string
pytorch_ao
public
public
0
0
test_squash_mask
def test_squash_mask(self):# check observers and parameterizations removedmodel = SimpleLinear()sparsifier = WandaSparsifier()sparsifier.prepare(model, config=None)sparsifier.squash_mask()for g in sparsifier.groups:module = g["module"]assert not is_parametrized(module, "weight")assert not hasattr(module, "mask")assert ...
2
10
1
67
0
44
54
44
null
[]
None
null
0
0
0
null
0
null
The function (test_squash_mask) defined within the public class called public.The function start at line 44 and ends at 54. It contains 10 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_one_layer_mlp_2x4
def test_one_layer_mlp_2x4(self):model = nn.Sequential(nn.Linear(8, 1))weights = torch.tensor([[1, 2, 3, 4, 5, 6, 7, 8]])model[0].weight.data.copy_(weights.data)X = torch.ones(1, 8)sparsifier = WandaSparsifier(semi_structured_block_size=4)sparsifier.prepare(model, config=None)model(X)sparsifier.step()sparsifier.squash_...
1
14
1
189
0
56
74
56
null
[]
None
null
0
0
0
null
0
null
The function (test_one_layer_mlp_2x4) defined within the public class called public.The function start at line 56 and ends at 74. It contains 14 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_one_layer_mlp_unstructured
def test_one_layer_mlp_unstructured(self):model = nn.Sequential(nn.Linear(4, 1))weights = torch.tensor([[1, 2, 3, 4]], dtype=torch.float32)model[0].weight.data.copy_(weights.data)X = torch.tensor([[100, 10, 1, 0.1]], dtype=torch.float32)sparsifier = WandaSparsifier(sparsity_level=0.5)sparsifier.prepare(model, config=No...
1
14
1
197
0
76
94
76
null
[]
None
null
0
0
0
null
0
null
The function (test_one_layer_mlp_unstructured) defined within the public class called public.The function start at line 76 and ends at 94. It contains 14 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_two_layer_mlp_unstructured
def test_two_layer_mlp_unstructured(self):model = nn.Sequential(nn.Linear(128, 200), nn.ReLU(), nn.Linear(200, 10))# C_in by C_outX1 = torch.randn(100, 128)# B1 by C_inX2 = torch.randn(50, 128)# B2 by C_insparsifier = WandaSparsifier(sparsity_level=0.5)sparsifier.prepare(model, config=None)model(X1)model(X2)sparsifier....
3
20
1
146
0
96
119
96
null
[]
None
null
0
0
0
null
0
null
The function (test_two_layer_mlp_unstructured) defined within the public class called public.The function start at line 96 and ends at 119. It contains 20 lines of code and it has a cyclomatic complexity of 3. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_two_layer_mlp_unstructured_custom_config
def test_two_layer_mlp_unstructured_custom_config(self):model = nn.Sequential(nn.Linear(128, 200), nn.ReLU(), nn.Linear(200, 10))# C_in by C_outX1 = torch.randn(100, 128)# B1 by C_inX2 = torch.randn(50, 128)# B2 by C_in# Define custom config to sparsify only the first Linear layer for testingconfig = [{"tensor_fqn": "0...
4
26
1
173
0
121
152
121
null
[]
None
null
0
0
0
null
0
null
The function (test_two_layer_mlp_unstructured_custom_config) defined within the public class called public.The function start at line 121 and ends at 152. It contains 26 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
_parse_version
def _parse_version(version_string):"""Parse version string representing pre-release with -1Examples: "2.5.0.dev20240708+cu121" -> [2, 5, -1], "2.5.0" -> [2, 5, 0]"""# Check for pre-release indicatorsis_prerelease = bool(re.search(r"(git|dev)", version_string))match = re.match(r"(\d+)\.(\d+)\.(\d+)", version_string)if m...
3
10
1
73
3
29
44
29
null
['patch', 'is_prerelease', 'match']
None
null
0
0
0
null
0
null
The function (_parse_version) defined within the public class called public.The function start at line 29 and ends at 44. It contains 10 lines of code and it has a cyclomatic complexity of 3. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_quantized_decomposed_quantize_per_channel_group_wrapper
def _quantized_decomposed_quantize_per_channel_group_wrapper(*args, **kwargs):"""Wrapper around torch.ops.quantized_decomposed.quantize_per_channel_group to mitigateavailability issue until it can be supplanted by new quantize_affine function."""return torch.ops.quantized_decomposed.quantize_per_channel_group(*args, **...
1
2
2
25
0
11
16
11
null
[]
None
null
0
0
0
null
0
null
The function (_quantized_decomposed_quantize_per_channel_group_wrapper) defined within the public class called public.The function start at line 11 and ends at 16. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [11.0] and does not return any value..
pytorch_ao
public
public
0
0
_quantized_decomposed_choose_qparams_per_token_asymmetric_wrapper
def _quantized_decomposed_choose_qparams_per_token_asymmetric_wrapper(*args, **kwargs):"""Wrapper around torch.ops.quantized_decomposed.choose_qparams_per_token_asymmetric to mitigateavailability issue until it can be supplanted by new choose_qparams_affine function."""return torch.ops.quantized_decomposed.choose_qpara...
1
4
2
25
0
19
26
19
null
[]
None
null
0
0
0
null
0
null
The function (_quantized_decomposed_choose_qparams_per_token_asymmetric_wrapper) defined within the public class called public.The function start at line 19 and ends at 26. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [19.0] and does not return any value..
pytorch_ao
public
public
0
0
_quantized_decomposed_dequantize_per_channel_group_wrapper
def _quantized_decomposed_dequantize_per_channel_group_wrapper(*args, **kwargs):"""Wrapper around torch.ops.quantized_decomposed.dequantize_per_channel_group to mitigateavailability issue until it can be supplanted by new choose_qparams_affine function."""return torch.ops.quantized_decomposed.dequantize_per_channel_gro...
1
2
2
25
0
29
34
29
null
[]
None
null
0
0
0
null
0
null
The function (_quantized_decomposed_dequantize_per_channel_group_wrapper) defined within the public class called public.The function start at line 29 and ends at 34. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [29.0] and does not return any value..
pytorch_ao
public
public
0
0
_quantized_decomposed_quantize_per_token_wrapper
def _quantized_decomposed_quantize_per_token_wrapper(*args, **kwargs):"""Wrapper around torch.ops.quantized_decomposed.quantize_per_token to mitigateavailability issue until it can be supplanted by new choose_qparams_affine function."""return torch.ops.quantized_decomposed.quantize_per_token(*args, **kwargs)
1
2
2
25
0
37
42
37
null
[]
None
null
0
0
0
null
0
null
The function (_quantized_decomposed_quantize_per_token_wrapper) defined within the public class called public.The function start at line 37 and ends at 42. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [37.0] and does not return any value..
pytorch_ao
public
public
0
0
_quantized_decomposed_dequantize_per_token_wrapper
def _quantized_decomposed_dequantize_per_token_wrapper(*args, **kwargs):"""Wrapper around torch.ops.quantized_decomposed.dequantize_per_token to mitigateavailability issue until it can be supplanted by new choose_qparams_affine function."""return torch.ops.quantized_decomposed.dequantize_per_token(*args, **kwargs)
1
2
2
25
0
45
50
45
null
[]
None
null
0
0
0
null
0
null
The function (_quantized_decomposed_dequantize_per_token_wrapper) defined within the public class called public.The function start at line 45 and ends at 50. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [45.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(activations: Tensor,packed_weights: Tensor,group_size: int,n: int,k: int,):assert activations.dim() == 2m, k_ = activations.shapeassert k_ == kreturn torch.empty(m, n, dtype=activations.dtype, device="meta")
1
11
5
62
0
17
27
17
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 17 and ends at 27. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [17.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(packed_weight_qvals: Tensor,num_embeddings: int,embedding_dim: int,weight_scales: Tensor,weight_zeros: Tensor,indices: Tensor,):assert indices.dim() == 1num_out = indices.shape[0]return torch.empty(num_out, embedding_dim, dtype=torch.float32, device="meta")
1
11
6
63
0
30
40
30
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 30 and ends at 40. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [30.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(packed_weights: Tensor, group_size: int, n: int, k: int, indices: Tensor):assert indices.dim() == 1num_out = indices.shape[0]return torch.empty(num_out, k, dtype=torch.float32, device="meta")
1
4
5
58
0
43
46
43
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 43 and ends at 46. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [43.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(activations: Tensor,packed_weights: Tensor,scale_group_size: int,lut_group_size: int,n: int,k: int,):assert activations.dim() == 2m, k_ = activations.shapeassert k_ == kreturn torch.empty(m, n, dtype=activations.dtype, device="meta")
1
12
6
66
0
52
63
52
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 52 and ends at 63. It contains 12 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [52.0] and does not return any value..
pytorch_ao
public
public
0
0
register_custom_op.decorator
def decorator(func):return torch.library.register_fake(f"{name}")(func)
1
2
1
18
0
77
78
77
null
[]
None
null
0
0
0
null
0
null
The function (register_custom_op.decorator) defined within the public class called public.The function start at line 77 and ends at 78. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
register_custom_op
def register_custom_op(name):def decorator(func):return torch.library.register_fake(f"{name}")(func)return decorator
1
3
1
9
0
76
80
76
null
[]
None
null
0
0
0
null
0
null
The function (register_custom_op) defined within the public class called public.The function start at line 76 and ends at 80. It contains 3 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
register_custom_op_impl.decorator
def decorator(func):return torch.library.custom_op(f"{name}", mutates_args=())(func)
1
2
1
23
0
84
85
84
null
[]
None
null
0
0
0
null
0
null
The function (register_custom_op_impl.decorator) defined within the public class called public.The function start at line 84 and ends at 85. 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
register_custom_op_impl
def register_custom_op_impl(name):def decorator(func):return torch.library.custom_op(f"{name}", mutates_args=())(func)return decorator
1
3
1
9
0
83
87
83
null
[]
None
null
0
0
0
null
0
null
The function (register_custom_op_impl) defined within the public class called public.The function start at line 83 and ends at 87. 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
cached_compute_capability
def cached_compute_capability():device_props = torch.cuda.get_device_properties(torch.cuda.current_device())compute_capability = device_props.major * 10 + device_props.minorreturn compute_capability
1
4
0
33
2
91
94
91
null
['device_props', 'compute_capability']
None
null
0
0
0
null
0
null
The function (cached_compute_capability) defined within the public class called public.The function start at line 91 and ends at 94. It contains 4 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
quant_llm_linear
def quant_llm_linear(EXPONENT: int,MANTISSA: int,_in_feats: Tensor,_weights: Tensor,_scales: Tensor,splitK: int = 1,) -> Tensor:"""Quant-LLM linear layer A @ W.T. See https://arxiv.org/abs/2401.14112 for more details.ArgumentsEXPONENT: number of exponent bitsMANTISSA: number of mantissa bits_in_feats: input activations...
1
16
6
75
1
97
127
97
null
['compute_capability']
None
null
0
0
0
null
0
null
The function (quant_llm_linear) defined within the public class called public.The function start at line 97 and ends at 127. It contains 16 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [97.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(EXPONENT: int,MANTISSA: int,_in_feats: Tensor,_weights: Tensor,_scales: Tensor,splitK: int = 1,) -> Tensor:torch._check(_in_feats.dim() == 2,lambda: f"input should be a 2d tensor, got {_in_feats.dim()}D",)torch._check(_in_feats.dtype in (torch.float16, torch.bfloat16),lambda: f"weight must be FP16 or BF16, got {_...
1
37
6
206
1
131
169
131
null
['N_BITS']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 131 and ends at 169. It contains 37 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [131.0] and does not return any value..
pytorch_ao
public
public
0
0
qscaled_dot_product
def qscaled_dot_product(query: Tensor,key: Tensor,value: Tensor,attn_mask: Optional[Tensor] = None,dropout_p: float = 0.0,is_causal: bool = False,scale: Optional[float] = None,q_scale: float = 1.0,q_zp: int = 0,k_scale: float = 1.0,k_zp: int = 0,v_scale: float = 1.0,v_zp: int = 0,a_scale: float = 1.0,a_zp: int = 0,o_sc...
1
38
17
167
0
172
232
172
null
[]
None
null
0
0
0
null
0
null
The function (qscaled_dot_product) defined within the public class called public.The function start at line 172 and ends at 232. It contains 38 lines of code and it has a cyclomatic complexity of 1. It takes 17 parameters, represented as [172.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(query: Tensor,key: Tensor,value: Tensor,attn_mask: Optional[Tensor] = None,dropout_p: float = 0.0,is_causal: bool = False,scale: Optional[float] = None,q_scale: float = 1.0,q_zp: int = 0,k_scale: float = 1.0,k_zp: int = 0,v_scale: float = 1.0,v_zp: int = 0,a_scale: float = 1.0,a_zp: int = 0,o_scale: float = 1.0,o...
1
20
17
122
0
236
255
236
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 236 and ends at 255. It contains 20 lines of code and it has a cyclomatic complexity of 1. It takes 17 parameters, represented as [236.0] and does not return any value..
pytorch_ao
public
public
0
0
unpack_tensor_core_tiled_layout
def unpack_tensor_core_tiled_layout(packed_w: Tensor, inner_k_tiles: int) -> Tensor:"""Unpacks weights that were packed with `torch.ops.aten._convert_weight_to_int4pack` to original tensor of shape `N x K`.Assumes that the packed weights were generated with `torch.ops.aten._convert_weight_to_int4pack` with `inner_k_til...
1
4
2
33
0
258
274
258
null
[]
None
null
0
0
0
null
0
null
The function (unpack_tensor_core_tiled_layout) defined within the public class called public.The function start at line 258 and ends at 274. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [258.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(packed_w: Tensor, inner_k_tiles: int) -> Tensor:torch._check(packed_w.dim() == 4,lambda: f"packed weight should be a 42d tensor, got {packed_w.dim()}D",)torch._check(packed_w.dtype is torch.int32,lambda: f"weight must be INT32, got {packed_w.dtype}",)torch._check(inner_k_tiles == 2 or inner_k_tiles == 4 or inner_...
3
21
2
152
2
278
299
278
null
['K', 'N']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 278 and ends at 299. It contains 21 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
dequantize_tensor_core_tiled_layout
def dequantize_tensor_core_tiled_layout(packed_w: Tensor, scales_and_zeros: Tensor, group_size: int, inner_k_tiles: int) -> Tensor:"""Dequantizes by:- Unpacking weights that were packed with `torch.ops.aten._convert_weight_to_int4pack` to original tensor of shape `N x K`- Upcasting to bfloat16- Dequantizing with the sc...
1
6
4
41
0
302
328
302
null
[]
None
null
0
0
0
null
0
null
The function (dequantize_tensor_core_tiled_layout) defined within the public class called public.The function start at line 302 and ends at 328. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [302.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(packed_w: Tensor, scales_and_zeros: Tensor, group_size: int, inner_k_tiles: int) -> Tensor:# packed_w preconditionstorch._check(packed_w.dim() == 4,lambda: f"packed weight should be a 4d tensor, got {packed_w.dim()}D",)torch._check(packed_w.dtype is torch.int32,lambda: f"weight must be INT32, got {packed_w.dtype}...
6
45
4
271
2
332
380
332
null
['K', 'N']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 332 and ends at 380. It contains 45 lines of code and it has a cyclomatic complexity of 6. It takes 4 parameters, represented as [332.0] and does not return any value..
pytorch_ao
public
public
0
0
marlin_24_gemm
def marlin_24_gemm(x: Tensor,weight_marlin: Tensor,meta: Tensor,s: Tensor,workspace: Tensor,bits: int,size_m: int,size_n: int,size_k: int,) -> Tensor:"""Sparse Marlin 2:4 matrix multiplication. Reference: https://github.com/IST-DASLab/Sparse-Marlin/tree/mainArgs:x: input matrix of shape `(n, k/2)` in column-major layou...
1
14
9
72
0
383
411
383
null
[]
None
null
0
0
0
null
0
null
The function (marlin_24_gemm) defined within the public class called public.The function start at line 383 and ends at 411. It contains 14 lines of code and it has a cyclomatic complexity of 1. It takes 9 parameters, represented as [383.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(x: Tensor,weight_marlin: Tensor,meta: Tensor,s: Tensor,workspace: Tensor,bits: int,size_m: int,size_n: int,size_k: int,) -> Tensor:TILE_SIZE = 16MIN_THREAD_N = 128MAX_PARALLELISM = 64# Verify num_bitstorch._check(bits == 4 or bits == 8, lambda: f"num_bits must be 4 or 8. Got = {bits}")pack_factor = 32 // bits# Ve...
4
86
9
478
7
415
524
415
null
['groupsize', 'actual_size_n', 'MAX_PARALLELISM', 'min_workspace_size', 'pack_factor', 'MIN_THREAD_N', 'TILE_SIZE']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 415 and ends at 524. It contains 86 lines of code and it has a cyclomatic complexity of 4. It takes 9 parameters, represented as [415.0] and does not return any value..
pytorch_ao
public
public
0
0
marlin_qqq_gemm
def marlin_qqq_gemm(x: Tensor,weight_marlin: Tensor,s_tok: Tensor,s_ch: Tensor,s_group: Tensor,workspace: Tensor,size_m: int,size_n: int,size_k: int,) -> Tensor:"""Marlin for W4A8 mixed precision matrix multiplication.See https://arxiv.org/pdf/2406.09904 for more details.Reference: https://github.com/HandH1998/QQQ/tree...
1
14
9
72
0
527
557
527
null
[]
None
null
0
0
0
null
0
null
The function (marlin_qqq_gemm) defined within the public class called public.The function start at line 527 and ends at 557. It contains 14 lines of code and it has a cyclomatic complexity of 1. It takes 9 parameters, represented as [527.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(x: Tensor,weight_marlin: Tensor,s_tok: Tensor,s_ch: Tensor,s_group: Tensor,workspace: Tensor,size_m: int,size_n: int,size_k: int,) -> Tensor:TILE_SIZE = 16MIN_THREAD_N = 64MAX_PARALLELISM = 16PACK_FACTOR = 32 // 4# Verify Mtorch._check(size_m == x.size(0),lambda: f"Shape mismatch: x.size(0) = {x.size(0)}, size_m ...
3
84
9
520
7
561
666
561
null
['groupsize', 'actual_size_n', 'MAX_PARALLELISM', 'min_workspace_size', 'MIN_THREAD_N', 'PACK_FACTOR', 'TILE_SIZE']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 561 and ends at 666. It contains 84 lines of code and it has a cyclomatic complexity of 3. It takes 9 parameters, represented as [561.0] and does not return any value..
pytorch_ao
public
public
0
0
rowwise_scaled_linear_cutlass_s8s4
def rowwise_scaled_linear_cutlass_s8s4(input: Tensor,input_scale: Tensor,weight: Tensor,weight_scale: Tensor,bias: Optional[Tensor] = None,out_dtype: Optional[torch.dtype] = None,) -> Tensor:"""CUTLASS-based row-wise scaled W4A8 linear operator.Args:input: quantized input tensor, in row-major layout.input_scale: scale ...
1
16
6
67
0
669
697
669
null
[]
None
null
0
0
0
null
0
null
The function (rowwise_scaled_linear_cutlass_s8s4) defined within the public class called public.The function start at line 669 and ends at 697. It contains 16 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [669.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(input: Tensor,input_scale: Tensor,weight: Tensor,weight_scale: Tensor,bias: Optional[Tensor] = None,out_dtype: Optional[torch.dtype] = None,) -> Tensor:# No checks here, as detailed checks are performed by the# operator itself.dtype = out_dtype if out_dtype is not None else input_scale.dtypedevice = input.devicer...
2
11
6
91
2
701
714
701
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 701 and ends at 714. It contains 11 lines of code and it has a cyclomatic complexity of 2. It takes 6 parameters, represented as [701.0] and does not return any value..
pytorch_ao
public
public
0
0
rowwise_scaled_linear_cutlass_s4s4
def rowwise_scaled_linear_cutlass_s4s4(input: Tensor,input_scale: Tensor,weight: Tensor,weight_scale: Tensor,bias: Optional[Tensor] = None,out_dtype: Optional[torch.dtype] = None,) -> Tensor:"""CUTLASS-based row-wise scaled W4A4 linear operator.Args:input: quantized input tensor, in row-major layout.input_scale: scale ...
1
11
6
66
0
717
740
717
null
[]
None
null
0
0
0
null
0
null
The function (rowwise_scaled_linear_cutlass_s4s4) defined within the public class called public.The function start at line 717 and ends at 740. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [717.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(input: Tensor,input_scale: Tensor,weight: Tensor,weight_scale: Tensor,bias: Optional[Tensor] = None,out_dtype: Optional[torch.dtype] = None,) -> Tensor:# No checks here, as detailed checks are performed by the# operator itself.dtype = out_dtype if out_dtype is not None else input_scale.dtypedevice = input.devicer...
2
11
6
91
2
744
757
701
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 744 and ends at 757. It contains 11 lines of code and it has a cyclomatic complexity of 2. It takes 6 parameters, represented as [701.0] and does not return any value..
pytorch_ao
public
public
0
0
rowwise_scaled_linear_sparse_cutlass_f8f8
def rowwise_scaled_linear_sparse_cutlass_f8f8(input: Tensor,input_scale: Tensor,weight: Tensor,weight_meta: Tensor,weight_scale: Tensor,bias: Optional[Tensor] = None,out_dtype: Optional[torch.dtype] = None,) -> Tensor:"""CUTLASS-based row-wise scaled F8F8 linear operator, for sparsified weight case.Args:input: quantize...
1
12
7
72
0
760
785
760
null
[]
None
null
0
0
0
null
0
null
The function (rowwise_scaled_linear_sparse_cutlass_f8f8) defined within the public class called public.The function start at line 760 and ends at 785. It contains 12 lines of code and it has a cyclomatic complexity of 1. It takes 7 parameters, represented as [760.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(input: Tensor,input_scale: Tensor,weight: Tensor,weight_meta: Tensor,weight_scale: Tensor,bias: Optional[Tensor] = None,out_dtype: Optional[torch.dtype] = None,) -> Tensor:# No checks here, as detailed checks are performed by the# operator itself.dtype = out_dtype if out_dtype is not None else input_scale.dtypede...
2
12
7
95
2
789
803
789
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 789 and ends at 803. It contains 12 lines of code and it has a cyclomatic complexity of 2. It takes 7 parameters, represented as [789.0] and does not return any value..
pytorch_ao
public
public
0
0
to_sparse_semi_structured_cutlass_sm9x_f8
def to_sparse_semi_structured_cutlass_sm9x_f8(weight: Tensor,) -> (Tensor, Tensor):"""CUTLASS-based conversion from sparsified input tensor to corresponding compressed tensor, along with corresponding metadata tensor.Args:weight: input tensor, in row-major layout.Returns:weight_compressed: compressed weight tensor, wit...
1
4
1
28
0
806
818
806
null
[]
None
null
0
0
0
null
0
null
The function (to_sparse_semi_structured_cutlass_sm9x_f8) defined within the public class called public.The function start at line 806 and ends at 818. It contains 4 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_
def _(weight: Tensor,) -> (Tensor, Tensor):# No checks here, as detailed checks are performed by the# operator itself.return (weight.new_empty(weight[0], weight[1] // 2),weight.new_empty(weight[0], max(weight[1] // 8, 16), dtype=torch.char),)
1
7
1
47
0
822
831
822
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 822 and ends at 831. 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
sparse24_sm90_sparsify
def sparse24_sm90_sparsify(input_tensor: Tensor,metadata_format: str,activation: str,algorithm: str,dtype=None,scale=None,) -> (Tensor, Tensor):return torch.ops.torchao.sparse24_sm90_sparsify(input_tensor, metadata_format, activation, algorithm, dtype=dtype, scale=scale)
1
11
6
59
0
834
844
834
null
[]
None
null
0
0
0
null
0
null
The function (sparse24_sm90_sparsify) defined within the public class called public.The function start at line 834 and ends at 844. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [834.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(input_tensor: Tensor,metadata_format: str,activation: str,algorithm: str,dtype=None,scale=None,):out_dtype = dtype if dtype is not None else input_tensor.dtypereturn (torch.empty((input_tensor.shape[0], input_tensor.shape[1] // 2),dtype=out_dtype,device=input_tensor.device,),torch.empty((input_tensor.shape[0], in...
2
21
6
107
1
848
868
848
null
['out_dtype']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 848 and ends at 868. It contains 21 lines of code and it has a cyclomatic complexity of 2. It takes 6 parameters, represented as [848.0] and does not return any value..
pytorch_ao
public
public
0
0
sparse24_fp8_sm90_cutlass_gemm
def sparse24_fp8_sm90_cutlass_gemm(a: Tensor,meta: Tensor,b: Tensor,a_scale: Optional[Tensor] = None,b_scale: Optional[Tensor] = None,swizzle_size: int = 8,swizzle_axis: str = "n",sm_count: int = 128,) -> Tensor:return torch.ops.torchao.sparse24_fp8_sm90_cutlass_gemm(a,meta,b,a_scale=a_scale,b_scale=b_scale,swizzle_siz...
1
20
8
90
0
871
890
871
null
[]
None
null
0
0
0
null
0
null
The function (sparse24_fp8_sm90_cutlass_gemm) defined within the public class called public.The function start at line 871 and ends at 890. It contains 20 lines of code and it has a cyclomatic complexity of 1. It takes 8 parameters, represented as [871.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(a: Tensor,meta: Tensor,b: Tensor,a_scale: Optional[Tensor] = None,b_scale: Optional[Tensor] = None,swizzle_size: int = 8,swizzle_axis: str = "n",sm_count: int = 128,):return torch.empty((a.shape[0], b.shape[1]), dtype=torch.bfloat16, device=a.device)
1
11
8
85
0
894
904
894
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 894 and ends at 904. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 8 parameters, represented as [894.0] and does not return any value..
pytorch_ao
public
public
0
0
swizzle_mm
def swizzle_mm(mat1: Tensor, mat2: Tensor, mat1_is_swizzled: bool, mat2_is_swizzled: bool) -> Tensor:"""Similar to torch.mm but Tensor inputs can be SwizzleTensor instances."""return torch.ops.torchao.swizzle_mm.default(mat1, mat2, mat1_is_swizzled, mat2_is_swizzled)
1
6
4
41
0
907
916
907
null
[]
None
null
0
0
0
null
0
null
The function (swizzle_mm) defined within the public class called public.The function start at line 907 and ends at 916. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [907.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(mat1: Tensor, mat2: Tensor, mat1_is_swizzled: bool, mat2_is_swizzled: bool) -> Tensor:return mat1.new_empty(mat1.shape[0], mat2.shape[1])
1
4
4
40
0
920
923
920
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 920 and ends at 923. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [920.0] and does not return any value..
pytorch_ao
public
public
0
0
swizzle_scaled_mm
def swizzle_scaled_mm(mat1: Tensor,mat2: Tensor,mat1_is_swizzled: bool,mat2_is_swizzled: bool,scale_a: Tensor,scale_b: Tensor,bias: Optional[Tensor],scale_result: Optional[Tensor],out_dtype: Optional[torch.dtype],) -> Tensor:"""Similar to torch.mm but Tensor inputs can be SwizzleTensor instances."""return torch.ops.tor...
1
22
9
84
0
926
951
926
null
[]
None
null
0
0
0
null
0
null
The function (swizzle_scaled_mm) defined within the public class called public.The function start at line 926 and ends at 951. It contains 22 lines of code and it has a cyclomatic complexity of 1. It takes 9 parameters, represented as [926.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(mat1: Tensor,mat2: Tensor,mat1_is_swizzled: bool,mat2_is_swizzled: bool,scale_a: Tensor,scale_b: Tensor,bias: Optional[Tensor],scale_result: Optional[Tensor],out_dtype: Optional[torch.dtype],) -> Tensor:return mat1.new_empty(mat1.shape[0], mat2.shape[1])
1
12
9
72
0
955
966
955
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 955 and ends at 966. It contains 12 lines of code and it has a cyclomatic complexity of 1. It takes 9 parameters, represented as [955.0] and does not return any value..
pytorch_ao
public
public
0
0
_get_dtypes
def _get_dtypes():"""TODO: when e8m0 is hardened and major release lets remove uint8 support"""if hasattr(torch, "float8_e8m0fnu"):return (torch.uint8, torch.float8_e8m0fnu)return (torch.uint8,)
2
4
0
30
0
970
974
970
null
[]
None
null
0
0
0
null
0
null
The function (_get_dtypes) defined within the public class called public.The function start at line 970 and ends at 974. 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
_check_scale_dtypes
def _check_scale_dtypes(A_scale, B_scale):allowed_dtypes = _get_dtypes()torch._check(A_scale.dtype in allowed_dtypes,lambda: f"A_scale tensor must be uint8 or float8_e8m0fnu, got {A_scale.dtype}",)torch._check(B_scale.dtype in allowed_dtypes,lambda: f"B_scale tensor must be uint8 or float8_e8m0fnu, got {B_scale.dtype}"...
1
10
2
44
1
977
987
977
null
['allowed_dtypes']
None
null
0
0
0
null
0
null
The function (_check_scale_dtypes) defined within the public class called public.The function start at line 977 and ends at 987. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [977.0] and does not return any value..
pytorch_ao
public
public
0
0
meta_mx_fp8_bf16
def meta_mx_fp8_bf16(A: Tensor, B: Tensor, A_scale: Tensor, B_scale: Tensor):"""Meta impl for mx_fp8_bf16"""return torch.empty((A.size(0), B.size(1)), dtype=torch.bfloat16, device=A.device)
1
2
4
53
0
991
993
991
null
[]
None
null
0
0
0
null
0
null
The function (meta_mx_fp8_bf16) defined within the public class called public.The function start at line 991 and ends at 993. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [991.0] and does not return any value..
pytorch_ao
public
public
0
0
mx_fp4_bf16
def mx_fp4_bf16(A: Tensor, B: Tensor, A_scale: Tensor, B_scale: Tensor):"""Defines a matmul between two fp4 tensors w/ MX scales in E8MO and returns a bf16 tensor.The expected format is fp4_e2m1 specified:https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final.pdf (Section 5.3.3)Note: The mx s...
1
3
4
45
0
996
1,018
996
null
[]
None
null
0
0
0
null
0
null
The function (mx_fp4_bf16) defined within the public class called public.The function start at line 996 and ends at 1018. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [996.0] and does not return any value..
pytorch_ao
public
public
0
0
meta_mx_fp4_bf16
def meta_mx_fp4_bf16(A: Tensor, B: Tensor, A_scale: Tensor, B_scale: Tensor):"""Meta impl for mx_fp4_bf16"""# Assume that the contraction happens in the K dim thus M,N are perserved post bit packreturn torch.empty((A.size(0), B.size(1)), dtype=torch.bfloat16, device=A.device)
1
2
4
53
0
1,022
1,025
1,022
null
[]
None
null
0
0
0
null
0
null
The function (meta_mx_fp4_bf16) defined within the public class called public.The function start at line 1022 and ends at 1025. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [1022.0] and does not return any value..
pytorch_ao
public
public
0
0
da8w4_linear_prepack_cpu
def da8w4_linear_prepack_cpu(weight: Tensor,scales: Tensor,qzeros: Tensor,) -> Tensor:"""Prepack weights for DA8W4 linear operator on CPU.Args:weight: weight tensor.scales: scales for weight tensor.qzeros: zero points for weight tensor.Returns:packed weight, scales, and zero points."""return torch.ops.torchao.da8w4_lin...
1
6
3
36
0
1,028
1,042
1,028
null
[]
None
null
0
0
0
null
0
null
The function (da8w4_linear_prepack_cpu) defined within the public class called public.The function start at line 1028 and ends at 1042. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [1028.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(weight: Tensor, scales: Tensor, qzeros: Tensor) -> Tensor:return weight, scales, qzeros, torch.Tensor()
1
2
3
29
0
1,046
1,047
1,046
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 1046 and ends at 1047. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [1046.0] and does not return any value..
pytorch_ao
public
public
0
0
da8w4_linear_cpu
def da8w4_linear_cpu(input: Tensor,input_scales: Tensor,input_qzeros: Tensor,weight: Tensor,weight_scales: Tensor,weight_qzeros: Tensor,compensation: Tensor,bias: Optional[Tensor],out_dtype: torch.dtype,):"""DA8W4 linear operator on CPU.Args:input: input tensor.input_scales: scales for input tensor.input_qzeros: zero p...
1
22
9
76
0
1,050
1,086
1,050
null
[]
None
null
0
0
0
null
0
null
The function (da8w4_linear_cpu) defined within the public class called public.The function start at line 1050 and ends at 1086. It contains 22 lines of code and it has a cyclomatic complexity of 1. It takes 9 parameters, represented as [1050.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(input: Tensor,input_scales: Tensor,input_qzeros: Tensor,weight: Tensor,weight_scales: Tensor,weight_qzeros: Tensor,compensation: Tensor,bias: Optional[Tensor],out_dtype: torch.dtype,) -> Tensor:assert weight.dim() == 4N = weight.size(0) * weight.size(3) * 2return input.new_empty(*input.shape[:-1], N, dtype=out_dt...
1
14
9
93
1
1,090
1,103
1,090
null
['N']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 1090 and ends at 1103. It contains 14 lines of code and it has a cyclomatic complexity of 1. It takes 9 parameters, represented as [1090.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(qweight: Tensor,indices: Tensor,offsets: Tensor,w_scales: Tensor,o_scale: float,mode: int,include_last_offset: bool,) -> Tensor:# Only support include_last_offset == Trueassert include_last_offset == Truebatch_size = offsets.shape[0] - 1return qweight.new_empty(batch_size, qweight.shape[1], dtype=qweight.dtype)
1
12
7
68
1
1,107
1,119
1,107
null
['batch_size']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 1107 and ends at 1119. It contains 12 lines of code and it has a cyclomatic complexity of 1. It takes 7 parameters, represented as [1107.0] and does not return any value..
pytorch_ao
public
public
0
0
_assert_and_get_unique_device
def _assert_and_get_unique_device(module: torch.nn.Module) -> Any:"""Returns the unique device for a module, or None if no device is found.Throws an error if multiple devices are detected."""devices = {p.device for p in module.parameters()} | {p.device for p in module.buffers()}assert len(devices) <= 1, ("prepare only ...
4
10
1
76
2
53
67
53
null
['device', 'devices']
None
null
0
0
0
null
0
null
The function (_assert_and_get_unique_device) defined within the public class called public.The function start at line 53 and ends at 67. It contains 10 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
benchmark_model
def benchmark_model(model, num_runs, args=(), kwargs=None, device_type=None):"""Benchmark model runs with `args` and `kwargs` both are optional"""if kwargs is None:kwargs = {}if device_type is None:assert isinstance(model, torch.nn.Module), ("Expecting `model` to be torch.nn.Module if device_type is not provided")devic...
9
40
3
314
7
70
123
70
null
['end_time', 'kwargs', 'device_type', 'end_event', 'start_event', 'average_time_per_run', 'start_time']
None
null
0
0
0
null
0
null
The function (benchmark_model) defined within the public class called public.The function start at line 70 and ends at 123. It contains 40 lines of code and it has a cyclomatic complexity of 9. It takes 3 parameters, represented as [70.0] and does not return any value..
pytorch_ao
public
public
0
0
profiler_runner
def profiler_runner(path, fn, *args, **kwargs):with torch.profiler.profile(activities=[torch.profiler.ProfilerActivity.CPU,torch.profiler.ProfilerActivity.CUDA,],record_shapes=True,) as prof:result = fn(*args, **kwargs)prof.export_chrome_trace(path)return result
1
11
4
67
1
126
136
126
null
['result']
None
null
0
0
0
null
0
null
The function (profiler_runner) defined within the public class called public.The function start at line 126 and ends at 136. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [126.0] and does not return any value..
pytorch_ao
public
public
0
0
get_available_devices
def get_available_devices():devices = ["cpu"]if torch.cuda.is_available():devices.append("cuda")elif torch.xpu.is_available():devices.append("xpu")if torch.mps.is_available():devices.append("mps")return devices
4
9
0
56
1
139
147
139
null
['devices']
None
null
0
0
0
null
0
null
The function (get_available_devices) defined within the public class called public.The function start at line 139 and ends at 147. It contains 9 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
get_compute_capability
def get_compute_capability():if torch.cuda.is_available():capability = torch.cuda.get_device_capability()return float(f"{capability[0]}.{capability[1]}")return 0.0
2
5
0
32
1
150
154
150
null
['capability']
None
null
0
0
0
null
0
null
The function (get_compute_capability) defined within the public class called public.The function start at line 150 and ends at 154. 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
compute_max_diff
def compute_max_diff(output: torch.Tensor, output_ref: torch.Tensor) -> torch.Tensor:return torch.mean(torch.abs(output - output_ref)) / torch.mean(torch.abs(output_ref))
1
4
2
45
0
157
160
157
null
[]
None
null
0
0
0
null
0
null
The function (compute_max_diff) defined within the public class called public.The function start at line 157 and ends at 160. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [157.0] and does not return any value..
pytorch_ao
public
public
0
0
benchmark_torch_function_in_microseconds
def benchmark_torch_function_in_microseconds(f, *args, **kwargs):import torch.utils.benchmark as benchmark# this avoids importing numpy when torchao module is loaded# Manual warmupf(*args, **kwargs)f(*args, **kwargs)t0 = benchmark.Timer(stmt="f(*args, **kwargs)",globals={"args": args, "kwargs": kwargs, "f": f},# noqa: ...
1
10
3
75
2
163
175
163
null
['measurement', 't0']
None
null
0
0
0
null
0
null
The function (benchmark_torch_function_in_microseconds) defined within the public class called public.The function start at line 163 and ends at 175. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [163.0] and does not return any value..
pytorch_ao
public
public
0
0
find_multiple
def find_multiple(n: int, *args: int) -> int:k: int = reduce(lambda x, y: x * y // gcd(x, y), args + (1,))# type: ignore[9]if n % k == 0:return nreturn n + k - (n % k)
2
5
2
48
0
178
182
178
null
[]
None
null
0
0
0
null
0
null
The function (find_multiple) defined within the public class called public.The function start at line 178 and ends at 182. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [178.0] and does not return any value..
pytorch_ao
public
public
0
0
_register_custom_op.decorator
def decorator(fn):from torch._library.infer_schema import infer_schemaassert not any(c in fn.__name__ for c in ".<>"), (f"Expecting op to be defined in normal functions, not lambda or local: {fn.__name__}")op_name = fn.__name__if op_name[0] == "_":op_name = op_name[1:]schema = op_name + infer_schema(fn, mutates_args={}...
4
16
1
115
0
218
235
218
null
[]
None
null
0
0
0
null
0
null
The function (_register_custom_op.decorator) defined within the public class called public.The function start at line 218 and ends at 235. It contains 16 lines of code and it has a cyclomatic complexity of 4. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_register_custom_op
def _register_custom_op(lib, inductor_decomposed=True):"""This decorator is used to preserve some high level operators for torch.export.exportwhile still allow them to be decomposed for inductor pathrequirement: make sure `fn.__name__[1:]` is the operator name you want to registerNOTE: This should be applied at the top...
2
9
2
31
5
185
237
185
null
['op', 'op_name', 'schema', 'lib_namespace', 'dispatch_key']
None
null
0
0
0
null
0
null
The function (_register_custom_op) defined within the public class called public.The function start at line 185 and ends at 237. It contains 9 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [185.0] and does not return any value..
pytorch_ao
public
public
0
0
_register_meta_op.decorator
def decorator(fn):op = lib.impl(op_name, fn, "Meta")return op
1
3
1
19
0
241
243
241
null
[]
None
null
0
0
0
null
0
null
The function (_register_meta_op.decorator) defined within the public class called public.The function start at line 241 and ends at 243. It contains 3 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_register_meta_op
def _register_meta_op(lib, op_name):def decorator(fn):op = lib.impl(op_name, fn, "Meta")return opreturn decorator
1
3
2
11
1
240
245
240
null
['op']
None
null
0
0
0
null
0
null
The function (_register_meta_op) defined within the public class called public.The function start at line 240 and ends at 245. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [240.0] and does not return any value..
pytorch_ao
public
public
0
0
get_model_size_in_bytes.flat_size
def flat_size(tensor):if hasattr(tensor, "__tensor_flatten__"):size = 0# 0th element is a list of attributes that# hold tensorsfor attr_name in tensor.__tensor_flatten__()[0]:sub_tensor = getattr(tensor, attr_name)size += flat_size(sub_tensor)return sizeelse:return tensor.numel() * tensor.element_size()
3
9
1
58
0
255
265
255
null
[]
None
null
0
0
0
null
0
null
The function (get_model_size_in_bytes.flat_size) defined within the public class called public.The function start at line 255 and ends at 265. It contains 9 lines of code and it has a cyclomatic complexity of 3. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
get_model_size_in_bytes
def get_model_size_in_bytes(model, ignore_embeddings=False):"""Returns the model size in bytes. The option to ignore embeddingsis useful for models with disproportionately large embeddings comparedto other model parameters that get quantized/sparsified."""def flat_size(tensor):if hasattr(tensor, "__tensor_flatten__"):s...
5
11
2
85
3
248
275
248
null
['model_size', 'size', 'sub_tensor']
None
null
0
0
0
null
0
null
The function (get_model_size_in_bytes) defined within the public class called public.The function start at line 248 and ends at 275. It contains 11 lines of code and it has a cyclomatic complexity of 5. It takes 2 parameters, represented as [248.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, *tensors):todo = list(tensors)for tp, meta, inner_tensors in reversed(self.rebuild_stack):nb_tensor = len(inner_tensors)inner_tensors = {a: b for a, b in zip(inner_tensors, todo[-nb_tensor:])}todo = todo[nb_tensor:]rebuilt = tp.__tensor_unflatten__(inner_tensors, meta, None, None)todo.append(rebuilt)a...
3
10
2
96
0
279
289
279
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 279 and ends at 289. It contains 10 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [279.0] and does not return any value..
pytorch_ao
public
public
0
0
right_inverse
def right_inverse(self, tensor):assert type(tensor) is not torch.Tensorrebuild_stack = []plain_tensors = []todo = [tensor]while todo:obj = todo.pop()inner_tensors, metadata = obj.__tensor_flatten__()rebuild_stack.append((type(obj), metadata, inner_tensors))for attr_name in inner_tensors:val = getattr(obj, attr_name)if ...
4
18
2
117
0
291
310
291
null
[]
None
null
0
0
0
null
0
null
The function (right_inverse) defined within the public class called public.The function start at line 291 and ends at 310. It contains 18 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [291.0] and does not return any value..
pytorch_ao
public
public
0
0
unwrap_tensor_subclass
def unwrap_tensor_subclass(model, filter_fn=None):"""Unwraps (nested) tensor subclass in the model to plain tensorsThis is a workaround to make a model with tensor subclass to work with `torch.export.export`and `torch.aot_compile`, we hope this can be integrated into compile stack soontracking issue: https://github.com...
11
20
2
141
0
313
338
313
null
[]
None
null
0
0
0
null
0
null
The function (unwrap_tensor_subclass) defined within the public class called public.The function start at line 313 and ends at 338. It contains 20 lines of code and it has a cyclomatic complexity of 11. It takes 2 parameters, represented as [313.0] and does not return any value..
pytorch_ao
public
public
0
0
_is_float8_type
def _is_float8_type(dtype: torch.dtype) -> bool:fp8_types = {torch.float8_e4m3fn,torch.float8_e4m3fnuz,torch.float8_e5m2,torch.float8_e5m2fnuz,}return dtype in fp8_types
1
8
1
35
1
341
348
341
null
['fp8_types']
None
null
0
0
0
null
0
null
The function (_is_float8_type) defined within the public class called public.The function start at line 341 and ends at 348. It contains 8 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
parse_version
def parse_version(version_string):"""Parse version string representing pre-release with -1Examples: "2.5.0.dev20240708+cu121" -> [2, 5, -1], "2.5.0" -> [2, 5, 0]"""# Check for pre-release indicatorsis_prerelease = bool(re.search(r"(git|dev)", version_string))match = re.match(r"(\d+)\.(\d+)\.(\d+)", version_string)if ma...
3
10
1
73
3
351
366
351
null
['patch', 'is_prerelease', 'match']
None
null
0
0
0
null
0
null
The function (parse_version) defined within the public class called public.The function start at line 351 and ends at 366. It contains 10 lines of code and it has a cyclomatic complexity of 3. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
is_fbcode
def is_fbcode():return not hasattr(torch.version, "git_version")
1
2
0
14
0
369
370
369
null
[]
None
null
0
0
0
null
0
null
The function (is_fbcode) defined within the public class called public.The function start at line 369 and ends at 370. 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_version_at_least
def torch_version_at_least(min_version):if is_fbcode():return True# Parser for local identifiersreturn parse_version(torch.__version__) >= parse_version(min_version)
2
4
1
24
0
373
378
373
null
[]
None
null
0
0
0
null
0
null
The function (torch_version_at_least) defined within the public class called public.The function start at line 373 and ends at 378. 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
_deprecated_torch_version_at_least
def _deprecated_torch_version_at_least(version_str: str) -> str:"""Wrapper for existing TORCH_VERSION_AT_LEAST* variables that will loga deprecation warning if the variable is used."""version_str_var_name = "_".join(version_str.split(".")[:2])deprecation_msg = f"TORCH_VERSION_AT_LEAST_{version_str_var_name} is deprecat...
1
7
1
42
2
381
391
381
null
['version_str_var_name', 'deprecation_msg']
None
null
0
0
0
null
0
null
The function (_deprecated_torch_version_at_least) defined within the public class called public.The function start at line 381 and ends at 391. 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
_deprecated_torch_version_after
def _deprecated_torch_version_after(version_str: str) -> str:"""Wrapper for existing TORCH_VERSION_AFTER* variables that will loga deprecation warning if the variable is used."""bool_value = is_fbcode() or version("torch") >= version_strversion_str_var_name = "_".join(version_str.split(".")[:2])deprecation_msg = f"TORC...
2
5
1
50
3
394
402
394
null
['bool_value', 'version_str_var_name', 'deprecation_msg']
None
null
0
0
0
null
0
null
The function (_deprecated_torch_version_after) defined within the public class called public.The function start at line 394 and ends at 402. 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
__init__
def __init__(self, bool_value: bool, msg: str):self.bool_value = bool_valueself.msg = msg
1
3
3
23
0
410
412
410
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 410 and ends at 412. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [410.0] and does not return any value..
pytorch_ao
public
public
0
0
__bool__
def __bool__(self):warnings.warn(self.msg)return self.bool_value
1
3
1
17
0
414
416
414
null
[]
None
null
0
0
0
null
0
null
The function (__bool__) defined within the public class called public.The function start at line 414 and ends at 416. 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
__eq__
def __eq__(self, other):return bool(self) == bool(other)
1
2
2
17
0
418
419
418
null
[]
None
null
0
0
0
null
0
null
The function (__eq__) defined within the public class called public.The function start at line 418 and ends at 419. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [418.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, bool_value: bool, msg: str):self.bool_value = bool_valueself.msg = msg
1
3
3
23
0
442
444
410
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 442 and ends at 444. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [410.0] and does not return any value..
pytorch_ao
public
public
0
0
__call__
def __call__(self, *args, **kwargs):warnings.warn(f"`{self.deprecated_name}` is deprecated and will be removed in a future release. "f"Please use `{self.config_cls.__name__}` instead. Example usage:\n"f"quantize_(model, {self.config_cls.__name__}(...))")return self.config_cls(*args, **kwargs)
1
7
3
33
0
446
452
446
null
[]
None
null
0
0
0
null
0
null
The function (__call__) defined within the public class called public.The function start at line 446 and ends at 452. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [446.0] and does not return any value..
pytorch_ao
public
public
0
0
_implements._implements.decorator.wrapper
def wrapper(f, types, args, kwargs):return func(f, types, args, kwargs)
1
2
4
22
0
490
491
490
null
[]
None
null
0
0
0
null
0
null
The function (_implements._implements.decorator.wrapper) defined within the public class called public.The function start at line 490 and ends at 491. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [490.0] and does not return any value..
pytorch_ao
public
public
0
0
_implements.decorator
def decorator(func):for op in aten_ops_or_torch_fns:@functools.wraps(op)def wrapper(f, types, args, kwargs):return func(f, types, args, kwargs)cls._ATEN_OP_OR_TORCH_FN_TABLE[cls][op] = wrapperreturn func
2
6
1
32
0
486
494
486
null
[]
None
null
0
0
0
null
0
null
The function (_implements.decorator) defined within the public class called public.The function start at line 486 and ends at 494. It contains 6 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_implements
def _implements(cls, aten_ops_or_torch_fns):"""Use this decorator to implement a function for an aten ops in __torch_dispatch__(if user passed in a list of ops)or torch function in __torch_function__ (if user passed in a single object)class MyTensor(torch.Tensor):...implements = classmethod(_implements)implements = MyT...
4
9
2
62
1
461
496
461
null
['aten_ops_or_torch_fns']
None
null
0
0
0
null
0
null
The function (_implements) defined within the public class called public.The function start at line 461 and ends at 496. It contains 9 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [461.0] and does not return any value..
pytorch_ao
public
public
0
0
_implements_common_tensor_ops._
def _(func, types, args, kwargs):return args[0]._apply_fn_to_data(lambda x: func(x, *args[1:], **kwargs))
1
2
4
37
0
508
509
508
null
[]
None
null
0
0
0
null
0
null
The function (_implements_common_tensor_ops._) defined within the public class called public.The function start at line 508 and ends at 509. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [508.0] and does not return any value..
pytorch_ao
public
public
0
0
_implements_common_tensor_ops._
def _(func, types, args, kwargs):return return_and_correct_aliasing(func,args,kwargs,args[0]._apply_fn_to_data(lambda x: func(x, *args[1:], **kwargs)),)
1
7
4
47
0
519
525
519
null
[]
None
null
0
0
0
null
0
null
The function (_implements_common_tensor_ops._) defined within the public class called public.The function start at line 519 and ends at 525. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [519.0] and does not return any value..
pytorch_ao
public
public
0
0
_implements_common_tensor_ops._same_metadata
def _same_metadata(self: TorchAOBaseTensor, src: TorchAOBaseTensor) -> bool:_tensor_shape_match = all(getattr(self, t_name).shape == getattr(src, t_name).shapefor t_name in self.tensor_data_names)_optional_tensor_shape_match = Trueif hasattr(self, "optional_tensor_data_names"):# either both are None or both are not Ten...
13
31
2
186
0
527
561
527
null
[]
None
null
0
0
0
null
0
null
The function (_implements_common_tensor_ops._same_metadata) defined within the public class called public.The function start at line 527 and ends at 561. It contains 31 lines of code and it has a cyclomatic complexity of 13. It takes 2 parameters, represented as [527.0] and does not return any value..
pytorch_ao
public
public
0
0
_implements_common_tensor_ops._
def _(func, types, args, kwargs):self = args[0]src = args[1]if _same_metadata(self, src):self_tensors = self.__tensor_flatten__()[0]for tensor_name in self_tensors:getattr(self, tensor_name).copy_(getattr(src, tensor_name))returnraise ValueError(f"Not supported args for copy_ due to metadata mismatch: {args[0], args[1]...
3
11
4
69
0
564
574
564
null
[]
None
null
0
0
0
null
0
null
The function (_implements_common_tensor_ops._) defined within the public class called public.The function start at line 564 and ends at 574. It contains 11 lines of code and it has a cyclomatic complexity of 3. It takes 4 parameters, represented as [564.0] and does not return any value..
pytorch_ao
public
public
0
0
_implements_common_tensor_ops._
def _(func, types, args, kwargs):self = args[0]if hasattr(self, "tensor_data_names") and hasattr(self, "tensor_attribute_names"):kwargs = self._get_to_kwargs(*args[1:], **kwargs)device = kwargs.pop("device")tensors = [getattr(self, name).to(device) for name in self.tensor_data_names]optional_tensors = []if hasattr(self...
12
38
4
220
0
577
618
577
null
[]
None
null
0
0
0
null
0
null
The function (_implements_common_tensor_ops._) defined within the public class called public.The function start at line 577 and ends at 618. It contains 38 lines of code and it has a cyclomatic complexity of 12. It takes 4 parameters, represented as [577.0] and does not return any value..
pytorch_ao
public
public
0
0
_implements_common_tensor_ops
def _implements_common_tensor_ops(cls):implements = cls.implementsaten = torch.ops.aten@implements([torch.Tensor.contiguous,])def _(func, types, args, kwargs):return args[0]._apply_fn_to_data(lambda x: func(x, *args[1:], **kwargs))@implements([aten.detach.default,aten.clone.default,aten.alias.default,aten.contiguous.de...
1
23
1
87
17
499
618
499
null
['optional_tensors', 'tensors', 'self', 'self_tensors', 'maybe_tensor', '_optional_tensor_shape_match', 'optional_tensor_attributes', '_tensor_shape_match', 'kwargs', 'implements', '_optional_attr_match', 'device', 't', '_attr_match', 'src', 'tensor_attributes', 'aten']
None
null
0
0
0
null
0
null
The function (_implements_common_tensor_ops) defined within the public class called public.The function start at line 499 and ends at 618. It contains 23 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
_torchao_base_tensor__setstate__
def _torchao_base_tensor__setstate__(self, state):assert hasattr(self, "tensor_data_names") and hasattr(self, "tensor_attribute_names")torch._utils._set_obj_state(self, state)for optional_tensor_data_name in getattr(self, "optional_tensor_data_names", []):if optional_tensor_data_name not in self.__dict__ and not hasatt...
8
17
2
105
0
621
638
621
null
[]
None
null
0
0
0
null
0
null
The function (_torchao_base_tensor__setstate__) defined within the public class called public.The function start at line 621 and ends at 638. It contains 17 lines of code and it has a cyclomatic complexity of 8. It takes 2 parameters, represented as [621.0] and does not return any value..
pytorch_ao
public
public
0
0
_dispatch__torch_function__
def _dispatch__torch_function__(cls, func, types, args=(), kwargs=None):"""Use this util function for a common `__torch_function__` implementationthat dispatches to ops/functions registered with `_implements`class MyTensor(torch.Tensor):...__torch_function__ = classmethod(_dispatch__torch_function__)"""kwargs = {} if k...
5
10
4
91
1
641
658
641
null
['kwargs']
None
null
0
0
0
null
0
null
The function (_dispatch__torch_function__) defined within the public class called public.The function start at line 641 and ends at 658. It contains 10 lines of code and it has a cyclomatic complexity of 5. It takes 4 parameters, represented as [641.0] and does not return any value..
pytorch_ao
public
public
0
0
_dispatch__torch_dispatch__
def _dispatch__torch_dispatch__(cls, func, types, args, kwargs):"""Use this util function for a common `__torch_dispatch__` implementationthat dispatches to ops/functions registered with `_implements`class MyTensor(torch.Tensor):...__torch_dispatch__ = classmethod(_dispatch__torch_dispatch__)"""if (hasattr(cls, "_ATEN_...
6
12
5
97
2
661
680
661
null
['kwarg_types', 'arg_types']
None
null
0
0
0
null
0
null
The function (_dispatch__torch_dispatch__) defined within the public class called public.The function start at line 661 and ends at 680. It contains 12 lines of code and it has a cyclomatic complexity of 6. It takes 5 parameters, represented as [661.0] and does not return any value..
pytorch_ao
public
public
0
0
_register_layout.decorator
def decorator(tensor_impl_class):tensor_class._LAYOUT_CONSTRUCTOR_TABLE[layout_class] = (tensor_impl_class.from_plain)# Allow serialization to work for models uses this tensor impl subclasstorch.serialization.add_safe_globals([layout_class, tensor_impl_class])return tensor_impl_class
1
6
1
31
0
701
707
701
null
[]
None
null
0
0
0
null
0
null
The function (_register_layout.decorator) defined within the public class called public.The function start at line 701 and ends at 707. 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
_register_layout
def _register_layout(tensor_class: Callable, layout_class: Callable):"""Helper function for layout registrations, this is used to implementregister_layout decorator for each tensor subclass, see aqt.py for example usageArgs:tensor_class: Tensor subclass typelayout_class: the class type of subclass of `Layout`, e.g. `Pl...
2
5
2
31
0
683
709
683
null
[]
None
null
0
0
0
null
0
null
The function (_register_layout) defined within the public class called public.The function start at line 683 and ends at 709. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [683.0] and does not return any value..