project_name string | class_name string | class_modifiers string | class_implements int64 | class_extends int64 | function_name string | function_body string | cyclomatic_complexity int64 | NLOC int64 | num_parameter int64 | num_token int64 | num_variable int64 | start_line int64 | end_line int64 | function_index int64 | function_params string | function_variable string | function_return_type string | function_body_line_type string | function_num_functions int64 | function_num_lines int64 | outgoing_function_count int64 | outgoing_function_names string | incoming_function_count int64 | incoming_function_names string | lexical_representation string |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
pytorch_ao | public | public | 0 | 0 | forward | def forward(self,input_ids: Optional[torch.LongTensor] = None,attention_mask: Optional[torch.FloatTensor] = None,position_ids: Optional[torch.LongTensor] = None,past_key_values: Optional[Union[Cache, List[torch.FloatTensor]]] = None,inputs_embeds: Optional[torch.FloatTensor] = None,start_positions: Optional[torch.LongT... | 6 | 43 | 12 | 328 | 0 | 1,017 | 1,075 | 1,017 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 1017 and ends at 1075. It contains 43 lines of code and it has a cyclomatic complexity of 6. It takes 12 parameters, represented as [1017.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, config):super().__init__(config)self.num_labels = config.num_labelsself.model = LlamaModel(config)if getattr(config, "classifier_dropout", None) is not None:classifier_dropout = config.classifier_dropoutelif getattr(config, "hidden_dropout", None) is not None:classifier_dropout = config.hidden_dropou... | 3 | 13 | 2 | 104 | 0 | 1,086 | 1,100 | 1,086 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 1086 and ends at 1100. It contains 13 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [1086.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_input_embeddings | def get_input_embeddings(self):return self.model.embed_tokens | 1 | 2 | 1 | 11 | 0 | 1,102 | 1,103 | 772 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_input_embeddings) defined within the public class called public.The function start at line 1102 and ends at 1103. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | set_input_embeddings | def set_input_embeddings(self, value):self.model.embed_tokens = value | 1 | 2 | 2 | 14 | 0 | 1,105 | 1,106 | 775 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (set_input_embeddings) defined within the public class called public.The function start at line 1105 and ends at 1106. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [775.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(self,input_ids: Optional[torch.LongTensor] = None,attention_mask: Optional[torch.Tensor] = None,position_ids: Optional[torch.LongTensor] = None,past_key_values: Optional[List[torch.FloatTensor]] = None,inputs_embeds: Optional[torch.FloatTensor] = None,labels: Optional[torch.LongTensor] = None,use_cache: Opt... | 5 | 40 | 11 | 276 | 0 | 1,114 | 1,163 | 1,114 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 1114 and ends at 1163. It contains 40 lines of code and it has a cyclomatic complexity of 5. It takes 11 parameters, represented as [1114.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(ctx, input, alpha, num_bits, layerwise):""":param input: input to be quantized:param alpha: the step size:param num_bits: quantization bits:param layerwise: rowwise quant:return: quantized output"""ctx.num_bits = num_bitsif num_bits >= 16:return inputif num_bits == 1 or num_bits == 0:Qn = -1Qp = 1else:Qn = ... | 6 | 25 | 5 | 197 | 0 | 19 | 53 | 19 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 19 and ends at 53. It contains 25 lines of code and it has a cyclomatic complexity of 6. It takes 5 parameters, represented as [19.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | backward | def backward(ctx, grad_output):if ctx.num_bits >= 16:return grad_output, None, None, Noneinput_, alpha = ctx.saved_tensorsgrad_scale, Qn, Qp, layerwise = ctx.otherq_w = input_ / alphaindicate_small = (q_w < Qn).float()indicate_big = (q_w > Qp).float()indicate_middle = (1.0 - indicate_small - indicate_big)# this is more... | 5 | 47 | 2 | 258 | 0 | 56 | 104 | 56 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (backward) defined within the public class called public.The function start at line 56 and ends at 104. It contains 47 lines of code and it has a cyclomatic complexity of 5. It takes 2 parameters, represented as [56.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(ctx, input, alpha, num_bits, layerwise):""":param input: input to be quantized:param alpha: the step size:param num_bits: quantization bits:param layerwise: rowwise quant:return: quantized output"""ctx.num_bits = num_bitsif num_bits >= 16:return inputif num_bits == 1 or num_bits == 0:Qn = -1Qp = 1else:Qn = ... | 7 | 39 | 5 | 258 | 0 | 114 | 161 | 114 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 114 and ends at 161. It contains 39 lines of code and it has a cyclomatic complexity of 7. It takes 5 parameters, represented as [114.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | backward | def backward(ctx, grad_output):if ctx.num_bits >= 16:return grad_output, None, None, Noneinput_, alpha = ctx.saved_tensorsgrad_scale, Qn, Qp, layerwise = ctx.otherq_w = input_ / alphaclip_val = 1 - 1e-2if ctx.num_bits == 0:n_levels = 1.5shift = 0else:n_levels = 2 ** (ctx.num_bits - 1)shift = 0.5indicate_small = (q_w < ... | 6 | 76 | 2 | 341 | 0 | 164 | 241 | 164 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (backward) defined within the public class called public.The function start at line 164 and ends at 241. It contains 76 lines of code and it has a cyclomatic complexity of 6. It takes 2 parameters, represented as [164.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self,*kargs,symmetric=True,bias=False,w_bits=16,weight_layerwise=False,):super(QuantizeLinear, self).__init__(*kargs, bias=False)self.w_bits = w_bitsself.weight_layerwise = weight_layerwise# params for weight quantif self.w_bits < 16:self.weight_clip_val = nn.Parameter(torch.Tensor(self.weight.shape[0], 1)... | 2 | 13 | 6 | 82 | 0 | 246 | 259 | 246 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 246 and ends at 259. It contains 13 lines of code and it has a cyclomatic complexity of 2. It takes 6 parameters, represented as [246.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(self, input_):# quantize weightassert len(self.weight.size()) == 2real_weights = self.weightif self.w_bits >= 16:weight = self.weightelif self.w_bits == 2 or self.w_bits == 0:weight = StretchedElasticQuant.apply(real_weights,self.weight_clip_val,self.w_bits,self.weight_layerwise,).to(input_.dtype)elif self.... | 6 | 25 | 2 | 157 | 0 | 261 | 289 | 261 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 261 and ends at 289. It contains 25 lines of code and it has a cyclomatic complexity of 6. It takes 2 parameters, represented as [261.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | set_seed | def set_seed(seed):np.random.seed(seed)torch.random.manual_seed(seed) | 1 | 3 | 1 | 21 | 0 | 25 | 27 | 25 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (set_seed) defined within the public class called public.The function start at line 25 and ends at 27. 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 | get_train_val_dataset | def get_train_val_dataset(train_path, valid_path=None):f = open(train_path, "r", encoding="utf-8")data = []while True:line = f.readline()if not line:breakdata.append(json.loads(line))f.close()train_data = []valid_data = []if valid_path:f = open(valid_path, "r", encoding="utf-8")while True:line = f.readline()if not line... | 6 | 24 | 2 | 133 | 5 | 30 | 53 | 30 | null | ['line', 'f', 'valid_data', 'data', 'train_data'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_train_val_dataset) defined within the public class called public.The function start at line 30 and ends at 53. It contains 24 lines of code and it has a cyclomatic complexity of 6. It takes 2 parameters, represented as [30.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, dataset, tokenizer, block_size=1024):raw_data = datasetself.tokenizer = tokenizerself.block_size = block_sizetokenized_datasets = []for d in raw_data:tokenized_datasets.append(self.tokenize_function(d))grouped_dataset = self.group_texts(tokenized_datasets)self.input_ids = grouped_dataset["input_ids"]... | 3 | 14 | 4 | 108 | 0 | 57 | 71 | 57 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 57 and ends at 71. It contains 14 lines of code and it has a cyclomatic complexity of 3. It takes 4 parameters, represented as [57.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __len__ | def __len__(self):return len(self.input_ids) | 1 | 2 | 1 | 12 | 0 | 73 | 74 | 73 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__len__) defined within the public class called public.The function start at line 73 and ends at 74. 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 | __getitem__ | def __getitem__(self, i):return dict(input_ids=self.input_ids[i], labels=self.labels[i]) | 1 | 2 | 2 | 28 | 0 | 76 | 77 | 76 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__getitem__) 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. It takes 2 parameters, represented as [76.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __iter__ | def __iter__(self):return iter(self.data) | 1 | 2 | 1 | 12 | 0 | 79 | 80 | 79 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__iter__) defined within the public class called public.The function start at line 79 and ends at 80. 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 | tokenize_function | def tokenize_function(self, examples):return self.tokenizer(examples["text"]) | 1 | 2 | 2 | 17 | 0 | 82 | 83 | 82 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (tokenize_function) defined within the public class called public.The function start at line 82 and ends at 83. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [82.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | group_texts | def group_texts(self, examples):# Concatenate all texts.# Initialize an empty dictionaryconcatenated_examples = {}# Loop through the list of dictionariesfor d in examples:# Loop through the keys in each dictionaryfor key in d.keys():# If the key is not already a key in the dict_of_lists, create a new listif key not in ... | 7 | 19 | 2 | 127 | 0 | 85 | 113 | 85 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (group_texts) defined within the public class called public.The function start at line 85 and ends at 113. It contains 19 lines of code and it has a cyclomatic complexity of 7. It takes 2 parameters, represented as [85.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | jload | def jload(filename, mode="r"):"""Load a .json file into a dictionary."""with open(filename, mode) as f:jdict = json.load(f)return jdict | 1 | 4 | 2 | 30 | 1 | 116 | 120 | 116 | null | ['jdict'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (jload) defined within the public class called public.The function start at line 116 and ends at 120. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [116.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | process_args | def process_args():parser = transformers.HfArgumentParser((ModelArguments, DataArguments, TrainingArguments))model_args, data_args, training_args = parser.parse_args_into_dataclasses()os.makedirs(model_args.local_dir, exist_ok=True)assert model_args.output_model_local_path is Nonemodel_args.output_model_local_path = os... | 1 | 11 | 0 | 76 | 1 | 80 | 94 | 80 | null | ['parser'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (process_args) defined within the public class called public.The function start at line 80 and ends at 94. It contains 11 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_logger | def get_logger(logger_name):# Get the logger with the specified namelogger = logging.getLogger(logger_name)# Set the logging level of the logger to INFOlogger.setLevel(logging.INFO)# Define a formatter for the log messagesformatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")# Create a co... | 1 | 10 | 1 | 50 | 3 | 16 | 35 | 16 | null | ['console_handler', 'formatter', 'logger'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_logger) defined within the public class called public.The function start at line 16 and ends at 35. It contains 10 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 | safe_save_model_for_hf_trainer | def safe_save_model_for_hf_trainer(trainer: transformers.Trainer, output_dir: str):"""Collects the state dict and dump to disk."""state_dict = trainer.model.state_dict()if trainer.args.should_save:cpu_state_dict = {}for key in state_dict.keys():if "teacher" in key:continuecpu_state_dict[key] = state_dict[key]del state_... | 4 | 10 | 2 | 70 | 2 | 38 | 48 | 38 | null | ['state_dict', 'cpu_state_dict'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (safe_save_model_for_hf_trainer) defined within the public class called public.The function start at line 38 and ends at 48. It contains 10 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [38.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_local_rank | def get_local_rank():if os.environ["LOCAL_RANK"]:return int(os.environ["LOCAL_RANK"])else:logging.warning("LOCAL_RANK from os.environ is None, fall back to get rank from torch distributed")return torch.distributed.get_rank() | 2 | 8 | 0 | 38 | 0 | 51 | 58 | 51 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_local_rank) defined within the public class called public.The function start at line 51 and ends at 58. It contains 8 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 | instantiate_module | def instantiate_module(module_path, module_suffix):return getattr(import_module(module_path), module_suffix) | 1 | 2 | 2 | 17 | 0 | 20 | 21 | 20 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (instantiate_module) defined within the public class called public.The function start at line 20 and ends at 21. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [20.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | is_dtensor | def is_dtensor(x):return HAS_DTENSOR and isinstance(x, DTensor) | 2 | 2 | 1 | 14 | 0 | 24 | 25 | 24 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (is_dtensor) 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 2. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | channel_bucketize | def channel_bucketize(input: Tensor, boundaries: Tensor, right: bool = False) -> Tensor:"""Generalizes torch.bucketize to run on 2-D boundaries."""inf_pad = torch.full_like(boundaries[:, :1], torch.inf)boundaries = (torch.cat((-inf_pad, boundaries), dim=1)if rightelse torch.cat((boundaries, inf_pad), dim=1))boundaries ... | 3 | 11 | 3 | 125 | 4 | 28 | 39 | 28 | null | ['boundaries', 'inf_pad', 'mask', 'input'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (channel_bucketize) defined within the public class called public.The function start at line 28 and ends at 39. It contains 11 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [28.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, anneal_start: int, anneal_end: int) -> None:self.anneal_start = anneal_startself.anneal_end = anneal_end | 1 | 3 | 3 | 25 | 0 | 19 | 21 | 19 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 19 and ends at 21. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [19.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | apply_ | def apply_(self,p: Tensor,q: Tensor,Q: Tensor,step_count: int,dim: Optional[int] = None,) -> None:if step_count < self.anneal_start:returnif q is None:# hard quantization to the nearest point in QQ_mid = (Q[..., :-1] + Q[..., 1:]) / 2if dim is None:q = Q[torch.bucketize(p, Q_mid)]else:q = Q.gather(1, channel_bucketize(... | 5 | 23 | 6 | 154 | 0 | 24 | 50 | 24 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (apply_) defined within the public class called public.The function start at line 24 and ends at 50. It contains 23 lines of code and it has a cyclomatic complexity of 5. It takes 6 parameters, represented as [24.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | amp_custom_fwd | def amp_custom_fwd(cast_inputs: Optional[torch.types._dtype] = None):try:return partial(torch.amp.custom_fwd, device_type="cuda", cast_inputs=cast_inputs)except AttributeError:return partial(torch.cuda.amp.custom_fwd, cast_inputs=cast_inputs) | 2 | 7 | 1 | 53 | 0 | 18 | 24 | 18 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (amp_custom_fwd) defined within the public class called public.The function start at line 18 and ends at 24. 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 | normalized_mirror_sigmoid | def normalized_mirror_sigmoid(t: float, t1: float, t2: float, s: float, c: float) -> float:"""Sigmoid-like function decreasing from 1 to 0 over interval [t1, t2).s is steepness of the sigmoid-like function, almost linear for s < 1.'mirror' means decreasing instead of increasing as true sigmoid,'normalized' means value ... | 2 | 9 | 5 | 118 | 4 | 27 | 39 | 27 | null | ['ft', 's2', 'st', 's1'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (normalized_mirror_sigmoid) defined within the public class called public.The function start at line 27 and ends at 39. It contains 9 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [27.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self,anneal_start: int,anneal_end: int,steepness: float = 10,anneal_center: float = 0.5,) -> None:assert anneal_start < anneal_end, "PARQ annealing: start before end."assert steepness > 0, "PARQ annealing steepness should be positive."self.anneal_start = anneal_startself.anneal_end = anneal_endself.steepne... | 1 | 13 | 5 | 62 | 0 | 43 | 55 | 43 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 43 and ends at 55. It contains 13 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [43.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | apply_ | def apply_(self,p: Tensor,q: Tensor,Q: Tensor,step_count: int,dim: Optional[int] = None,) -> float:"""Prox-map of PARQ with gradual annealing to hard quantization."""if step_count < self.anneal_start:inv_slope = 1.0elif step_count >= self.anneal_end:inv_slope = 0.0if q is None:# hard quantization to the nearest point i... | 6 | 48 | 6 | 361 | 0 | 59 | 113 | 59 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (apply_) defined within the public class called public.The function start at line 59 and ends at 113. It contains 48 lines of code and it has a cyclomatic complexity of 6. It takes 6 parameters, represented as [59.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | apply_ | def apply_(self, p: Tensor, q: Tensor, Q: Tensor, step_count: int) -> None:"""Provide interface for proximal mapping (modify p in-place):prox_map.apply_(p, q, Q, step_count)Inputs:p (Tensor): tensor to be quantizedq (Tensor): None or hard quantized tensor of same size as pQ (Tensor): set of target quantization valuesst... | 1 | 1 | 5 | 24 | 0 | 19 | 27 | 19 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (apply_) defined within the public class called public.The function start at line 19 and ends at 27. It contains 1 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [19.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | apply_ | def apply_(self,p: Tensor,q: Tensor,Q: Tensor,step_count: int,dim: Optional[int] = None,) -> None:if q is None:# quantize to the nearest point in QQ_mid = (Q[..., :-1] + Q[..., 1:]) / 2if dim is None:q = Q[torch.bucketize(p, Q_mid)]else:q = Q.gather(1, channel_bucketize(p, Q_mid))p.copy_(q) | 3 | 15 | 6 | 101 | 0 | 34 | 49 | 34 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (apply_) defined within the public class called public.The function start at line 34 and ends at 49. It contains 15 lines of code and it has a cyclomatic complexity of 3. It takes 6 parameters, represented as [34.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self,base_optimizer: Optimizer,quantizer: Quantizer,prox_map: ProxMap,warmup_steps: int = 0,quant_period: int = 10,quant_per_channel: bool = False,quant_shrink: bool = False,anneal_wd_frac: float = 0.0,group_quantizer_map: Optional[dict[int, Quantizer]] = None,) -> None:if not 0 <= anneal_wd_frac <= 1:rais... | 4 | 28 | 10 | 163 | 0 | 49 | 82 | 49 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 49 and ends at 82. It contains 28 lines of code and it has a cyclomatic complexity of 4. It takes 10 parameters, represented as [49.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __getattribute__ | def __getattribute__(self, name: str):try:attr = super(Optimizer, self).__getattribute__(name)except AttributeError:attr = self.base_optimizer.__getattribute__(name)return attr | 2 | 6 | 2 | 39 | 0 | 86 | 91 | 86 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__getattribute__) defined within the public class called public.The function start at line 86 and ends at 91. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [86.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __repr__ | def __repr__(self) -> str:base_optimizer = "\n".join(self.base_optimizer.__repr__().split("\n"))quantizer = self.quantizer.__class__.__name__prox_map = self.prox_map.__class__.__name__extra_repr = "\n".join(("(", base_optimizer, f"{quantizer=}", f"{prox_map=}"))return f"{self.__class__.__name__} {extra_repr}\n)" | 1 | 6 | 1 | 65 | 0 | 93 | 98 | 93 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__repr__) defined within the public class called public.The function start at line 93 and ends at 98. 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 | state | def state(self) -> defaultdict[Tensor, Any]:# pyre-ignore[3]return self._state if hasattr(self, "_state") else self.base_optimizer.state | 2 | 2 | 1 | 29 | 0 | 101 | 102 | 101 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (state) defined within the public class called public.The function start at line 101 and ends at 102. 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 | num_steps | def num_steps(self) -> int:for group in self.regularized_param_groups():return group.setdefault("num_steps", 0) | 2 | 3 | 1 | 25 | 0 | 105 | 107 | 105 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (num_steps) defined within the public class called public.The function start at line 105 and ends at 107. 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 | num_steps | def num_steps(self, value: int) -> None:for group in self.regularized_param_groups():group["num_steps"] = valuereturn | 2 | 4 | 2 | 27 | 0 | 110 | 113 | 110 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (num_steps) defined within the public class called public.The function start at line 110 and ends at 113. It contains 4 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [110.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | num_steps | def num_steps(self) -> int:for group in self.regularized_param_groups():return group.setdefault("num_steps", 0) | 2 | 4 | 1 | 25 | 0 | 116 | 119 | 105 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (num_steps) defined within the public class called public.The function start at line 116 and ends at 119. 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 | quantize_ | def quantize_(p: Tensor,quants: Tensor,quantizer: Quantizer,b: int,dim: Optional[int] = None,) -> Optional[Tensor]:"""Optionally update the quantization targets `quants` in place.Return the quantized `p` as a by-product if `quant_update=True`."""q, Q = quantizer.quantize(p, b, dim=dim)# pyre-ignore[28]quants.copy_(Q)re... | 1 | 10 | 5 | 59 | 0 | 122 | 134 | 122 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (quantize_) defined within the public class called public.The function start at line 122 and ends at 134. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [122.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | regularized_param_groups | def regularized_param_groups(self) -> Generator[dict[str, Any], None, None]:"""Yield parameter groups that need to be quantized."""for group in self.param_groups:if group.get("quant_bits", 16) < 16:yield group | 3 | 4 | 1 | 41 | 0 | 136 | 140 | 136 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (regularized_param_groups) defined within the public class called public.The function start at line 136 and ends at 140. 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 | _param_sets | def _param_sets(self) -> Generator[set[int], None, None]:for group in self.regularized_param_groups():yield {p.data_ptr() for p in group["params"]} | 3 | 3 | 1 | 41 | 0 | 142 | 144 | 142 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_param_sets) defined within the public class called public.The function start at line 142 and ends at 144. It contains 3 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_filter_fns._filter_fn | def _filter_fn(module: nn.Module, *args, param_set) -> bool:for p in module.parameters(recurse=False):if p.data_ptr() in param_set:return Truereturn False | 3 | 5 | 3 | 41 | 0 | 149 | 153 | 149 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_filter_fns._filter_fn) defined within the public class called public.The function start at line 149 and ends at 153. It contains 5 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [149.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_filter_fns | def get_filter_fns(self, module: nn.Module) -> Generator[Callable[[nn.Module], bool], None, None]:def _filter_fn(module: nn.Module, *args, param_set) -> bool:for p in module.parameters(recurse=False):if p.data_ptr() in param_set:return Truereturn Falsefor param_set in self._param_sets():yield partial(_filter_fn, param_... | 2 | 6 | 2 | 49 | 0 | 146 | 156 | 146 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_filter_fns) defined within the public class called public.The function start at line 146 and ends at 156. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [146.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _get_quantizer | def _get_quantizer(self, group_idx: int) -> Optional[Quantizer]:if self.group_quantizer_map and group_idx in self.group_quantizer_map:return self.group_quantizer_map[group_idx]return self.quantizer | 3 | 4 | 2 | 36 | 0 | 158 | 161 | 158 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_get_quantizer) defined within the public class called public.The function start at line 158 and ends at 161. It contains 4 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [158.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | torchao_convert | def torchao_convert(self,model: nn.Module,weight_only: bool = False,embed_weight_only: bool = False,) -> None:"""Converts model parameters to torchao quantized tensor subclasses."""model.eval()self.restore_latent_params()# TODO(lvj): find more robust way to identify embedding layersembed_data_ptrs = set()linear_data_pt... | 19 | 58 | 4 | 399 | 0 | 163 | 233 | 163 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (torchao_convert) defined within the public class called public.The function start at line 163 and ends at 233. It contains 58 lines of code and it has a cyclomatic complexity of 19. It takes 4 parameters, represented as [163.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | state_dict | def state_dict(self) -> dict[str, Any]:return self.base_optimizer.state_dict() | 1 | 2 | 1 | 20 | 0 | 236 | 237 | 236 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (state_dict) defined within the public class called public.The function start at line 236 and ends at 237. 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 | load_state_dict | def load_state_dict(self, state_dict: dict[str, Any]) -> None:self.base_optimizer.load_state_dict(state_dict) | 1 | 2 | 2 | 24 | 0 | 240 | 241 | 240 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (load_state_dict) 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. It takes 2 parameters, represented as [240.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | step | def step(self, closure: Optional[Callable[[], float]] = None) -> Optional[float]:"""Performs a single optimization step.Arguments:closure (callable, optional): A closure that reevaluates the modeland returns the loss."""if self.num_steps < self.warmup_steps:# warmup stage: running the base optimizer onlyloss = self.bas... | 25 | 89 | 3 | 658 | 0 | 244 | 369 | 244 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (step) defined within the public class called public.The function start at line 244 and ends at 369. It contains 89 lines of code and it has a cyclomatic complexity of 25. It takes 3 parameters, represented as [244.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | restore_latent_params | def restore_latent_params(self) -> None:"""Restore latent parameters as optimizer parameters"""for group in self.regularized_param_groups():for p in group["params"]:if p.requires_grad:p.copy_(self.state[p]["latent"]) | 4 | 5 | 1 | 44 | 0 | 373 | 378 | 373 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (restore_latent_params) defined within the public class called public.The function start at line 373 and ends at 378. It contains 5 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 | save_latent_params | def save_latent_params(self) -> None:"""Save updated latent parameters before applying prox-map"""if self.warmup_steps == 0:assert len(self.state) == 0, "Expected empty state at first step()"# Maintain the invariant that `len(self.state) == 0` before first# self.base_optimizer.step() call by using a temporary state buf... | 6 | 12 | 1 | 95 | 0 | 382 | 397 | 382 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (save_latent_params) defined within the public class called public.The function start at line 382 and ends at 397. It contains 12 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 | _int8_dynamic_activation_stretched_intx_transform | def _int8_dynamic_activation_stretched_intx_transform(module: nn.Module, config: StretchedIntxWeightConfig) -> nn.Module:weight = module.weightgranularity = config.granularitymapping_type = MappingType.ASYMMETRICif config.version != 2:raise NotImplementedError(f"Unsupported {config.version=}")assert weight.dim() == 2, ... | 5 | 53 | 2 | 292 | 11 | 51 | 109 | 51 | null | ['granularity', 'n_blocks', 'zero_point', 'q_args', 'block_size', 'group_size', 'qdata', 'scale', 'target_dtype', 'mapping_type', 'weight'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_int8_dynamic_activation_stretched_intx_transform) defined within the public class called public.The function start at line 51 and ends at 109. It contains 53 lines of code and it has a cyclomatic complexity of 5. It takes 2 parameters, represented as [51.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _get_config_from_quantizer | def _get_config_from_quantizer(quantizer,weight_only: bool,device: torch.device,b: int,block_size: Optional[int],version: int = 2,) -> AOBaseConfig:granularity = PerGroup(block_size) if block_size is not None else PerAxis(0)weight_dtype = _BIT_WIDTH_TO_DTYPE[b]if isinstance(quantizer, Int4UnifTorchaoQuantizer):config =... | 7 | 44 | 6 | 200 | 3 | 112 | 155 | 112 | null | ['granularity', 'weight_dtype', 'config'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_get_config_from_quantizer) defined within the public class called public.The function start at line 112 and ends at 155. It contains 44 lines of code and it has a cyclomatic complexity of 7. It takes 6 parameters, represented as [112.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _is_hf_model | def _is_hf_model(model: nn.Module) -> bool:return TRANSFORMERS_AVAIL and isinstance(getattr(model, "config", None), PretrainedConfig) | 2 | 4 | 1 | 27 | 0 | 158 | 161 | 158 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_is_hf_model) defined within the public class called public.The function start at line 158 and ends at 161. 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 | _attach_hf_quantization_config | def _attach_hf_quantization_config(model: nn.Module,filter_fns: list[Callable[nn.Module, bool]],configs: list[AOBaseConfig],module_to_config: Optional[dict[str, AOBaseConfig]] = None,) -> None:"""Attaches torchao quantization config(s) to Hugging Face model.Args:model: nn.Module - Hugging Face model.filter_fns: list[Ca... | 8 | 28 | 4 | 183 | 3 | 164 | 209 | 164 | null | ['modules_to_not_convert', 'tied_weights_keys', 'module_to_config'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_attach_hf_quantization_config) defined within the public class called public.The function start at line 164 and ends at 209. It contains 28 lines of code and it has a cyclomatic complexity of 8. It takes 4 parameters, represented as [164.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | binary_sign | def binary_sign(input: Tensor) -> Tensor:"""Same as `torch.sign(input)` but map 0 to 1."""return torch.where(input == 0, 1.0, input.sign()) | 1 | 2 | 1 | 29 | 0 | 18 | 20 | 18 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (binary_sign) defined within the public class called public.The function start at line 18 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 | binary_quant_residue | def binary_quant_residue(u: Tensor, vs: Iterable[float]) -> Tensor:"""Return residue for foldable binary quantization"""r = u.detach().clone()for v in vs:r.sub_(v * binary_sign(r))return r | 2 | 5 | 2 | 46 | 1 | 23 | 28 | 23 | null | ['r'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (binary_quant_residue) defined within the public class called public.The function start at line 23 and ends at 28. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [23.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | compute_v_per_channel | def compute_v_per_channel(p: Tensor, dim: Optional[int] = None, ternary: bool = False):"""Vectorized computation of optimal `v` for ternary/2-bit algorithm."""v_cands = p.abs().sort(dim=dim).valuescumsum = v_cands.cumsum(dim=dim)cumsum, total_sum = cumsum[:, 1:-1], cumsum[:, -1:]# compute cumulative mean from right to ... | 4 | 33 | 3 | 451 | 16 | 31 | 76 | 31 | null | ['counts_r2l', 'cumsum', 'cmean_r2l', 'r', 'extra_col', 'optimal_v', 'cmean_l2r', 'split_sizes', 'row_invalid', 'costs', 'v', 'indices', 'mask', 'counts', 'v_cands', 'v_best'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (compute_v_per_channel) defined within the public class called public.The function start at line 31 and ends at 76. It contains 33 lines of code and it has a cyclomatic complexity of 4. It takes 3 parameters, represented as [31.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self,center: bool = False,optimal: bool = False,ternary_multiplier: float = 1.1,) -> None:"""ternary_mult is factor multipled to 1-bit range as heuristic."""super().__init__(center)# optimal choice only meaningful for b=1, b=2 and ternaryself.optimal = optimalself.ternary_multiplier = ternary_multiplier | 1 | 9 | 4 | 47 | 0 | 84 | 94 | 84 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 84 and ends at 94. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [84.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_quant_size | def get_quant_size(self, b: int) -> int:return 2**b if b > 0 else 3 | 2 | 2 | 2 | 21 | 0 | 96 | 97 | 96 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_quant_size) 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 2. It takes 2 parameters, represented as [96.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | quantize | def quantize(self, p: Tensor, b: int, dim: Optional[int] = None) -> tuple[Tensor, Tensor]:"""Instantiation of Quantizer.quantize(), with b=0 for ternary"""if b < 0:raise ValueError(f"Invalid {b=}; must be nonnegative")if self.optimal and b > 2:raise NotImplementedError(f"Unsupported {self.optimal=} for {b=}")if self.ce... | 11 | 25 | 4 | 217 | 0 | 99 | 128 | 99 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (quantize) defined within the public class called public.The function start at line 99 and ends at 128. It contains 25 lines of code and it has a cyclomatic complexity of 11. It takes 4 parameters, represented as [99.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | quantize_greedy | def quantize_greedy(p: Tensor, b: int, dim: Optional[int] = None) -> tuple[Tensor, Tensor]:r = p.detach().clone()vs = []keepdim = dim is not Nonefor _ in range(b):v = r.abs().mean(dim=dim, keepdim=keepdim)r.sub_(binary_sign(r).mul_(v))vs.append(v)q = p - r# generate 2^b by b basis tensor Bbasis = list(itertools.product... | 3 | 20 | 3 | 214 | 0 | 131 | 152 | 131 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (quantize_greedy) defined within the public class called public.The function start at line 131 and ends at 152. It contains 20 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [131.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | quantize_optimal_2bits | def quantize_optimal_2bits(p: Tensor, dim: Optional[int] = None) -> tuple[Tensor, Tensor]:# generate 4 x 2 basis tensor B, sorted lexicographically along dim 0basis = list(itertools.product((-1, 1), repeat=2))B = torch.tensor(basis, dtype=p.dtype, device=p.device)if dim is not None:v1 = compute_v_per_channel(p, dim=dim... | 9 | 45 | 2 | 445 | 0 | 155 | 210 | 155 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (quantize_optimal_2bits) defined within the public class called public.The function start at line 155 and ends at 210. It contains 45 lines of code and it has a cyclomatic complexity of 9. It takes 2 parameters, represented as [155.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | quantize_optimal_ternary | def quantize_optimal_ternary(p: Tensor, dim: Optional[int] = None) -> tuple[Tensor, Tensor]:"""Formula look reasonable, but derivation in reference incorrect?"""if dim is not None:v = compute_v_per_channel(p, dim=dim, ternary=True)p_sign = binary_sign(p)r = p.sub(p_sign.mul(v))# 0 if sign(p) != sign(r), else sign(p) * ... | 8 | 37 | 2 | 406 | 0 | 213 | 260 | 213 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (quantize_optimal_ternary) defined within the public class called public.The function start at line 213 and ends at 260. It contains 37 lines of code and it has a cyclomatic complexity of 8. It takes 2 parameters, represented as [213.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | quantize_simple_ternary | def quantize_simple_ternary(p: Tensor, multiplier: float, dim: Optional[int] = None) -> tuple[Tensor, Tensor]:"""Heuristic by setting v as given multiple of |p|.abs().mean()"""v = multiplier * p.abs().mean(dim=dim, keepdim=dim is not None)Q = v * torch.tensor([-1.0, 0.0, 1.0], device=p.device)if dim is None:boundaries ... | 2 | 12 | 3 | 171 | 0 | 263 | 276 | 263 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (quantize_simple_ternary) defined within the public class called public.The function start at line 263 and ends at 276. It contains 12 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [263.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | choose_qparams_stretched_affine | def choose_qparams_stretched_affine(input_float: torch.Tensor,mapping_type: MappingType,block_size: Tuple[int, ...],target_dtype: torch.dtype,b: int,quant_min: Optional[Union[int, float]] = None,quant_max: Optional[Union[int, float]] = None,eps: Optional[float] = None,scale_dtype: Optional[torch.dtype] = None,zero_poin... | 4 | 32 | 10 | 269 | 8 | 20 | 54 | 20 | null | ['scale_dtype', 'input_float', 'max_val', 'zero_point', 'eps', 'scale', 'zero_point_dtype', 'q_abs'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (choose_qparams_stretched_affine) defined within the public class called public.The function start at line 20 and ends at 54. It contains 32 lines of code and it has a cyclomatic complexity of 4. It takes 10 parameters, represented as [20.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | quantize_stretched_affine | def quantize_stretched_affine(input_float: torch.Tensor,block_size: Tuple[int, ...],scale: torch.Tensor,zero_point: torch.Tensor,target_dtype: torch.dtype,quant_min: Optional[int] = None,quant_max: Optional[int] = None,) -> torch.Tensor:if target_dtype in _SUB_BYTE_UINT_BOUNDS:target_dtype = torch.uint8assert input_flo... | 5 | 36 | 7 | 243 | 8 | 57 | 95 | 57 | null | ['input_float', 'shape_after_reduction', 'max_val', 'zero_point', 'scale', 'target_dtype', 'quant', 'original_shape'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (quantize_stretched_affine) defined within the public class called public.The function start at line 57 and ends at 95. It contains 36 lines of code and it has a cyclomatic complexity of 5. It takes 7 parameters, represented as [57.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, center: bool = False) -> None:self.center = center | 1 | 2 | 2 | 18 | 0 | 16 | 17 | 16 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) 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 | get_quant_size | def get_quant_size(self, b: int) -> int:"""Given number of bits b, return total number of quantization values""" | 1 | 1 | 2 | 12 | 0 | 20 | 21 | 20 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_quant_size) defined within the public class called public.The function start at line 20 and ends at 21. It contains 1 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [20.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | quantize | def quantize(self, p: Tensor, b: int) -> tuple[Tensor, Tensor]:"""Provide interface for quantization:q, Q = Quantizer.quantize(p)Inputs:p (Tensor): tensor to be quantizedOutputs:q (Tensor): quantized tensor of same size as pQ (Tensor): set of 2^b quantization valuesInstantiation should not modify p, leaving update to P... | 1 | 1 | 3 | 21 | 0 | 24 | 33 | 24 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (quantize) defined within the public class called public.The function start at line 24 and ends at 33. It contains 1 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [24.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | remove_mean | def remove_mean(p: Tensor, dim: Optional[int] = None) -> tuple[Tensor, Tensor]:"""Center parameters in a Tensor, called if self.center == True.Note that this is different from direct asymmetric quantization,and may lead to (hopefully only) slightly different performance."""mean = p.mean(dim=dim, keepdim=dim is not None... | 1 | 4 | 2 | 50 | 0 | 36 | 43 | 36 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (remove_mean) defined within the public class called public.The function start at line 36 and ends at 43. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [36.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_q_max | def get_q_max(q: Tensor, b: int, dim: Optional[int] = None, scale_method: str = "mean") -> Tensor:if scale_method == "mean":# set range of quantization: min(b * |q|.mean(), |q|.max())q_abs = q.abs()if dim is not None:q_max = torch.minimum(b * q_abs.mean(dim=dim, keepdim=True),# pyre-ignore[6,9]torch.max(q_abs, dim=dim,... | 5 | 21 | 4 | 160 | 2 | 16 | 37 | 16 | null | ['q_max', 'q_abs'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_q_max) defined within the public class called public.The function start at line 16 and ends at 37. It contains 21 lines of code and it has a cyclomatic complexity of 5. It takes 4 parameters, represented as [16.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self,center: bool = False,scale_method: str = "mean",int_shift: float = 0.5,zero_point: float = 0.5,):"""Set quantization function parameters.Args:center: whether to subtract p.mean() prior to quantizationscale_method: compute scale based 'mean', multiples of |p|.mean(),or 'max', |p|.max() (default: 'mean'... | 1 | 12 | 5 | 71 | 0 | 43 | 66 | 43 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 43 and ends at 66. It contains 12 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [43.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_quant_size | def get_quant_size(self, b: int) -> int:"""Levels in [-2^{b-1} + self.int_shift, 2^{b-1} - self.int_shift].Note that range_absmax = 2^{b-1} - self.int_shift on both ends of theboundary and the interval is closed."""return math.floor(2**b - 2 * self.int_shift) + 1 | 1 | 2 | 2 | 29 | 0 | 68 | 73 | 68 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_quant_size) defined within the public class called public.The function start at line 68 and ends at 73. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [68.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | quantize | def quantize(self, p: Tensor, b: int, dim: Optional[int] = None) -> tuple[Tensor, Tensor]:"""Instantiation of Quantizer.quantize() method"""assert b != 0, "Please use TernaryUnifQuantizer instead"if self.center:q, mean = super().remove_mean(p.detach(), dim=dim)else:q = p.detach().clone()mean = torch.zeros(1, dtype=p.dt... | 4 | 26 | 4 | 266 | 0 | 75 | 113 | 75 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (quantize) defined within the public class called public.The function start at line 75 and ends at 113. It contains 26 lines of code and it has a cyclomatic complexity of 4. It takes 4 parameters, represented as [75.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self,center: bool = False,scale_method: str = "max",int_shift: float = 1.0,zero_point: float = 0.0,):"""Set quantization function with int_shift=1.0.The final quantization range includes 2^b - 1 quantized values. E.g.,[-1, 0, 1] for b=2. The quantization scale is determined by |p|.max()by default and zero ... | 1 | 13 | 5 | 58 | 0 | 117 | 135 | 117 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 117 and ends at 135. It contains 13 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [117.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_quant_size | def get_quant_size(self, b: int) -> int:"""Equivalent to int_max - int_min + 1, where int_min = -2^{b-1} andint_max = 2^{b-1} - 1."""return 2**b | 1 | 2 | 2 | 16 | 0 | 139 | 142 | 139 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_quant_size) defined within the public class called public.The function start at line 139 and ends at 142. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [139.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | quantize | def quantize(self, p: Tensor, b: int, dim: Optional[int] = None) -> tuple[Tensor, Tensor]:assert b != 0, "Please use TernaryUnifQuantizer instead"if self.center:q, mean = super().remove_mean(p.detach(), dim=dim)else:q = p.detach().clone()mean = torch.zeros(1, dtype=p.dtype, device=p.device)if dim is not None:q_min = q.... | 5 | 30 | 4 | 303 | 0 | 144 | 180 | 144 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (quantize) defined within the public class called public.The function start at line 144 and ends at 180. It contains 30 lines of code and it has a cyclomatic complexity of 5. It takes 4 parameters, represented as [144.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_quant_size | def get_quant_size(self, b: int) -> int:return 3 | 1 | 2 | 2 | 13 | 0 | 186 | 187 | 186 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_quant_size) defined within the public class called public.The function start at line 186 and ends at 187. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [186.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | quantize | def quantize(self, p: Tensor, b: int, dim: Optional[int] = None) -> tuple[Tensor, Tensor]:assert b == 0, f"Unexpected {b=} for ternary case"if self.center:q, mean = super().remove_mean(p.detach(), dim=dim)else:q = p.detach().clone()mean = torch.zeros(1, dtype=p.dtype, device=p.device)q_max = get_q_max(q, b, dim=dim, sc... | 4 | 22 | 4 | 230 | 0 | 189 | 214 | 189 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (quantize) defined within the public class called public.The function start at line 189 and ends at 214. It contains 22 lines of code and it has a cyclomatic complexity of 4. It takes 4 parameters, represented as [189.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self,mapping_type: MappingType = MappingType.SYMMETRIC,target_dtype: torch.dtype = torch.int8,quant_min: Optional[Union[int, float]] = None,quant_max: Optional[Union[int, float]] = None,eps: Optional[float] = None,preserve_zero: bool = True,zero_point_domain: ZeroPointDomain = ZeroPointDomain.INT,) -> None... | 8 | 29 | 8 | 194 | 0 | 39 | 71 | 39 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 39 and ends at 71. It contains 29 lines of code and it has a cyclomatic complexity of 8. It takes 8 parameters, represented as [39.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _init_quant_min_max | def _init_quant_min_max(self, b: int) -> None:if self.quant_min is None or self.quant_max is None:assert b in _BIT_WIDTH_TO_DTYPE, f"Unsupported bitwidth {b}"self.quant_min, self.quant_max = _DTYPE_TO_QVALUE_BOUNDS[_BIT_WIDTH_TO_DTYPE[b]] | 3 | 6 | 2 | 46 | 0 | 73 | 78 | 73 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_init_quant_min_max) defined within the public class called public.The function start at line 73 and ends at 78. It contains 6 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [73.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_quant_size | def get_quant_size(self, b: int) -> int:self._init_quant_min_max(b)return self.quant_max - self.quant_min + 1 | 1 | 3 | 2 | 27 | 0 | 80 | 82 | 80 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_quant_size) defined within the public class called public.The function start at line 80 and ends at 82. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [80.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | quantize | def quantize(self, p: Tensor, b: int, dim: Optional[int] = None) -> tuple[Tensor, Tensor]:self._init_quant_min_max(b)if self.eps is None:self.eps = torch.finfo(p.dtype).eps# assume that p has already been grouped in QuantOptimizer.stepblock_size = (1, p.size(-1)) if dim is not None else p.size()s, zero_point = self._ch... | 5 | 48 | 4 | 329 | 0 | 84 | 138 | 84 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (quantize) defined within the public class called public.The function start at line 84 and ends at 138. It contains 48 lines of code and it has a cyclomatic complexity of 5. It takes 4 parameters, represented as [84.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, b: int, int_shift: float = 0.5, **kwargs) -> None:quant_absmax = 2 ** (b - 1) - int_shiftself.quant_min = -quant_absmaxself.quant_max = quant_absmaxself.int_shift = int_shiftsuper().__init__(mapping_type=MappingType.ASYMMETRIC,quant_min=self.quant_min,quant_max=self.quant_max,**kwargs,)self._choose_q... | 1 | 13 | 4 | 94 | 0 | 142 | 156 | 142 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 142 and ends at 156. It contains 13 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [142.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_quant_size | def get_quant_size(self, b: int) -> int:return math.floor(2**b - 2 * self.int_shift) + 1 | 1 | 2 | 2 | 28 | 0 | 158 | 159 | 158 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_quant_size) defined within the public class called public.The function start at line 158 and ends at 159. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [158.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self) -> None:super().__init__(mapping_type=MappingType.ASYMMETRIC,target_dtype=torch.int32,quant_min=0,quant_max=15,eps=1e-6,preserve_zero=False,zero_point_domain=ZeroPointDomain.FLOAT,) | 1 | 10 | 1 | 50 | 0 | 165 | 174 | 165 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 165 and ends at 174. It contains 10 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(ctx,_input: torch.Tensor,weight: torch.Tensor,bias: Optional[torch.Tensor],activation_config: NVFP4FakeQuantizeConfig,weight_config: NVFP4FakeQuantizeConfig,) -> torch.Tensor:# quantize input activationsif activation_config.use_per_tensor_scale:tensor_amax = torch.max(torch.abs(_input))per_tensor_scale = pe... | 3 | 38 | 6 | 176 | 0 | 42 | 87 | 42 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 42 and ends at 87. It contains 38 lines of code and it has a cyclomatic complexity of 3. It takes 6 parameters, represented as [42.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | backward | def backward(ctx, grad_output: torch.Tensor) -> torch.Tensor:_input, weight = ctx.saved_tensorsassert isinstance(_input, NVFP4Tensor)assert isinstance(weight, NVFP4Tensor)_input = _input.to_dtype(_input._orig_dtype)weight = weight.to_dtype(weight._orig_dtype)grad_input = torch.mm(grad_output, weight)grad_weight = torch... | 1 | 9 | 2 | 90 | 0 | 90 | 98 | 90 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (backward) defined within the public class called public.The function start at line 90 and ends at 98. It contains 9 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 | __init__ | def __init__(self,in_features: int,out_features: int,bias: bool = False,activation_config: Optional[NVFP4FakeQuantizeConfig] = None,weight_config: Optional[NVFP4FakeQuantizeConfig] = None,*args,**kwargs,):super().__init__(in_features,out_features,bias,*args,**kwargs,)if weight_config is None:raise ValueError("Must spec... | 3 | 23 | 8 | 93 | 0 | 126 | 148 | 126 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 126 and ends at 148. It contains 23 lines of code and it has a cyclomatic complexity of 3. It takes 8 parameters, represented as [126.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(self, x: torch.Tensor) -> torch.Tensor:if x.dim() == 3:batch_size = x.shape[0]x = x.view(-1, x.shape[-1])else:batch_size = Nonefq = _NVFP4QuantizedForwardFakeQuantizedBackward.apply(x, self.weight, self.bias, self.activation_config, self.weight_config)assert fq.dtype == x.dtypeif batch_size is not None:retu... | 3 | 14 | 2 | 114 | 0 | 150 | 163 | 150 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 150 and ends at 163. It contains 14 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [150.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | from_linear | def from_linear(cls,mod: torch.nn.Linear,activation_config: Optional[NVFP4FakeQuantizeConfig] = None,weight_config: Optional[NVFP4FakeQuantizeConfig] = None,):new_linear = NVFP4FakeQuantizedLinear(mod.in_features,mod.out_features,mod.bias is not None,activation_config=activation_config,weight_config=weight_config,devic... | 2 | 19 | 4 | 106 | 0 | 166 | 187 | 166 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (from_linear) defined within the public class called public.The function start at line 166 and ends at 187. It contains 19 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [166.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _is_linear | def _is_linear(mod, *args):# avoid circular dependenciesfrom torchao.quantization.qat.affine_fake_quantized_tensor import (_AffineFakeQuantizedTensor,)# adding weight tensor subclass isinstance check to make sure the weight is only quantized once# when it is shared by multiple linear modulesreturn (isinstance(mod, torc... | 8 | 14 | 2 | 107 | 0 | 72 | 89 | 72 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_is_linear) defined within the public class called public.The function start at line 72 and ends at 89. It contains 14 lines of code and it has a cyclomatic complexity of 8. It takes 2 parameters, represented as [72.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _graph_equals | def _graph_equals(g1, g2):if len(g1.nodes) != len(g2.nodes):return Falsefor n1, n2 in zip(g1.nodes, g2.nodes):if n1.op != n2.op:return Falseif n1.op in ["call_function", "call_method"] and n1.target != n2.target:return Falseif len(n1.args) != len(n2.args):return Falsereturn True | 7 | 11 | 2 | 91 | 0 | 93 | 106 | 93 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_graph_equals) defined within the public class called public.The function start at line 93 and ends at 106. It contains 11 lines of code and it has a cyclomatic complexity of 7. It takes 2 parameters, represented as [93.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | check_cache | def check_cache(gm, cls, shapes_and_dtype):for gm_, cls_, shapes_and_dtype_ in _AUTOQUANT_CACHE.keys():graph_equals = _graph_equals(gm_.graph, gm.graph)if graph_equals and cls_ is cls and shapes_and_dtype_ == shapes_and_dtype:return _AUTOQUANT_CACHE[(gm_, cls_, shapes_and_dtype_)]return None | 5 | 6 | 3 | 58 | 1 | 119 | 124 | 119 | null | ['graph_equals'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (check_cache) defined within the public class called public.The function start at line 119 and ends at 124. It contains 6 lines of code and it has a cyclomatic complexity of 5. It takes 3 parameters, represented as [119.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | update_cache | def update_cache(gm, cls, shapes_and_dtype, res):_AUTOQUANT_CACHE[(gm, cls, shapes_and_dtype)] = res | 1 | 2 | 4 | 23 | 0 | 127 | 128 | 127 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (update_cache) defined within the public class called public.The function start at line 127 and ends at 128. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [127.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | resize_input | def resize_input(t, extracted_bsz, target_bsz):if len(t.shape) > 1:new_shape = []for i in range(len(t.size())):if t.size(i) == extracted_bsz:new_shape.append(target_bsz)else:new_shape.append(t.size(i))t = torch.randn(*new_shape, dtype=t.dtype, device=t.device)return t | 4 | 10 | 3 | 90 | 2 | 135 | 144 | 135 | null | ['t', 'new_shape'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (resize_input) defined within the public class called public.The function start at line 135 and ends at 144. It contains 10 lines of code and it has a cyclomatic complexity of 4. It takes 3 parameters, represented as [135.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.