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
forward
def forward(ctx,input_hp: torch.Tensor,weight_hp: torch.Tensor,in_elem_dtype: Any,w_elem_dtype: Any,grad_elem_dtype: Any,block_size: int,gemm_kernel_choice: MXGemmKernelChoice,mxfp8_cast_kernel_choice: MXFP8Dim1CastKernelChoice,scale_calculation_mode: ScaleCalculationMode,):ctx.save_for_backward(input_hp, weight_hp)ctx...
1
39
10
189
0
39
81
39
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 39 and ends at 81. It contains 39 lines of code and it has a cyclomatic complexity of 1. It takes 10 parameters, represented as [39.0] and does not return any value..
pytorch_ao
public
public
0
0
backward
def backward(ctx, grad_output_hp: torch.Tensor):input_hp, weight_hp = ctx.saved_tensorsin_elem_dtype = ctx.in_elem_dtypew_elem_dtype = ctx.w_elem_dtypegrad_elem_dtype = ctx.grad_elem_dtypeblock_size = ctx.block_sizegemm_kernel_choice = ctx.gemm_kernel_choicemxfp8_cast_kernel_choice = ctx.mxfp8_cast_kernel_choicescale_c...
4
83
2
372
0
84
175
84
null
[]
None
null
0
0
0
null
0
null
The function (backward) defined within the public class called public.The function start at line 84 and ends at 175. It contains 83 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [84.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls,mod,config: Optional[MXLinearConfig] = MXLinearConfig(),):assert isinstance(mod, torch.nn.Linear), f"unsupported type(mod) {type(mod)}"assert isinstance(config, MXLinearConfig)mod.__class__ = MXLinearmod.config = configreturn mod
1
10
3
52
0
190
199
190
null
[]
None
null
0
0
0
null
0
null
The function (from_float) defined within the public class called public.The function start at line 190 and ends at 199. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [190.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, x):if torch.is_autocast_enabled():# special case autocastautocast_dtype = torch.get_autocast_dtype("cuda")x = x.to(autocast_dtype)w = self.weight.to(autocast_dtype)else:w = self.weightconfig = self.configy = mx_mm.apply(x,w,config.elem_dtype,config.elem_dtype_weight_override or config.elem_dtype,confi...
5
22
2
116
0
201
224
201
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 201 and ends at 224. It contains 22 lines of code and it has a cyclomatic complexity of 5. It takes 2 parameters, represented as [201.0] and does not return any value..
pytorch_ao
public
public
0
0
extra_repr
def extra_repr(self):s = f"{super().extra_repr()}, {self.config.short_str()}"return s
1
3
1
11
0
226
228
226
null
[]
None
null
0
0
0
null
0
null
The function (extra_repr) defined within the public class called public.The function start at line 226 and ends at 228. 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
_mx_linear_transform
def _mx_linear_transform(module: torch.nn.Module, config: MXLinearConfig):return MXLinear.from_float(module, config=config)
1
2
2
26
0
232
233
232
null
[]
None
null
0
0
0
null
0
null
The function (_mx_linear_transform) defined within the public class called public.The function start at line 232 and ends at 233. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [232.0] and does not return any value..
pytorch_ao
public
public
0
0
_to_mx_rceil
def _to_mx_rceil(data_hp: torch.Tensor,max_abs: torch.Tensor,max_pos: float,) -> tuple[torch.Tensor, torch.Tensor]:"""A prototype implementation of MXFP scale factor derivation method described inhttps://docs.nvidia.com/cuda/cublas/#d-block-quantizationFor Nvidia GPU with Blackwell+ architecture, the scale factor deriv...
1
23
3
146
4
91
136
91
null
['descale', 'data_lp', 'exponent', 'descale_fp']
None
null
0
0
0
null
0
null
The function (_to_mx_rceil) defined within the public class called public.The function start at line 91 and ends at 136. It contains 23 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [91.0] and does not return any value..
pytorch_ao
public
public
0
0
to_mx
def to_mx(data_hp: torch.Tensor,elem_dtype: Union[torch.dtype, str],block_size: int,scaling_mode: ScaleCalculationMode = ScaleCalculationMode.FLOOR,pack_fp6: bool = False,):"""Takes a high precision tensor and converts to MX scale and raw data, innaive layout (scale and raw data are separate tensors)."""assert data_hp....
18
120
5
792
20
139
331
139
null
['nan_mask', 'target_max_pow2', 'orig_shape', 'mask', 'hp_ebits', 'mantissa_gt_one', 'hp_exp_bias', 'max_pos', 'hp_int_dtype', 'hp_mbits', 'data_lp', 'val_to_add', 'data_hp', 'scale_e8m0_biased', 'max_abs_int32', 'scale_e8m0_unbiased', 'max_abs', 'extracted_pow2', 'mbits', 'scale_fp32']
None
null
0
0
0
null
0
null
The function (to_mx) defined within the public class called public.The function start at line 139 and ends at 331. It contains 120 lines of code and it has a cyclomatic complexity of 18. It takes 5 parameters, represented as [139.0] and does not return any value..
pytorch_ao
public
public
0
0
get_fp_scale
def get_fp_scale(scale_e8m0):scale_e8m0 = scale_e8m0.view(torch.uint8)s_offset = scale_e8m0.to(torch.int16) - E8M0_EXPONENT_BIAS# TODO(later): it would be nice if there was a way to do the 2^x operation# in PyTorch without creating a tensor of twostwo = torch.full(s_offset.size(), 2.0, device=scale_e8m0.device)# pow(tw...
1
7
1
78
4
334
348
334
null
['s_fp', 'scale_e8m0', 'two', 's_offset']
None
null
0
0
0
null
0
null
The function (get_fp_scale) defined within the public class called public.The function start at line 334 and ends at 348. 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
to_dtype
def to_dtype(data_lp,scale_e8m0,elem_dtype,block_size,target_dtype,pack_fp6: bool = False,):orig_shape = data_lp.shapeis_transposed = not data_lp.is_contiguous()# if the underlying data is transposed, convert to row major before# unpacking and unscalingif is_transposed:data_lp = data_lp.t()assert data_lp.is_contiguous(...
11
58
6
353
8
351
421
351
null
['data_lp', 'data_hp', 'is_transposed', 'f4_unpacked', 'orig_shape', 'f32', 's_fp', 'data_hp_rescaled']
None
null
0
0
0
null
0
null
The function (to_dtype) defined within the public class called public.The function start at line 351 and ends at 421. It contains 58 lines of code and it has a cyclomatic complexity of 11. It takes 6 parameters, represented as [351.0] and does not return any value..
pytorch_ao
public
public
0
0
tensor_size_hp_to_fp4x2
def tensor_size_hp_to_fp4x2(orig_size, is_contiguous):new_size = orig_sizeif is_contiguous:new_size = [*list(new_size[:-1]), new_size[-1] // 2]else:new_size = [new_size[0] // 2, *list(new_size[1:])]return new_size
2
7
2
45
1
424
430
424
null
['new_size']
None
null
0
0
0
null
0
null
The function (tensor_size_hp_to_fp4x2) defined within the public class called public.The function start at line 424 and ends at 430. It contains 7 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [424.0] and does not return any value..
pytorch_ao
public
public
0
0
tensor_size_fp4x2_to_hp
def tensor_size_fp4x2_to_hp(orig_size, is_contiguous):new_size = orig_sizeif is_contiguous:new_size = [*list(new_size[:-1]), new_size[-1] * 2]else:new_size = [new_size[0] * 2, *list(new_size[1:])]return new_size
2
7
2
59
1
433
439
433
null
['new_size']
None
null
0
0
0
null
0
null
The function (tensor_size_fp4x2_to_hp) defined within the public class called public.The function start at line 433 and ends at 439. It contains 7 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [433.0] and does not return any value..
pytorch_ao
public
public
0
0
tensor_size_hpx3_to_fp6x4
def tensor_size_hpx3_to_fp6x4(orig_size, is_contiguous):new_size = orig_sizeif is_contiguous:new_size = [*list(new_size[:-1]), 3 * new_size[-1] // 4]else:new_size = [3 * new_size[0] // 4, *list(new_size[1:])]return new_size
2
7
2
49
1
442
448
442
null
['new_size']
None
null
0
0
0
null
0
null
The function (tensor_size_hpx3_to_fp6x4) defined within the public class called public.The function start at line 442 and ends at 448. It contains 7 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [442.0] and does not return any value..
pytorch_ao
public
public
0
0
tensor_size_fp6x4_to_hpx3
def tensor_size_fp6x4_to_hpx3(orig_size, is_contiguous):new_size = orig_sizeif is_contiguous:new_size = [*list(new_size[:-1]), 4 * new_size[-1] // 3]else:new_size = [4 * new_size[0] // 3, *list(new_size[1:])]return new_size
2
7
2
49
1
451
457
451
null
['new_size']
None
null
0
0
0
null
0
null
The function (tensor_size_fp6x4_to_hpx3) defined within the public class called public.The function start at line 451 and ends at 457. It contains 7 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [451.0] and does not return any value..
pytorch_ao
public
public
0
0
__new__
def __new__(cls,qdata,scale_e8m0_bits,elem_dtype,block_size,orig_dtype,gemm_kernel_choice,pack_fp6,act_quant_kwargs,):new_size = qdata.size()if elem_dtype == torch.float4_e2m1fn_x2:# set the tensor size to what it would be without 2x4 packing# Note: `is_contiguous` is going to return True for a tensor of size# (M, 1) r...
9
68
9
315
0
471
549
471
null
[]
None
null
0
0
0
null
0
null
The function (__new__) defined within the public class called public.The function start at line 471 and ends at 549. It contains 68 lines of code and it has a cyclomatic complexity of 9. It takes 9 parameters, represented as [471.0] and does not return any value..
pytorch_ao
public
public
0
0
__repr__
def __repr__(self):# TODO better elem dtype print for fp4return f"MXTensor: elem_dtype: {self._elem_dtype}, s_e8m0: {self._scale_e8m0}, d: {self.qdata}, act_quant_kwargs: {self.act_quant_kwargs}"# noqa: E501
1
2
1
8
0
551
553
551
null
[]
None
null
0
0
0
null
0
null
The function (__repr__) defined within the public class called public.The function start at line 551 and ends at 553. 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
_quantization_type
def _quantization_type(self):return f"{self._elem_dtype=}, {self._block_size=}, {self._orig_dtype=}, {self._gemm_kernel_choice=}, {self.act_quant_kwargs=}"
1
2
1
8
0
555
556
555
null
[]
None
null
0
0
0
null
0
null
The function (_quantization_type) defined within the public class called public.The function start at line 555 and ends at 556. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
to_dtype
def to_dtype(self, target_dtype):return to_dtype(self.qdata,self._scale_e8m0,self._elem_dtype,self._block_size,target_dtype,self._pack_fp6,)
1
9
2
33
0
558
566
558
null
[]
None
null
0
0
0
null
0
null
The function (to_dtype) defined within the public class called public.The function start at line 558 and ends at 566. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [558.0] and does not return any value..
pytorch_ao
public
public
0
0
to_mx
def to_mx(data_hp: torch.Tensor,elem_dtype: Union[torch.dtype, str],block_size: int = BLOCK_SIZE_DEFAULT,scaling_mode: ScaleCalculationMode = ScaleCalculationMode.FLOOR,# TODO(future PR): switch default gemm to cublasgemm_kernel_choice: MXGemmKernelChoice = MXGemmKernelChoice.EMULATED,pack_fp6: bool = False,act_quant_k...
2
44
7
186
0
570
614
570
null
[]
None
null
0
0
0
null
0
null
The function (to_mx) defined within the public class called public.The function start at line 570 and ends at 614. It contains 44 lines of code and it has a cyclomatic complexity of 2. It takes 7 parameters, represented as [570.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return return_and_correct_aliasing(func, args, kwargs, args[0]._apply_fn_to_data(func))
1
4
4
30
0
624
627
624
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 624 and ends at 627. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [624.0] and does not return any value..
pytorch_ao
public
public
0
0
_get_gemm_choice
def _get_gemm_choice(choice_a: Optional[MXGemmKernelChoice], choice_b: Optional[MXGemmKernelChoice]) -> MXGemmKernelChoice:if choice_a is not None and choice_b is not None:assert choice_a == choice_b, ("Both MXTensor inputs must have the same gemm config if specified")return choice_a# Assert that at least one is set an...
5
12
2
63
0
630
643
630
null
[]
None
null
0
0
0
null
0
null
The function (_get_gemm_choice) defined within the public class called public.The function start at line 630 and ends at 643. It contains 12 lines of code and it has a cyclomatic complexity of 5. It takes 2 parameters, represented as [630.0] and does not return any value..
pytorch_ao
public
public
0
0
_addmm_mx_dispatch
def _addmm_mx_dispatch(a: torch.Tensor, b: MXTensor, aten_op, bias: Optional[torch.Tensor] = None) -> torch.Tensor:"""Core implementation shared between mx_mm and mx_addmm.The only difference is whether bias is None or not."""if not isinstance(a, MXTensor):assert b.act_quant_kwargs is not None, "weight-only quant not y...
6
57
4
401
10
646
721
646
null
['res', 'a_scale_block', 'a_hp', 'gemm_choice', 'b_scale_block', 'a_scale', 'k', 'a', 'b_hp', 'b_scale']
None
null
0
0
0
null
0
null
The function (_addmm_mx_dispatch) defined within the public class called public.The function start at line 646 and ends at 721. It contains 57 lines of code and it has a cyclomatic complexity of 6. It takes 4 parameters, represented as [646.0] and does not return any value..
pytorch_ao
public
public
0
0
mx_mm
def mx_mm(func, types, args, kwargs):a = args[0]b = args[1]assert isinstance(b, MXTensor)return _addmm_mx_dispatch(a, b, func)
1
5
4
39
2
725
730
725
null
['b', 'a']
None
null
0
0
0
null
0
null
The function (mx_mm) defined within the public class called public.The function start at line 725 and ends at 730. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [725.0] and does not return any value..
pytorch_ao
public
public
0
0
mx_addmm
def mx_addmm(func, types, args, kwargs):assert isinstance(args[0], torch.Tensor) and isinstance(args[2], MXTensor)bias = args[0]a = args[1]b = args[2]return _addmm_mx_dispatch(a, b, func, bias=bias)
2
6
4
64
3
734
739
734
null
['b', 'a', 'bias']
None
null
0
0
0
null
0
null
The function (mx_addmm) defined within the public class called public.The function start at line 734 and ends at 739. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [734.0] and does not return any value..
pytorch_ao
public
public
0
0
mx_t
def mx_t(func, types, args, kwargs):# For now, only transpose(input, 0, 1) is supported.old = args[0]new = MXTensor(old.qdata.t(),old._scale_e8m0,old._elem_dtype,old._block_size,old._orig_dtype,old._gemm_kernel_choice,old._pack_fp6,old.act_quant_kwargs,)return new
1
13
4
60
2
743
756
743
null
['new', 'old']
None
null
0
0
0
null
0
null
The function (mx_t) defined within the public class called public.The function start at line 743 and ends at 756. It contains 13 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [743.0] and does not return any value..
pytorch_ao
public
public
0
0
mx_cast_up_op.unwrap
def unwrap(x):if isinstance(x, MXTensor):return x.to_dtype(x._orig_dtype)return x
2
4
1
24
0
769
772
769
null
[]
None
null
0
0
0
null
0
null
The function (mx_cast_up_op.unwrap) defined within the public class called public.The function start at line 769 and ends at 772. 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
mx_cast_up_op
def mx_cast_up_op(func, types, args, kwargs):"""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_gradOut""...
1
5
4
39
2
760
776
760
null
['new_args', 'new_kwargs']
None
null
0
0
0
null
0
null
The function (mx_cast_up_op) defined within the public class called public.The function start at line 760 and ends at 776. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [760.0] and does not return any value..
pytorch_ao
public
public
0
0
mx_view_op
def mx_view_op(func, types, args, kwargs):data = args[0].qdatanew_size = args[1]if args[0]._elem_dtype == torch.float4_e2m1fn_x2:# special case fp4 as we pack two elements per bytenew_size = tensor_size_hp_to_fp4x2(new_size, data.is_contiguous())elif args[0]._elem_dtype in [DTYPE_FP6_E3M2, DTYPE_FP6_E2M3] and args[0]._...
4
18
4
155
3
780
799
780
null
['new_data', 'new_size', 'data']
None
null
0
0
0
null
0
null
The function (mx_view_op) defined within the public class called public.The function start at line 780 and ends at 799. It contains 18 lines of code and it has a cyclomatic complexity of 4. It takes 4 parameters, represented as [780.0] and does not return any value..
pytorch_ao
public
public
0
0
mx_slice
def mx_slice(func, types, args, kwargs):x, dim, start, end, step = fill_defaults(args, 5, [0, None, None, 1])if step != 1:raise ValueError("Only support aten.slice with step=1")M, K = x.shape[0], x.shape[1]# TODO why doesn't scale have shape?scale_shaped = x._scale_e8m0.view(M, K // x._block_size)if dim == 0:# Slicing ...
8
41
4
277
5
803
859
803
null
['end_block', 'sliced_scale', 'sliced_data', 'start_block', 'scale_shaped']
None
null
0
0
0
null
0
null
The function (mx_slice) defined within the public class called public.The function start at line 803 and ends at 859. It contains 41 lines of code and it has a cyclomatic complexity of 8. It takes 4 parameters, represented as [803.0] and does not return any value..
pytorch_ao
public
public
0
0
mx_clone
def mx_clone(func, types, args, kwargs):self = args[0]memory_format = kwargs.get("memory_format", None)if memory_format is not None:clone_fn = lambda x: x.clone(memory_format=memory_format)else:clone_fn = lambda x: x.clone()return self._apply_fn_to_data(clone_fn)
2
8
4
65
3
863
872
863
null
['memory_format', 'clone_fn', 'self']
None
null
0
0
0
null
0
null
The function (mx_clone) defined within the public class called public.The function start at line 863 and ends at 872. It contains 8 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [863.0] and does not return any value..
pytorch_ao
public
public
0
0
mx_select
def mx_select(func, types, args, kwargs):old_mx_tensor, dim, index = argsassert dim == 0, f"MXTensor aten.select.int with {dim=} is not yet supported"assert len(old_mx_tensor.qdata.shape) == len(old_mx_tensor._scale_e8m0.shape), ("unsupported")new_mx_tensor = old_mx_tensor.__class__(old_mx_tensor.qdata[index],old_mx_te...
1
17
4
103
1
876
892
876
null
['new_mx_tensor']
None
null
0
0
0
null
0
null
The function (mx_select) defined within the public class called public.The function start at line 876 and ends at 892. It contains 17 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [876.0] and does not return any value..
pytorch_ao
public
public
0
0
implements.decorator
def decorator(func):for op in aten_ops:NVFP4_OPS_TABLE[op] = funcreturn func
2
4
1
18
0
61
64
61
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 61 and ends at 64. 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
implements
def implements(aten_ops):"""Register aten ops to the NVFP4 op table"""def decorator(func):for op in aten_ops:NVFP4_OPS_TABLE[op] = funcreturn funcreturn decorator
1
3
1
10
0
58
66
58
null
[]
None
null
0
0
0
null
0
null
The function (implements) defined within the public class called public.The function start at line 58 and ends at 66. 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
__new__
def __new__(cls,qdata,blockwise_scales,block_size,orig_dtype,_per_tensor_scale=None,_act_per_tensor_scale=None,_is_swizzled_scales=False,use_triton_kernel=False,act_quant_kwargs=None,):# FP4 tensor size handling two paths, contiguous or notnew_size = qdata.size()new_size = tensor_size_fp4x2_to_hp(new_size,qdata.stride(...
1
34
10
136
0
98
135
98
null
[]
None
null
0
0
0
null
0
null
The function (__new__) defined within the public class called public.The function start at line 98 and ends at 135. It contains 34 lines of code and it has a cyclomatic complexity of 1. It takes 10 parameters, represented as [98.0] and does not return any value..
pytorch_ao
public
public
0
0
__repr__
def __repr__(self):return f"NVFP4Tensor: blockwise_scales: {self._scale_e4m3}, per_tensor_scale: {self._per_tensor_scale}, d: {self.qdata}, d_hp: {self.to_dtype(self._orig_dtype)}"
1
2
1
8
0
137
138
137
null
[]
None
null
0
0
0
null
0
null
The function (__repr__) defined within the public class called public.The function start at line 137 and ends at 138. 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
_quantization_type
def _quantization_type(self):return f"{self._is_swizzled_scales=}, {self.use_triton_kernel=}, {self.act_quant_kwargs=}"
1
2
1
8
0
140
141
140
null
[]
None
null
0
0
0
null
0
null
The function (_quantization_type) defined within the public class called public.The function start at line 140 and ends at 141. 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__
def __torch_dispatch__(cls, func, types, args, kwargs=None):# Use NVFP4-specific ops tableif func in NVFP4_OPS_TABLE:return NVFP4_OPS_TABLE[func](func, types, args, kwargs)raise NotImplementedError(f"{func} not implemented for NVFP4Tensor")
2
4
5
40
0
144
149
144
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 144 and ends at 149. It contains 4 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [144.0] and does not return any value..
pytorch_ao
public
public
0
0
to_nvfp4
def to_nvfp4(data_hp: torch.Tensor,block_size: int = 16,per_tensor_scale: Optional[torch.Tensor] = None,act_per_tensor_scale: Optional[torch.Tensor] = None,is_swizzled_scales: bool = False,use_triton_kernel: bool = False,act_quant_kwargs: Optional[QuantizeTensorToNVFP4Kwargs] = None,):"""Convert high precision tensor t...
4
42
7
217
0
152
214
152
null
[]
None
null
0
0
0
null
0
null
The function (to_nvfp4) defined within the public class called public.The function start at line 152 and ends at 214. It contains 42 lines of code and it has a cyclomatic complexity of 4. It takes 7 parameters, represented as [152.0] and does not return any value..
pytorch_ao
public
public
0
0
to_dtype
def to_dtype(self, target_dtype: torch.dtype) -> torch.Tensor:"""Convert NVFP4Tensor back to high precision dtype.Args:target_dtype: Target dtype for dequantization (e.g., torch.float32, torch.bfloat16)Returns:torch.Tensor: Dequantized tensor in the target dtype"""is_transposed = self.qdata.stride(0) < self.qdata.strid...
4
16
2
175
0
219
245
219
null
[]
None
null
0
0
0
null
0
null
The function (to_dtype) defined within the public class called public.The function start at line 219 and ends at 245. It contains 16 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [219.0] and does not return any value..
pytorch_ao
public
public
0
0
get_hp_scales
def get_hp_scales(self) -> torch.Tensor:"""Get the scales of the NVFP4Tensor in original dtype.Returns:torch.Tensor: Scales of the NVFP4Tensor"""is_transposed = self.qdata.stride(0) < self.qdata.stride(1)if is_transposed:M, K = self.shape[1], self.shape[0]scale_e4m3 = self._scale_e4m3.t()else:M, K = self.shape[0], self...
4
15
1
127
0
247
268
247
null
[]
None
null
0
0
0
null
0
null
The function (get_hp_scales) defined within the public class called public.The function start at line 247 and ends at 268. It contains 15 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
_same_metadata
def _same_metadata(cls, self: "NVFP4Tensor", src: "NVFP4Tensor") -> bool:"""Check if two NVFP4Tensors have the same metadata.Args:self: First NVFP4Tensor to comparesrc: Second NVFP4Tensor to compareReturns:bool: True if both tensors have identical metadata, False otherwise"""per_tensor_scale_equal = (self._per_tensor_s...
14
19
3
150
0
271
299
271
null
[]
None
null
0
0
0
null
0
null
The function (_same_metadata) defined within the public class called public.The function start at line 271 and ends at 299. It contains 19 lines of code and it has a cyclomatic complexity of 14. It takes 3 parameters, represented as [271.0] and does not return any value..
pytorch_ao
public
public
0
0
nvfp4_detach_alias
def nvfp4_detach_alias(func, types, args, kwargs):return return_and_correct_aliasing(func, args, kwargs, args[0]._apply_fn_to_data(func))
1
4
4
30
0
303
306
303
null
[]
None
null
0
0
0
null
0
null
The function (nvfp4_detach_alias) defined within the public class called public.The function start at line 303 and ends at 306. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [303.0] and does not return any value..
pytorch_ao
public
public
0
0
nvfp4_to_copy
def nvfp4_to_copy(func, types, args, kwargs):"""Autocast + device movement"""assert isinstance(args[0], NVFP4Tensor)# Handle dtype parameterdtype = kwargs.pop("dtype", None)if dtype is not None:assert dtype in {torch.float16,torch.bfloat16,torch.float32,}, "Only support floating point conversion for autocast w/ NVFP4Te...
4
29
4
164
4
310
345
310
null
['tensor', 'res', 'dtype', 'device']
None
null
0
0
0
null
0
null
The function (nvfp4_to_copy) defined within the public class called public.The function start at line 310 and ends at 345. It contains 29 lines of code and it has a cyclomatic complexity of 4. It takes 4 parameters, represented as [310.0] and does not return any value..
pytorch_ao
public
public
0
0
nvfp4_copy_
def nvfp4_copy_(func, types, args, kwargs):self = args[0]src = args[1]if NVFP4Tensor._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))return selfraise ValueError(f"Not supported args for copy_ due to metadata ...
3
11
4
72
3
349
359
349
null
['self_tensors', 'src', 'self']
None
null
0
0
0
null
0
null
The function (nvfp4_copy_) defined within the public class called public.The function start at line 349 and ends at 359. It contains 11 lines of code and it has a cyclomatic complexity of 3. It takes 4 parameters, represented as [349.0] and does not return any value..
pytorch_ao
public
public
0
0
nvfp4_clone
def nvfp4_clone(func, types, args, kwargs):self = args[0]memory_format = kwargs.get("memory_format", None)if memory_format is not None:clone_fn = lambda x: x.clone(memory_format=memory_format)else:clone_fn = lambda x: x.clone()return self._apply_fn_to_data(clone_fn)
2
8
4
65
3
363
372
363
null
['memory_format', 'clone_fn', 'self']
None
null
0
0
0
null
0
null
The function (nvfp4_clone) defined within the public class called public.The function start at line 363 and ends at 372. It contains 8 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [363.0] and does not return any value..
pytorch_ao
public
public
0
0
nvfp4_slice
def nvfp4_slice(func, types, args, kwargs):x, dim, start, end, step = fill_defaults(args, 5, [0, None, None, 1])if step != 1:raise ValueError("Only support aten.slice with step=1")assert x.qdata.is_contiguous(), "Only support contiguous data for now"M, K = x.shape[0], x.shape[1]# The scale manipulations below assume a ...
45
133
4
845
30
376
565
376
null
['sliced_M', 'scale_rows', 'end_block', 'packed_end', 'sliced_K', 'sliced_data', 'end_scale_col', 'start_col_block', 'row_start', 'n_row_blocks', 'scale_shaped', 'elements_per_block', 'col_end', 'slices_to_extract', 'end_col_block', 'scale_cols', 'scale_M', 'n_col_blocks', 'start_block', 'blocks_per_row', 'result', 'en...
None
null
0
0
0
null
0
null
The function (nvfp4_slice) defined within the public class called public.The function start at line 376 and ends at 565. It contains 133 lines of code and it has a cyclomatic complexity of 45. It takes 4 parameters, represented as [376.0] and does not return any value..
pytorch_ao
public
public
0
0
nvfp4_t
def nvfp4_t(func, types, args, kwargs):# For now, only transpose(input, 0, 1) is supported.old = args[0]new = NVFP4Tensor(old.qdata.t(),old._scale_e4m3.t(),old._block_size,old._orig_dtype,old._per_tensor_scale,old._act_per_tensor_scale,old._is_swizzled_scales,old.use_triton_kernel,old.act_quant_kwargs,)return new
1
14
4
68
2
569
583
569
null
['new', 'old']
None
null
0
0
0
null
0
null
The function (nvfp4_t) defined within the public class called public.The function start at line 569 and ends at 583. It contains 14 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [569.0] and does not return any value..
pytorch_ao
public
public
0
0
nvfp4_view_op
def nvfp4_view_op(func, types, args, kwargs):data = args[0].qdatanew_size = args[1]new_size = tensor_size_hp_to_fp4x2(new_size, data.is_contiguous())new_data = func(data, new_size, *args[2:], **kwargs)return NVFP4Tensor(new_data,args[0]._scale_e4m3,args[0]._block_size,args[0]._orig_dtype,args[0]._per_tensor_scale,args[...
1
16
4
117
3
587
602
587
null
['new_data', 'new_size', 'data']
None
null
0
0
0
null
0
null
The function (nvfp4_view_op) defined within the public class called public.The function start at line 587 and ends at 602. It contains 16 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [587.0] and does not return any value..
pytorch_ao
public
public
0
0
_addmm_nvfp4_dispatch
def _addmm_nvfp4_dispatch(a: NVFP4Tensor, b: NVFP4Tensor, aten_op, bias: Optional[torch.Tensor] = None) -> torch.Tensor:"""Core implementation shared between nvfp4_mm, nvfp4_addmm, and nvfp4_linear.The only difference is whether bias is None or not."""assert a.qdata.is_contiguous()assert a._scale_e4m3.is_contiguous()as...
9
41
4
325
8
605
667
605
null
['a_scale_blocked', 'b_scale_blocked', 'scale_result', 'a_scale', 'should_add_bias_separately', 'N', 'b_scale', 'result']
None
null
0
0
0
null
0
null
The function (_addmm_nvfp4_dispatch) defined within the public class called public.The function start at line 605 and ends at 667. It contains 41 lines of code and it has a cyclomatic complexity of 9. It takes 4 parameters, represented as [605.0] and does not return any value..
pytorch_ao
public
public
0
0
nvfp4_linear
def nvfp4_linear(func, types, args, kwargs):input_tensor, weight_tensor, bias = (args[0],args[1],args[2] if len(args) > 2 else None,)if not isinstance(weight_tensor, NVFP4Tensor):raise NotImplementedError("NVFP4Tensor: weight must be NVFP4Tensor")if weight_tensor.act_quant_kwargs is None:# weight_only quantweight_dequa...
5
26
4
175
5
671
700
671
null
['k', 'weight_dequant', 'tensor_amax', 'input_tensor', 'per_tensor_scale']
None
null
0
0
0
null
0
null
The function (nvfp4_linear) defined within the public class called public.The function start at line 671 and ends at 700. It contains 26 lines of code and it has a cyclomatic complexity of 5. It takes 4 parameters, represented as [671.0] and does not return any value..
pytorch_ao
public
public
0
0
nvfp4_mm
def nvfp4_mm(func, types, args, kwargs):input_tensor, weight_tensor = args[0], args[1]if not isinstance(weight_tensor, NVFP4Tensor):raise NotImplementedError("NVFP4Tensor: weight must be NVFP4Tensor")if weight_tensor.act_quant_kwargs is None:weight_dequant = weight_tensor.to_dtype(weight_tensor._orig_dtype)if isinstanc...
6
27
4
176
6
704
732
704
null
['k', 'weight_dequant', 'tensor_amax', 'input_tensor', 'input_dequant', 'per_tensor_scale']
None
null
0
0
0
null
0
null
The function (nvfp4_mm) defined within the public class called public.The function start at line 704 and ends at 732. It contains 27 lines of code and it has a cyclomatic complexity of 6. It takes 4 parameters, represented as [704.0] and does not return any value..
pytorch_ao
public
public
0
0
nvfp4_addmm
def nvfp4_addmm(func, types, args, kwargs):bias, input_tensor, weight_tensor = args[0], args[1], args[2]if not isinstance(weight_tensor, NVFP4Tensor):raise NotImplementedError("NVFP4Tensor: weight must be NVFP4Tensor")if weight_tensor.act_quant_kwargs is None:weight_dequant = weight_tensor.to_dtype(weight_tensor._orig_...
6
27
4
195
6
736
765
736
null
['k', 'weight_dequant', 'tensor_amax', 'input_tensor', 'input_dequant', 'per_tensor_scale']
None
null
0
0
0
null
0
null
The function (nvfp4_addmm) defined within the public class called public.The function start at line 736 and ends at 765. It contains 27 lines of code and it has a cyclomatic complexity of 6. It takes 4 parameters, represented as [736.0] and does not return any value..
pytorch_ao
public
public
0
0
per_tensor_amax_to_scale
def per_tensor_amax_to_scale(amax: torch.Tensor) -> torch.Tensor:"""Convert per-tensor amax to per-tensor scale for NVFP4 quantization.Divides by both F8E4M3_MAX and F4_E2M1_MAX to ensure block scales can utilizethe full FP8 E4M3 range (up to 448) when block_max equals tensor_max.Without F4_E2M1_MAX, the maximum scale ...
1
2
1
29
0
768
781
768
null
[]
None
null
0
0
0
null
0
null
The function (per_tensor_amax_to_scale) defined within the public class called public.The function start at line 768 and ends at 781. 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
nvfp4_quantize
def nvfp4_quantize(data_hp: torch.Tensor,block_size: int = 16,per_tensor_scale: Optional[torch.Tensor] = None,) -> tuple[torch.Tensor, torch.Tensor]:"""NVIDIA FP4 quantization with UE4M3 scales.Implements the NVIDIA algorithm for quantizing tensors to FP4 formatwith unsigned E4M3 (UE4M3) scales.Args:data_hp: High preci...
2
38
3
295
13
784
857
784
null
['data_lp', 'data_hp', 'block_scale_fp32', 'max_abs', 'block_scale_fp8', 'scaled_block_scales_fp32', 'orig_shape', 'out_scales', 'scaled_block_scales', 'total_scale', 'scaled_block_scales_fp8', 'data_scaled', 'block_scale']
None
null
0
0
0
null
0
null
The function (nvfp4_quantize) defined within the public class called public.The function start at line 784 and ends at 857. It contains 38 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [784.0] and does not return any value..
pytorch_ao
public
public
0
0
ceil_div
def ceil_div(a, b):return (a + b - 1) // b
1
2
2
16
0
25
26
25
null
[]
None
null
0
0
0
null
0
null
The function (ceil_div) defined within the public class called public.The function start at line 25 and ends at 26. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [25.0] and does not return any value..
pytorch_ao
public
public
0
0
to_blocked
def to_blocked(input_matrix, use_triton_kernel: bool = False) -> Tensor:"""Rearrange a large matrix by breaking it into blocks and applying the rearrangement pattern.See:https://docs.nvidia.com/cuda/cublas/index.html#d-block-scaling-factors-layoutArgs:input_matrix: Input tensor of shape (H, W)use_triton_kernel: Whether...
4
19
2
181
7
29
69
29
null
['padded_cols', 'n_col_blocks', 'blocks', 'padded_rows', 'rearranged', 'n_row_blocks', 'padded']
None
null
0
0
0
null
0
null
The function (to_blocked) defined within the public class called public.The function start at line 29 and ends at 69. It contains 19 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [29.0] and does not return any value..
pytorch_ao
public
public
0
0
from_blocked
def from_blocked(blocked_tensor: Tensor, original_rows: int, original_cols: int) -> Tensor:"""Inverse of to_blocked: convert from blocked layout back to regular row-major layout.Args:blocked_tensor: Flattened blocked tensor from to_blocked()original_rows: Original number of rows before blockingoriginal_cols: Original n...
1
12
3
125
7
72
101
72
null
['temp', 'n_col_blocks', 'blocks', 'rearranged', 'n_row_blocks', 'padded', 'padded_view']
None
null
0
0
0
null
0
null
The function (from_blocked) defined within the public class called public.The function start at line 72 and ends at 101. It contains 12 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [72.0] and does not return any value..
pytorch_ao
public
public
0
0
hp_data_dims_to_swizzled_scale_dims_nvfp4
def hp_data_dims_to_swizzled_scale_dims_nvfp4(hp_data_M,hp_data_K,) -> Tuple[int, int]:"""Given the `M` and `K` dimensions of a high precision contiguous tensor,returns a 2d tuple of the dims of the swizzled nvfp4 scale corresponding tothat tensor."""# a 128x64 unpacked or 128x32 packed qdata tile corresponds# to a swi...
1
7
2
40
2
104
117
104
null
['scale_M', 'scale_K']
None
null
0
0
0
null
0
null
The function (hp_data_dims_to_swizzled_scale_dims_nvfp4) defined within the public class called public.The function start at line 104 and ends at 117. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [104.0] and does not return any value..
pytorch_ao
public
public
0
0
_to_blocked_single
def _to_blocked_single(scales: Tensor) -> Tensor:"""Assume that we have a 128x4 block of scales in K Major orderTo see more information on the individual tile layout:https://docs.nvidia.com/cuda/cublas/index.html#d-block-scaling-factors-layout"""assert scales.shape == (128, 4)scales_tiled = scales.view(4, 32, 4)# view ...
1
4
1
48
1
120
128
120
null
['scales_tiled']
None
null
0
0
0
null
0
null
The function (_to_blocked_single) defined within the public class called public.The function start at line 120 and ends at 128. 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
_to_mxfp8_dim1_kernel_wrapper
def _to_mxfp8_dim1_kernel_wrapper(a,block_size,elem_dtype,hp_dtype,gemm_kernel_choice,cast_kernel_choice,scale_calculation_mode: ScaleCalculationMode,):# avoid circular import# TODO(future PR): split this utils file in twofrom torchao.prototype.mx_formats.mx_tensor import MXTensorif cast_kernel_choice == MXFP8Dim1CastK...
4
60
7
236
4
131
194
131
null
['inner', 'a_scale_local', 'a_data_local', 'mx_tensor']
None
null
0
0
0
null
0
null
The function (_to_mxfp8_dim1_kernel_wrapper) defined within the public class called public.The function start at line 131 and ends at 194. It contains 60 lines of code and it has a cyclomatic complexity of 4. It takes 7 parameters, represented as [131.0] and does not return any value..
pytorch_ao
public
public
0
0
train
def train():dist.init_process_group(backend="nccl")model_args, data_args, training_args = process_args()log.info("Start to load model...")dtype = torch.bfloat16 if training_args.bf16 else torch.floatconfig = LlamaConfig.from_pretrained(model_args.input_model_filename)config.w_bits = model_args.w_bitsmodel = LlamaForCau...
16
82
0
573
16
24
118
24
null
['weight_param', 'config', 'perplexity', 'maxq', 'trainer', 'weight_name', 'tokenizer', 'myTrainer', 'model', 'scale', 'train_result', 'metrics', 'dtype', 'max_eval_samples', 'valid_data', 'train_data']
None
null
0
0
0
null
0
null
The function (train) defined within the public class called public.The function start at line 24 and ends at 118. It contains 82 lines of code and it has a cyclomatic complexity of 16. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,vocab_size=32000,hidden_size=4096,intermediate_size=11008,num_hidden_layers=32,num_attention_heads=32,num_key_value_heads=None,hidden_act="silu",max_position_embeddings=2048,initializer_range=0.02,rms_norm_eps=1e-6,use_cache=True,pad_token_id=None,bos_token_id=1,eos_token_id=2,pretraining_tp=1,tie_wor...
5
58
25
279
0
165
228
165
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 165 and ends at 228. It contains 58 lines of code and it has a cyclomatic complexity of 5. It takes 25 parameters, represented as [165.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, hidden_size, eps=1e-6):"""LlamaRMSNorm is equivalent to T5LayerNorm"""super().__init__()self.weight = nn.Parameter(torch.ones(hidden_size))self.variance_epsilon = eps
1
4
3
41
0
67
73
67
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 67 and ends at 73. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [67.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, hidden_states):input_dtype = hidden_states.dtypehidden_states = hidden_states.to(torch.float32)variance = hidden_states.pow(2).mean(-1, keepdim=True)hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)return self.weight * hidden_states.to(input_dtype)
1
6
2
65
0
75
80
75
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 75 and ends at 80. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [75.0] and does not return any value..
pytorch_ao
public
public
0
0
extra_repr
def extra_repr(self):return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
1
2
1
8
0
82
83
82
null
[]
None
null
0
0
0
null
0
null
The function (extra_repr) defined within the public class called public.The function start at line 82 and ends at 83. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, config: LlamaConfig, device=None):super().__init__()# BC: "rope_type" was originally "type"if hasattr(config, "rope_scaling") and config.rope_scaling is not None:self.rope_type = config.rope_scaling.get("rope_type", config.rope_scaling.get("type"))else:self.rope_type = "default"self.max_seq_len_cache...
3
13
3
127
0
90
105
90
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 90 and ends at 105. It contains 13 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [90.0] and does not return any value..
pytorch_ao
public
public
0
0
_dynamic_frequency_update
def _dynamic_frequency_update(self, position_ids, device):"""dynamic RoPE layers should recompute `inv_freq` in the following situations:1 - growing beyond the cached sequence length (allow scaling)2 - the current sequence length is in the original scale (avoid losing precision with small sequences)"""seq_len = torch.m...
4
10
3
112
0
107
124
107
null
[]
None
null
0
0
0
null
0
null
The function (_dynamic_frequency_update) defined within the public class called public.The function start at line 107 and ends at 124. It contains 10 lines of code and it has a cyclomatic complexity of 4. It takes 3 parameters, represented as [107.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, x, position_ids):if "dynamic" in self.rope_type:self._dynamic_frequency_update(position_ids, device=x.device)# Core RoPE blockinv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1)position_ids_expanded = position_ids[:, None, :].float()# Force float32 (see https:...
4
15
3
199
0
127
147
127
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 127 and ends at 147. It contains 15 lines of code and it has a cyclomatic complexity of 4. It takes 3 parameters, represented as [127.0] and does not return any value..
pytorch_ao
public
public
0
0
rotate_half
def rotate_half(x):"""Rotates half the hidden dims of the input."""x1 = x[..., : x.shape[-1] // 2]x2 = x[..., x.shape[-1] // 2 :]return torch.cat((-x2, x1), dim=-1)
1
4
1
52
2
150
154
150
null
['x2', 'x1']
None
null
0
0
0
null
0
null
The function (rotate_half) defined within the public class called public.The function start at line 150 and ends at 154. 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
apply_rotary_pos_emb
def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):"""Applies Rotary Position Embedding to the query and key tensors.Args:q (`torch.Tensor`): The query tensor.k (`torch.Tensor`): The key tensor.cos (`torch.Tensor`): The cosine part of the rotary embedding.sin (`torch.Tensor`): The sine part of...
1
6
6
72
4
157
181
157
null
['sin', 'k_embed', 'q_embed', 'cos']
None
null
0
0
0
null
0
null
The function (apply_rotary_pos_emb) defined within the public class called public.The function start at line 157 and ends at 181. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [157.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, config):super().__init__()self.config = configself.hidden_size = config.hidden_sizeself.intermediate_size = config.intermediate_sizeself.gate_proj = QuantizeLinear(self.hidden_size, self.intermediate_size, bias=config.mlp_bias, w_bits=config.w_bits)self.up_proj = QuantizeLinear(self.hidden_size, self...
1
9
2
121
0
185
193
185
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 185 and ends at 193. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [185.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, x):down_proj = self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))return down_proj
1
3
2
34
0
195
197
195
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 195 and ends at 197. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [195.0] and does not return any value..
pytorch_ao
public
public
0
0
repeat_kv
def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:"""This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)"""batch, num_key_value_heads, slen, head_dim = h...
2
6
2
78
1
200
209
200
null
['hidden_states']
None
null
0
0
0
null
0
null
The function (repeat_kv) defined within the public class called public.The function start at line 200 and ends at 209. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [200.0] and does not return any value..
pytorch_ao
public
public
0
0
eager_attention_forward
def eager_attention_forward(module: nn.Module,query: torch.Tensor,key: torch.Tensor,value: torch.Tensor,attention_mask: Optional[torch.Tensor],scaling: float,dropout: float = 0.0,**kwargs,):key_states = repeat_kv(key, module.num_key_value_groups)value_states = repeat_kv(value, module.num_key_value_groups)attn_weights =...
2
21
8
197
5
212
235
212
null
['value_states', 'key_states', 'attn_output', 'causal_mask', 'attn_weights']
None
null
0
0
0
null
0
null
The function (eager_attention_forward) defined within the public class called public.The function start at line 212 and ends at 235. It contains 21 lines of code and it has a cyclomatic complexity of 2. It takes 8 parameters, represented as [212.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, config: LlamaConfig, layer_idx: int):super().__init__()self.config = configself.layer_idx = layer_idxself.head_dim = getattr(config, "head_dim", config.hidden_size // config.num_attention_heads)self.num_key_value_groups = config.num_attention_heads // config.num_key_value_headsself.scaling = self.hea...
1
21
3
196
0
241
262
241
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 241 and ends at 262. It contains 21 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [241.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self,hidden_states: torch.Tensor,position_embeddings: Tuple[torch.Tensor, torch.Tensor],attention_mask: Optional[torch.Tensor],past_key_value: Optional[Cache] = None,cache_position: Optional[torch.LongTensor] = None,**kwargs: Unpack[FlashAttentionKwargs],) -> Tuple[torch.Tensor, Optional[torch.Tensor], Opti...
6
41
7
347
0
264
311
264
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 264 and ends at 311. It contains 41 lines of code and it has a cyclomatic complexity of 6. It takes 7 parameters, represented as [264.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, config: LlamaConfig, layer_idx: int):super().__init__()self.hidden_size = config.hidden_sizeself.self_attn = LlamaAttention(config=config, layer_idx=layer_idx)self.mlp = LlamaMLP(config)self.input_layernorm = LlamaRMSNorm(config.hidden_size, eps=config.rms_norm_eps)self.post_attention_layernorm = Lla...
1
7
3
81
0
315
323
315
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 315 and ends at 323. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [315.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self,hidden_states: torch.Tensor,attention_mask: Optional[torch.Tensor] = None,position_ids: Optional[torch.LongTensor] = None,past_key_value: Optional[Cache] = None,output_attentions: Optional[bool] = False,use_cache: Optional[bool] = False,cache_position: Optional[torch.LongTensor] = None,position_embeddi...
2
34
10
220
0
325
365
325
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 325 and ends at 365. It contains 34 lines of code and it has a cyclomatic complexity of 2. It takes 10 parameters, represented as [325.0] and does not return any value..
pytorch_ao
public
public
0
0
_init_weights
def _init_weights(self, module):std = self.config.initializer_rangeif isinstance(module, nn.Linear):module.weight.data.normal_(mean=0.0, std=std)if module.bias is not None:module.bias.data.zero_()elif isinstance(module, nn.Embedding):module.weight.data.normal_(mean=0.0, std=std)if module.padding_idx is not None:module....
5
10
2
109
0
403
412
403
null
[]
None
null
0
0
0
null
0
null
The function (_init_weights) defined within the public class called public.The function start at line 403 and ends at 412. It contains 10 lines of code and it has a cyclomatic complexity of 5. It takes 2 parameters, represented as [403.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, config: LlamaConfig):super().__init__(config)self.padding_idx = config.pad_token_idself.vocab_size = config.vocab_sizeself.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)self.layers = nn.ModuleList([LlamaDecoderLayer(config, layer_idx) for layer_idx in range(confi...
2
12
2
113
0
502
516
502
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 502 and ends at 516. It contains 12 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [502.0] and does not return any value..
pytorch_ao
public
public
0
0
get_input_embeddings
def get_input_embeddings(self):return self.embed_tokens
1
2
1
9
0
518
519
518
null
[]
None
null
0
0
0
null
0
null
The function (get_input_embeddings) defined within the public class called public.The function start at line 518 and ends at 519. 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
set_input_embeddings
def set_input_embeddings(self, value):self.embed_tokens = value
1
2
2
12
0
521
522
521
null
[]
None
null
0
0
0
null
0
null
The function (set_input_embeddings) defined within the public class called public.The function start at line 521 and ends at 522. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [521.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self,input_ids: torch.LongTensor = None,attention_mask: Optional[torch.Tensor] = None,position_ids: Optional[torch.LongTensor] = None,past_key_values: Optional[Cache] = None,inputs_embeds: Optional[torch.FloatTensor] = None,use_cache: Optional[bool] = None,output_attentions: Optional[bool] = None,output_hid...
25
85
12
510
0
525
629
525
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 525 and ends at 629. It contains 85 lines of code and it has a cyclomatic complexity of 25. It takes 12 parameters, represented as [525.0] and does not return any value..
pytorch_ao
public
public
0
0
_update_causal_mask
def _update_causal_mask(self,attention_mask: torch.Tensor,input_tensor: torch.Tensor,cache_position: torch.Tensor,past_key_values: Cache,output_attentions: bool,):if self.config._attn_implementation == "flash_attention_2":if attention_mask is not None and (attention_mask == 0.0).any():return attention_maskreturn None# ...
15
50
6
273
0
631
694
631
null
[]
None
null
0
0
0
null
0
null
The function (_update_causal_mask) defined within the public class called public.The function start at line 631 and ends at 694. It contains 50 lines of code and it has a cyclomatic complexity of 15. It takes 6 parameters, represented as [631.0] and does not return any value..
pytorch_ao
public
public
0
0
_prepare_4d_causal_attention_mask_with_cache_position
def _prepare_4d_causal_attention_mask_with_cache_position(attention_mask: torch.Tensor,sequence_length: int,target_length: int,dtype: torch.dtype,device: torch.device,cache_position: torch.Tensor,batch_size: int,**kwargs,):"""Creates a causal 4D mask of shape `(batch_size, 1, query_length, key_value_length)` from a 2D ...
5
32
8
252
0
697
752
697
null
[]
None
null
0
0
0
null
0
null
The function (_prepare_4d_causal_attention_mask_with_cache_position) defined within the public class called public.The function start at line 697 and ends at 752. It contains 32 lines of code and it has a cyclomatic complexity of 5. It takes 8 parameters, represented as [697.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, config):super().__init__(config)self.model = LlamaModel(config)self.vocab_size = config.vocab_sizeself.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)# Initialize weights and apply final processingself.post_init()
1
6
2
55
0
763
770
763
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 763 and ends at 770. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [763.0] and does not return any value..
pytorch_ao
public
public
0
0
get_input_embeddings
def get_input_embeddings(self):return self.model.embed_tokens
1
2
1
11
0
772
773
772
null
[]
None
null
0
0
0
null
0
null
The function (get_input_embeddings) defined within the public class called public.The function start at line 772 and ends at 773. 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
set_input_embeddings
def set_input_embeddings(self, value):self.model.embed_tokens = value
1
2
2
14
0
775
776
775
null
[]
None
null
0
0
0
null
0
null
The function (set_input_embeddings) defined within the public class called public.The function start at line 775 and ends at 776. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [775.0] and does not return any value..
pytorch_ao
public
public
0
0
get_output_embeddings
def get_output_embeddings(self):return self.lm_head
1
2
1
9
0
778
779
778
null
[]
None
null
0
0
0
null
0
null
The function (get_output_embeddings) defined within the public class called public.The function start at line 778 and ends at 779. 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
set_output_embeddings
def set_output_embeddings(self, new_embeddings):self.lm_head = new_embeddings
1
2
2
12
0
781
782
781
null
[]
None
null
0
0
0
null
0
null
The function (set_output_embeddings) defined within the public class called public.The function start at line 781 and ends at 782. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [781.0] and does not return any value..
pytorch_ao
public
public
0
0
set_decoder
def set_decoder(self, decoder):self.model = decoder
1
2
2
12
0
784
785
784
null
[]
None
null
0
0
0
null
0
null
The function (set_decoder) defined within the public class called public.The function start at line 784 and ends at 785. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [784.0] and does not return any value..
pytorch_ao
public
public
0
0
get_decoder
def get_decoder(self):return self.model
1
2
1
9
0
787
788
787
null
[]
None
null
0
0
0
null
0
null
The function (get_decoder) defined within the public class called public.The function start at line 787 and ends at 788. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self,input_ids: torch.LongTensor = None,attention_mask: Optional[torch.Tensor] = None,position_ids: Optional[torch.LongTensor] = None,past_key_values: Optional[Union[Cache, List[torch.FloatTensor]]] = None,inputs_embeds: Optional[torch.FloatTensor] = None,labels: Optional[torch.LongTensor] = None,use_cache:...
8
50
14
381
0
793
881
793
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 793 and ends at 881. It contains 50 lines of code and it has a cyclomatic complexity of 8. It takes 14 parameters, represented as [793.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, config):super().__init__(config)self.model = LlamaModel(config)self.vocab_size = config.vocab_sizeself.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)# Initialize weights and apply final processingself.post_init()
1
6
2
55
0
900
907
763
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 900 and ends at 907. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [763.0] and does not return any value..
pytorch_ao
public
public
0
0
get_input_embeddings
def get_input_embeddings(self):return self.model.embed_tokens
1
2
1
11
0
909
910
772
null
[]
None
null
0
0
0
null
0
null
The function (get_input_embeddings) defined within the public class called public.The function start at line 909 and ends at 910. 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
set_input_embeddings
def set_input_embeddings(self, value):self.model.embed_tokens = value
1
2
2
14
0
912
913
775
null
[]
None
null
0
0
0
null
0
null
The function (set_input_embeddings) defined within the public class called public.The function start at line 912 and ends at 913. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [775.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self,input_ids: Optional[torch.LongTensor] = None,attention_mask: Optional[torch.Tensor] = None,position_ids: Optional[torch.LongTensor] = None,past_key_values: Optional[Union[Cache, List[torch.FloatTensor]]] = None,inputs_embeds: Optional[torch.FloatTensor] = None,labels: Optional[torch.LongTensor] = None,...
10
59
11
438
0
916
988
916
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 916 and ends at 988. It contains 59 lines of code and it has a cyclomatic complexity of 10. It takes 11 parameters, represented as [916.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, config):super().__init__(config)self.transformer = LlamaModel(config)self.qa_outputs = nn.Linear(config.hidden_size, 2)# Initialize weights and apply final processingself.post_init()
1
5
2
42
0
1,002
1,008
1,002
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 1002 and ends at 1008. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [1002.0] and does not return any value..
pytorch_ao
public
public
0
0
get_input_embeddings
def get_input_embeddings(self):return self.model.embed_tokens
1
2
1
11
0
1,010
1,011
772
null
[]
None
null
0
0
0
null
0
null
The function (get_input_embeddings) defined within the public class called public.The function start at line 1010 and ends at 1011. 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
set_input_embeddings
def set_input_embeddings(self, value):self.model.embed_tokens = value
1
2
2
14
0
1,013
1,014
775
null
[]
None
null
0
0
0
null
0
null
The function (set_input_embeddings) defined within the public class called public.The function start at line 1013 and ends at 1014. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [775.0] and does not return any value..