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 | write_history_to_csv | def write_history_to_csv(history, output_file, keyword):# keyword example: ['cal_PPL', 'cal_throughput', 'config']with open(output_file, mode="w", newline="") as file:writer = csv.writer(file)# Write the header rowwriter.writerow(keyword)for eval_results, config in history:obj1 = eval_results[keyword[0]][0]obj2 = eval_... | 2 | 8 | 3 | 82 | 3 | 19 | 32 | 19 | null | ['writer', 'obj1', 'obj2'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (write_history_to_csv) defined within the public class called public.The function start at line 19 and ends at 32. It contains 8 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [19.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | quantize_by_fqn_to_config.filter_fn_sen | def filter_fn_sen(child: torch.nn.Module, cur_fqn: str) -> bool:return isinstance(child, torch.nn.Linear) and (fqn in cur_fqn) | 2 | 2 | 2 | 34 | 0 | 45 | 46 | 45 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (quantize_by_fqn_to_config.filter_fn_sen) defined within the public class called public.The function start at line 45 and ends at 46. It contains 2 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [45.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | quantize_by_fqn_to_config | def quantize_by_fqn_to_config(model, device, fqn_to_config):it = iter(fqn_to_config.items())while True:try:k1, v1 = next(it)k2, v2 = next(it)fqn = k1[8:]bit_width, groupsize = v1, v2def filter_fn_sen(child: torch.nn.Module, cur_fqn: str) -> bool:return isinstance(child, torch.nn.Linear) and (fqn in cur_fqn)quantize_(mo... | 3 | 16 | 3 | 85 | 2 | 36 | 54 | 36 | null | ['fqn', 'it'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (quantize_by_fqn_to_config) defined within the public class called public.The function start at line 36 and ends at 54. It contains 16 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [36.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | cal_wikitext_ppl | def cal_wikitext_ppl(model, tokenizer, limit=62):with torch.no_grad():result = evaluate(HFLM(pretrained=model, tokenizer=tokenizer, batch_size=1),get_task_dict("wikitext"),limit=limit,)return result["results"]["wikitext"]["word_perplexity,none"] | 1 | 8 | 3 | 58 | 1 | 58 | 66 | 58 | null | ['result'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (cal_wikitext_ppl) defined within the public class called public.The function start at line 58 and ends at 66. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [58.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | cal_model_size | def cal_model_size(model, fqn_to_config):_sum = 0fqn_cofg_dict = dict()it = iter(fqn_to_config.items())while True:try:k1, v1 = next(it)k2, v2 = next(it)bit_width, groupsize = v1, v2bit_zeropoint = 32bit_scale = 8fqn = k1[8:]fqn_cofg_dict[fqn] = (bit_width, groupsize, bit_zeropoint, bit_scale)except StopIteration:breakf... | 9 | 31 | 2 | 194 | 9 | 70 | 103 | 70 | null | ['fqn_cofg_dict', '_sum', '_sum_in_GB', '_sum_in_byte', 'fqn', 'it', 'flag', 'bit_zeropoint', 'bit_scale'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (cal_model_size) defined within the public class called public.The function start at line 70 and ends at 103. It contains 31 lines of code and it has a cyclomatic complexity of 9. It takes 2 parameters, represented as [70.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | load_model | def load_model(repo_id, device):tokenizer = AutoTokenizer.from_pretrained(repo_id)model = AutoModelForCausalLM.from_pretrained(repo_id, dtype=torch.bfloat16).to(device=device)return model, tokenizer | 1 | 6 | 2 | 40 | 2 | 106 | 111 | 106 | null | ['tokenizer', 'model'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (load_model) defined within the public class called public.The function start at line 106 and ends at 111. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [106.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | load_parameters_from_json | def load_parameters_from_json(json_path):with open(json_path, "r") as f:config = json.load(f)bitwidth_config = next(param for param in config["parameters"] if param["name"] == "bitwidth")groupsize_config = next(param for param in config["parameters"] if param["name"] == "groupsize")parameters_list = []# Ensure that we ... | 11 | 40 | 1 | 259 | 6 | 114 | 161 | 114 | null | ['groupsize_config', 'config', 'bitwidth_param', 'groupsize_param', 'bitwidth_config', 'parameters_list'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (load_parameters_from_json) defined within the public class called public.The function start at line 114 and ends at 161. It contains 40 lines of code and it has a cyclomatic complexity of 11. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | load_initial_samples | def load_initial_samples(json_path):with open(json_path, "r") as f:config = json.load(f)return config["initial_samples"] | 1 | 4 | 1 | 28 | 1 | 164 | 167 | 164 | null | ['config'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (load_initial_samples) defined within the public class called public.The function start at line 164 and ends at 167. 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 | get_layer_parent_by_name | def get_layer_parent_by_name(model: nn.Module, input_name: str) -> nn.Module:parent_name = input_name.rsplit(".", 1)[:-1]if len(parent_name) == 0:# parent is model itselfreturn modelelse:parent_name = parent_name[0]for name, module in model.named_modules():if parent_name == name:return moduleraise ValueError(f"Layer {i... | 4 | 10 | 2 | 74 | 1 | 55 | 65 | 55 | null | ['parent_name'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_layer_parent_by_name) defined within the public class called public.The function start at line 55 and ends at 65. It contains 10 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [55.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | quantize_module_swap | def quantize_module_swap(model: nn.Module, recipe: QuantizationRecipe, dtype: torch.dtype = torch.float32) -> nn.Module:model = replace_all_linear_with_quantized_linear(model, recipe)if recipe.embedding_quantization:model = replace_all_embedding_with_quantized(model, recipe)initialize_model_parameters(model, recipe, dt... | 2 | 8 | 3 | 58 | 1 | 69 | 76 | 69 | null | ['model'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (quantize_module_swap) defined within the public class called public.The function start at line 69 and ends at 76. It contains 8 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [69.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | replace_all_embedding_with_quantized | def replace_all_embedding_with_quantized(model: nn.Module, recipe: QuantizationRecipe) -> nn.Module:for name, module in model.named_modules():if isinstance(module, nn.Embedding):if name in recipe.exclude_layers:logger.info(f"skip layer {name} in exclude list")else:quantized_embedding = QuantizedEmbedding(num_embeddings... | 4 | 28 | 2 | 174 | 3 | 79 | 107 | 79 | null | ['parent_of_module', 'attribute_name', 'quantized_embedding'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (replace_all_embedding_with_quantized) defined within the public class called public.The function start at line 79 and ends at 107. It contains 28 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [79.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | replace_all_linear_with_quantized_linear | def replace_all_linear_with_quantized_linear(model: nn.Module, recipe: QuantizationRecipe) -> nn.Module:for name, module in model.named_modules():if isinstance(module, nn.Linear):if name in recipe.exclude_layers:logger.info(f"skip layer {name} in exclude list")else:if recipe.weight_codebook:weight_quantizer = CodeBookQ... | 5 | 42 | 2 | 241 | 4 | 110 | 155 | 110 | null | ['parent_of_module', 'attribute_name', 'quantized_linear', 'weight_quantizer'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (replace_all_linear_with_quantized_linear) defined within the public class called public.The function start at line 110 and ends at 155. It contains 42 lines of code and it has a cyclomatic complexity of 5. It takes 2 parameters, represented as [110.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | initialize_model_parameters | def initialize_model_parameters(model: nn.Module, recipe: QuantizationRecipe, dtype: torch.dtype = torch.float32) -> None:"""Initialize the model weights and/or codebook if codebook quantization is used"""if not recipe.dynamic_weights:set_weight_min_max(model)if recipe.weight_codebook:kmeans_codebook(model, dtype=dtype... | 3 | 7 | 3 | 49 | 0 | 158 | 167 | 158 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (initialize_model_parameters) defined within the public class called public.The function start at line 158 and ends at 167. It contains 7 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [158.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | set_weight_scale_to_min_max | def set_weight_scale_to_min_max(self) -> None:if not self.weight_quantizer.dynamic:self.weight_quantizer.set_scale_offset_to_min_max(self.weight)else:raise ValueError("Weights are quantized dynamically, no range/scale is used") | 2 | 7 | 1 | 32 | 0 | 17 | 23 | 17 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (set_weight_scale_to_min_max) defined within the public class called public.The function start at line 17 and ends at 23. It contains 7 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | weight_scale | def weight_scale(self) -> torch.Tensor:return self.weight_quantizer.scale | 1 | 2 | 1 | 15 | 0 | 26 | 27 | 26 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (weight_scale) defined within the public class called public.The function start at line 26 and ends at 27. 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 | quantized_weight | def quantized_weight(self) -> torch.Tensor:return self.weight_quantizer(self.weight) | 1 | 2 | 1 | 18 | 0 | 30 | 31 | 30 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (quantized_weight) defined within the public class called public.The function start at line 30 and ends at 31. 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,activation_bits: int,weight_quantizer: SupportedQuantizers,input_quantization: bool = True,output_quantization: bool = False,activation_group_size: Union[int, str] = "per_token",weight_quantization: bool = True,activation_quantization: bool = True,dynamic_activations: bool = True,range_learning: bool ... | 4 | 54 | 13 | 292 | 0 | 35 | 94 | 35 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 35 and ends at 94. It contains 54 lines of code and it has a cyclomatic complexity of 4. It takes 13 parameters, represented as [35.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(self, input: torch.Tensor) -> torch.Tensor:x = inputif self.input_quantization:assert self.input_quantizer is not Noneself.input_quantizer.quantize = self.activation_quantizationx = self.input_quantizer(x)for transform in self.pre_transforms:x = transform(x)if self.weight_quantization:weight = self.quantize... | 6 | 20 | 2 | 135 | 0 | 96 | 121 | 96 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 96 and ends at 121. It contains 20 lines of code and it has a cyclomatic complexity of 6. It takes 2 parameters, represented as [96.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | validate_group_sizes | def validate_group_sizes(weight_group_size: Union[int, str],activation_group_size: Union[int, str],dynamic_activations: bool,) -> Tuple[Union[int, str], Union[int, str]]:assert (isinstance(weight_group_size, int)or weight_group_size in __supported_group_size_strings__)if weight_group_size == "per_token":raise ValueErro... | 7 | 22 | 3 | 106 | 0 | 124 | 147 | 124 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (validate_group_sizes) defined within the public class called public.The function start at line 124 and ends at 147. It contains 22 lines of code and it has a cyclomatic complexity of 7. It takes 3 parameters, represented as [124.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __repr__ | def __repr__(self) -> str:output_string = "QuantizedLinear("empty_space = " " * len(output_string)output_string += (f"weight_quantizer={self.weight_quantizer} - {self.weight_quantization}, \n")if self.input_quantizer is not None:output_string += (empty_space+ f"input_quant={self.input_quantizer} - {self.activation_quan... | 5 | 23 | 1 | 91 | 0 | 149 | 171 | 149 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__repr__) defined within the public class called public.The function start at line 149 and ends at 171. It contains 23 lines of code and it has a cyclomatic complexity of 5. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self,num_bits: int,group_size: Union[int, str],quantization_mode: str,range_learning: bool = False,scale_eps: float = 1e-9,dynamic_weights: bool = False,*args,**kwargs,) -> None:super().__init__(*args, **kwargs)self.weight_quantizer = IntQuantizer(num_bits=num_bits,group_size=group_size,dynamic=dynamic_wei... | 2 | 25 | 9 | 125 | 0 | 175 | 200 | 175 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 175 and ends at 200. It contains 25 lines of code and it has a cyclomatic complexity of 2. It takes 9 parameters, represented as [175.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(self, input: torch.Tensor) -> torch.Tensor:if self.weight_quantization:weight = self.weight_quantizer(self.weight)else:weight = self.weightreturn torch.nn.functional.embedding(input,weight,self.padding_idx,self.max_norm,self.norm_type,self.scale_grad_by_freq,self.sparse,) | 2 | 14 | 2 | 71 | 0 | 202 | 216 | 202 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 202 and ends at 216. It contains 14 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [202.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(ctx, x: torch.Tensor) -> torch.Tensor:return torch.round(x) | 1 | 2 | 2 | 22 | 0 | 12 | 13 | 12 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 12 and ends at 13. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [12.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | backward | def backward(ctx, output_grad: torch.Tensor) -> torch.Tensor:return output_grad | 1 | 2 | 2 | 17 | 0 | 16 | 17 | 16 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (backward) defined within the public class called public.The function start at line 16 and ends at 17. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [16.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self,num_bits: int,group_size: Union[int, str],dynamic: bool,quantization_mode: str,range_learning: bool = False,scale_eps: float = 1e-9,) -> None:super().__init__()self.num_bits = num_bitsself.group_size = group_sizeself.dynamic = dynamicself.quantization_mode = quantization_modeself.scale_eps = scale_eps... | 1 | 20 | 7 | 122 | 0 | 21 | 41 | 21 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 21 and ends at 41. It contains 20 lines of code and it has a cyclomatic complexity of 1. It takes 7 parameters, represented as [21.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(self, x: torch.Tensor) -> torch.Tensor:if not self.quantize:return xq_min, q_max = self.get_qmin_qmax(self.num_bits, self.quant_mode_to_signed(self.quantization_mode))if self.dynamic:scale, offset = IntQuantizer.get_scale_offset(x,self.group_size,self.quantization_mode,q_min,q_max,)else:scale = self.scaleof... | 6 | 33 | 2 | 179 | 0 | 43 | 81 | 43 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 43 and ends at 81. It contains 33 lines of code and it has a cyclomatic complexity of 6. It takes 2 parameters, represented as [43.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | q_min | def q_min(self) -> int:q_min, _ = self.get_qmin_qmax(self.num_bits, self.quant_mode_to_signed(self.quantization_mode))return q_min | 1 | 5 | 1 | 30 | 0 | 84 | 88 | 84 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (q_min) defined within the public class called public.The function start at line 84 and ends at 88. 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 | q_max | def q_max(self) -> int:_, q_max = self.get_qmin_qmax(self.num_bits, self.quant_mode_to_signed(self.quantization_mode))return q_max | 1 | 5 | 1 | 30 | 0 | 91 | 95 | 91 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (q_max) defined within the public class called public.The function start at line 91 and ends at 95. 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 | quant_mode_to_signed | def quant_mode_to_signed(quant_mode: str) -> bool:if quant_mode == "symmetric":return Trueelif quant_mode == "asymmetric":return Falseelse:raise NotImplementedError | 3 | 7 | 1 | 27 | 0 | 98 | 104 | 98 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (quant_mode_to_signed) defined within the public class called public.The function start at line 98 and ends at 104. It contains 7 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_scale_param_size | def get_scale_param_size(x: torch.Tensor, group_size: Union[int, str]) -> torch.Size:int_group_size = IntQuantizer.process_group_size_to_int(group_size, x)if int_group_size is None:return torch.Size([1])else:if len(x.shape) == 1:return torch.Size([x.shape[0] // int_group_size])else:size_list = [x.shape[i] for i in rang... | 4 | 13 | 2 | 116 | 0 | 107 | 119 | 107 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_scale_param_size) defined within the public class called public.The function start at line 107 and ends at 119. It contains 13 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [107.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_qmin_qmax | def get_qmin_qmax(n_bits: int, signed: bool) -> Tuple[int, int]:if signed:qmin = -(2 ** (n_bits - 1))qmax = 2 ** (n_bits - 1) - 1else:qmin = 0qmax = 2**n_bits - 1return qmin, qmax | 2 | 8 | 2 | 60 | 0 | 122 | 129 | 122 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_qmin_qmax) defined within the public class called public.The function start at line 122 and ends at 129. It contains 8 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [122.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_scale_offset | def get_scale_offset(x: torch.Tensor,group_size: Union[int, str],quantization_mode: str,q_min: int,q_max: int,scale_eps: float = 1e-9,) -> Tuple[torch.Tensor, Optional[torch.Tensor]]:if not isinstance(group_size, int) and group_size == "per_tensor":x_min = torch.min(x)x_max = torch.max(x)else:int_group_size = IntQuanti... | 5 | 31 | 6 | 212 | 0 | 132 | 164 | 132 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_scale_offset) defined within the public class called public.The function start at line 132 and ends at 164. It contains 31 lines of code and it has a cyclomatic complexity of 5. It takes 6 parameters, represented as [132.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | quantize_forward | def quantize_forward(x: torch.Tensor,scale: torch.Tensor,offset: Optional[torch.Tensor],q_min: int,q_max: int,group_size: Optional[int] = None,) -> torch.Tensor:# if quantization is per_group, we need to reshape the tensor to apply it overreshaped = Falseorig_shape = x.shapeif group_size is not None and group_size != x... | 9 | 34 | 6 | 253 | 0 | 167 | 207 | 167 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (quantize_forward) defined within the public class called public.The function start at line 167 and ends at 207. It contains 34 lines of code and it has a cyclomatic complexity of 9. It takes 6 parameters, represented as [167.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | process_group_size_to_int | def process_group_size_to_int(group_size: Union[int, str], x: torch.Tensor) -> Optional[int]:if isinstance(group_size, int):return group_sizeelif group_size == "per_channel" or group_size == "per_token":return x.shape[-1]elif group_size == "per_tensor":return Noneelse:raise NotImplementedError | 5 | 11 | 2 | 61 | 0 | 210 | 220 | 210 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (process_group_size_to_int) defined within the public class called public.The function start at line 210 and ends at 220. It contains 11 lines of code and it has a cyclomatic complexity of 5. It takes 2 parameters, represented as [210.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_scale_from_min_max | def get_scale_from_min_max(x_min: torch.Tensor,x_max: torch.Tensor,q_min: int,q_max: int,eps: float = 1e-9,) -> torch.Tensor:smin = x_min / float(q_min)smax = x_max / float(q_max)mask = smin > smaxscale = torch.where(mask, smin, smax)scale = torch.clamp(scale, min=eps)return scale | 1 | 13 | 5 | 83 | 0 | 223 | 235 | 223 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_scale_from_min_max) defined within the public class called public.The function start at line 223 and ends at 235. It contains 13 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [223.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_scale_offset_from_min_max | def get_scale_offset_from_min_max(x_min: torch.Tensor,x_max: torch.Tensor,q_min: int,q_max: int,eps: float = 1e-9,) -> Tuple[torch.Tensor, torch.Tensor]:scale = ((x_max - x_min) / (abs(q_min) + abs(q_max))).detach()offset = (-x_min / scale).detach()offset = torch.round(offset)offset = torch.clamp(offset, q_min, q_max)s... | 1 | 13 | 5 | 116 | 0 | 238 | 252 | 238 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_scale_offset_from_min_max) defined within the public class called public.The function start at line 238 and ends at 252. It contains 13 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [238.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | set_scale_offset_to_min_max | def set_scale_offset_to_min_max(self, x: torch.Tensor) -> None:assert not self.dynamicx = x.detach()x = x.to(self.quant_dtype)signed = self.quant_mode_to_signed(self.quantization_mode)q_min, q_max = self.get_qmin_qmax(self.num_bits, signed=signed)scale, offset = self.get_scale_offset(x, self.group_size, self.quantizati... | 4 | 24 | 2 | 195 | 0 | 254 | 283 | 254 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (set_scale_offset_to_min_max) defined within the public class called public.The function start at line 254 and ends at 283. It contains 24 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [254.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self,n_bits: int,features: int,codebook_dim: int = 1,seed: int = 1337,) -> None:super().__init__()self.group_size = codebook_dimself.codebook_dim = codebook_dimself.dynamic = Trueself.scale_eps = 1e-9assert features % codebook_dim == 0torch.manual_seed(seed)N = 2 ** (n_bits * codebook_dim)codebook_shape = ... | 1 | 20 | 5 | 124 | 0 | 287 | 308 | 287 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 287 and ends at 308. It contains 20 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [287.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(self, x: torch.Tensor) -> torch.Tensor:scaling_factor = torch.mean(abs(x), dim=1, keepdim=True).detach()output = scaling_factor * VectorQuantizerFunction.apply(x / scaling_factor, self.codebook)return output | 1 | 6 | 2 | 56 | 0 | 310 | 315 | 310 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 310 and ends at 315. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [310.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(ctx, inputs: torch.Tensor, codebook: torch.Tensor) -> torch.Tensor:flat_inputs = inputs.view(-1, codebook.shape[1])distances = torch.cdist(flat_inputs, codebook)indices = torch.argmin(distances, dim=1)sums = torch.zeros_like(codebook).float().cuda()counts = torch.zeros(codebook.size(0), dtype=torch.float).c... | 1 | 13 | 3 | 183 | 0 | 321 | 342 | 321 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 321 and ends at 342. It contains 13 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [321.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | backward | def backward(ctx, grad_output: torch.Tensor) -> Tuple[torch.Tensor, None]:return grad_output, None | 1 | 2 | 2 | 24 | 0 | 346 | 347 | 346 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (backward) defined within the public class called public.The function start at line 346 and ends at 347. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [346.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | set_weight_min_max | def set_weight_min_max(model: nn.Module) -> None:for _, module in model.named_modules():if isinstance(module, QuantizedLinear):module.set_weight_scale_to_min_max() | 3 | 4 | 1 | 35 | 0 | 24 | 27 | 24 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (set_weight_min_max) defined within the public class called public.The function start at line 24 and ends at 27. It contains 4 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 | set_weight_mse | def set_weight_mse(model: nn.Module, num_points: int = 100, max_shrink: float = 0, norm: float = 2.0) -> None:for _, module in model.named_modules():if isinstance(module, QuantizedLinear):loss_fn = lambda m: torch.sum(# noqatorch.pow(torch.abs(m.weight - m.quantized_weight), norm), dim=-1)best_scale = find_optimal_scal... | 3 | 12 | 4 | 103 | 2 | 30 | 41 | 30 | null | ['best_scale', 'loss_fn'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (set_weight_mse) defined within the public class called public.The function start at line 30 and ends at 41. It contains 12 lines of code and it has a cyclomatic complexity of 3. It takes 4 parameters, represented as [30.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_batched_output | def get_batched_output(module: nn.Module, input_data: torch.Tensor, batch_size: int) -> torch.Tensor:device = module.weight.devicedtype = module.weight.dtypenum_samples = input_data.shape[0]num_batches = num_samples // batch_sizeoutput_data = []for i in range(num_batches):this_batch = input_data[i * batch_size : (i + 1... | 2 | 13 | 3 | 118 | 6 | 44 | 59 | 44 | null | ['this_batch', 'num_batches', 'device', 'dtype', 'output_data', 'num_samples'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_batched_output) defined within the public class called public.The function start at line 44 and ends at 59. It contains 13 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [44.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | set_weight_range_activation_loss | def set_weight_range_activation_loss(model: nn.Module,data: torch.Tensor,batch_size: int,num_points: int = 100,progressive: bool = True,data_getter: Optional[DataGetter] = None,) -> None:# store quantization settings so this algorithm does not change those implicitlyquantization_setting_mapping_dict = {name: [module.we... | 12 | 53 | 6 | 363 | 7 | 62 | 128 | 62 | null | ['data_getter_progressive', 'dim', 'best_scale', 'input_data', 'loss_fn', 'output_data', 'quantization_setting_mapping_dict'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (set_weight_range_activation_loss) defined within the public class called public.The function start at line 62 and ends at 128. It contains 53 lines of code and it has a cyclomatic complexity of 12. It takes 6 parameters, represented as [62.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | set_activation_min_max | def set_activation_min_max(model: nn.Module, data: torch.Tensor, batch_size: int) -> None:# store quantization settings so this algorithm does not change those implicitlyquantization_setting_mapping_dict = {name: [module.weight_quantization, module.activation_quantization]for name, module in model.named_modules()if isi... | 10 | 28 | 3 | 196 | 3 | 131 | 162 | 131 | null | ['quantization_setting_mapping_dict', 'input_data', 'output_data'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (set_activation_min_max) defined within the public class called public.The function start at line 131 and ends at 162. It contains 28 lines of code and it has a cyclomatic complexity of 10. It takes 3 parameters, represented as [131.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | find_optimal_scales_with_loss | def find_optimal_scales_with_loss(module: QuantizedLinear,loss_fn: Callable[[nn.Module], torch.Tensor],num_points: int,max_shrink: float = 0,) -> torch.Tensor:assert max_shrink >= 0 and max_shrink < 1.0assert num_points > 0with torch.no_grad():grid = torch.linspace(max_shrink, 1, num_points + 1)module.set_weight_scale_... | 3 | 22 | 4 | 159 | 7 | 165 | 189 | 165 | null | ['best_loss', 'orig_scales', 'test_scale', 'best_scale', 'grid', 'mask', 'loss'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (find_optimal_scales_with_loss) defined within the public class called public.The function start at line 165 and ends at 189. It contains 22 lines of code and it has a cyclomatic complexity of 3. It takes 4 parameters, represented as [165.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | quantize_per_group_scales | def quantize_per_group_scales(model: nn.Module, bit_width: int) -> None:for name, module in model.named_modules():if isinstance(module, QuantizedLinear):scale = module.weight_quantizer.scaleassert isinstance(scale, torch.Tensor)if len(scale.shape) < 2 or scale.shape[-1] == 1:logger.warning(f"Module {name} is not quanti... | 5 | 19 | 2 | 152 | 3 | 192 | 216 | 192 | null | ['scale', 'per_channel_scales', 'quant_max'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (quantize_per_group_scales) defined within the public class called public.The function start at line 192 and ends at 216. It contains 19 lines of code and it has a cyclomatic complexity of 5. It takes 2 parameters, represented as [192.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_layer_by_name | def get_layer_by_name(model: nn.Module, query_name: str) -> nn.Module:"""Retrieves a layer from a PyTorch model by its name.Args:model (nn.Module): The PyTorch model.name (str): The name of the layer to retrieve.Returns:nn.Module: The retrieved layer."""for name, module in model.named_modules():if name == query_name:re... | 3 | 5 | 2 | 42 | 0 | 9 | 23 | 9 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_layer_by_name) defined within the public class called public.The function start at line 9 and ends at 23. It contains 5 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [9.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | all_quantizers_off | def all_quantizers_off(module: nn.Module) -> None:if isinstance(module, QuantizedLinear):module.weight_quantization = Falsemodule.activation_quantization = False | 2 | 4 | 1 | 29 | 0 | 26 | 29 | 26 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (all_quantizers_off) defined within the public class called public.The function start at line 26 and ends at 29. 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 | all_quantizers_on | def all_quantizers_on(module: nn.Module) -> None:if isinstance(module, QuantizedLinear):module.weight_quantization = Truemodule.activation_quantization = True | 2 | 4 | 1 | 29 | 0 | 32 | 35 | 32 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (all_quantizers_on) defined within the public class called public.The function start at line 32 and ends at 35. 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 | all_activation_quantizers_off | def all_activation_quantizers_off(module: nn.Module) -> None:if isinstance(module, QuantizedLinear):module.activation_quantization = False | 2 | 3 | 1 | 24 | 0 | 38 | 40 | 38 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (all_activation_quantizers_off) defined within the public class called public.The function start at line 38 and ends at 40. It contains 3 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | all_activation_quantizers_on | def all_activation_quantizers_on(module: nn.Module) -> None:if isinstance(module, QuantizedLinear):module.activation_quantization = True | 2 | 3 | 1 | 24 | 0 | 43 | 45 | 43 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (all_activation_quantizers_on) defined within the public class called public.The function start at line 43 and ends at 45. It contains 3 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | all_weight_quantizers_on | def all_weight_quantizers_on(module: nn.Module) -> None:if isinstance(module, QuantizedLinear):module.weight_quantization = True | 2 | 3 | 1 | 24 | 0 | 48 | 50 | 48 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (all_weight_quantizers_on) defined within the public class called public.The function start at line 48 and ends at 50. It contains 3 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | set_bit_widths_by_name | def set_bit_widths_by_name(model: nn.Module, bit_width_dict: Dict[str, Dict[str, int]]) -> None:for name, bit_width_assignment in bit_width_dict.items():this_layer = get_layer_by_name(model, name)for quantizer, bit_width in bit_width_assignment.items():assert isinstance(this_layer, QuantizedLinear)if quantizer == "weig... | 7 | 19 | 2 | 126 | 1 | 53 | 71 | 53 | null | ['this_layer'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (set_bit_widths_by_name) defined within the public class called public.The function start at line 53 and ends at 71. It contains 19 lines of code and it has a cyclomatic complexity of 7. It takes 2 parameters, represented as [53.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | kmeans_codebook | def kmeans_codebook(model: nn.Module,niter: int = 30,nredo: int = 1,dtype: torch.dtype = torch.float32,) -> None:import faisswith torch.no_grad():for layer in model.modules():if isinstance(layer, QuantizedLinear):if isinstance(layer.weight_quantizer, CodeBookQuantizer):weight = layer.weightcodebook_dim = layer.weight_q... | 5 | 31 | 4 | 203 | 5 | 8 | 40 | 8 | null | ['num_centroids', 'codebook_dim', 'C', 'kmeans', 'weight'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (kmeans_codebook) defined within the public class called public.The function start at line 8 and ends at 40. It contains 31 lines of code and it has a cyclomatic complexity of 5. It takes 4 parameters, represented as [8.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, model: LlamaForCausalLM, data: torch.Tensor, batch_size: int) -> None:super().__init__()self.initialize(model, data, batch_size) | 1 | 5 | 4 | 38 | 0 | 32 | 36 | 32 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 32 and ends at 36. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [32.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | initialize | def initialize(self, model: nn.Module, data: torch.Tensor, batch_size: int) -> None:assert isinstance(model, LlamaForCausalLM)assert isinstance(data, torch.Tensor)# set attention_mask and/or position_idsself.layer_kwargs: Dict[str, torch.Tensor] = self.get_layer_kwargs(model, data)self.input_data_cache: torch.Tensor = ... | 1 | 15 | 4 | 136 | 0 | 38 | 55 | 38 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (initialize) defined within the public class called public.The function start at line 38 and ends at 55. It contains 15 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [38.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | pop | def pop(self, model: nn.Module, name: str) -> torch.Tensor:assert isinstance(model, LlamaForCausalLM)with torch.no_grad():# special case for the last layerif name != "lm_head":query_layer_idx = int(name.split(".")[2])else:query_layer_idx = len(model.model.layers)assert query_layer_idx >= self.current_layer_idx, ("pop()... | 7 | 35 | 3 | 216 | 0 | 57 | 105 | 57 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (pop) defined within the public class called public.The function start at line 57 and ends at 105. It contains 35 lines of code and it has a cyclomatic complexity of 7. It takes 3 parameters, represented as [57.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_layer_kwargs.__init__ | def __init__(self, module):super().__init__()self.module = module | 1 | 3 | 2 | 19 | 0 | 114 | 116 | 114 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_layer_kwargs.__init__) defined within the public class called public.The function start at line 114 and ends at 116. It contains 3 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 | get_layer_kwargs.forward | def forward(self, inp, **kwargs):if kwargs["attention_mask"] is not None:layer_kwargs["attention_mask"] = kwargs["attention_mask"]if kwargs["position_ids"] is not None:layer_kwargs["position_ids"] = kwargs["position_ids"]raise ValueError | 3 | 6 | 3 | 48 | 0 | 118 | 123 | 118 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_layer_kwargs.forward) defined within the public class called public.The function start at line 118 and ends at 123. It contains 6 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [118.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_layer_kwargs | def get_layer_kwargs(self, model: LlamaForCausalLM, data: torch.Tensor) -> Dict[str, torch.Tensor]:# get used attention_mask and position_idslayer_kwargs: Dict[str, torch.Tensor] = {}class Catcher(nn.Module):def __init__(self, module):super().__init__()self.module = moduledef forward(self, inp, **kwargs):if kwargs["att... | 2 | 15 | 3 | 123 | 0 | 107 | 133 | 107 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_layer_kwargs) defined within the public class called public.The function start at line 107 and ends at 133. It contains 15 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [107.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self) -> None:return | 1 | 2 | 1 | 8 | 0 | 12 | 13 | 12 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 12 and ends at 13. 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 | pop | def pop(self, model: nn.Module, name: str) -> torch.Tensor:raise NotImplementedError() | 1 | 2 | 3 | 23 | 0 | 15 | 16 | 15 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (pop) defined within the public class called public.The function start at line 15 and ends at 16. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [15.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_base_name | def get_base_name(self, name: str) -> str:base_name = name.split(".")[-1]if base_name.isnumeric():base_name = name.split(".")[-2]return base_name | 2 | 5 | 2 | 44 | 0 | 18 | 22 | 18 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_base_name) defined within the public class called public.The function start at line 18 and ends at 22. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [18.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | initialize | def initialize(self, model: nn.Module, data: torch.Tensor, batch_size: int) -> None:raise NotImplementedError() | 1 | 2 | 4 | 27 | 0 | 24 | 25 | 24 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (initialize) defined within the public class called public.The function start at line 24 and ends at 25. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [24.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_module_input_data._input_data_hook | def _input_data_hook(module: nn.Module, input: List[torch.Tensor], output: List[torch.Tensor]) -> None:input_data.append(input[0].detach())assert len(input) == 1raise ExpectedError | 1 | 6 | 3 | 51 | 0 | 45 | 50 | 45 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_module_input_data._input_data_hook) defined within the public class called public.The function start at line 45 and ends at 50. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [45.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_module_input_data | def get_module_input_data(model: nn.Module,data: torch.Tensor,module: nn.Module,batch_size: int,layer_kwargs: Dict[str, torch.Tensor] = {},# noqa) -> torch.Tensor:with torch.no_grad():if isinstance(data, list):num_data = len(data)else:num_data = data.shape[0]num_batches = num_data // batch_sizeassert num_data % batch_s... | 5 | 30 | 5 | 188 | 5 | 28 | 67 | 28 | null | ['num_data', 'num_batches', 'hook', 'this_batch', 'return_data'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_module_input_data) defined within the public class called public.The function start at line 28 and ends at 67. It contains 30 lines of code and it has a cyclomatic complexity of 5. It takes 5 parameters, represented as [28.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | maybe_short_name | def maybe_short_name(torch_fn):"""Tries to format things like'<built-in method cat of type object at 0x7f3f7a202c60>'as'torch.cat'"""if hasattr(torch_fn, "__name__"):# torch.cat -> catif hasattr(torch, torch_fn.__name__):if getattr(torch, torch_fn.__name__) == torch_fn:return torch_fn.__name__# F.layer_norm -> layer_no... | 9 | 15 | 1 | 98 | 0 | 38 | 71 | 38 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (maybe_short_name) defined within the public class called public.The function start at line 38 and ends at 71. It contains 15 lines of code and it has a cyclomatic complexity of 9. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_meta_val | def get_meta_val(n: torch.fx.Node):# from https://github.com/pytorch/pytorch/blob/8d708090c0eb306facfd8f85d58c578a8cbbe689/torch/fx/graph.py#L644-L647meta_val = n.meta.get("val", n.meta.get("tensor_meta", n.meta.get("example_value", None)))return meta_val | 1 | 5 | 1 | 43 | 1 | 74 | 79 | 74 | null | ['meta_val'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_meta_val) defined within the public class called public.The function start at line 74 and ends at 79. 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 | get_stack_summary | def get_stack_summary(n: torch.fx.Node):# from https://github.com/pytorch/pytorch/blob/8d708090c0eb306facfd8f85d58c578a8cbbe689/torch/fx/graph.py#L609if n.stack_trace:parsed_stack_trace = torch.fx.graph._parse_stack_trace(n.stack_trace)summary = parsed_stack_trace.get_summary_str()return summaryreturn None | 2 | 6 | 1 | 41 | 2 | 82 | 88 | 82 | null | ['summary', 'parsed_stack_trace'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_stack_summary) defined within the public class called public.The function start at line 82 and ends at 88. 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 | is_first_node_of_dual_linear | def is_first_node_of_dual_linear(gm: torch.fx.GraphModule, n: torch.fx.Node):first_user = list(n.users.items())[0][0]if first_user.op == "call_module":first_user_mod = getattr(gm, first_user.target)if type(first_user_mod) is torch.nn.Linear:return Trueelif first_user.op == "call_function":if first_user.target is torch.... | 5 | 10 | 2 | 92 | 2 | 91 | 100 | 91 | null | ['first_user', 'first_user_mod'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (is_first_node_of_dual_linear) defined within the public class called public.The function start at line 91 and ends at 100. It contains 10 lines of code and it has a cyclomatic complexity of 5. It takes 2 parameters, represented as [91.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | debug_single_linear.printme | def printme(s):# write both to stdout and log file# print(s)with open(debug_logs_filename, "a") as f:f.write(s + "\n") | 1 | 3 | 1 | 23 | 0 | 110 | 114 | 110 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (debug_single_linear.printme) defined within the public class called public.The function start at line 110 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 | debug_single_linear | def debug_single_linear(gm: torch.fx.GraphModule,linear_node: torch.fx.Node,linear_mod: torch.nn.Module,debug_logs_filename: str,subgraph_idx: int,):def printme(s):# write both to stdout and log file# print(s)with open(debug_logs_filename, "a") as f:f.write(s + "\n")printme(f"\ndebugging linear {linear_node.target} {su... | 14 | 90 | 5 | 483 | 18 | 103 | 211 | 103 | null | ['dual_linear', 'cur_linear_2_weight', 'prev_prev_meta', 'mod', 'prev_node_type', 'subgraph_summary', 'weight_shape', 'prev_input_shape', 'linear_node_2', 'linear_mod_2', 'linear_node_to_use', 'next_node_types', 'linear_str', 'summary_result', 'cur_linear_size', 'cur_linear_weight', 'linear_shape_str', 'cur_linear_2_si... | None | null | 0 | 0 | 0 | null | 0 | null | The function (debug_single_linear) defined within the public class called public.The function start at line 103 and ends at 211. It contains 90 lines of code and it has a cyclomatic complexity of 14. It takes 5 parameters, represented as [103.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | extract_linear_subgraph.prev_node_map_arg | def prev_node_map_arg(old_arg):if isinstance(old_arg, torch.fx.Node):if old_arg in prev_old_arg_to_new_arg:return prev_old_arg_to_new_arg[old_arg]with new_g.inserting_before(new_linear_node):new_arg = new_g.placeholder(old_arg.name)# copy the metadata overnew_arg.meta = old_arg.metaprev_old_arg_to_new_arg[old_arg] = ne... | 3 | 10 | 1 | 62 | 0 | 278 | 289 | 278 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (extract_linear_subgraph.prev_node_map_arg) defined within the public class called public.The function start at line 278 and ends at 289. It contains 10 lines of code and it has a cyclomatic complexity of 3. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | extract_linear_subgraph.next_node_map_arg | def next_node_map_arg(old_arg):if isinstance(old_arg, torch.fx.Node):if old_arg in next_old_arg_to_new_arg:# handle the same arg being used multiple timesreturn next_old_arg_to_new_arg[old_arg]if old_arg == old_linear_node:next_old_arg_to_new_arg[old_arg] = new_linear_nodereturn new_linear_nodeelif old_arg == old_old_l... | 7 | 22 | 1 | 113 | 0 | 385 | 409 | 385 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (extract_linear_subgraph.next_node_map_arg) defined within the public class called public.The function start at line 385 and ends at 409. It contains 22 lines of code and it has a cyclomatic complexity of 7. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | extract_linear_subgraph | def extract_linear_subgraph(old_gm: torch.fx.GraphModule,old_linear_node: torch.fx.Node,old_linear_mod: torch.nn.Module,subgraph_save_filename: str,) -> None:"""Input: a GraphModule with a `linear_node` calling `linear_mod`.This function does the following:* find the subgraph prev_op -> linear_node -> [*next_ops]* crea... | 24 | 156 | 4 | 1,090 | 36 | 214 | 491 | 214 | null | ['first_new_linear_node', 'new_g', 'new_next_n', 'new_arg', 'new_shape2', 'old_shape', 'weight_val', 'old_old_linear_node', 'next_node_is_output', 'new_inputs', 'new_name', 'new_prev_node', 'new_gm', 'new_dual_linear_node', 'old_2nd_linear_node', 'new_shape', 'new_output_nodes', 'cur_output_node', 'new_m', 'prev_old_ar... | None | null | 0 | 0 | 0 | null | 0 | null | The function (extract_linear_subgraph) defined within the public class called public.The function start at line 214 and ends at 491. It contains 156 lines of code and it has a cyclomatic complexity of 24. It takes 4 parameters, represented as [214.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | print_and_append_to_logs | def print_and_append_to_logs(logger, filename, s):logger.debug(s)with open(filename, "a") as f:f.write(s + "\n") | 1 | 4 | 3 | 33 | 0 | 498 | 501 | 498 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (print_and_append_to_logs) defined within the public class called public.The function start at line 498 and ends at 501. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [498.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | prepare_target_folder | def prepare_target_folder(target_folder: str):# ensure target folder existsif not os.path.isdir(target_folder):os.makedirs(target_folder)# ensure target folder only has file extensions we could have writtenfor root, dirs, files in os.walk(target_folder):for file in files:if not (file.endswith(".txt")or file.endswith(".... | 11 | 18 | 1 | 127 | 1 | 504 | 527 | 504 | null | ['DEBUG_LINEARS_CALL_COUNTER'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (prepare_target_folder) defined within the public class called public.The function start at line 504 and ends at 527. It contains 18 lines of code and it has a cyclomatic complexity of 11. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | debug_linears_for_float8.log_skip_linear | def log_skip_linear(n, mod, reason):print_and_append_to_logs(graph_tabular_log, skip_logs_filename, f"SKIP: {reason}")print_and_append_to_logs(graph_tabular_log, skip_logs_filename, f"node: {n.format_node()}")print_and_append_to_logs(graph_tabular_log, skip_logs_filename, f"node.meta: {get_meta_val(n)}")print_and_appen... | 1 | 15 | 3 | 62 | 0 | 587 | 601 | 587 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (debug_linears_for_float8.log_skip_linear) defined within the public class called public.The function start at line 587 and ends at 601. It contains 15 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [587.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | debug_linears_for_float8 | def debug_linears_for_float8(g: torch.fx.Graph,target_folder: str,linear_mod_filter_fn: Optional[Callable] = None,linear_node_filter_fn: Optional[Callable] = None,) -> None:"""This function:1. looks for subgraphs containing `torch.nn.Linear` modules, including the preceding and subsequent ops2. for each found subgraph ... | 19 | 86 | 4 | 472 | 12 | 530 | 685 | 530 | null | ['is_input_placeholder', 'module_instance', 'is_second_linear_of_dual_linear', 'skip_logs_filename', 'subgraph_idx', 'debug_logs_filename', 'summary_result', 'gm', 'module_fqn', 'subgraph_save_filename', 'summary_filename', 'summary_results'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (debug_linears_for_float8) defined within the public class called public.The function start at line 530 and ends at 685. It contains 86 lines of code and it has a cyclomatic complexity of 19. It takes 4 parameters, represented as [530.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | scaled_int8_mm | def scaled_int8_mm(A: Tensor, B: Tensor, row_scale: Tensor, col_scale: Tensor) -> Tensor:return torch._int_mm(A, B) * col_scale.view(-1) * row_scale.view(-1, 1) | 1 | 4 | 4 | 48 | 0 | 35 | 38 | 35 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (scaled_int8_mm) defined within the public class called public.The function start at line 35 and ends at 38. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [35.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __new__ | def __new__(cls, data: Tensor, precomputed_scale: Optional[Tensor] = None):return Tensor._make_wrapper_subclass(cls,data.shape,dtype=data.dtype,device=data.device,) | 1 | 7 | 3 | 42 | 0 | 47 | 53 | 47 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__new__) defined within the public class called public.The function start at line 47 and ends at 53. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [47.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, data: Tensor, precomputed_scale: Optional[Tensor] = None):self._data = dataself._precomputed_scale = precomputed_scale | 1 | 3 | 3 | 28 | 0 | 56 | 58 | 56 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 56 and ends at 58. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [56.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __tensor_flatten__ | def __tensor_flatten__(self):if self._precomputed_scale is not None:return ["_data", "_precomputed_scale"], []else:return ["_data"], [] | 2 | 5 | 1 | 31 | 0 | 60 | 64 | 60 | 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 60 and ends at 64. It contains 5 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __tensor_unflatten__ | def __tensor_unflatten__(cls, tensor_data_dict, tensor_attributes, outer_size=None, outer_stride=None):return cls(tensor_data_dict["_data"],tensor_data_dict.get("_precomputed_scale", None),*tensor_attributes,) | 1 | 8 | 5 | 38 | 0 | 67 | 74 | 67 | 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 67 and ends at 74. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [67.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __repr__ | def __repr__(self):return f"{self.__class__.__name__}(data={self._data})" | 1 | 2 | 1 | 8 | 0 | 76 | 77 | 76 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__repr__) defined within the public class called public.The function start at line 76 and ends at 77. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __torch_dispatch__ | def __torch_dispatch__(cls, func, types, args, kwargs):out = func(*pytree.tree_map_only(cls, lambda x: x._data, args),**pytree.tree_map_only(cls, lambda x: x._data, kwargs),)# NOTE: _precomputed_scale does not propagate through any opsif func is aten.copy_.default:# return original objectreturn args[0]elif func in {ate... | 3 | 23 | 5 | 159 | 0 | 81 | 108 | 81 | 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 81 and ends at 108. It contains 23 lines of code and it has a cyclomatic complexity of 3. It takes 5 parameters, represented as [81.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | fsdp_pre_all_gather | def fsdp_pre_all_gather(self, mesh):# quantize and pack into 2-bit to save comm bandwidthif self._precomputed_scale is not None:scale = self._precomputed_scaleelse:scale = get_bitnet_scale(self._data)dist.all_reduce(scale, op=dist.ReduceOp.AVG)# NOTE: scale is in FP32data_i8 = quantize_bitnet_weight(self._data, scale)d... | 2 | 9 | 2 | 70 | 0 | 111 | 123 | 111 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (fsdp_pre_all_gather) defined within the public class called public.The function start at line 111 and ends at 123. It contains 9 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [111.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | fsdp_post_all_gather | def fsdp_post_all_gather(self,all_gather_outputs: Tuple[Tensor, ...],metadata: Any,param_dtype: torch.dtype,*,out: Optional[Tensor] = None,):(data_i2,) = all_gather_outputs(scale,) = metadatascale = scale.to(param_dtype)if out is not None:assert isinstance(out, BitNetPacked2bitLinearWeight)out.scale = scalereturnreturn... | 2 | 16 | 5 | 84 | 0 | 125 | 140 | 125 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (fsdp_post_all_gather) defined within the public class called public.The function start at line 125 and ends at 140. It contains 16 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [125.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _ | def _(func, types, args, kwargs):if torch.is_autocast_enabled("cuda"):dtype = torch.get_autocast_gpu_dtype()args = tuple(x.to(dtype) if x is not None else x for x in args)return _BitNetTrainingLinear.apply(*args, **kwargs) | 4 | 5 | 4 | 59 | 2 | 144 | 148 | 144 | null | ['args', 'dtype'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_) defined within the public class called public.The function start at line 144 and ends at 148. It contains 5 lines of code and it has a cyclomatic complexity of 4. It takes 4 parameters, represented as [144.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_bitnet_scale | def get_bitnet_scale(x: Tensor):"Tensor-wise abs-mean. Always return FP32."return x.float().abs().mean() | 1 | 3 | 1 | 22 | 0 | 151 | 153 | 151 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_bitnet_scale) defined within the public class called public.The function start at line 151 and ends at 153. 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 | quantize_bitnet_weight | def quantize_bitnet_weight(w: Tensor, scale: Tensor, eps: float = 1e-5) -> Tensor:w = w.float() / scale.clip(eps)w = w.round().clip(-1, 1).to(torch.int8)return w | 1 | 4 | 3 | 59 | 1 | 156 | 159 | 156 | null | ['w'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (quantize_bitnet_weight) defined within the public class called public.The function start at line 156 and ends at 159. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [156.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | precompute_bitnet_scale_for_fsdp | def precompute_bitnet_scale_for_fsdp(module: nn.Module):"""Calculate scale for all BitNetTrainingLinearWeight parameters.This should be run after the optimizer step. It performs a single all-reduce for allparameters to reduce overhead."""bitnet_params = [pfor p in module.parameters()if isinstance(p, DTensor)and isinsta... | 7 | 14 | 1 | 95 | 2 | 163 | 183 | 163 | null | ['bitnet_params', 'bitnet_scales'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (precompute_bitnet_scale_for_fsdp) defined within the public class called public.The function start at line 163 and ends at 183. It contains 14 lines of code and it has a cyclomatic complexity of 7. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(ctx,input: Tensor,weight: BitNetTrainingLinearWeight,bias: Optional[Tensor] = None,):batch_dims = input.shape[:-1]input = input.view(-1, weight.shape[1])# https://github.com/microsoft/unilm/blob/master/bitnet/The-Era-of-1-bit-LLMs__Training_Tips_Code_FAQ.pdf# Figure 3input_i8, row_scale = quantize_int8_roww... | 2 | 19 | 4 | 155 | 0 | 188 | 216 | 188 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 188 and ends at 216. It contains 19 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [188.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | backward | def backward(ctx, grad_output):input_i8, row_scale, weight_i8, tensor_scale = ctx.saved_tensorsgrad_input = grad_weight = grad_bias = Nonebatch_dims = grad_output.shape[:-1]grad_output = grad_output.view(-1, weight_i8.shape[0])# NOTE: we can potentially speedup training by also quantizing the backward pass# to use INT8... | 4 | 13 | 2 | 140 | 0 | 219 | 240 | 219 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (backward) defined within the public class called public.The function start at line 219 and ends at 240. It contains 13 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 | _bitnet_training_transform | def _bitnet_training_transform(module: torch.nn.Module,config: BitNetTrainingConfig,) -> torch.nn.Module:new_weight = BitNetTrainingLinearWeight(module.weight)module.weight = torch.nn.Parameter(new_weight, requires_grad=True)return module | 1 | 7 | 2 | 48 | 1 | 252 | 258 | 252 | null | ['new_weight'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_bitnet_training_transform) defined within the public class called public.The function start at line 252 and ends at 258. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [252.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _pack_i2_in_i8 | def _pack_i2_in_i8(x: Tensor):# perform packing: [xxxx xxaa, xxxx xxxbb, xxxx xxcc, xxxx xxdd] -> [aabb ccdd]# for each value, xxxx can be either all 0s or all 1s because these are signed numbers.# thus, we have to mask out the 2 least significant bits (right-most) before bit-shift.# e.g. 1111 1111 (value=-1) -> 0000 0... | 1 | 8 | 1 | 75 | 4 | 261 | 273 | 261 | null | ['x3', 'x2', 'x1', 'x0'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_pack_i2_in_i8) defined within the public class called public.The function start at line 261 and ends at 273. It contains 8 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _unpack_i2_in_i8 | def _unpack_i2_in_i8(x: Tensor):# NOTE: this is signed integer, so left-shift then right-shift will perform sign extension correctly# e.g. aa10bbcc -> 10bbcc00 -> 11111110return torch.stack([x >> 6, x << 2 >> 6, x << 4 >> 6, x << 6 >> 6], dim=-1).view(x.shape[0], -1) | 1 | 4 | 1 | 61 | 0 | 276 | 281 | 276 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_unpack_i2_in_i8) defined within the public class called public.The function start at line 276 and ends at 281. 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 | __new__ | def __new__(cls, int_data: Tensor, scale: Tensor):M, N = int_data.shapeshape = (M, N * 4)return Tensor._make_wrapper_subclass(cls,shape,dtype=scale.dtype,device=scale.device,) | 1 | 9 | 3 | 51 | 0 | 289 | 297 | 289 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__new__) defined within the public class called public.The function start at line 289 and ends at 297. It contains 9 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.. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.