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
float8_view
def float8_view(aten_op, args, kwargs=None):t, new_shape = args[0], args[1]# if the new shape is the same as old, return an equivalent tensor# note that we have to create a new wrapper to make PyTorch internals happyif new_shape == list(t._data.shape):new_data = aten_op(args[0]._data, *args[1:], **kwargs)return Float8T...
7
44
3
288
5
191
242
191
null
['new_axiswise_dim', 'axiswise_dim', 'new_scale_shape', 'new_scale', 'new_data']
None
null
0
0
0
null
0
null
The function (float8_view) defined within the public class called public.The function start at line 191 and ends at 242. It contains 44 lines of code and it has a cyclomatic complexity of 7. It takes 3 parameters, represented as [191.0] and does not return any value..
pytorch_ao
public
public
0
0
float8_split.make_float8
def make_float8(data):return Float8TrainingTensor(data,args[0]._scale,args[0]._orig_dtype,args[0]._linear_mm_config,args[0]._gemm_input_role,)
1
8
1
39
0
250
257
250
null
[]
None
null
0
0
0
null
0
null
The function (float8_split.make_float8) defined within the public class called public.The function start at line 250 and ends at 257. 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
float8_split
def float8_split(aten_op, args, kwargs=None):new_data_tensors = aten_op(args[0]._data, *args[1:], **kwargs)_assert_tensorwise_scale(aten_op, args[0]._scale)def make_float8(data):return Float8TrainingTensor(data,args[0]._scale,args[0]._orig_dtype,args[0]._linear_mm_config,args[0]._gemm_input_role,)out = map(make_float8,...
1
6
3
58
2
246
260
246
null
['out', 'new_data_tensors']
None
null
0
0
0
null
0
null
The function (float8_split) defined within the public class called public.The function start at line 246 and ends at 260. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [246.0] and does not return any value..
pytorch_ao
public
public
0
0
float8_cat
def float8_cat(aten_op, args, kwargs=None):chunked_tensors: Tuple[Float8TrainingTensor] = args[0]orig_dtype = chunked_tensors[0]._orig_dtypescale = chunked_tensors[0]._scalemm_config = chunked_tensors[0]._linear_mm_configfp8_dtype = chunked_tensors[0]._data.dtypegemm_input_role = chunked_tensors[0]._gemm_input_rolechun...
2
32
3
196
7
265
298
265
null
['gemm_input_role', 'chunk_data', 'fp8_dtype', 'scale', 'mm_config', 'new_data', 'orig_dtype']
None
null
0
0
0
null
0
null
The function (float8_cat) defined within the public class called public.The function start at line 265 and ends at 298. It contains 32 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [265.0] and does not return any value..
pytorch_ao
public
public
0
0
float8_cast_up_op.unwrap
def unwrap(x):if isinstance(x, Float8TrainingTensor):return x.to_original_precision()return x
2
4
1
21
0
312
315
312
null
[]
None
null
0
0
0
null
0
null
The function (float8_cast_up_op.unwrap) defined within the public class called public.The function start at line 312 and ends at 315. 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
float8_cast_up_op
def float8_cast_up_op(aten_op, args, kwargs=None):"""Be careful with this function, this is a "fallback" op thatcasts the output of the op to the original precision. And performs the op.We currently need this to support the backward for admmm bias."addmm" -> out"hp_gradBias" <-"sum" <- "identity" <- gradOut <- "hp_grad...
1
6
3
50
2
302
319
302
null
['new_args', 'new_kwargs']
None
null
0
0
0
null
0
null
The function (float8_cast_up_op) defined within the public class called public.The function start at line 302 and ends at 319. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [302.0] and does not return any value..
pytorch_ao
public
public
0
0
preprocess_addmm
def preprocess_addmm(a: Float8TrainingTensor, b: Float8TrainingTensor):a_data = a._dataa_scale = a._scaleb_data = b._datascaled_mm_config = choose_scaled_mm_config(a._gemm_input_role,a._linear_mm_config,b._gemm_input_role,b._linear_mm_config,)if scaled_mm_config.pad_inner_dim:assert a._data.size(1) == b._data.size(0), ...
8
26
2
221
5
322
360
322
null
['a_data', 'scaled_mm_config', 'b_data', 'a_scale', 'b_scale']
None
null
0
0
0
null
0
null
The function (preprocess_addmm) defined within the public class called public.The function start at line 322 and ends at 360. It contains 26 lines of code and it has a cyclomatic complexity of 8. It takes 2 parameters, represented as [322.0] and does not return any value..
pytorch_ao
public
public
0
0
float8_mm
def float8_mm(aten_op, args, kwargs=None):a = args[0]b = args[1]assert isinstance(a, Float8TrainingTensor) and isinstance(b, Float8TrainingTensor), "Expectingboth Float8TrainingTensor for mm inputs but found {} and {}".format(type(a), type(b))a_data, a_scale, b_data, b_scale = preprocess_addmm(a, b)output_dtype = a._or...
3
31
3
162
5
364
395
364
null
['scaled_mm_config', 'a', 'output_dtype', 'b', 'tensor_out']
None
null
0
0
0
null
0
null
The function (float8_mm) defined within the public class called public.The function start at line 364 and ends at 395. It contains 31 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [364.0] and does not return any value..
pytorch_ao
public
public
0
0
float8_addmm
def float8_addmm(aten_op, args, kwargs=None):assert (isinstance(args[0], torch.Tensor)and isinstance(args[1], Float8TrainingTensor)and isinstance(args[2], Float8TrainingTensor))bias = args[0]a = args[1]b = args[2]a_data, a_scale, b_data, b_scale = preprocess_addmm(a, b)output_dtype = a._orig_dtypeassert bias.dtype == o...
4
34
3
186
7
399
432
399
null
['out', 'scaled_mm_config', 'a', 'output_dtype', 'bias', 'b', 'tensor_out']
None
null
0
0
0
null
0
null
The function (float8_addmm) defined within the public class called public.The function start at line 399 and ends at 432. It contains 34 lines of code and it has a cyclomatic complexity of 4. It takes 3 parameters, represented as [399.0] and does not return any value..
pytorch_ao
public
public
0
0
float8_is_same_size
def float8_is_same_size(aten_op, args, kwargs=None):_assert_tensorwise_scale(aten_op, args[0]._scale)return args[0].shape == args[1].shape
1
3
3
36
0
436
438
436
null
[]
None
null
0
0
0
null
0
null
The function (float8_is_same_size) defined within the public class called public.The function start at line 436 and ends at 438. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [436.0] and does not return any value..
pytorch_ao
public
public
0
0
autocast_to_copy
def autocast_to_copy(aten_op, args, kwargs=None):"""This gets called when running matmul under autocastwhen the input is a Float8TrainingTensor, presenting as a fp32tensor."""assert isinstance(args[0], Float8TrainingTensor)assert len(kwargs) == 1 and "dtype" in kwargs, ("Only support dtype kwarg for autocast")assert kw...
2
17
3
99
0
442
462
442
null
[]
None
null
0
0
0
null
0
null
The function (autocast_to_copy) defined within the public class called public.The function start at line 442 and ends at 462. It contains 17 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [442.0] and does not return any value..
pytorch_ao
public
public
0
0
allgather_fp8
def allgather_fp8(aten_op, args, kwargs=None):"""override funcol with FP8 handling"""_assert_tensorwise_scale(aten_op, args[0]._scale)fp8_input = args[0]assert isinstance(fp8_input, Float8TrainingTensor), (f"expecting a Float8TrainingTensor for allgather but found {type(fp8_input)}")fp8_data = fp8_input._datafp8_data =...
1
16
3
91
3
471
490
471
null
['fp8_input', 'fp8_data', 'fp8_out']
None
null
0
0
0
null
0
null
The function (allgather_fp8) defined within the public class called public.The function start at line 471 and ends at 490. It contains 16 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [471.0] and does not return any value..
pytorch_ao
public
public
0
0
wait_tensor_fp8
def wait_tensor_fp8(aten_op, args, kwargs=None):_assert_tensorwise_scale(aten_op, args[0]._scale)fp8_input = args[0]assert isinstance(fp8_input, Float8TrainingTensor)fp8_data = fp8_input._datafp8_out = aten_op(fp8_data, *args[1:], **kwargs)return Float8TrainingTensor(fp8_out,fp8_input._scale,fp8_input._orig_dtype,fp8_i...
1
13
3
78
3
494
507
494
null
['fp8_input', 'fp8_data', 'fp8_out']
None
null
0
0
0
null
0
null
The function (wait_tensor_fp8) defined within the public class called public.The function start at line 494 and ends at 507. It contains 13 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [494.0] and does not return any value..
pytorch_ao
public
public
0
0
index_put_fp8
def index_put_fp8(aten_op, args, kwargs=None):fp8_self = args[0]fp8_values = args[2]assert isinstance(fp8_self, Float8TrainingTensor)assert isinstance(fp8_values, Float8TrainingTensor)_assert_tensorwise_scale(fp8_self, args[0]._scale)assert fp8_self._scale == fp8_values._scaleassert fp8_self.dtype == fp8_values.dtypeas...
1
19
3
127
5
511
530
511
null
['fp8_out', 'fp8_data', 'fp8_values_data', 'fp8_values', 'fp8_self']
None
null
0
0
0
null
0
null
The function (index_put_fp8) defined within the public class called public.The function start at line 511 and ends at 530. It contains 19 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [511.0] and does not return any value..
pytorch_ao
public
public
0
0
copy_fp8
def copy_fp8(aten_op, args, kwargs=None):# For a copy op with Float8TrainingTensors involved, only the following combinations are allowed:# 1. self is a high precision (hp) tensor, src is a Float8TrainingTensor:#in this case src is upcasted and unscaled to go into the hp tensor# 2. self and src are Float8TrainingTensor...
5
38
3
209
4
534
579
534
null
['src_hp', 'src', 'fp8_out', 'self']
None
null
0
0
0
null
0
null
The function (copy_fp8) defined within the public class called public.The function start at line 534 and ends at 579. It contains 38 lines of code and it has a cyclomatic complexity of 5. It takes 3 parameters, represented as [534.0] and does not return any value..
pytorch_ao
public
public
0
0
hp_tensor_to_float8_dynamic
def hp_tensor_to_float8_dynamic(hp_tensor: torch.Tensor,float8_dtype: torch.dtype,linear_mm_config: LinearMMConfig,reduce_amax: bool = False,gemm_input_role: GemmInputRole = GemmInputRole.INPUT,device_mesh=None,scaling_granularity: ScalingGranularity = ScalingGranularity.TENSORWISE,axiswise_dim: Optional[int] = None,ro...
1
28
9
99
1
29
72
29
null
['scale']
None
null
0
0
0
null
0
null
The function (hp_tensor_to_float8_dynamic) defined within the public class called public.The function start at line 29 and ends at 72. It contains 28 lines of code and it has a cyclomatic complexity of 1. It takes 9 parameters, represented as [29.0] and does not return any value..
pytorch_ao
public
public
0
0
get_maybe_axiswise_dim
def get_maybe_axiswise_dim(axiswise_dim: int,scaling_granularity: ScalingGranularity,) -> Optional[int]:"""Convenience function which takes in an axiswise dim which is only relevantfor axiswise scaing, and a scaling type.The output is pass-throughif scaling type is axiswise, and None otherwise.This is done to keep thel...
2
7
2
29
0
75
87
75
null
[]
None
null
0
0
0
null
0
null
The function (get_maybe_axiswise_dim) defined within the public class called public.The function start at line 75 and ends at 87. It contains 7 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [75.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(ctx,tensor,linear_mm_config: LinearMMConfig,target_dtype: torch.dtype,):ctx.linear_mm_config = linear_mm_configctx.target_dtype = target_dtypereturn tensor
1
9
4
30
0
98
106
98
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 98 and ends at 106. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [98.0] and does not return any value..
pytorch_ao
public
public
0
0
backward
def backward(ctx, gradY):if tensor_already_casted_to_fp8(gradY):return gradY, None, NonegradY_scale = tensor_to_scale(gradY, ctx.target_dtype)fp8_tensor = hp_tensor_and_scale_to_float8(gradY,gradY_scale,ctx.target_dtype,ctx.linear_mm_config,GemmInputRole.GRAD_OUTPUT,)return fp8_tensor, None, None
2
12
2
56
0
109
120
109
null
[]
None
null
0
0
0
null
0
null
The function (backward) defined within the public class called public.The function start at line 109 and ends at 120. It contains 12 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [109.0] and does not return any value..
pytorch_ao
public
public
0
0
_float8_linear_supports_float8_allgather
def _float8_linear_supports_float8_allgather(m):# TODO(future PR): also gate this by granularityreturn (m.scaling_type_input == ScalingType.DYNAMICand m.scaling_type_grad_output == ScalingType.DYNAMIC)
2
5
1
23
0
34
39
34
null
[]
None
null
0
0
0
null
0
null
The function (_float8_linear_supports_float8_allgather) defined within the public class called public.The function start at line 34 and ends at 39. 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
_prepare_input_fn
def _prepare_input_fn(input_layouts, desired_input_layouts, mod, inputs, device_mesh):# annotate module input placements/sharding with input_layoutsinput_tensor = inputs[0]if not isinstance(input_tensor, DTensor):input_tensor = DTensor.from_local(input_tensor, device_mesh, input_layouts, run_check=False)if not tensor_a...
4
20
5
97
0
49
72
49
null
[]
None
null
0
0
0
null
0
null
The function (_prepare_input_fn) defined within the public class called public.The function start at line 49 and ends at 72. It contains 20 lines of code and it has a cyclomatic complexity of 4. It takes 5 parameters, represented as [49.0] and does not return any value..
pytorch_ao
public
public
0
0
_prepare_output_fn
def _prepare_output_fn(output_layouts, use_local_output, mod, outputs, device_mesh):# outputs is a shard on last dimension DTensor, i.e. Shard(-1)if outputs.placements != output_layouts:outputs = outputs.redistribute(placements=output_layouts, async_op=True)# DTensor(torch.Tensor)# fwd noop bwd cast to DTensor(Float8Tr...
3
11
5
65
0
75
90
75
null
[]
None
null
0
0
0
null
0
null
The function (_prepare_output_fn) defined within the public class called public.The function start at line 75 and ends at 90. It contains 11 lines of code and it has a cyclomatic complexity of 3. It takes 5 parameters, represented as [75.0] and does not return any value..
pytorch_ao
public
public
0
0
_apply
def _apply(self, module: nn.Module, device_mesh: DeviceMesh) -> nn.Module:from torchao.float8.float8_linear import Float8Linearif not isinstance(module, Float8Linear):raise ValueError(f"Expecting module to be Float8Linear but found {type(module)}")elif isinstance(module, Float8Linear) and not _float8_linear_supports_fl...
4
11
3
72
0
92
104
92
null
[]
None
null
0
0
0
null
0
null
The function (_apply) defined within the public class called public.The function start at line 92 and ends at 104. It contains 11 lines of code and it has a cyclomatic complexity of 4. It takes 3 parameters, represented as [92.0] and does not return any value..
pytorch_ao
public
public
0
0
_prepare_input_fn
def _prepare_input_fn(input_layouts, desired_input_layouts, mod, inputs, device_mesh):# annotate module input placements/sharding with input_layoutsinput_tensor = inputs[0]if not isinstance(input_tensor, DTensor):input_tensor = DTensor.from_local(input_tensor, device_mesh, input_layouts, run_check=False)if not tensor_a...
4
20
5
97
0
114
135
49
null
[]
None
null
0
0
0
null
0
null
The function (_prepare_input_fn) defined within the public class called public.The function start at line 114 and ends at 135. It contains 20 lines of code and it has a cyclomatic complexity of 4. It takes 5 parameters, represented as [49.0] and does not return any value..
pytorch_ao
public
public
0
0
_prepare_output_fn
def _prepare_output_fn(output_layouts, use_local_output, mod, outputs, device_mesh):# outputs is a shard on last dimension DTensor, i.e. Shard(-1)if outputs.placements != output_layouts:outputs = outputs.redistribute(placements=output_layouts, async_op=True)# DTensor(torch.Tensor)# fwd noop bwd cast to DTensor(Float8Tr...
3
9
5
65
0
138
153
75
null
[]
None
null
0
0
0
null
0
null
The function (_prepare_output_fn) defined within the public class called public.The function start at line 138 and ends at 153. It contains 9 lines of code and it has a cyclomatic complexity of 3. It takes 5 parameters, represented as [75.0] and does not return any value..
pytorch_ao
public
public
0
0
_apply
def _apply(self, module: nn.Module, device_mesh: DeviceMesh) -> nn.Module:from torchao.float8.float8_linear import Float8Linearif not isinstance(module, Float8Linear):raise ValueError(f"Expecting module to be Float8Linear but found {type(module)}")elif isinstance(module, Float8Linear) and not _float8_linear_supports_fl...
4
11
3
72
0
155
167
92
null
[]
None
null
0
0
0
null
0
null
The function (_apply) defined within the public class called public.The function start at line 155 and ends at 167. It contains 11 lines of code and it has a cyclomatic complexity of 4. It takes 3 parameters, represented as [92.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,*,input_layouts=None,desired_input_layouts=None,input_kwarg_layouts=None,desired_input_kwarg_layouts=None,use_local_output=False,float8_dtype=torch.float8_e4m3fn,fwd_config_submodule_fqn=None,):super().__init__(input_layouts=input_layouts,desired_input_layouts=desired_input_layouts,input_kwarg_layouts...
2
25
8
94
0
189
216
189
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 189 and ends at 216. It contains 25 lines of code and it has a cyclomatic complexity of 2. It takes 8 parameters, represented as [189.0] and does not return any value..
pytorch_ao
public
public
0
0
_prepare_input_arg
def _prepare_input_arg(self, input, mesh, input_layout, desired_layout):if input_layout is not None:if isinstance(input, DTensor):# TODO: re-enable the check once we fix the compile path# assert inp.placements[0] == input_layoutdt_inp = inputelse:assert isinstance(input, torch.Tensor), ("expecting input to be a torch.T...
6
22
5
122
0
218
243
218
null
[]
None
null
0
0
0
null
0
null
The function (_prepare_input_arg) defined within the public class called public.The function start at line 218 and ends at 243. It contains 22 lines of code and it has a cyclomatic complexity of 6. It takes 5 parameters, represented as [218.0] and does not return any value..
pytorch_ao
public
public
0
0
_apply
def _apply(self, module: nn.Module, device_mesh: DeviceMesh) -> nn.Module:from torchao.float8.float8_linear import Float8Linearif self.fwd_config_submodule_fqn is not None:fwd_linear = module.get_submodule(self.fwd_config_submodule_fqn)assert isinstance(fwd_linear, Float8Linear)self.linear_mm_config = fwd_linear.linear...
5
18
3
125
0
245
265
245
null
[]
None
null
0
0
0
null
0
null
The function (_apply) defined within the public class called public.The function start at line 245 and ends at 265. It contains 18 lines of code and it has a cyclomatic complexity of 5. It takes 3 parameters, represented as [245.0] and does not return any value..
pytorch_ao
public
public
0
0
choose_scaled_mm_config
def choose_scaled_mm_config(a_role: GemmInputRole,a_linear_mm_config: LinearMMConfig,b_role: GemmInputRole,b_linear_mm_config: LinearMMConfig,):if a_role is GemmInputRole.INPUT and b_role is GemmInputRole.WEIGHT:assert a_linear_mm_config.output == b_linear_mm_config.output, (f"linear_mm_config.output mismatch: {a_linea...
7
23
4
118
0
97
119
97
null
[]
None
null
0
0
0
null
0
null
The function (choose_scaled_mm_config) defined within the public class called public.The function start at line 97 and ends at 119. It contains 23 lines of code and it has a cyclomatic complexity of 7. It takes 4 parameters, represented as [97.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(ctx,tensor: torch.Tensor,scale: torch.Tensor,float8_dtype: torch.dtype,linear_mm_config: Optional[LinearMMConfig] = None,gemm_input_role: Optional[GemmInputRole] = GemmInputRole.INPUT,axiswise_dim: Optional[int] = None,):"""This function will apply the scaling, and then convert to a Float8TrainingTensorNote...
2
43
7
198
0
131
188
131
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 131 and ends at 188. It contains 43 lines of code and it has a cyclomatic complexity of 2. It takes 7 parameters, represented as [131.0] and does not return any value..
pytorch_ao
public
public
0
0
backward
def backward(ctx, g):return g, None, None, None, None, None
1
2
2
19
0
191
192
191
null
[]
None
null
0
0
0
null
0
null
The function (backward) defined within the public class called public.The function start at line 191 and ends at 192. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [191.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(ctx, tensor):return tensor._data.to(tensor._orig_dtype) / tensor._scale
1
2
2
22
0
204
205
204
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 204 and ends at 205. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [204.0] and does not return any value..
pytorch_ao
public
public
0
0
backward
def backward(ctx, g):return g, None, None
1
2
2
13
0
208
209
208
null
[]
None
null
0
0
0
null
0
null
The function (backward) defined within the public class called public.The function start at line 208 and ends at 209. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [208.0] and does not return any value..
pytorch_ao
public
public
0
0
hp_tensor_and_scale_to_float8
def hp_tensor_and_scale_to_float8(hp_tensor: torch.Tensor,s: torch.Tensor,float8_dtype: torch.dtype,linear_mm_config: Optional[LinearMMConfig] = None,gemm_input_role: Optional[GemmInputRole] = GemmInputRole.INPUT,axiswise_dim: Optional[int] = None,):"""Given a high precision tensor `hp_tensor` and a precalculated scale...
1
11
6
69
0
212
239
212
null
[]
None
null
0
0
0
null
0
null
The function (hp_tensor_and_scale_to_float8) defined within the public class called public.The function start at line 212 and ends at 239. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [212.0] and does not return any value..
pytorch_ao
public
public
0
0
__new__
def __new__(cls,data: torch.Tensor,scale: torch.Tensor,orig_dtype: torch.dtype,linear_mm_config: Optional[LinearMMConfig],gemm_input_role: Optional[GemmInputRole] = GemmInputRole.INPUT,axiswise_dim: Optional[int] = None,):self = torch.Tensor._make_wrapper_subclass(cls,data.size(),strides=data.stride(),storage_offset=da...
2
29
7
163
0
290
319
290
null
[]
None
null
0
0
0
null
0
null
The function (__new__) defined within the public class called public.The function start at line 290 and ends at 319. It contains 29 lines of code and it has a cyclomatic complexity of 2. It takes 7 parameters, represented as [290.0] and does not return any value..
pytorch_ao
public
public
0
0
__repr__
def __repr__(self):return f"Float8TrainingTensor(lp_dtype={self._data.dtype}, scale={self._scale}, linear_mm_config={self._linear_mm_config}, axiswise_dim={self._axiswise_dim}\ngemm_input_role={self._gemm_input_role}\nas_orig_prec={self.to_original_precision()}"
1
2
1
8
0
321
322
321
null
[]
None
null
0
0
0
null
0
null
The function (__repr__) defined within the public class called public.The function start at line 321 and ends at 322. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
__tensor_flatten__
def __tensor_flatten__(self):ctx = {"_orig_dtype": self._orig_dtype,"_linear_mm_config": self._linear_mm_config,"_gemm_input_role": self._gemm_input_role,"_axiswise_dim": self._axiswise_dim,}return ["_data", "_scale"], ctx
1
8
1
41
0
324
331
324
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 324 and ends at 331. 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
__tensor_unflatten__
def __tensor_unflatten__(inner_tensors: Dict, metadata, outer_size, outer_stride):assert len(inner_tensors) == 2return Float8TrainingTensor(inner_tensors["_data"],inner_tensors["_scale"],metadata["_orig_dtype"],metadata["_linear_mm_config"],metadata["_gemm_input_role"],metadata["_axiswise_dim"],)
1
10
4
54
0
334
343
334
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 334 and ends at 343. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [334.0] and does not return any value..
pytorch_ao
public
public
0
0
to_original_precision
def to_original_precision(self):return _FromFloat8ConstrFunc.apply(self)
1
2
1
12
0
345
346
345
null
[]
None
null
0
0
0
null
0
null
The function (to_original_precision) defined within the public class called public.The function start at line 345 and ends at 346. 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__.allowed_subclasses
def allowed_subclasses(type):return (issubclass(cls, type)or issubclass(torch._subclasses.fake_tensor.FakeTensor, type)or issubclass(torch._subclasses.functional_tensor.FunctionalTensor, type))
3
8
1
40
0
361
368
361
null
[]
None
null
0
0
0
null
0
null
The function (__torch_dispatch__.allowed_subclasses) defined within the public class called public.The function start at line 361 and ends at 368. It contains 8 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
__torch_dispatch__
def __torch_dispatch__(cls, func, types, args, kwargs=None):# 1. tracing through __torch_function__ logic is not supported yet in# PT2.0, so we explicitly disallow it here for callsites from user code.# 2. We do need to handle a couple of ops in order for# TorchDynamo tracing to succeed.# Lazy import to avoid circular ...
4
8
5
64
0
349
375
349
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 349 and ends at 375. It contains 8 lines of code and it has a cyclomatic complexity of 4. It takes 5 parameters, represented as [349.0] and does not return any value..
pytorch_ao
public
public
0
0
amax_to_scale
def amax_to_scale(amax: torch.Tensor,float8_dtype: torch.dtype,round_scales_to_power_of_2: bool = False,):"""Converts the amax value of a tensor to the fp8 scale.Args:amax: The amax value of the tensor.float8_dtype: The float8 dtype.round_scales_to_power_of_2: if true, round scaling factor down to the nearest power of ...
3
14
3
88
2
32
53
32
null
['res', 'amax']
None
null
0
0
0
null
0
null
The function (amax_to_scale) defined within the public class called public.The function start at line 32 and ends at 53. It contains 14 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [32.0] and does not return any value..
pytorch_ao
public
public
0
0
tensor_to_amax
def tensor_to_amax(x: torch.Tensor,reduce_amax: bool = False,device_mesh=None,scaling_granularity: ScalingGranularity = ScalingGranularity.TENSORWISE,axiswise_dim: Optional[int] = None,) -> torch.Tensor:if scaling_granularity is ScalingGranularity.TENSORWISE:amax = torch.max(torch.abs(x))else:assert scaling_granularity...
7
20
5
168
3
57
82
57
null
['group', 'amax', 'pg']
None
null
0
0
0
null
0
null
The function (tensor_to_amax) defined within the public class called public.The function start at line 57 and ends at 82. It contains 20 lines of code and it has a cyclomatic complexity of 7. It takes 5 parameters, represented as [57.0] and does not return any value..
pytorch_ao
public
public
0
0
tensor_to_scale
def tensor_to_scale(hp_tensor: torch.Tensor,float8_dtype: torch.dtype,reduce_amax: bool = False,device_mesh=None,scaling_granularity: ScalingGranularity = ScalingGranularity.TENSORWISE,axiswise_dim: Optional[int] = None,round_scales_to_power_of_2: bool = False,) -> torch.Tensor:"""Compute scaling factor for the given h...
1
19
7
80
1
86
115
86
null
['amax']
None
null
0
0
0
null
0
null
The function (tensor_to_scale) defined within the public class called public.The function start at line 86 and ends at 115. It contains 19 lines of code and it has a cyclomatic complexity of 1. It takes 7 parameters, represented as [86.0] and does not return any value..
pytorch_ao
public
public
0
0
to_fp8_saturated
def to_fp8_saturated(x: torch.Tensor, float8_dtype: torch.dtype):"""Converts a tensor to a saturated fp8 tensor.Note:The default behavior in PyTorch for casting to `float8_e4m3fn`and `e5m2` is to not saturate. In this context, we should saturate.A common case where we want to saturate is when the history of atensor has...
2
7
2
61
2
118
134
118
null
['max_value', 'x']
None
null
0
0
0
null
0
null
The function (to_fp8_saturated) defined within the public class called public.The function start at line 118 and ends at 134. It contains 7 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [118.0] and does not return any value..
pytorch_ao
public
public
0
0
compute_error
def compute_error(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:"""Computes the error between two tensors in dB.For more details see:https://en.wikipedia.org/wiki/Signal-to-noise_ratioArgs:x: The original tensor.y: The tensor to compare to the original tensor."""Ps = torch.linalg.vector_norm(x)Pn = torch.linalg.vec...
1
4
2
53
2
137
149
137
null
['Pn', 'Ps']
None
null
0
0
0
null
0
null
The function (compute_error) defined within the public class called public.The function start at line 137 and ends at 149. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [137.0] and does not return any value..
pytorch_ao
public
public
0
0
fp8_tensor_statistics
def fp8_tensor_statistics(tensor: torch.Tensor, float8_dtype: torch.dtype) -> Tuple[int, ...]:"""Calculate FP8 tensor statsArgs:tensor: The tensor to calculate stats for.float8_dtype: The float8 dtype.Returns:A tuple containing the number of zeros and the number of max values."""if float8_dtype in FP8_TYPES:FP8_MAX = t...
2
11
2
101
4
152
171
152
null
['num_zero', 'tensor_orig_type', 'num_max', 'FP8_MAX']
None
null
0
0
0
null
0
null
The function (fp8_tensor_statistics) defined within the public class called public.The function start at line 152 and ends at 171. It contains 11 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [152.0] and does not return any value..
pytorch_ao
public
public
0
0
is_row_major
def is_row_major(stride):assert len(stride) == 2, "is_row_major only supports 2D tensors"return stride[0] > stride[1] and stride[1] == 1
2
3
1
31
0
174
176
174
null
[]
None
null
0
0
0
null
0
null
The function (is_row_major) defined within the public class called public.The function start at line 174 and ends at 176. It contains 3 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_get_min_alignment
def _get_min_alignment(size: int, alignment_value: int) -> int:"""Returns the minimum alignment value that is greater than or equal to the given size.Args:size: The size of the data to be aligned.alignment_value: The alignment value to be used.Returns:int: The minimum alignment value that is greater than or equal to th...
1
2
2
25
0
179
196
179
null
[]
None
null
0
0
0
null
0
null
The function (_get_min_alignment) defined within the public class called public.The function start at line 179 and ends at 196. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [179.0] and does not return any value..
pytorch_ao
public
public
0
0
pad_tensor_for_matmul
def pad_tensor_for_matmul(tensor: torch.Tensor, dims: Union[int, Iterable[int]]) -> torch.Tensor:"""Pads a 2D tensor with zeros to ensure that its dimensions are multiples of 16, which is required `torch._scaled_mm`Args:tensor: The tensor to pad.dims: Dimensions to pad.Returns:torch.Tensor: The padded tensor.Usage:```>...
4
12
2
114
5
199
236
199
null
['dims', 'dim2_aligned', 'pad_dim2', 'pad_dim1', 'dim1_aligned']
None
null
0
0
0
null
0
null
The function (pad_tensor_for_matmul) defined within the public class called public.The function start at line 199 and ends at 236. It contains 12 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [199.0] and does not return any value..
pytorch_ao
public
public
0
0
_round_scale_down_to_power_of_2
def _round_scale_down_to_power_of_2(scale: torch.Tensor):assert scale.dtype == torch.float32, "scale must be float32 tensor"return torch.exp2(torch.floor(torch.log2(scale)))
1
3
1
36
0
239
241
239
null
[]
None
null
0
0
0
null
0
null
The function (_round_scale_down_to_power_of_2) defined within the public class called public.The function start at line 239 and ends at 241. 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
precompute_float8_dynamic_scale_for_fsdp
def precompute_float8_dynamic_scale_for_fsdp(module: nn.Module) -> None:"""Calculate scale dynamically for all float8 parameters.This should be run after the optimizer step. It performs a single all-reduce to compute thescales for all float8 weights.Example usage:model(input).sum().backward()optim.step()precompute_floa...
10
32
1
253
5
28
79
28
null
['local_scale_tensor', 'amax_tensor', 'scale_tensor', 'origin_dtype', 'max_weights']
None
null
0
0
0
null
0
null
The function (precompute_float8_dynamic_scale_for_fsdp) defined within the public class called public.The function start at line 28 and ends at 79. It contains 32 lines of code and it has a cyclomatic complexity of 10. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
__new__
def __new__(cls,tensor: torch.Tensor,linear_mm_config: LinearMMConfig,dtype: torch.dtype,precomputed_scale: Optional[torch.Tensor] = None,):return torch.Tensor._make_wrapper_subclass(cls,tensor.size(),strides=tensor.stride(),storage_offset=tensor.storage_offset(),memory_format=suggest_memory_format(tensor),dtype=tensor...
1
19
5
104
0
135
153
135
null
[]
None
null
0
0
0
null
0
null
The function (__new__) defined within the public class called public.The function start at line 135 and ends at 153. It contains 19 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [135.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,tensor: torch.Tensor,linear_mm_config: LinearMMConfig,dtype: torch.dtype,precomputed_scale: Optional[torch.Tensor] = None,):self._tensor = tensorself._linear_mm_config = linear_mm_configself._dtype = dtype# for dynamic scaling# `precompute_float8_dynamic_scale_for_fsdp` calculates scales# for all floa...
1
11
5
53
0
155
168
155
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 155 and ends at 168. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [155.0] and does not return any value..
pytorch_ao
public
public
0
0
__torch_dispatch__.unwrap
def unwrap(t):nonlocal mm_configif mm_config is None:mm_config = t._linear_mm_configelse:assert t._linear_mm_config == mm_confignonlocal dtypeif dtype is None:dtype = t._dtypeelse:assert t._dtype == dtypereturn t._tensor
3
12
1
49
0
179
190
179
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 179 and ends at 190. It contains 12 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
__torch_dispatch__
def __torch_dispatch__(cls, func, types, args, kwargs=None):if func == torch.ops.aten.detach.default:return WeightWithDynamicFloat8CastTensor(args[0]._tensor, args[0]._linear_mm_config, args[0]._dtype)mm_config: Optional[LinearMMConfig] = Nonedtype: Optional[torch.dtype] = Nonedef unwrap(t):nonlocal mm_configif mm_conf...
4
19
5
135
0
171
202
171
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 171 and ends at 202. It contains 19 lines of code and it has a cyclomatic complexity of 4. It takes 5 parameters, represented as [171.0] and does not return any value..
pytorch_ao
public
public
0
0
__tensor_flatten__
def __tensor_flatten__(self):tensors = ["_tensor"]if self._precomputed_scale:tensors.append("_precomputed_scale")return tensors, {"mm_config": self._linear_mm_config, "dtype": self._dtype}
2
5
1
37
0
204
208
204
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 204 and ends at 208. 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
__tensor_unflatten__
def __tensor_unflatten__(inner_tensors, flatten_spec, outer_size, outer_stride):return WeightWithDynamicFloat8CastTensor(inner_tensors["_tensor"],flatten_spec["mm_config"],flatten_spec["dtype"],getattr(inner_tensors, "_precomputed_scale", None),)
1
7
4
39
0
211
217
211
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 211 and ends at 217. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [211.0] and does not return any value..
pytorch_ao
public
public
0
0
__repr__
def __repr__(self):return f"WeightWithDynamicFloat8CastTensor(tensor={self._tensor}, linear_mm_config={self._linear_mm_config}, dtype={self._dtype})"
1
2
1
8
0
219
220
219
null
[]
None
null
0
0
0
null
0
null
The function (__repr__) defined within the public class called public.The function start at line 219 and ends at 220. 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
fsdp_pre_all_gather
def fsdp_pre_all_gather(self, mesh):if self._precomputed_scale is not None:float8_training_tensor = hp_tensor_and_scale_to_float8(self._tensor,self._precomputed_scale,self._dtype,self._linear_mm_config,GemmInputRole.WEIGHT,)else:float8_training_tensor = hp_tensor_to_float8_dynamic(self._tensor,self._dtype,self._linear_...
2
19
2
87
0
222
240
222
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 222 and ends at 240. It contains 19 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [222.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[torch.Tensor, ...],metadata: Any,param_dtype: torch.dtype,*,out: Optional[torch.Tensor] = None,):(data,) = all_gather_outputs(scale,) = metadataif out is not None:from torch.distributed._tensor import DTensorif isinstance(out, Float8TrainingTensor):out._scale = sc...
5
30
5
137
0
242
272
242
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 242 and ends at 272. It contains 30 lines of code and it has a cyclomatic complexity of 5. It takes 5 parameters, represented as [242.0] and does not return any value..
pytorch_ao
public
public
0
0
preprocess_data
def preprocess_data(a_data: Tensor,b_data: Tensor,scaled_mm_config: Float8MMConfig,) -> Tuple[Tensor, Tensor]:"""Preprocess the inner fp8 data tensors for admmmArgs:a_data: Input tensor A.b_data: Input tensor B.scaled_mm_config: Configuration for _scaled_mm.Returns:Preprocessed tensors A and B in the format for _scaled...
4
16
3
115
2
44
67
44
null
['a_data', 'b_data']
None
null
0
0
0
null
0
null
The function (preprocess_data) defined within the public class called public.The function start at line 44 and ends at 67. It contains 16 lines of code and it has a cyclomatic complexity of 4. It takes 3 parameters, represented as [44.0] and does not return any value..
pytorch_ao
public
public
0
0
preprocess_scale
def preprocess_scale(input_scale: torch.Tensor, input_shape: Tuple[int, ...]):"""Ensures input tensor is correctly formatted for _scaled_mm"""# For PerTensor quantization, scale should be a scalar or have shape [1]if input_scale.numel() == 1:# Already a scalar, ensure it has the right shape for _scaled_mmreturn input_s...
3
7
2
74
1
70
85
70
null
['input_scale']
None
null
0
0
0
null
0
null
The function (preprocess_scale) defined within the public class called public.The function start at line 70 and ends at 85. It contains 7 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [70.0] and does not return any value..
pytorch_ao
public
public
0
0
addmm_float8_unwrapped_inference
def addmm_float8_unwrapped_inference(a_data: Tensor,a_scale: Tensor,b_data: Tensor,b_scale: Tensor,output_dtype: torch.dtype,output_scale: Optional[Tensor] = None,bias: Optional[Tensor] = None,use_fast_accum: bool = False,) -> Tensor:"""This is the unwrapped version of addmm_float8, which does not take in Float8Trainin...
3
31
8
134
1
88
125
88
null
['output']
None
null
0
0
0
null
0
null
The function (addmm_float8_unwrapped_inference) defined within the public class called public.The function start at line 88 and ends at 125. It contains 31 lines of code and it has a cyclomatic complexity of 3. It takes 8 parameters, represented as [88.0] and does not return any value..
pytorch_ao
public
public
0
0
_slice_scale_for_dimension
def _slice_scale_for_dimension(scale: torch.Tensor,data_shape: List[int],dim: int,start: int,end: int,step: int,) -> torch.Tensor:"""Slice the scale tensor appropriately based on the data tensor slicing.This function calculates how the scale should be sliced when the data tensoris sliced along a given dimension, taking...
6
29
6
168
5
128
176
128
null
['scale_start', 'scale_end', 'block_sizes', 'block_size_for_dim', 'aten']
None
null
0
0
0
null
0
null
The function (_slice_scale_for_dimension) defined within the public class called public.The function start at line 128 and ends at 176. It contains 29 lines of code and it has a cyclomatic complexity of 6. It takes 6 parameters, represented as [128.0] and does not return any value..
pytorch_ao
public
public
0
0
_is_rowwise_scaled
def _is_rowwise_scaled(x: torch.Tensor) -> bool:"""Checks if a quantized tensor is rowwise scaledArgs:x: quantized tensor (should have `block_size` attribute)"""assert hasattr(x, "block_size"), "Expecting input to have `block_size` attribute"return tuple(x.block_size) == (1,) * (x.dim() - 1) + (x.shape[-1],)
1
3
1
54
0
179
185
179
null
[]
None
null
0
0
0
null
0
null
The function (_is_rowwise_scaled) defined within the public class called public.The function start at line 179 and ends at 185. 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
_is_tensorwise_scaled
def _is_tensorwise_scaled(x: torch.Tensor) -> bool:"""Checks if a quantized tensor is rowwise scaledArgs:x: quantized tensor (should have `block_size` attribute)"""assert hasattr(x, "block_size"), "Expecting input to have `block_size` attribute"return all(x.block_size[i] == -1 or x.block_size[i] == x.shape[i] for i in ...
3
5
1
57
0
188
196
188
null
[]
None
null
0
0
0
null
0
null
The function (_is_tensorwise_scaled) defined within the public class called public.The function start at line 188 and ends at 196. It contains 5 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
_normalize_granularity
def _normalize_granularity(granularity: Optional[Union[FP8Granularity,Tuple[FP8Granularity, FP8Granularity],list[FP8Granularity],]],) -> Tuple[FP8Granularity, FP8Granularity]:processed_granularity = Noneif granularity is None:processed_granularity = (PerTensor(), PerTensor())elif isinstance(granularity, (PerTensor, Per...
8
32
2
169
1
199
230
199
null
['processed_granularity']
None
null
0
0
0
null
0
null
The function (_normalize_granularity) defined within the public class called public.The function start at line 199 and ends at 230. It contains 32 lines of code and it has a cyclomatic complexity of 8. It takes 2 parameters, represented as [199.0] and does not return any value..
pytorch_ao
public
public
0
0
_check_hardware_support
def _check_hardware_support(granularities: Tuple[FP8Granularity, FP8Granularity],) -> None:"""Validate that the hardware supports the requested granularities.Args:granularities: Tuple of (activation_granularity, weight_granularity)Raises:AssertionError: If hardware doesn't support the requested granularityValueError: I...
4
11
1
52
0
233
254
233
null
[]
None
null
0
0
0
null
0
null
The function (_check_hardware_support) defined within the public class called public.The function start at line 233 and ends at 254. It contains 11 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
do_bench_triton
def do_bench_triton(fn,warmup=25,rep=100,grad_to_none=None,quantiles=None,fast_flush=True,return_mode="mean",):assert return_mode in ["min", "max", "mean", "median"]import torch"""Benchmark the runtime of the provided function. By default, return the median runtime of :code:`fn` along withthe 20-th and 80-th performanc...
12
50
7
385
8
16
100
16
null
['times', 'cache', 'ret', 'end_event', 'start_event', 'n_repeat', 'estimate_ms', 'n_warmup']
None
null
0
0
0
null
0
null
The function (do_bench_triton) defined within the public class called public.The function start at line 16 and ends at 100. It contains 50 lines of code and it has a cyclomatic complexity of 12. It takes 7 parameters, represented as [16.0] and does not return any value..
pytorch_ao
public
public
0
0
_save_best_configs
def _save_best_configs(best_configs):device_name = torch.cuda.get_device_name()if AUTOTUNER_DATA_PATH is None:saved_configs = pathlib.Path.cwd() / "data.pkl"else:saved_configs = pathlib.Path(AUTOTUNER_DATA_PATH)logging.info(f"Trying to store configs for {device_name} locally under {saved_configs}")with open(saved_confi...
2
13
1
74
2
106
119
106
null
['saved_configs', 'device_name']
None
null
0
0
0
null
0
null
The function (_save_best_configs) defined within the public class called public.The function start at line 106 and ends at 119. It contains 13 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
_load_best_configs
def _load_best_configs():device_name = torch.cuda.get_device_name()import importlibif AUTOTUNER_DATA_PATH is None:saved_configs = importlib.resources.files("torchao")saved_configs = saved_configs / "kernel" / "configs" / "data_a100.pkl"if not device_name.startswith("NVIDIA A100"):logging.info("Warning! Loaded configura...
4
16
0
104
2
122
139
122
null
['saved_configs', 'device_name']
None
null
0
0
0
null
0
null
The function (_load_best_configs) defined within the public class called public.The function start at line 122 and ends at 139. 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
get_arg_key
def get_arg_key(a):if torch.is_tensor(a):return (a.dtype, a.size(), a.stride())return (a,)
2
4
1
36
0
142
145
142
null
[]
None
null
0
0
0
null
0
null
The function (get_arg_key) defined within the public class called public.The function start at line 142 and ends at 145. 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
get_args_key
def get_args_key(args):return sum(tuple(get_arg_key(a) for a in args), ())
2
2
1
23
0
148
149
148
null
[]
None
null
0
0
0
null
0
null
The function (get_args_key) defined within the public class called public.The function start at line 148 and ends at 149. It contains 2 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
do_bench_basic
def do_bench_basic(fn, rep):# Modified version of Triton's basic benchfn()torch.cuda.synchronize()# Fast flushcache = torch.empty(int(256e6 // 4), dtype=torch.int, device="cuda")cache.zero_()start_event = torch.cuda.Event(enable_timing=True)end_event = torch.cuda.Event(enable_timing=True)start_event.record()for _ in ra...
2
14
2
96
4
152
167
152
null
['cache', 'start_event', 'estimate_ms', 'end_event']
None
null
0
0
0
null
0
null
The function (do_bench_basic) defined within the public class called public.The function start at line 152 and ends at 167. It contains 14 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [152.0] and does not return any value..
pytorch_ao
public
public
0
0
do_bench.wrapped_fn
def wrapped_fn():return fn(*(args + [config]))
1
2
0
16
0
172
173
172
null
[]
None
null
0
0
0
null
0
null
The function (do_bench.wrapped_fn) defined within the public class called public.The function start at line 172 and ends at 173. 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
do_bench
def do_bench(fn, args, config, best_time=None):# TODO: CUDA graph compatible versiondef wrapped_fn():return fn(*(args + [config]))# Get fast estimate to abort stupid configs# Run it once and skip if it crashes or is 100x slowertry:time = do_bench_basic(wrapped_fn, 1)except RuntimeError:time = Noneexcept triton.runtime....
8
14
4
94
1
170
193
170
null
['time']
None
null
0
0
0
null
0
null
The function (do_bench) defined within the public class called public.The function start at line 170 and ends at 193. It contains 14 lines of code and it has a cyclomatic complexity of 8. It takes 4 parameters, represented as [170.0] and does not return any value..
pytorch_ao
public
public
0
0
get_best_config_by_key
def get_best_config_by_key(key):if key in BEST_CONFIGS:return BEST_CONFIGS[key][0]
2
3
1
18
0
196
198
196
null
[]
None
null
0
0
0
null
0
null
The function (get_best_config_by_key) defined within the public class called public.The function start at line 196 and ends at 198. It contains 3 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
get_best_config_fn
def get_best_config_fn(fn, args, configs):global BEST_CONFIGSif BEST_CONFIGS is None:BEST_CONFIGS = _load_best_configs()# This means no config file was loadedif BEST_CONFIGS is None:BEST_CONFIGS = {}if len(configs) == 0:return Nonekey = get_args_key(args)best_config = get_best_config_by_key(key)if best_config is not No...
7
31
3
210
6
201
242
201
null
['best_time', 'key', 'i', 'time', 'BEST_CONFIGS', 'best_config']
None
null
0
0
0
null
0
null
The function (get_best_config_fn) defined within the public class called public.The function start at line 201 and ends at 242. It contains 31 lines of code and it has a cyclomatic complexity of 7. It takes 3 parameters, represented as [201.0] and does not return any value..
pytorch_ao
public
public
0
0
tune_bsr_dense_addmm.tune_bsr_dense_addmm.bench.test_func
def test_func():return bsr_dense_addmm(input,bsr,dense,beta=beta,alpha=alpha,left_alpha=left_alpha,right_alpha=right_alpha,meta=meta,out=out,)
1
12
0
38
0
95
106
95
null
[]
None
null
0
0
0
null
0
null
The function (tune_bsr_dense_addmm.tune_bsr_dense_addmm.bench.test_func) defined within the public class called public.The function start at line 95 and ends at 106. It contains 12 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
tune_bsr_dense_addmm.bench
def bench(meta, input=input, bsr=bsr, dense=dense, alpha=alpha, out=out):def test_func():return bsr_dense_addmm(input,bsr,dense,beta=beta,alpha=alpha,left_alpha=left_alpha,right_alpha=right_alpha,meta=meta,out=out,)return triton.testing.do_bench(test_func, warmup=500, rep=100)
1
3
6
44
0
94
108
94
null
[]
None
null
0
0
0
null
0
null
The function (tune_bsr_dense_addmm.bench) defined within the public class called public.The function start at line 94 and ends at 108. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [94.0] and does not return any value..
pytorch_ao
public
public
0
0
tune_bsr_dense_addmm.step_meta_parameter
def step_meta_parameter(name, value, direction, meta, M=M, N=N, K=K, BM=BM, BK=BK):# return next value in positive or negative direction, or# input value if the step will result an invalid# value. The input value is assumed to be valid.is_log = name in {"SPLIT_N", "num_warps"}min_value = dict(SPLIT_N=1, num_warps=1, nu...
7
20
9
167
0
111
133
111
null
[]
None
null
0
0
0
null
0
null
The function (tune_bsr_dense_addmm.step_meta_parameter) defined within the public class called public.The function start at line 111 and ends at 133. It contains 20 lines of code and it has a cyclomatic complexity of 7. It takes 9 parameters, represented as [111.0] and does not return any value..
pytorch_ao
public
public
0
0
tune_bsr_dense_addmm
def tune_bsr_dense_addmm(input,bsr,dense,*,beta=1,alpha=1,left_alpha=None,right_alpha=None,out=None,store=False,verbose=False,force=False,opname=None,):"""Tune bsr_dense_addmm kernel parameters against the given inputs.When store is True, the tuning results will be stored in thedatabase of kernel parameters."""import t...
13
73
12
399
20
26
159
26
null
['opname', 'may_skip_update', 'values', 'crow_indices', 'max_value', 'next_value', 'N', 'device_name', 'version_dtype', 'is_log', 'value_step', 'initial_meta', 'key', 'min_value', 'dtype', 'reference_meta', 'sparsity', 'out_dtype', 'batch_ndim', 'version']
None
null
0
0
0
null
0
null
The function (tune_bsr_dense_addmm) defined within the public class called public.The function start at line 26 and ends at 159. It contains 73 lines of code and it has a cyclomatic complexity of 13. It takes 12 parameters, represented as [26.0] and does not return any value..
pytorch_ao
public
public
0
0
bsr_dense_addmm_meta
def bsr_dense_addmm_meta(M,K,N,Ms,Ks,beta,alpha,SPLIT_N=None,GROUP_SIZE_ROW=None,num_warps=None,num_stages=None,sparsity=None,dtype=None,out_dtype=None,_version=0,**extra,):# Specifying _version is useful for situations when one wants to# discard existing triton kernel tuning results, say, in testing# bsr_dense_addmm_m...
22
90
16
452
16
162
256
162
null
['split_n', 'version_dtype', 'SPLIT_N', 'meta_', 'n', 'key', 'GROUP_SIZE_ROW', 'c', 'dtype', 'sparsity', 'matching_meta', 'out_dtype', 'num_warps', 'meta', 'num_stages', 'device_name']
None
null
0
0
0
null
0
null
The function (bsr_dense_addmm_meta) defined within the public class called public.The function start at line 162 and ends at 256. It contains 90 lines of code and it has a cyclomatic complexity of 22. It takes 16 parameters, represented as [162.0] and does not return any value..
pytorch_ao
public
public
0
0
bsr_dense_addmm.kernel
def kernel(grid, *sliced_tensors):_bsr_strided_addmm_kernel[grid](*ptr_stride_extractor(*sliced_tensors),beta,alpha,beta_is_one=beta == 1,beta_is_nonzero=beta != 0,alpha_is_one=alpha == 1,left_alpha_is_one=left_alpha_is_one,right_alpha_is_one=right_alpha_is_one,BLOCKSIZE_ROW=BM,BLOCKSIZE_INNER=BK,BLOCKSIZE_COL=BN,allow...
1
17
2
78
0
415
431
415
null
[]
None
null
0
0
0
null
0
null
The function (bsr_dense_addmm.kernel) defined within the public class called public.The function start at line 415 and ends at 431. It contains 17 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [415.0] and does not return any value..
pytorch_ao
public
public
0
0
bsr_dense_addmm
def bsr_dense_addmm(input: torch.Tensor,bsr: torch.Tensor,dense: torch.Tensor,*,beta=1,alpha=1,left_alpha: Optional[torch.Tensor] = None,right_alpha: Optional[torch.Tensor] = None,out: Optional[torch.Tensor] = None,skip_checks: bool = False,max_grid: Optional[tuple[Optional[int], Optional[int], Optional[int]]] = None,m...
15
137
13
919
28
259
440
259
null
['dot_out_dtype', 'values', 'crow_indices', 'n_block_rows', 'f_name', 'N', 'out_backup', 'left_alpha_is_one', 'SPLIT_N', 'right_alpha', 'dense', 'n_block_cols', 'out', 'input', 'right_alpha_is_one', 'full_grid', 'sparsity', 'col_indices', 'blocksize', 'n_batches', 'BN', 'out_untiled', 'tensor_dims_map', 'batch_ndim', '...
None
null
0
0
0
null
0
null
The function (bsr_dense_addmm) defined within the public class called public.The function start at line 259 and ends at 440. It contains 137 lines of code and it has a cyclomatic complexity of 15. It takes 13 parameters, represented as [259.0] and does not return any value..
pytorch_ao
public
public
0
0
_bsr_strided_addmm_kernel
def _bsr_strided_addmm_kernel(# values prologuevalues_ptr,values_batch_stride,values_nnz_stride,values_row_block_stride,values_col_block_stride,# values epilogue# crow_indices prologuecrow_indices_ptr,crow_indices_batch_stride,crow_indices_stride,# crow_indices epilogue# col_indices prologuecol_indices_ptr,col_indices_...
9
166
55
747
0
448
661
448
null
[]
None
null
0
0
0
null
0
null
The function (_bsr_strided_addmm_kernel) defined within the public class called public.The function start at line 448 and ends at 661. It contains 166 lines of code and it has a cyclomatic complexity of 9. It takes 55 parameters, represented as [448.0] and does not return any value..
pytorch_ao
public
public
0
0
safe_int_mm
def safe_int_mm(input: torch.Tensor, mat2: torch.Tensor) -> torch.Tensor:"""Performs a safe integer matrix multiplication, considering different paths fortorch.compile, cublas, and fallback cases.Args:input (torch.Tensor): The input tensor of shape [i, j].mat2 (torch.Tensor): The matrix to multiply with, of shape [j, k...
13
34
2
328
6
30
88
30
null
['input', 'bad_dimensions_for_cublas', 'device_cpu', 'j_is_nonzero_multiple_of_8', 'mat2', 'k_is_nonzero_multiple_of_8']
None
null
0
0
0
null
0
null
The function (safe_int_mm) defined within the public class called public.The function start at line 30 and ends at 88. It contains 34 lines of code and it has a cyclomatic complexity of 13. It takes 2 parameters, represented as [30.0] and does not return any value..
pytorch_ao
public
public
0
0
int_matmul
def int_matmul(a: torch.Tensor, b: torch.Tensor) -> torch.Tensor:"""Performs integer matrix multiplication using intmm_triton if available and autotuner is enabled,otherwise falls back to safe_int_mm.Args:a (torch.Tensor): The first matrix to multiply.b (torch.Tensor): The second matrix to multiply.Returns:torch.Tensor...
3
4
2
48
0
91
105
91
null
[]
None
null
0
0
0
null
0
null
The function (int_matmul) defined within the public class called public.The function start at line 91 and ends at 105. It contains 4 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [91.0] and does not return any value..
pytorch_ao
public
public
0
0
int_scaled_matmul
def int_scaled_matmul(a: torch.Tensor, b: torch.Tensor, scales1: torch.Tensor) -> torch.Tensor:"""Performs scaled integer matrix multiplication.Args:a (torch.Tensor): The first matrix to multiply.b (torch.Tensor): The second matrix to multiply.scales1 (torch.Tensor): The scaling factors for the rows of the result.Retur...
5
17
3
156
2
108
143
108
null
['c', 'scales1']
None
null
0
0
0
null
0
null
The function (int_scaled_matmul) defined within the public class called public.The function start at line 108 and ends at 143. It contains 17 lines of code and it has a cyclomatic complexity of 5. It takes 3 parameters, represented as [108.0] and does not return any value..
pytorch_ao
public
public
0
0
matmul_kernel_with_block_pointers
def matmul_kernel_with_block_pointers(# Pointers to matricesa_ptr,b_ptr,c_ptr,# Matrix dimensionsM,N,K,# The stride variables represent how much to increase the ptr by when moving by 1# element in a particular dimension. E.g. `stride_am` is how much to increase `a_ptr`# by to get the element one row down (A has M rows)...
2
60
16
404
16
78
173
78
null
['first_pid_m', 'a_block_ptr', 'num_pid_in_group', 'num_pid_m', 'pid', 'GROUP_M', 'group_id', 'num_pid_n', 'accumulator', 'a', 'b', 'c', 'c_block_ptr', 'pid_m', 'b_block_ptr', 'pid_n']
None
null
0
0
0
null
0
null
The function (matmul_kernel_with_block_pointers) defined within the public class called public.The function start at line 78 and ends at 173. It contains 60 lines of code and it has a cyclomatic complexity of 2. It takes 16 parameters, represented as [78.0] and does not return any value..
pytorch_ao
public
public
0
0
scaled_matmul_kernel_with_block_pointers
def scaled_matmul_kernel_with_block_pointers(# Pointers to matricesa_ptr,b_ptr,c_ptr,s1_ptr,# Matrix dimensionsM,N,K,# The stride variables represent how much to increase the ptr by when moving by 1# element in a particular dimension. E.g. `stride_am` is how much to increase `a_ptr`# by to get the element one row down ...
3
61
21
503
23
177
252
177
null
['width', 'tmp0', 'mask', 'pid_m', 'rm', 'rbn', 'idx_n', 'grid_n', 'acc', 'B', 'pid', 'a', 'b', 'A', 'pid_n', 'xindex', 'ram', 'rk', 'idx_m', 'group_id', 'group_size', 'rn', 'grid_m']
None
null
0
0
0
null
0
null
The function (scaled_matmul_kernel_with_block_pointers) defined within the public class called public.The function start at line 177 and ends at 252. It contains 61 lines of code and it has a cyclomatic complexity of 3. It takes 21 parameters, represented as [177.0] and does not return any value..
pytorch_ao
public
public
0
0
int_matmul_kernel
def int_matmul_kernel(a, b, c, config):M, K = a.shapeK, N = b.shapegrid = lambda META: (triton.cdiv(M, META["BLOCK_M"]) * triton.cdiv(N, META["BLOCK_N"]),)matmul_kernel_with_block_pointers[grid](a,b,c,#M,N,K,#a.stride(0),a.stride(1),#b.stride(0),b.stride(1),#c.stride(0),c.stride(1),num_warps=config.num_warps,num_stages...
1
25
4
141
1
255
279
255
null
['grid']
None
null
0
0
0
null
0
null
The function (int_matmul_kernel) defined within the public class called public.The function start at line 255 and ends at 279. It contains 25 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [255.0] and does not return any value..
pytorch_ao
public
public
0
0
int_scaled_matmul_kernel
def int_scaled_matmul_kernel(a, b, scales1, c, config):M, K = a.shapeK, N = b.shape# print("a.sizes(): ", a.size(), "a.strides(): ", a.stride(), "a.dtype: ", a.dtype)# print("b.sizes(): ", b.size(), "b.strides(): ", b.stride(), "b.dtype: ", b.dtype)# print("c.sizes(): ", c.size(), "c.strides(): ", c.stride(), "c.dtype:...
1
29
5
169
1
282
314
282
null
['grid']
None
null
0
0
0
null
0
null
The function (int_scaled_matmul_kernel) defined within the public class called public.The function start at line 282 and ends at 314. It contains 29 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [282.0] and does not return any value..
pytorch_ao
public
public
0
0
int_matmul_meta
def int_matmul_meta(a, b):M, K = a.shapeK, N = b.shapereturn torch.empty((M, N), device=a.device, dtype=torch.int32)
1
4
2
44
0
323
326
323
null
[]
None
null
0
0
0
null
0
null
The function (int_matmul_meta) defined within the public class called public.The function start at line 323 and ends at 326. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [323.0] and does not return any value..
pytorch_ao
public
public
0
0
int_matmul_cuda
def int_matmul_cuda(a, b):# Check constraints.assert a.shape[1] == b.shape[0], "Incompatible dimensions"# assert a.is_contiguous(), "Matrix A must be contiguous"# assert b.is_contiguous(), "Matrix B must be contiguous"# Allocates output.M, K = a.shapeK, N = b.shapec = torch.empty((M, N), device=a.device, dtype=torch.in...
2
11
2
101
2
330
346
330
null
['c', 'best_config']
None
null
0
0
0
null
0
null
The function (int_matmul_cuda) defined within the public class called public.The function start at line 330 and ends at 346. It contains 11 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [330.0] and does not return any value..
pytorch_ao
public
public
0
0
int_scaled_matmul_meta
def int_scaled_matmul_meta(a, b, scales1):M, K = a.shapeK, N = b.shapereturn torch.empty((M, N), device=a.device, dtype=scales1.dtype)
1
4
3
46
0
350
353
350
null
[]
None
null
0
0
0
null
0
null
The function (int_scaled_matmul_meta) defined within the public class called public.The function start at line 350 and ends at 353. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [350.0] and does not return any value..
pytorch_ao
public
public
0
0
int_scaled_matmul_cuda
def int_scaled_matmul_cuda(a, b, scales1):# Check constraints.assert a.shape[1] == b.shape[0], "Incompatible dimensions"# assert a.is_contiguous(), "Matrix A must be contiguous"# assert b.is_contiguous(), "Matrix B must be contiguous"# Allocates output.M, K = a.shapeK, N = b.shapec = torch.empty((M, N), device=a.device...
1
9
3
94
2
357
370
357
null
['c', 'best_config']
None
null
0
0
0
null
0
null
The function (int_scaled_matmul_cuda) defined within the public class called public.The function start at line 357 and ends at 370. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [357.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,params,lr,betas,eps,weight_decay,amsgrad,*,block_size,bf16_stochastic_round,is_adamw,) -> None:if not 0.0 <= lr:raise ValueError("Invalid learning rate: {}".format(lr))if not 0.0 <= eps:raise ValueError("Invalid epsilon value: {}".format(eps))if not 0.0 <= betas[0] < 1.0:raise ValueError("Invalid beta...
5
32
10
170
0
20
51
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 51. It contains 32 lines of code and it has a cyclomatic complexity of 5. It takes 10 parameters, represented as [20.0] and does not return any value..