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 | from_plain.quant_2d | def quant_2d(int_data_2d):int_data_2d = (int_data_2d[::, ::2] << 4 | int_data_2d[::, 1::2]).to(torch.uint8)return torch.ops.aten._convert_weight_to_int4pack(int_data_2d.contiguous(), _layout.inner_k_tiles) | 1 | 7 | 1 | 54 | 0 | 279 | 285 | 279 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (from_plain.quant_2d) defined within the public class called public.The function start at line 279 and ends at 285. 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 | from_plain | def from_plain(cls,int_data: torch.Tensor,scale: torch.Tensor,zero_point: Optional[torch.Tensor],_layout: Layout,):assert isinstance(_layout, TensorCoreTiledLayout)assert int_data.dtype == torch.int32, ("torch.ops.aten._convert_weight_to_int4pack in torch 2.4 expects `int32` dtype")def quant_2d(int_data_2d):int_data_2d... | 5 | 36 | 5 | 255 | 0 | 267 | 311 | 267 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (from_plain) defined within the public class called public.The function start at line 267 and ends at 311. It contains 36 lines of code and it has a cyclomatic complexity of 5. It takes 5 parameters, represented as [267.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | to | def to(self, *args, **kwargs):kwargs = self._get_to_kwargs(*args, **kwargs)device = kwargs["device"]# tensor core tiled layout supports both cpu and cuda but does not support the conversion# between these two devices, in the future we should not use the same layout for# cpu and cuda device: https://github.com/pytorch/a... | 2 | 13 | 3 | 86 | 0 | 313 | 328 | 313 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (to) defined within the public class called public.The function start at line 313 and ends at 328. It contains 13 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [313.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _apply_fn_to_data | def _apply_fn_to_data(self, fn):# self.packed_weight = fn(self.packed_weight)# self.scale_and_zero = fn(self.scale_and_zero)# return selfreturn self.__class__(fn(self.packed_weight),fn(self.scale_and_zero),self.transposed,self._layout,) | 1 | 7 | 2 | 35 | 0 | 330 | 339 | 330 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_apply_fn_to_data) defined within the public class called public.The function start at line 330 and ends at 339. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [330.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __torch_dispatch__ | def __torch_dispatch__(cls, func, types, args, kwargs):kwargs = {} if kwargs is None else kwargsif func is aten.detach.default:return return_and_correct_aliasing(func, args, kwargs, args[0]._apply_fn_to_data(torch.detach))if func is aten.clone.default:return return_and_correct_aliasing(func, args, kwargs, args[0]._appl... | 14 | 90 | 5 | 569 | 0 | 342 | 448 | 342 | 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 342 and ends at 448. It contains 90 lines of code and it has a cyclomatic complexity of 14. It takes 5 parameters, represented as [342.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | block_size | def block_size(self):from torchao.quantization.utils import unpack_tinygemm_scales_and_zerosscale, zero = unpack_tinygemm_scales_and_zeros(self.scale_and_zero)cur_shape = self.shapeif len(cur_shape) == 5:ones = [1, 1]cur_shape = cur_shape[1:]else:assert len(cur_shape) == 4ones = [1]inner_k_tiles = cur_shape[-1] * 2orig... | 2 | 14 | 1 | 121 | 0 | 453 | 467 | 453 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (block_size) defined within the public class called public.The function start at line 453 and ends at 467. It contains 14 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_plain.dequant_4d | def dequant_4d(self):cur_shape = self.shapescale, zero = unpack_tinygemm_scales_and_zeros(self.scale_and_zero)assert len(cur_shape) == 4inner_k_tiles = cur_shape[-1] * 2original_shape = (cur_shape[0] * 8, cur_shape[1] * (inner_k_tiles * 16))eye_shape = original_shape[1]groupsize = int(original_shape[1] / scale.shape[-2... | 2 | 19 | 1 | 157 | 0 | 472 | 490 | 472 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_plain.dequant_4d) defined within the public class called public.The function start at line 472 and ends at 490. It contains 19 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_plain | def get_plain(self) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:from torchao.quantization.utils import unpack_tinygemm_scales_and_zerosdef dequant_4d(self):cur_shape = self.shapescale, zero = unpack_tinygemm_scales_and_zeros(self.scale_and_zero)assert len(cur_shape) == 4inner_k_tiles = cur_shape[-1] * 2original_... | 3 | 29 | 1 | 191 | 0 | 469 | 521 | 469 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_plain) defined within the public class called public.The function start at line 469 and ends at 521. It contains 29 lines of code and it has a cyclomatic complexity of 3. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_layout | def get_layout(self) -> Layout:return self._layout | 1 | 2 | 1 | 11 | 0 | 523 | 524 | 523 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_layout) defined within the public class called public.The function start at line 523 and ends at 524. 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 | down_size | def down_size(size):assert size[-1] % 2 == 0, f"{size} last dim not divisible by two"return (*size[:-1], size[-1] // 2) | 1 | 3 | 1 | 34 | 0 | 14 | 16 | 14 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (down_size) defined within the public class called public.The function start at line 14 and ends at 16. 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 | up_size | def up_size(size):return (*size[:-1], size[-1] * 2) | 1 | 2 | 1 | 23 | 0 | 19 | 20 | 19 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (up_size) defined within the public class called public.The function start at line 19 and ends at 20. 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 | unpack_uint4 | def unpack_uint4(uint8_data) -> torch.Tensor:"""Get the original weight from the normalized float weight format"""# since we are using uint8 we will decode 2 entries per byte# Shift elements down 4 and select out the bottom 4 bitsshape = uint8_data.shapefirst_elements = (uint8_data >> 4).to(torch.uint8)second_elements ... | 1 | 5 | 1 | 68 | 3 | 27 | 34 | 27 | null | ['first_elements', 'shape', 'second_elements'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (unpack_uint4) defined within the public class called public.The function start at line 27 and ends at 34. It contains 5 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | pack_uint4 | def pack_uint4(uint8_data) -> torch.Tensor:# converting to uint8 for operationsshape = uint8_data.shapeassert shape[-1] % 2 == 0uint8_data = uint8_data.contiguous().view(-1)return (uint8_data[::2] << 4 | uint8_data[1::2]).view(down_size(shape)) | 1 | 5 | 1 | 63 | 2 | 37 | 42 | 37 | null | ['uint8_data', 'shape'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (pack_uint4) defined within the public class called public.The function start at line 37 and ends at 42. It contains 5 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | quantize_per_tensor_uint4 | def quantize_per_tensor_uint4(input: torch.Tensor,scale: float,zero_point: int,) -> torch.Tensor:inv_scale = 1.0 / scalereturn pack_uint4(torch.clamp(torch.round(input * inv_scale) + zero_point, 0, 15).to(torch.uint8)) | 1 | 9 | 3 | 59 | 1 | 52 | 60 | 52 | null | ['inv_scale'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (quantize_per_tensor_uint4) defined within the public class called public.The function start at line 52 and ends at 60. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [52.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | dequantize_per_tensor_uint4 | def dequantize_per_tensor_uint4(input: torch.Tensor,scale: float,zero_point: int,) -> torch.Tensor:input = unpack_uint4(input)return (input.view(torch.uint8).to(torch.float32) - zero_point) * scale | 1 | 7 | 3 | 50 | 1 | 69 | 75 | 69 | null | ['input'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (dequantize_per_tensor_uint4) defined within the public class called public.The function start at line 69 and ends at 75. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [69.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __new__ | def __new__(cls, elem, **kwargs):assert elem.dtype is torch.uint8assert not kwargs.get("requires_grad", False)kwargs["requires_grad"] = Falsereturn torch.Tensor._make_wrapper_subclass(cls, up_size(elem.shape), dtype=torch.uint4, **kwargs) | 1 | 7 | 3 | 59 | 0 | 80 | 87 | 80 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__new__) defined within the public class called public.The function start at line 80 and ends at 87. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [80.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, elem, **kwargs):self.elem = elem | 1 | 2 | 3 | 15 | 0 | 89 | 90 | 89 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 89 and ends at 90. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [89.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | from_unpacked | def from_unpacked(cls, unpacked):return UInt4Tensor(pack_uint4(unpacked)) | 1 | 2 | 2 | 15 | 0 | 93 | 94 | 93 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (from_unpacked) defined within the public class called public.The function start at line 93 and ends at 94. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [93.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | tolist | def tolist(self):return self.to(torch.uint8).tolist() | 1 | 2 | 1 | 18 | 0 | 96 | 97 | 96 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (tolist) defined within the public class called public.The function start at line 96 and ends at 97. 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):return ["elem"], None | 1 | 2 | 1 | 11 | 0 | 99 | 100 | 99 | 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 99 and ends at 100. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __tensor_unflatten__ | def __tensor_unflatten__(flattened, meta, outer_size, outer_stride):assert meta is Noneelem = flattened["elem"]return UInt4Tensor(elem) | 1 | 4 | 4 | 26 | 0 | 103 | 106 | 103 | 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 103 and ends at 106. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [103.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __hash__ | def __hash__(self):return hash(self.elem) | 1 | 2 | 1 | 12 | 0 | 108 | 109 | 108 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__hash__) defined within the public class called public.The function start at line 108 and ends at 109. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __eq__ | def __eq__(self, other):return torch.equal(self.elem, other.elem) | 1 | 2 | 2 | 20 | 0 | 111 | 112 | 111 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__eq__) defined within the public class called public.The function start at line 111 and ends at 112. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [111.0] 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 is torch.ops.aten.view.default:self, size = argssize = utils.infer_size(size, self.numel())assert not kwargs# WARNING: views not preservedreturn UInt4Tensor(self.elem.reshape(down_size(size)))elif func is torch.ops.aten.view.dtype:self, dtype = argsif ... | 22 | 87 | 5 | 759 | 0 | 115 | 216 | 115 | 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 115 and ends at 216. It contains 87 lines of code and it has a cyclomatic complexity of 22. It takes 5 parameters, represented as [115.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _dynamically_quantize_per_channel_int4 | def _dynamically_quantize_per_channel_int4(x, quant_min, quant_max, target_dtype):# assumes symmetric quantization# assumes axis == 0# assumes dense memory format# TODO(future): relax ^ as needed# default setup for affine quantization of activationseps = torch.finfo(torch.float32).eps# get min and maxmin_val, max_val =... | 2 | 22 | 4 | 225 | 10 | 221 | 262 | 221 | null | ['x_zp', 'max_val_pos', 'zero_point', 'device', 'x_round', 'x_div', 'eps', 'scale', 'min_val_neg', 'quant'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_dynamically_quantize_per_channel_int4) defined within the public class called public.The function start at line 221 and ends at 262. It contains 22 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [221.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __new__ | def __new__(cls, elem, scales, **kwargs):return super().__new__(cls, elem, **kwargs) | 1 | 2 | 4 | 26 | 0 | 267 | 268 | 267 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__new__) defined within the public class called public.The function start at line 267 and ends at 268. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [267.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, elem, scales, **kwargs):super().__init__(elem, **kwargs)self.scales = scales | 1 | 3 | 4 | 28 | 0 | 270 | 273 | 270 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 270 and ends at 273. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [270.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __tensor_flatten__ | def __tensor_flatten__(self):return ["elem", "scales"], None | 1 | 2 | 1 | 13 | 0 | 275 | 276 | 275 | 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 275 and ends at 276. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __tensor_unflatten__ | def __tensor_unflatten__(flattened, meta, outer_size, outer_stride):assert meta is Noneelem = flattened["elem"]scales = flattened["scales"]return PerChannelSymmetricWeightUInt4Tensor(elem, scales) | 1 | 5 | 4 | 34 | 0 | 279 | 283 | 279 | 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 279 and ends at 283. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [279.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | from_unpacked | def from_unpacked(cls, unpacked, scales):return cls(pack_uint4(unpacked), scales) | 1 | 2 | 3 | 19 | 0 | 289 | 290 | 289 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (from_unpacked) defined within the public class called public.The function start at line 289 and ends at 290. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [289.0] 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 is torch.ops.aten.addmm.default:bias, x, weight = argsx_view = x.view(-1, x.shape[-1])y = torch.mm(x_view, weight.to(torch.uint8).to(x.dtype)) * weight.scalesy = y.reshape(*x.shape[:-1], -1)if bias is not None:y += biasreturn yelif func is torch.ops.at... | 5 | 20 | 5 | 198 | 0 | 293 | 313 | 293 | 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 293 and ends at 313. It contains 20 lines of code and it has a cyclomatic complexity of 5. It takes 5 parameters, represented as [293.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | from_float | def from_float(cls, w_fp32):w_int4, scales, _zp = _dynamically_quantize_per_channel_int4(w_fp32, 0, 15, torch.uint4)w_int4 = w_int4.to(device=w_fp32.device)return w_int4 | 1 | 6 | 2 | 39 | 0 | 316 | 321 | 316 | 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 316 and ends at 321. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [316.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __new__ | def __new__(cls,shards: List[torch.Tensor],packed_shape: List[int],bit_width: int,pack_dim: int = -1,):kwargs = {"device": shards[0].device}kwargs["device"] = shards[0].devicekwargs["layout"] = shards[0].layoutkwargs["requires_grad"] = Falsekwargs["dtype"] = torch.uint8return torch.Tensor._make_wrapper_subclass(cls, pa... | 1 | 13 | 5 | 95 | 0 | 61 | 73 | 61 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__new__) defined within the public class called public.The function start at line 61 and ends at 73. It contains 13 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [61.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self,shards: List[torch.Tensor],packed_shape: List[int],bit_width: int,pack_dim: int = -1,):for i, attrib in enumerate(self.bits_to_shard[bit_width]):setattr(self, attrib, shards[i])self.packed_shape = packed_shapeself.bit_width = bit_widthself.pack_dim = pack_dim | 2 | 12 | 5 | 74 | 0 | 75 | 87 | 75 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 75 and ends at 87. It contains 12 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [75.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_shards | def get_shards(self):return [getattr(self, i) for i in self.__class__.bits_to_shard[self.bit_width]] | 2 | 2 | 1 | 27 | 0 | 89 | 90 | 89 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_shards) defined within the public class called public.The function start at line 89 and ends at 90. 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 | __repr__ | def __repr__(self):return f"Int{self.bit_width}Tensor(shape = {self.packed_shape}, data = {unpack(self.get_shards(), self.bit_width, dim=self.pack_dim)})" | 1 | 2 | 1 | 8 | 0 | 92 | 93 | 92 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__repr__) defined within the public class called public.The function start at line 92 and ends at 93. 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):return self.__class__.bits_to_shard[self.bit_width], [self.packed_shape,self.bit_width,self.pack_dim,] | 1 | 6 | 1 | 31 | 0 | 95 | 100 | 95 | 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 95 and ends at 100. It contains 6 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __tensor_unflatten__ | def __tensor_unflatten__(cls, tensor_data_dict, tensor_attributes, outer_size, outer_stride):shards = list(tensor_data_dict.values())packed_shape, bit_width, pack_dim = tensor_attributesreturn cls(shards, packed_shape, bit_width, pack_dim) | 1 | 6 | 5 | 41 | 0 | 103 | 108 | 103 | 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 103 and ends at 108. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [103.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_plain | def get_plain(self):return unpack(self.get_shards(), self.bit_width, dim=self.pack_dim) | 1 | 2 | 1 | 24 | 0 | 110 | 111 | 110 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_plain) defined within the public class called public.The function start at line 110 and ends at 111. 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 | apply_transformation | def apply_transformation(self, fn):og = self.get_plain()new = fn(og)dtype = _BIT_WIDTH_TO_DTYPE[self.bit_width]return self.from_uint8(new, dtype, self.pack_dim) | 1 | 5 | 2 | 41 | 0 | 114 | 118 | 114 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (apply_transformation) defined within the public class called public.The function start at line 114 and ends at 118. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [114.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | apply_fn_to_shards | def apply_fn_to_shards(self, fn):new_shards = [fn(shard) for shard in self.get_shards()]return self.__class__(new_shards, self.packed_shape, self.bit_width, self.pack_dim) | 2 | 5 | 2 | 42 | 0 | 121 | 125 | 121 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (apply_fn_to_shards) defined within the public class called public.The function start at line 121 and ends at 125. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [121.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | from_uint8 | def from_uint8(cls, int_data: torch.Tensor, dtype: torch.dtype, pack_dim: int = -1):assert dtype in _DTYPE_TO_BIT_WIDTH.keys(), ("Expected dtype to be one of {_DTYPE_TO_BIT_WIDTH.keys()}")bit_width = _DTYPE_TO_BIT_WIDTH[dtype]shards = pack(int_data, bit_width, dim=pack_dim)shape = list(int_data.shape)shape[pack_dim] = ... | 1 | 9 | 4 | 87 | 0 | 128 | 136 | 128 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (from_uint8) defined within the public class called public.The function start at line 128 and ends at 136. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [128.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _get_to_kwargs | def _get_to_kwargs(self, *args, **kwargs):device, dtype, _, memory_format = torch._C._nn._parse_to(*args, **kwargs)device = self.device if device is None else devicedtype = self.dtype if dtype is None else dtypememory_format = (memory_format if memory_format is not None else torch.preserve_format)kwargs = {"device": de... | 4 | 13 | 3 | 87 | 0 | 138 | 150 | 138 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_get_to_kwargs) defined within the public class called public.The function start at line 138 and ends at 150. It contains 13 lines of code and it has a cyclomatic complexity of 4. It takes 3 parameters, represented as [138.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | to | def to(self, *args, **kwargs):if "copy" in kwargs:return super().to(*args, **kwargs)kwargs = self._get_to_kwargs(*args, **kwargs)if "device" in kwargs:return self.__class__(list(shard.to(kwargs["device"]) for shard in self.get_shards()),self.packed_shape,self.bit_width,self.pack_dim,)return super().to(*args, **kwargs) | 4 | 12 | 3 | 98 | 0 | 152 | 163 | 152 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (to) defined within the public class called public.The function start at line 152 and ends at 163. It contains 12 lines of code and it has a cyclomatic complexity of 4. It takes 3 parameters, represented as [152.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_shards(torch.detach)) | 1 | 4 | 4 | 32 | 0 | 170 | 173 | 170 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_) defined within the public class called public.The function start at line 170 and ends at 173. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [170.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _ | def _(func, types, args, kwargs):return return_and_correct_aliasing(func, args, kwargs, args[0].apply_transformation(lambda x: x.view(*args[1:]))) | 1 | 4 | 4 | 43 | 0 | 177 | 180 | 177 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_) defined within the public class called public.The function start at line 177 and ends at 180. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [177.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]) | 1 | 2 | 4 | 25 | 0 | 184 | 185 | 184 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_) defined within the public class called public.The function start at line 184 and ends at 185. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [184.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_transformation(lambda x: (x - args[1]).to(torch.uint8)),) | 1 | 7 | 4 | 48 | 0 | 189 | 195 | 189 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_) defined within the public class called public.The function start at line 189 and ends at 195. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [189.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_transformation(lambda x: (x - args[1]).to(torch.uint8)),) | 1 | 7 | 4 | 48 | 0 | 199 | 205 | 189 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_) defined within the public class called public.The function start at line 199 and ends at 205. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [189.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | post_process | def post_process(self,input: torch.Tensor,scale: torch.Tensor,zero_point: torch.Tensor,block_size: Tuple[int, ...],) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:return to_uintx(input, self.dtype, self.pack_dim), scale, zero_point | 1 | 8 | 5 | 65 | 0 | 228 | 235 | 228 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (post_process) defined within the public class called public.The function start at line 228 and ends at 235. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [228.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_plain | def get_plain(self) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:return self.int_data.get_plain(), self.scale, self.zero_point | 1 | 2 | 1 | 36 | 0 | 240 | 241 | 240 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_plain) defined within the public class called public.The function start at line 240 and ends at 241. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | from_plain | def from_plain(cls,int_data: torch.Tensor,scale: torch.Tensor,zero_point: torch.Tensor,_layout: Layout,):assert isinstance(_layout, UintxLayout)return cls(int_data, scale, zero_point, _layout) | 1 | 9 | 5 | 46 | 0 | 244 | 252 | 244 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (from_plain) defined within the public class called public.The function start at line 244 and ends at 252. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [244.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _quantize | def _quantize(vals: torch.Tensor, group_size: int, nbit: int, has_weight_zeros: bool, signed=True):assert nbit >= 1 and nbit <= 8if signed:qmin = -(1 << (nbit - 1))qmax = (1 << (nbit - 1)) - 1else:qmin = 0qmax = (1 << nbit) - 1n, k = vals.shapevals = vals.reshape(-1, group_size)vmins, _ = torch.min(vals, axis=1)vmaxs, ... | 6 | 34 | 5 | 249 | 6 | 27 | 66 | 27 | null | ['group_scales', 'vals', 'group_zeros', 'group_qvals', 'qmax', 'qmin'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_quantize) defined within the public class called public.The function start at line 27 and ends at 66. It contains 34 lines of code and it has a cyclomatic complexity of 6. It takes 5 parameters, represented as [27.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self,pack_weight_op,linear_op,):super().__init__()self._pack_weights_op = pack_weight_opself._linear_op = linear_op | 1 | 8 | 3 | 27 | 0 | 70 | 77 | 70 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 70 and ends at 77. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [70.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | quantize_and_pack_weights | def quantize_and_pack_weights(self, weights, nbit, group_size):self.nbit = nbitself.group_size = group_sizeweight_qvals, weight_scales, weight_zeros = _quantize(weights, self.group_size, self.nbit, has_weight_zeros=True, signed=False)weight_zeros = -weight_zeros * weight_scalesself.weight_scales = nn.Parameter(weight_s... | 1 | 11 | 4 | 114 | 0 | 79 | 90 | 79 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (quantize_and_pack_weights) defined within the public class called public.The function start at line 79 and ends at 90. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [79.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(self, x):assert x.dim() >= 2if x.dim() == 2:return self._linear_op(x,self.packed_weights,self.group_size,self.weight_scales,self.weight_zeros,)lead_shape = x.shape[0:-1]k = x.shape[-1]n = self.weight_scales.shape[0]return self._linear_op(x.reshape(-1, k),self.packed_weights,self.group_size,self.weight_scale... | 2 | 20 | 2 | 118 | 0 | 92 | 112 | 92 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 92 and ends at 112. It contains 20 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [92.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _replace_linear_with_quantized_linear_mps | def _replace_linear_with_quantized_linear_mps(module: nn.Module, kwargs={}):group_size = kwargs["group_size"]nbit = kwargs["nbit"]assert not isinstance(module, nn.Linear)assert nbit >= 1 and nbit <= 7for name, child in module.named_children():if not isinstance(child, nn.Linear):_replace_linear_with_quantized_linear_mps... | 4 | 18 | 2 | 133 | 3 | 116 | 135 | 116 | null | ['qlinear', 'nbit', 'group_size'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_replace_linear_with_quantized_linear_mps) defined within the public class called public.The function start at line 116 and ends at 135. It contains 18 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [116.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self,device,precision,*,bitwidth: Optional[int] = None,groupsize: Optional[int] = None,):if device != "mps":raise NotImplementedError("Only device=mps is currently supported in UIntxWeightOnlyLinearQuantizer")else:self.device = deviceif precision not in [torch.float32, torch.float16, torch.bfloat16]:raise ... | 7 | 38 | 5 | 156 | 0 | 139 | 179 | 139 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 139 and ends at 179. It contains 38 lines of code and it has a cyclomatic complexity of 7. It takes 5 parameters, represented as [139.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | quantize | def quantize(self, model: nn.Module) -> nn.Module:model = model.to(self.device).to(self.precision)_replace_linear_with_quantized_linear_mps(model,kwargs={"group_size": self.groupsize,"nbit": self.bitwidth,},)return model | 1 | 10 | 2 | 56 | 0 | 181 | 190 | 181 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (quantize) defined within the public class called public.The function start at line 181 and ends at 190. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [181.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _ | def _(activations: Tensor,packed_weights: Tensor,group_size: int,scales: int,zeros: int,):assert activations.dtype in [torch.float32, torch.float16, torch.bfloat16]assert activations.is_contiguous()assert activations.dim() == 2assert packed_weights.dtype == torch.uint8assert packed_weights.is_contiguous()m = activation... | 1 | 25 | 5 | 183 | 0 | 15 | 46 | 15 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_) defined within the public class called public.The function start at line 15 and ends at 46. It contains 25 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [15.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _init_tensors | def _init_tensors(self, group_size, M, K, N, nbit, device="mps"):ceil_K_group_size = (K + group_size - 1) // group_sizeA = torch.rand(M, K, dtype=torch.float32, device=device)W = torch.randint(0, 1 << nbit, (N, K), dtype=torch.uint8, device=device)S = torch.rand(N, ceil_K_group_size, dtype=torch.float32, device=device)... | 1 | 14 | 7 | 146 | 0 | 63 | 76 | 63 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_init_tensors) defined within the public class called public.The function start at line 63 and ends at 76. It contains 14 lines of code and it has a cyclomatic complexity of 1. It takes 7 parameters, represented as [63.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _reference_linear_lowbit_quant_weights | def _reference_linear_lowbit_quant_weights(self, A, W, group_size, S, Z, nbit):# A is (M, K)# W is (N, K)# S is (K // group_size, N)# Z is (K // group_size, N)N = W.shape[0]K = W.shape[1]W = W.to(torch.float32)scales = S.unsqueeze(2).repeat(1, 1, group_size).view(N, -1)[:, :K]zeros = Z.unsqueeze(2).repeat(1, 1, group_s... | 1 | 8 | 7 | 125 | 0 | 78 | 89 | 78 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_reference_linear_lowbit_quant_weights) defined within the public class called public.The function start at line 78 and ends at 89. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 7 parameters, represented as [78.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | test_linear | def test_linear(self, nbit, M=1, K=32, N=32, group_size=32):print(f"nbit: {nbit}, M: {M}, K: {K}, N: {N}, group_size: {group_size}")A, W, S, Z = self._init_tensors(group_size, M, K, N, nbit=nbit)packing_op = getattr(torch.ops.torchao, f"_pack_weight_{nbit}bit")linear_op = getattr(torch.ops.torchao, f"_linear_fp_act_{nb... | 1 | 11 | 6 | 169 | 0 | 92 | 102 | 92 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (test_linear) defined within the public class called public.The function start at line 92 and ends at 102. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [92.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _model_setup | def _model_setup(self):group_size = 32k0 = 96k1 = 224k2 = 160n = 44layers = [torch.nn.Linear(k0, k1, bias=False),torch.nn.Linear(k1, k2, bias=False),torch.nn.Linear(k2, n, bias=False),]model = torch.nn.Sequential(*layers)return model, group_size, k0, n | 1 | 13 | 1 | 88 | 0 | 48 | 60 | 48 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_model_setup) defined within the public class called public.The function start at line 48 and ends at 60. It contains 13 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 | _quantize_model | def _quantize_model(self, model, precision, nbit, group_size):quantizer = UIntxWeightOnlyLinearQuantizer(device="mps",precision=precision,bitwidth=nbit,groupsize=group_size,)quantized_model = copy.deepcopy(model)quantized_model = quantizer.quantize(quantized_model)return quantized_model | 1 | 10 | 5 | 52 | 0 | 62 | 71 | 62 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_quantize_model) defined within the public class called public.The function start at line 62 and ends at 71. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [62.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | test_export | def test_export(self, nbit):model, group_size, k0, n = self._model_setup()m = 3activations = torch.randn(m, k0, dtype=torch.float32, device="mps")quantized_model = self._quantize_model(model, torch.float32, nbit, group_size)exported = torch.export.export(quantized_model, (activations,), strict=True)for node in exported... | 3 | 12 | 2 | 108 | 0 | 74 | 87 | 74 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (test_export) defined within the public class called public.The function start at line 74 and ends at 87. It contains 12 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [74.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | test_export_accuracy | def test_export_accuracy(self, nbit):group_size = 32m = 3n = 12k = 64with torch.no_grad():activations = torch.rand(m, k, dtype=torch.float32, device="mps")model = torch.nn.Sequential(*[torch.nn.Linear(k, n, bias=False)])# Compute expected resultweight_cpu = model[0].weight.dataweight_qvals_cpu, weight_scales_cpu, weigh... | 1 | 28 | 2 | 216 | 0 | 90 | 123 | 90 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (test_export_accuracy) defined within the public class called public.The function start at line 90 and ends at 123. It contains 28 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [90.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | test_2d_output_device_and_shape | def test_2d_output_device_and_shape(self, nbit):model, group_size, k0, n = self._model_setup()m = 3activations = torch.randn(m, k0, dtype=torch.float32, device="mps")quantized_model = self._quantize_model(model, torch.float32, nbit, group_size)result = quantized_model(activations)self.assertTrue(result.is_mps)self.asse... | 1 | 8 | 2 | 87 | 0 | 126 | 134 | 126 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (test_2d_output_device_and_shape) defined within the public class called public.The function start at line 126 and ends at 134. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [126.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | test_3d_output_device_and_shape | def test_3d_output_device_and_shape(self, nbit):model, group_size, k0, n = self._model_setup()leading_shape = (3, 5)activations = torch.randn(*leading_shape, k0, dtype=torch.float32, device="mps")quantized_model = self._quantize_model(model, torch.float32, nbit, group_size)result = quantized_model(activations)self.asse... | 1 | 8 | 2 | 93 | 0 | 137 | 145 | 137 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (test_3d_output_device_and_shape) defined within the public class called public.The function start at line 137 and ends at 145. It contains 8 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 | test_valid_groupsizes | def test_valid_groupsizes(self, nbit, group_size):k0 = 3 * group_sizek1 = 7 * group_sizen = 44layers = [torch.nn.Linear(k0, k1, bias=False),torch.nn.Linear(k1, n, bias=False),]model = torch.nn.Sequential(*layers)m = 5activations = torch.randn(m, k0, dtype=torch.float32, device="mps")quantized_model = self._quantize_mod... | 1 | 15 | 3 | 134 | 0 | 148 | 163 | 148 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (test_valid_groupsizes) defined within the public class called public.The function start at line 148 and ends at 163. It contains 15 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [148.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | test_invalid_groupsizes | def test_invalid_groupsizes(self, nbit):group_size = 16k0 = 3 * group_sizek1 = 7 * group_sizen = 44layers = [torch.nn.Linear(k0, k1, bias=False),torch.nn.Linear(k1, n, bias=False),]model = torch.nn.Sequential(*layers)with self.assertRaises(ValueError):self._quantize_model(model, torch.float32, nbit, group_size) | 1 | 12 | 2 | 90 | 0 | 166 | 178 | 166 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (test_invalid_groupsizes) defined within the public class called public.The function start at line 166 and ends at 178. It contains 12 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [166.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _reference_linear_lowbit_quant_weights | def _reference_linear_lowbit_quant_weights(self, A, W, group_size, S, Z):N = W.shape[0]K = W.shape[1]W = W.to(torch.float32)scales = S.unsqueeze(2).repeat(1, 1, group_size).view(N, -1)[:, :K]zeros = Z.unsqueeze(2).repeat(1, 1, group_size).view(N, -1)[:, :K]W = scales * W + zerosreturn torch.mm(A, W.t()) | 1 | 8 | 6 | 123 | 0 | 181 | 188 | 181 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_reference_linear_lowbit_quant_weights) defined within the public class called public.The function start at line 181 and ends at 188. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [181.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | test_accuracy | def test_accuracy(self, nbit):print(f"nbit: {nbit}")group_size = 32m = 3n = 12k = 64with torch.no_grad():activations = torch.rand(m, k, dtype=torch.float32, device="mps")model = torch.nn.Sequential(*[torch.nn.Linear(k, n, bias=False)])quantized_model = self._quantize_model(model, torch.float32, nbit, group_size)result ... | 1 | 26 | 2 | 182 | 0 | 191 | 220 | 191 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (test_accuracy) defined within the public class called public.The function start at line 191 and ends at 220. It contains 26 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 | short_str | def short_str(self):if self is ScalingType.DYNAMIC:return "dyn"else:assert self is ScalingType.DISABLEDreturn "dis" | 2 | 6 | 1 | 24 | 0 | 25 | 30 | 25 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (short_str) defined within the public class called public.The function start at line 25 and ends at 30. It contains 6 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | short_str | def short_str(self):if self is ScalingType.DYNAMIC:return "dyn"else:assert self is ScalingType.DISABLEDreturn "dis" | 2 | 6 | 1 | 24 | 0 | 44 | 49 | 25 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (short_str) defined within the public class called public.The function start at line 44 and ends at 49. It contains 6 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __post_init__ | def __post_init__(self):if torch.version.hip and torch.cuda.is_available() and is_MI300():self.e4m3_dtype = torch.float8_e4m3fnuzself.e5m2_dtype = torch.float8_e5m2fnuz | 4 | 4 | 1 | 38 | 0 | 66 | 69 | 66 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__post_init__) defined within the public class called public.The function start at line 66 and ends at 69. It contains 4 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 | short_str | def short_str(self):if self is ScalingType.DYNAMIC:return "dyn"else:assert self is ScalingType.DISABLEDreturn "dis" | 1 | 3 | 1 | 24 | 0 | 88 | 90 | 25 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (short_str) defined within the public class called public.The function start at line 88 and ends at 90. 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 | __post_init__ | def __post_init__(self):if self.scaling_granularity is ScalingGranularity.AXISWISE:assert self.scaling_type is ScalingType.DYNAMIC, ("only dynamic scaling type is supported for axiswise scaling granularity")assert self.target_dtype is None or (self.target_dtype.is_floating_point and self.target_dtype.itemsize == 1), "m... | 4 | 8 | 1 | 50 | 0 | 92 | 99 | 92 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__post_init__) defined within the public class called public.The function start at line 92 and ends at 99. It contains 8 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 | __post_init__ | def __post_init__(self):# Populate the additional cast overrides, if the user did not specify them# Note: this hacks around the frozen-ness of this dataclass# by using `object.__setattr__`.This is fine, as what we really need# is for this object to be frozen after `__post_init__` for torch.compile# to work.# Source of ... | 10 | 51 | 1 | 275 | 0 | 207 | 273 | 207 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__post_init__) defined within the public class called public.The function start at line 207 and ends at 273. It contains 51 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 | from_recipe_name | def from_recipe_name(recipe_name: Union[Float8LinearRecipeName, str],) -> "Float8LinearConfig":"""Input: `Float8LinearRecipeName` value, or a string representing a `Float8LinearRecipeName` valueOutput: a `Float8LinearConfig` configured to implement the specified recipe"""if type(recipe_name) == str:valid_names = [n.val... | 6 | 49 | 1 | 245 | 0 | 276 | 340 | 276 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (from_recipe_name) defined within the public class called public.The function start at line 276 and ends at 340. It contains 49 lines of code and it has a cyclomatic complexity of 6. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | tensor_already_casted_to_fp8 | def tensor_already_casted_to_fp8(tensor: torch.Tensor) -> bool:"""Check if the tensor is already casted to fp8, works if the localtensor is wrapped in DTensor."""if isinstance(tensor, Float8TrainingTensor):return Trueelif isinstance(tensor, DTensor):# TODO: shall we stick to public API and directly use tensor.to_local(... | 4 | 8 | 1 | 56 | 0 | 14 | 27 | 14 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (tensor_already_casted_to_fp8) defined within the public class called public.The function start at line 14 and ends at 27. It contains 8 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 | forward | def forward(ctx,input_hp: torch.Tensor,weight_hp_t: torch.Tensor,linear_mm_config: LinearMMConfig,config: Float8LinearConfig,):ctx.save_for_backward(input_hp, weight_hp_t)ctx.linear_mm_config = linear_mm_configctx.config = configc = configif tensor_already_casted_to_fp8(input_hp):input_maybe_fp8 = input_hpelif c.cast_c... | 5 | 48 | 5 | 248 | 0 | 38 | 91 | 38 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 38 and ends at 91. It contains 48 lines of code and it has a cyclomatic complexity of 5. It takes 5 parameters, represented as [38.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | backward | def backward(ctx, grad_output):input_hp, weight_hp_t = ctx.saved_tensorsc = ctx.config# the reshapes are needed in order to make the shapes compatible with# torch.mmgrad_output_orig_shape = grad_output.shapegrad_output_reshaped = grad_output.reshape(-1, grad_output_orig_shape[-1])## calculate grad_input#if tensor_alrea... | 9 | 87 | 2 | 431 | 0 | 94 | 204 | 94 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (backward) defined within the public class called public.The function start at line 94 and ends at 204. It contains 87 lines of code and it has a cyclomatic complexity of 9. It takes 2 parameters, represented as [94.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, *args, **kwargs):"""Additional arguments on top of `torch.nn.Linear`'s arguments:* `config`: Float8LinearConfig"""config = kwargs.pop("config")super().__init__(*args, **kwargs)# Defines the scaling behavior of input, weight, grad_outputself.scaling_type_input = config.cast_config_input.scaling_typese... | 1 | 27 | 3 | 143 | 0 | 216 | 253 | 216 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 216 and ends at 253. It contains 27 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [216.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(self, input: torch.Tensor) -> torch.Tensor:# Duplicate the autocast logic for F.linear, so that the output# of our module has the right original precisionif torch.is_autocast_enabled():# For now, hardcode to GPU's autocast dtype# if we need CPU support in the future, we can add itautocast_dtype = torch.get_... | 3 | 13 | 2 | 86 | 0 | 255 | 273 | 255 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 255 and ends at 273. It contains 13 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [255.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | extra_repr | def extra_repr(self):c = self.configci = f"i:{c.cast_config_input.short_str()}"cw = f"w:{c.cast_config_weight.short_str()}"cgo = f"go:{c.cast_config_grad_output.short_str()}"parts = [ci, cw, cgo]if c.cast_config_input_for_grad_weight != c.cast_config_input:parts.append(f"i_gw:{c.cast_config_input_for_grad_weight.short_... | 4 | 17 | 1 | 93 | 0 | 275 | 291 | 275 | 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 275 and ends at 291. It contains 17 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 | from_float | def from_float(cls,mod,config: Optional[Float8LinearConfig] = None,):"""Create an nn.Linear with fp8 compute from a regular nn.LinearArgs:mod (torch.nn.Linear): nn.Linear to convertconfig (Optional[Float8LinearConfig]): configuration for conversion to float8"""if config is None:config = Float8LinearConfig()with torch.d... | 3 | 27 | 3 | 127 | 0 | 294 | 335 | 294 | 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 294 and ends at 335. It contains 27 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [294.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | swap_linear_layers.post_order_traversal | def post_order_traversal(module: nn.Module,cur_fqn: Optional[str] = None,parent_module: Optional[nn.Module] = None,):if cur_fqn is None:cur_fqn = ""for child_module_name, child_module in module.named_children():if cur_fqn == "":new_fqn = child_module_nameelse:new_fqn = f"{cur_fqn}.{child_module_name}"post_order_travers... | 7 | 22 | 3 | 130 | 0 | 56 | 80 | 56 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (swap_linear_layers.post_order_traversal) defined within the public class called public.The function start at line 56 and ends at 80. It contains 22 lines of code and it has a cyclomatic complexity of 7. It takes 3 parameters, represented as [56.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | swap_linear_layers | def swap_linear_layers(module: nn.Module,from_float_func: Callable[[nn.Linear], nn.Linear],*,module_filter_fn: Optional[Callable[[nn.Module, str], bool]] = None,) -> nn.Module:"""Generic function to swap linear layers in a module with a new type of linear layer.Note:If applied to a root-level nn.Linear, the module will... | 5 | 20 | 4 | 113 | 5 | 20 | 83 | 20 | null | ['new_linear_module', 'cur_fqn', 'new_fqn', 'root_module', 'cur_module_name'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (swap_linear_layers) defined within the public class called public.The function start at line 20 and ends at 83. It contains 20 lines of code and it has a cyclomatic complexity of 5. It takes 4 parameters, represented as [20.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | convert_to_float8_training | def convert_to_float8_training(module: nn.Module,*,module_filter_fn: Optional[Callable[[nn.Module, str], bool]] = None,config: Optional[Float8LinearConfig] = None,) -> nn.Module:"""Swaps `torch.nn.Linear` in `module` with `Float8Linear`.Args:module: Module to modify.module_filter_fn: If specified, only the `torch.nn.Li... | 2 | 18 | 4 | 92 | 2 | 86 | 118 | 86 | null | ['config', 'from_float'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (convert_to_float8_training) defined within the public class called public.The function start at line 86 and ends at 118. It contains 18 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [86.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _auto_filter_for_recipe | def _auto_filter_for_recipe(recipe: Union[str, Float8LinearRecipeName], filter_fqns: List[str]) -> Callable[[nn.Module, str], bool]:"""Returns function which automatically filters nn.Linear modules that meet at least one of the following criteria:1. Dims not divisible by 16 (hardware requirement for float8).2. Dim size... | 5 | 13 | 2 | 100 | 1 | 121 | 146 | 121 | null | ['recipe'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_auto_filter_for_recipe) defined within the public class called public.The function start at line 121 and ends at 146. It contains 13 lines of code and it has a cyclomatic complexity of 5. It takes 2 parameters, represented as [121.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _auto_filter_for_rowwise | def _auto_filter_for_rowwise(mod: nn.Module, fqn: str, filter_fqns: List[str]) -> bool:if not isinstance(mod, nn.Linear):return False# If the fqn matches any filtered fqn, then we should not convert this module.is_filtered_fqn = any(filter_fqn in fqn for filter_fqn in filter_fqns)if is_filtered_fqn:return False# All di... | 10 | 17 | 3 | 107 | 2 | 149 | 174 | 149 | null | ['dims_multiples_of_16', 'is_filtered_fqn'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_auto_filter_for_rowwise) defined within the public class called public.The function start at line 149 and ends at 174. It contains 17 lines of code and it has a cyclomatic complexity of 10. It takes 3 parameters, represented as [149.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _auto_filter_for_tensorwise | def _auto_filter_for_tensorwise(mod: nn.Module, fqn: str, filter_fqns: List[str]) -> bool:if not isinstance(mod, nn.Linear):return False# If the fqn matches any filtered fqn, then we should not convert this module.is_filtered_fqn = any(filter_fqn in fqn for filter_fqn in filter_fqns)if is_filtered_fqn:return False# All... | 8 | 15 | 3 | 93 | 2 | 177 | 200 | 177 | null | ['dims_multiples_of_16', 'is_filtered_fqn'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_auto_filter_for_tensorwise) defined within the public class called public.The function start at line 177 and ends at 200. It contains 15 lines of code and it has a cyclomatic complexity of 8. It takes 3 parameters, represented as [177.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | addmm_float8_unwrapped | def addmm_float8_unwrapped(a_data: torch.Tensor,a_scale: torch.Tensor,b_data: torch.Tensor,b_scale: torch.Tensor,output_dtype: torch.dtype,output_scale: Optional[torch.Tensor] = None,bias: Optional[torch.Tensor] = None,use_fast_accum: bool = False,) -> torch.Tensor:"""This is the unwrapped version of addmm_float8, whic... | 11 | 45 | 8 | 263 | 9 | 28 | 91 | 28 | null | ['a_inverse_scale', 'output', 'is_rowwise_scaling', 'bias', 'output_dtype', 'post_bias', 'b_inverse_scale', 'post_inverse_scale', 'orig_dtype'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (addmm_float8_unwrapped) defined within the public class called public.The function start at line 28 and ends at 91. It contains 45 lines of code and it has a cyclomatic complexity of 11. It takes 8 parameters, represented as [28.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _assert_tensorwise_scale | def _assert_tensorwise_scale(aten_op, scale):assert (# TODO(future PR): figure out why tensorwise scaling can have# both rank 0 and rank 1len(scale.shape) in (0, 1)), f"{aten_op} with axiswise scaling is not supported yet" | 1 | 4 | 2 | 25 | 0 | 94 | 99 | 94 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_assert_tensorwise_scale) defined within the public class called public.The function start at line 94 and ends at 99. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [94.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | implements.decorator | def decorator(func):for op in aten_ops:if op in FLOAT8_OPS_TABLE:raise RuntimeError(f"Float8 op {op} is already registered to {FLOAT8_OPS_TABLE[op].__name__}")FLOAT8_OPS_TABLE[op] = funcreturn func | 3 | 8 | 1 | 29 | 0 | 105 | 112 | 105 | 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 105 and ends at 112. 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 | implements | def implements(aten_ops):"""Register aten ops to the float8 op table"""def decorator(func):for op in aten_ops:if op in FLOAT8_OPS_TABLE:raise RuntimeError(f"Float8 op {op} is already registered to {FLOAT8_OPS_TABLE[op].__name__}")FLOAT8_OPS_TABLE[op] = funcreturn funcreturn decorator | 1 | 3 | 1 | 10 | 0 | 102 | 114 | 102 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (implements) defined within the public class called public.The function start at line 102 and ends at 114. 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 | float8_desugar_op | def float8_desugar_op(aten_op, args, kwargs=None):_assert_tensorwise_scale(aten_op, args[0]._scale)new_data = aten_op(args[0]._data, *args[1:], **kwargs)return Float8TrainingTensor(new_data,args[0]._scale,args[0]._orig_dtype,args[0]._linear_mm_config,args[0]._gemm_input_role,) | 1 | 10 | 3 | 77 | 1 | 127 | 136 | 127 | null | ['new_data'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (float8_desugar_op) defined within the public class called public.The function start at line 127 and ends at 136. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [127.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | float8_desugar_data_and_scale_op | def float8_desugar_data_and_scale_op(aten_op, args, kwargs=None):new_data = aten_op(args[0]._data, *args[1:], **kwargs)new_scale = aten_op(args[0]._scale, *args[1:], **kwargs)return Float8TrainingTensor(new_data,new_scale,args[0]._orig_dtype,args[0]._linear_mm_config,args[0]._gemm_input_role,) | 1 | 10 | 3 | 82 | 2 | 144 | 153 | 144 | null | ['new_data', 'new_scale'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (float8_desugar_data_and_scale_op) defined within the public class called public.The function start at line 144 and ends at 153. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [144.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | float8_transpose | def float8_transpose(aten_op, args, kwargs=None):new_data = aten_op(args[0]._data, *args[1:], **kwargs)if args[0]._scale.ndim > 1:new_scale = aten_op(args[0]._scale, *args[1:], **kwargs)else:new_scale = args[0]._scaleif aten_op == aten.transpose.int:_assert_tensorwise_scale(aten_op, args[0]._scale)old_axiswise_dim = ar... | 5 | 23 | 3 | 157 | 4 | 162 | 187 | 162 | null | ['old_axiswise_dim', 'new_data', 'new_axiswise_dim', 'new_scale'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (float8_transpose) defined within the public class called public.The function start at line 162 and ends at 187. It contains 23 lines of code and it has a cyclomatic complexity of 5. It takes 3 parameters, represented as [162.0] and does not return any value.. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.