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 | _get_tensor_impl_constructor | def _get_tensor_impl_constructor(tensor_class: Callable, layout_class: Callable) -> Callable:"""Get TensorImpl class constructor (TensorImplClass.from_plain) for `tensor_class` based on `layout_class``layout_class` means the class type of subclass of `Layout`, e.g. `PlainLayout`Args:tensor_class: Tensor subclass typela... | 3 | 12 | 2 | 50 | 0 | 712 | 734 | 712 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_get_tensor_impl_constructor) defined within the public class called public.The function start at line 712 and ends at 734. It contains 12 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [712.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _get_to_kwargs | def _get_to_kwargs(self, *args, **kwargs):# `torch._C._nn._parse_to` can't handle `layout` argumentargs = tuple(arg for arg in args if not isinstance(arg, torch.layout))if "layout" in kwargs:kwargs.pop("layout")# ignoring `non_blocking` and `memory_format` args since these are not# very useful for most of the tensor su... | 6 | 12 | 3 | 100 | 4 | 737 | 753 | 737 | null | ['kwargs', 'args', 'dtype', 'device'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_get_to_kwargs) defined within the public class called public.The function start at line 737 and ends at 753. It contains 12 lines of code and it has a cyclomatic complexity of 6. It takes 3 parameters, represented as [737.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init_subclass__ | def __init_subclass__(cls, **kwargs):if not hasattr(cls, "_ATEN_OP_OR_TORCH_FN_TABLE"):cls._ATEN_OP_OR_TORCH_FN_TABLE = {}if cls not in cls._ATEN_OP_OR_TORCH_FN_TABLE:cls._ATEN_OP_OR_TORCH_FN_TABLE[cls] = {}# define the common ops and __set_state__ for BC# if the tensor_data_names and tensor_attribute_names are defined... | 7 | 13 | 2 | 95 | 0 | 852 | 871 | 852 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init_subclass__) defined within the public class called public.The function start at line 852 and ends at 871. It contains 13 lines of code and it has a cyclomatic complexity of 7. It takes 2 parameters, represented as [852.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, *args, **kwargs):torch._C._log_api_usage_once(str(type(self))) | 1 | 2 | 3 | 25 | 0 | 881 | 882 | 881 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 881 and ends at 882. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [881.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __tensor_flatten__ | def __tensor_flatten__(self):if hasattr(self, "tensor_data_names") and hasattr(self, "tensor_attribute_names"):tensor_data_names = self.tensor_data_names.copy()if hasattr(self, "optional_tensor_data_names"):for tensor_data_name in self.optional_tensor_data_names:maybe_tensor = getattr(self, tensor_data_name)if maybe_te... | 9 | 22 | 1 | 119 | 0 | 884 | 908 | 884 | 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 884 and ends at 908. It contains 22 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 | __tensor_unflatten__ | def __tensor_unflatten__(cls, tensor_data_dict, tensor_attributes, outer_size, outer_stride):if hasattr(cls, "tensor_data_names") and hasattr(cls, "tensor_attribute_names"):required_tensors = [tensor_data_dict[name] for name in cls.tensor_data_names]optional_tensor_dict = {}if hasattr(cls, "optional_tensor_data_names")... | 9 | 31 | 5 | 137 | 0 | 911 | 944 | 911 | 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 911 and ends at 944. It contains 31 lines of code and it has a cyclomatic complexity of 9. It takes 5 parameters, represented as [911.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _apply_fn_to_data | def _apply_fn_to_data(self, fn):if hasattr(self, "tensor_data_names") and hasattr(self, "tensor_attribute_names"):required_tensors = [fn(getattr(self, attr)) for attr in self.tensor_data_names]optional_tensor_dict = {}if hasattr(self, "optional_tensor_data_names"):for tensor_data_name in self.optional_tensor_data_names... | 10 | 33 | 2 | 160 | 0 | 946 | 981 | 946 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_apply_fn_to_data) defined within the public class called public.The function start at line 946 and ends at 981. It contains 33 lines of code and it has a cyclomatic complexity of 10. It takes 2 parameters, represented as [946.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __repr__ | def __repr__(self):if hasattr(self, "tensor_data_names") and hasattr(self, "tensor_attribute_names"):repr_str = ""# required tensor datarepr_str += f"{self.tensor_data_names[0]}={getattr(self, self.tensor_data_names[0])}"for tensor_data_name in self.tensor_data_names[1:]:repr_str += f", {tensor_data_name}={getattr(self... | 9 | 24 | 1 | 103 | 0 | 983 | 1,015 | 983 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__repr__) defined within the public class called public.The function start at line 983 and ends at 1015. It contains 24 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_layout | def get_layout(self):if not hasattr(self, "_layout"):return Nonereturn self._layout | 2 | 4 | 1 | 20 | 0 | 1,017 | 1,020 | 1,017 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_layout) defined within the public class called public.The function start at line 1017 and ends at 1020. 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 | fill_defaults | def fill_defaults(args, n, defaults_tail):"""__torch_dispatch__ doesn't guarantee the number of arguments you arepassed (e.g., defaulted arguments are not passed); but usually it isconvenient to pad out the arguments list with defaults.This functionhelps you do that.Args:args: the list of positional arguments passed to... | 3 | 7 | 3 | 65 | 1 | 1,023 | 1,045 | 1,023 | null | ['r'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (fill_defaults) defined within the public class called public.The function start at line 1023 and ends at 1045. It contains 7 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [1023.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | is_ROCM | def is_ROCM():return torch.cuda.is_available() and torch.version.hip | 2 | 2 | 0 | 18 | 0 | 1,057 | 1,058 | 1,057 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (is_ROCM) defined within the public class called public.The function start at line 1057 and ends at 1058. 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 | is_MI300 | def is_MI300():if is_ROCM():mxArchName = ["gfx940", "gfx941", "gfx942"]archName = torch.cuda.get_device_properties(0).gcnArchNamefor arch in mxArchName:if arch in archName:return Truereturn False | 4 | 8 | 0 | 44 | 2 | 1,061 | 1,068 | 1,061 | null | ['mxArchName', 'archName'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (is_MI300) defined within the public class called public.The function start at line 1061 and ends at 1068. It contains 8 lines of code and it has a cyclomatic complexity of 4. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | is_MI350 | def is_MI350():if is_ROCM():archName = torch.cuda.get_device_properties(0).gcnArchNameif "gfx950" in archName:return Truereturn False | 3 | 6 | 0 | 30 | 1 | 1,071 | 1,076 | 1,071 | null | ['archName'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (is_MI350) defined within the public class called public.The function start at line 1071 and ends at 1076. It contains 6 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 | is_Navi4 | def is_Navi4():if is_ROCM():archName = torch.cuda.get_device_properties(0).gcnArchNameif "gfx1200" or "gfx1201" in archName:return Truereturn False | 4 | 6 | 0 | 32 | 1 | 1,079 | 1,084 | 1,079 | null | ['archName'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (is_Navi4) defined within the public class called public.The function start at line 1079 and ends at 1084. It contains 6 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 | is_sm_version | def is_sm_version(major: int, minor: int) -> bool:"""Check if the CUDA version is exactly major.minor"""is_cuda = torch.cuda.is_available() and torch.version.cudareturn torch.cuda.get_device_capability() == (major, minor) if is_cuda else False | 3 | 3 | 2 | 47 | 1 | 1,087 | 1,090 | 1,087 | null | ['is_cuda'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (is_sm_version) defined within the public class called public.The function start at line 1087 and ends at 1090. It contains 3 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [1087.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | is_sm_at_least_89 | def is_sm_at_least_89():return (torch.cuda.is_available()and torch.version.cudaand torch.cuda.get_device_capability() >= (8, 9)) | 3 | 6 | 0 | 34 | 0 | 1,093 | 1,098 | 1,093 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (is_sm_at_least_89) defined within the public class called public.The function start at line 1093 and ends at 1098. It contains 6 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 | is_sm_at_least_90 | def is_sm_at_least_90():return (torch.cuda.is_available()and torch.version.cudaand torch.cuda.get_device_capability() >= (9, 0)) | 3 | 6 | 0 | 34 | 0 | 1,101 | 1,106 | 1,101 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (is_sm_at_least_90) defined within the public class called public.The function start at line 1101 and ends at 1106. It contains 6 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 | is_sm_at_least_100 | def is_sm_at_least_100():return (torch.cuda.is_available()and torch.version.cudaand torch.cuda.get_device_capability() >= (10, 0)) | 3 | 6 | 0 | 34 | 0 | 1,110 | 1,115 | 1,110 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (is_sm_at_least_100) defined within the public class called public.The function start at line 1110 and ends at 1115. It contains 6 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 | check_cpu_version | def check_cpu_version(device, version="2.6.0"):if isinstance(device, torch.device):device = device.typereturn device == "cpu" and torch_version_at_least(version) | 3 | 4 | 2 | 33 | 1 | 1,118 | 1,121 | 1,118 | null | ['device'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (check_cpu_version) defined within the public class called public.The function start at line 1118 and ends at 1121. It contains 4 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [1118.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | check_xpu_version | def check_xpu_version(device, version="2.8.0"):if isinstance(device, torch.device):device = device.typereturn device == "xpu" and torch_version_at_least(version) | 3 | 4 | 2 | 33 | 1 | 1,124 | 1,127 | 1,124 | null | ['device'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (check_xpu_version) defined within the public class called public.The function start at line 1124 and ends at 1127. It contains 4 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [1124.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | ceil_div | def ceil_div(a, b):return (a + b - 1) // b | 1 | 2 | 2 | 16 | 0 | 1,130 | 1,131 | 1,130 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (ceil_div) defined within the public class called public.The function start at line 1130 and ends at 1131. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [1130.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | is_package_at_least | def is_package_at_least(package_name: str, min_version: str):package_exists = importlib.util.find_spec(package_name) is not Noneif not package_exists:return Falsereturn version(package_name) >= min_version | 2 | 5 | 2 | 37 | 1 | 1,134 | 1,139 | 1,134 | null | ['package_exists'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (is_package_at_least) defined within the public class called public.The function start at line 1134 and ends at 1139. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [1134.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _is_fbgemm_gpu_genai_available | def _is_fbgemm_gpu_genai_available():# TODO: use is_package_at_least("fbgemm_gpu", "1.2.0") when# https://github.com/pytorch/FBGEMM/issues/4198 is fixedif importlib.util.find_spec("fbgemm_gpu") is None:return Falseimport fbgemm_gpu.experimental.gen_ai# noqa: F401if not is_fbcode() and fbgemm_gpu.__version__ < "1.2.0":r... | 4 | 7 | 0 | 40 | 0 | 1,142 | 1,153 | 1,142 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_is_fbgemm_gpu_genai_available) defined within the public class called public.The function start at line 1142 and ends at 1153. It contains 7 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 | __init__ | def __init__(self, weight: torch.Tensor, bias: Optional[torch.Tensor] = None):super().__init__()self.weight = weightself.bias = bias | 1 | 4 | 3 | 39 | 0 | 1,161 | 1,164 | 1,161 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 1161 and ends at 1164. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [1161.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, model, tokenizer, max_seq_length, input_prep_func=None, device="cuda"):try:super().__init__(device=device)except TypeError:# lm_eval 0.4.2 removed the default initsuper().__init__("gpt2", device="cpu")self._model = modelself.tokenizer = tokenizerself._device = torch.device(device)self._max_seq_length... | 3 | 14 | 6 | 91 | 0 | 34 | 52 | 34 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 34 and ends at 52. It contains 14 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 | _model_call | def _model_call(self, inps):# TODO: make batches workinput = self.input_prep_func(inps)max_seq_length = min(max(inps.size()), self.max_length)with torch.device(self._device):if hasattr(self._model, "setup_caches"):self._model.setup_caches(self.batch_size, max_seq_length)output = self._model(*input)from transformers.mod... | 3 | 16 | 2 | 116 | 0 | 54 | 72 | 54 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_model_call) defined within the public class called public.The function start at line 54 and ends at 72. It contains 16 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [54.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | run_eval | def run_eval(self, tasks, limit):try:lm_eval.tasks.initialize_tasks()except:passtask_dict = get_task_dict(tasks)print("Evaluating Model On: ", task_dict)with torch.no_grad():result = evaluate(self,task_dict,limit=limit,)for task, res in result["results"].items():print(f"{task}: {res}")return result | 3 | 16 | 3 | 74 | 0 | 74 | 90 | 74 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (run_eval) defined within the public class called public.The function start at line 74 and ends at 90. It contains 16 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [74.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | eot_token_id | def eot_token_id(self):try:return self.tokenizer.eos_id()except:try:return self.tokenizer.eos_idexcept:idx = self.tokenizer.all_special_tokens.index("<|endoftext|>")return self.tokenizer.all_special_ids[idx] | 3 | 9 | 1 | 48 | 0 | 93 | 101 | 93 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (eot_token_id) defined within the public class called public.The function start at line 93 and ends at 101. It contains 9 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 | max_length | def max_length(self):return self._max_seq_length | 1 | 2 | 1 | 9 | 0 | 104 | 105 | 104 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (max_length) defined within the public class called public.The function start at line 104 and ends at 105. 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 | max_gen_toks | def max_gen_toks(self):return 50 | 1 | 2 | 1 | 7 | 0 | 108 | 109 | 108 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (max_gen_toks) defined within the public class called public.The function start at line 108 and ends at 109. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | batch_size | def batch_size(self):return 1 | 1 | 2 | 1 | 7 | 0 | 112 | 113 | 112 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (batch_size) defined within the public class called public.The function start at line 112 and ends at 113. 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 | device | def device(self):return self._device | 1 | 2 | 1 | 9 | 0 | 116 | 117 | 116 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (device) defined within the public class called public.The function start at line 116 and ends at 117. 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 | tok_decode | def tok_decode(self, tokens, **kwargs):decoded = self.tokenizer.decode(tokens, **kwargs)return decoded | 1 | 3 | 3 | 25 | 0 | 119 | 121 | 119 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (tok_decode) defined within the public class called public.The function start at line 119 and ends at 121. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [119.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | tok_encode | def tok_encode(self, string: str, **kwargs):tokens = self.tokenizer.encode(string)if hasattr(self.tokenizer, "bos_id"):try:tokens = [self.tokenizer.bos_id()] + tokensexcept:tokens = [self.tokenizer.bos_id] + tokensreturn tokens | 3 | 8 | 3 | 62 | 0 | 123 | 130 | 123 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (tok_encode) defined within the public class called public.The function start at line 123 and ends at 130. It contains 8 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [123.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self,tokenizer,calibration_seq_length,input_prep_func=None,vocab_size=32000,pad_calibration_inputs=False,pad_token=0,device="cpu",base_input_recorder_class=MultiTensorInputRecorder,):super().__init__(model=None,tokenizer=tokenizer,max_seq_length=calibration_seq_length,input_prep_func=input_prep_func,device... | 1 | 23 | 9 | 88 | 0 | 134 | 159 | 134 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 134 and ends at 159. It contains 23 lines of code and it has a cyclomatic complexity of 1. It takes 9 parameters, represented as [134.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | record_inputs | def record_inputs(self, calibration_tasks, calibration_limit):try:lm_eval.tasks.initialize_tasks()except:passtask_dict = get_task_dict(calibration_tasks)print("Obtaining GPTQ calibration inputs on: ", calibration_tasks)evaluate(self,task_dict,limit=calibration_limit,)return self | 2 | 13 | 3 | 46 | 0 | 161 | 175 | 161 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (record_inputs) defined within the public class called public.The function start at line 161 and ends at 175. It contains 13 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [161.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_inputs | def get_inputs(self):# for BCreturn self.get_recorded_inputs() | 1 | 2 | 1 | 11 | 0 | 177 | 178 | 177 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_inputs) defined within the public class called public.The function start at line 177 and ends at 178. 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 | get_recorded_inputs | def get_recorded_inputs(self):return self.base_input_recorder.get_recorded_inputs() | 1 | 2 | 1 | 13 | 0 | 180 | 181 | 180 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_recorded_inputs) defined within the public class called public.The function start at line 180 and ends at 181. 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 | get_recorded_args_and_kwargs | def get_recorded_args_and_kwargs(self):return self.base_input_recorder.get_recorded_args_and_kwargs() | 1 | 2 | 1 | 13 | 0 | 183 | 184 | 183 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_recorded_args_and_kwargs) defined within the public class called public.The function start at line 183 and ends at 184. 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 | _model_call | def _model_call(self, inps):inps = inps.squeeze(0)T = len(inps)if (# Can't use inputs that are too short when padding is disabled(T < self.calibration_seq_length and not self.pad_calibration_inputs)or# Can't use inputs that actually use the token we use for padding(self.pad_calibration_inputs and self.pad_token in inps... | 6 | 23 | 2 | 168 | 0 | 186 | 217 | 186 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_model_call) defined within the public class called public.The function start at line 186 and ends at 217. It contains 23 lines of code and it has a cyclomatic complexity of 6. It takes 2 parameters, represented as [186.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_arch_name | def get_arch_name() -> str:if torch.cuda.is_available():return torch.cuda.get_device_name()else:# This returns x86_64 or arm64 (for aarch64)return platform.machine() | 2 | 5 | 0 | 31 | 0 | 16 | 21 | 16 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_arch_name) defined within the public class called public.The function start at line 16 and ends at 21. 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 | write_json_result_ossci | def write_json_result_ossci(output_json_path, headers, row):"""Write the result into JSON format, so that it can be uploaded to the benchmark databaseto be displayed on OSS dashboard. The JSON format is defined athttps://github.com/pytorch/pytorch/wiki/How-to-integrate-with-PyTorch-OSS-benchmark-databaseOSS CI version,... | 2 | 27 | 3 | 160 | 2 | 24 | 59 | 24 | null | ['mapping_headers', 'record'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (write_json_result_ossci) defined within the public class called public.The function start at line 24 and ends at 59. It contains 27 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [24.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | write_json_result_local | def write_json_result_local(output_json_path, headers, row):"""Write the result into JSON format, so that it can be uploaded to the benchmark databaseto be displayed on OSS dashboard. The JSON format is defined athttps://github.com/pytorch/pytorch/wiki/How-to-integrate-with-PyTorch-OSS-benchmark-databaseLocal version (... | 2 | 41 | 3 | 263 | 7 | 62 | 111 | 62 | null | ['first_second', 'today', 'workflow_id', 'mapping_headers', 'sha_hash', 'job_id', 'record'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (write_json_result_local) defined within the public class called public.The function start at line 62 and ends at 111. It contains 41 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [62.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | run_evaluation | def run_evaluation(checkpoint_path: Path,tasks: List[str],limit: Optional[int] = None,device="cuda",precision=torch.bfloat16,quantization: Optional[str] = None,sparsity: Optional[str] = None,compile=False,max_length=None,calibration_tasks: Optional[List[str]] = None,calibration_limit: Optional[int] = None,calibration_s... | 28 | 237 | 13 | 1,279 | 21 | 33 | 291 | 33 | null | ['t0', 'quantizer', '_tokenizer', 'tokenizer', '_default_quant_args', 'tokenizer_path', '_quant_args', 'is_observed_linear', '_NBITS_TO_DTYPE', 'use_hqq', '_model_devie', 'is_target_module', 'granularity', 'quant_dtype', 'dtype', 'nbits', 'inputs', 'groupsize', 'group_size', 'model', 'max_length'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (run_evaluation) defined within the public class called public.The function start at line 33 and ends at 291. It contains 237 lines of code and it has a cyclomatic complexity of 28. It takes 13 parameters, represented as [33.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self):self.event_time = None | 1 | 2 | 1 | 10 | 0 | 30 | 31 | 30 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) 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 | record | def record(self):self.event_time = time.perf_counter() | 1 | 2 | 1 | 14 | 0 | 33 | 34 | 33 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (record) defined within the public class called public.The function start at line 33 and ends at 34. 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 | elapsed_time | def elapsed_time(self, other_event):if self.event_time is None:raise ValueError("Event not recorded!")# return ms to match cuda eventreturn abs(other_event.event_time - self.event_time) * 1000 | 2 | 4 | 2 | 32 | 0 | 36 | 40 | 36 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (elapsed_time) defined within the public class called public.The function start at line 36 and ends at 40. It contains 4 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [36.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | device_timer | def device_timer(device):if "cuda" in device:return torch.cuda.Event(enable_timing=True)elif "xpu" in device:return torch.xpu.Event(enable_timing=True)elif ("cpu" in device) or ("mps" in device):return HostEvent()else:print(f"device={device} is not yet suppported") | 5 | 9 | 1 | 61 | 0 | 43 | 51 | 43 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (device_timer) defined within the public class called public.The function start at line 43 and ends at 51. It contains 9 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 | device_sync | def device_sync(device):if "cuda" in device:torch.cuda.synchronize(device)elif "xpu" in device:torch.xpu.synchronize(device)elif ("cpu" in device) or ("mps" in device):passelse:print(f"device={device} is not yet suppported") | 5 | 9 | 1 | 52 | 0 | 54 | 62 | 54 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (device_sync) defined within the public class called public.The function start at line 54 and ends at 62. It contains 9 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 | multinomial_sample_one_no_sync | def multinomial_sample_one_no_sync(probs_sort,):# Does multinomial sampling without a cuda synchronizationq = torch.empty_like(probs_sort).exponential_(1)return torch.argmax(probs_sort / q, dim=-1, keepdim=True).to(dtype=torch.int) | 1 | 5 | 1 | 46 | 1 | 81 | 85 | 81 | null | ['q'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (multinomial_sample_one_no_sync) defined within the public class called public.The function start at line 81 and ends at 85. 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 | logits_to_probs | def logits_to_probs(logits, temperature: float = 1.0, top_k: Optional[int] = None):logits = logits / max(temperature, 1e-5)if top_k is not None:v, _ = torch.topk(logits, min(top_k, logits.size(-1)))pivot = v.select(-1, -1).unsqueeze(-1)logits = torch.where(logits < pivot, -float("Inf"), logits)probs = torch.nn.function... | 2 | 8 | 3 | 118 | 3 | 88 | 96 | 88 | null | ['pivot', 'logits', 'probs'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (logits_to_probs) defined within the public class called public.The function start at line 88 and ends at 96. It contains 8 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [88.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | sample | def sample(logits, temperature: float = 1.0, top_k: Optional[int] = None):probs = logits_to_probs(logits[:, -1], temperature, top_k)idx_next = multinomial_sample_one_no_sync(probs)return idx_next, probs | 1 | 4 | 3 | 48 | 2 | 99 | 102 | 99 | null | ['probs', 'idx_next'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (sample) defined within the public class called public.The function start at line 99 and ends at 102. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [99.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | prefill | def prefill(model: Transformer, x: torch.Tensor, input_pos: torch.Tensor, **sampling_kwargs) -> torch.Tensor:# input_pos: [B, S]logits = model(x, input_pos)return sample(logits, **sampling_kwargs)[0] | 1 | 5 | 4 | 45 | 1 | 105 | 110 | 105 | null | ['logits'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (prefill) defined within the public class called public.The function start at line 105 and ends at 110. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [105.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | decode_one_token | def decode_one_token(model: Transformer, x: torch.Tensor, input_pos: torch.Tensor, **sampling_kwargs) -> Tuple[torch.Tensor, torch.Tensor]:# input_pos: [B, 1]assert input_pos.shape[-1] == 1logits = model(x, input_pos)return sample(logits, **sampling_kwargs) | 1 | 6 | 4 | 59 | 1 | 113 | 119 | 113 | null | ['logits'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (decode_one_token) defined within the public class called public.The function start at line 113 and ends at 119. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [113.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | decode_n_tokens | def decode_n_tokens(model: Transformer,cur_token: torch.Tensor,input_pos: torch.Tensor,num_new_tokens: int,callback=lambda _: _,**sampling_kwargs,):new_tokens, new_probs = [], []for i in range(num_new_tokens):with torch.nn.attention.sdpa_kernel(torch.nn.attention.SDPBackend.MATH):next_token, next_prob = decode_one_toke... | 2 | 21 | 6 | 135 | 1 | 122 | 144 | 122 | null | ['cur_token'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (decode_n_tokens) defined within the public class called public.The function start at line 122 and ends at 144. It contains 21 lines of code and it has a cyclomatic complexity of 2. It takes 6 parameters, represented as [122.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | model_forward | def model_forward(model, x, input_pos):return model(x, input_pos) | 1 | 2 | 3 | 16 | 0 | 147 | 148 | 147 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (model_forward) defined within the public class called public.The function start at line 147 and ends at 148. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [147.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | generate | def generate(model: Transformer,prompt: torch.Tensor,max_new_tokens: int,batch_size: int,*,interactive: bool,callback=lambda x: x,kv_cache_quantization: bool = False,cache_size: Optional[int] = None,linear_causal_mask: bool = False,prefill_start_event: Optional[torch.cuda.Event] = None,prefill_end_event: Optional[torch... | 7 | 64 | 14 | 418 | 9 | 152 | 233 | 152 | null | ['input_pos', 'seq', 'device', 'T', 'prompt', 'new_tokens', 'cache_size', 'next_token', 'max_seq_length'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (generate) defined within the public class called public.The function start at line 152 and ends at 233. It contains 64 lines of code and it has a cyclomatic complexity of 7. It takes 14 parameters, represented as [152.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | encode_tokens | def encode_tokens(tokenizer, string, bos=True, device=default_device):tokens = tokenizer.encode(string)if bos:tokens = [tokenizer.bos_id()] + tokensreturn torch.tensor(tokens, dtype=torch.int, device=device) | 2 | 5 | 4 | 54 | 1 | 236 | 240 | 236 | null | ['tokens'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (encode_tokens) defined within the public class called public.The function start at line 236 and ends at 240. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [236.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _load_model | def _load_model(checkpoint_path, device, precision):checkpoint = torch.load(str(checkpoint_path), mmap=True, weights_only=True, map_location="cpu")if "model" in checkpoint and "stories" in str(checkpoint_path):checkpoint = checkpoint["model"]with torch.device("meta"):model = Transformer.from_name(checkpoint_path)model.... | 3 | 11 | 3 | 96 | 2 | 243 | 254 | 243 | null | ['checkpoint', '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 243 and ends at 254. It contains 11 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [243.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | main.ffn_only | def ffn_only(mod, fqn):return isinstance(mod, torch.nn.Linear) and "feed_forward" in fqn | 2 | 2 | 2 | 22 | 0 | 329 | 330 | 329 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (main.ffn_only) defined within the public class called public.The function start at line 329 and ends at 330. It contains 2 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [329.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | main.not_ffn_only | def not_ffn_only(mod, fqn):return isinstance(mod, torch.nn.Linear) and not ffn_only(mod, fqn) | 2 | 2 | 2 | 26 | 0 | 332 | 333 | 332 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (main.not_ffn_only) defined within the public class called public.The function start at line 332 and ends at 333. It contains 2 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [332.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | main.ffn_or_attn_only | def ffn_or_attn_only(mod, fqn):return isinstance(mod, torch.nn.Linear) and ("feed_forward" in fqn or "attention" in fqn) | 3 | 4 | 2 | 28 | 0 | 335 | 338 | 335 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (main.ffn_or_attn_only) defined within the public class called public.The function start at line 335 and ends at 338. It contains 4 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [335.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | main.callback | def callback(x):nonlocal done_generatingif done_generating:returnbuffer.append(tokenizer.decode([period_id] + x.squeeze(0).tolist())[1:])if x.item() == tokenizer.eos_id():done_generating = Trueif len(buffer) == 4 or done_generating:print("".join(buffer), end="", flush=True)buffer.clear() | 5 | 10 | 1 | 87 | 0 | 902 | 911 | 902 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (main.callback) defined within the public class called public.The function start at line 902 and ends at 911. It contains 10 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 | main.callback | def callback(x):buffer.append(tokenizer.decode([period_id] + x.squeeze(0).tolist())[1:])if len(buffer) == 4:print("".join(buffer), end="", flush=True)buffer.clear() | 2 | 5 | 1 | 63 | 0 | 918 | 922 | 918 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (main.callback) defined within the public class called public.The function start at line 918 and ends at 922. 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 | main | def main(prefill_size: Optional[int] = None,prompt: str = "Hello, my name is",demo_summarize_prompt: Optional[str] = None,interactive: bool = False,num_samples: int = 5,max_new_tokens: int = 100,batch_size: int = 1,top_k: int = 200,temperature: float = 0.8,checkpoint_path: Path = Path("checkpoints/meta-Transformer/Tran... | 106 | 740 | 10 | 3,637 | 61 | 260 | 1,102 | 260 | null | ['callback', 't0', 'prof', 'encoded', 'decode_tokpersec', 'tokenizer', 'tokpersec', 'model_size', 'output_dir', 'tokenizer_path', '_quant_args', 'is_observed_linear', 'f', 'weight_dtype', 'result_txt', '_NBITS_TO_DTYPE', 'is_asymmetric', 'memory_result', 'prompt_length', 'use_hqq', 'tok_list', 'granularity', 'decode_on... | None | null | 0 | 0 | 0 | null | 0 | null | The function (main) defined within the public class called public.The function start at line 260 and ends at 1102. It contains 740 lines of code and it has a cyclomatic complexity of 106. It takes 10 parameters, represented as [260.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | prepare_inputs_for_model | def prepare_inputs_for_model(inps, max_new_tokens=1):# this is because input from lm-eval is 2dif inps.dim() > 2:raise ValueError(f"Expected input to be of dim 1 or 2, but got {inps.dim()}")# this now works with batched inputsinput_pos = torch.arange(0, inps.shape[-1], device=inps.device).to(torch.int32)return (inps.vi... | 2 | 5 | 2 | 73 | 1 | 19 | 26 | 19 | null | ['input_pos'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (prepare_inputs_for_model) defined within the public class called public.The function start at line 19 and ends at 26. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [19.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __post_init__ | def __post_init__(self):if self.n_local_heads == -1:self.n_local_heads = self.n_headif self.intermediate_size is None:hidden_dim = 4 * self.dimn_hidden = int(2 * hidden_dim / 3)self.intermediate_size = find_multiple(n_hidden, 256)self.head_dim = self.dim // self.n_head | 3 | 8 | 1 | 62 | 0 | 44 | 51 | 44 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__post_init__) defined within the public class called public.The function start at line 44 and ends at 51. It contains 8 lines of code and it has a cyclomatic complexity of 3. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | from_name | def from_name(cls, name: str):if name in transformer_configs:return cls(**transformer_configs[name])# fuzzy searchconfig = [configfor config in transformer_configsif config in str(name).upper() or config in str(name)]# We may have two or more configs matched (e.g. "7B" and "Mistral-7B"). Find the best config match,# ta... | 6 | 14 | 2 | 102 | 0 | 54 | 72 | 54 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (from_name) defined within the public class called public.The function start at line 54 and ends at 72. It contains 14 lines of code and it has a cyclomatic complexity of 6. It takes 2 parameters, represented as [54.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, max_batch_size, max_seq_length, n_heads, head_dim, dtype=torch.bfloat16):super().__init__()cache_shape = (max_batch_size, n_heads, max_seq_length, head_dim)self.register_buffer("k_cache", torch.zeros(cache_shape, dtype=dtype))self.register_buffer("v_cache", torch.zeros(cache_shape, dtype=dtype)) | 1 | 7 | 6 | 71 | 0 | 167 | 173 | 167 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 167 and ends at 173. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [167.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | update | def update(self, input_pos, k_val, v_val):# input_pos: [S], k_val: [B, H, S, D]assert input_pos.shape[0] == k_val.shape[2]if use_index_put_for_kv_cache:k_out = torch.ops.aten.index_put_(self.k_cache, [None, None, input_pos], k_val)v_out = torch.ops.aten.index_put_(self.v_cache, [None, None, input_pos], v_val)else:k_out... | 2 | 15 | 4 | 112 | 0 | 175 | 192 | 175 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (update) defined within the public class called public.The function start at line 175 and ends at 192. It contains 15 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [175.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self,max_batch_size,max_seq_length,n_heads,head_dim,scale_dtype=torch.bfloat16,):super().__init__()cache_shape = (max_batch_size, n_heads, max_seq_length, head_dim)scale_shape = (max_batch_size, n_heads, max_seq_length, 1)self.register_buffer("k_cache", torch.zeros(cache_shape, dtype=torch.int8))self.regis... | 1 | 19 | 6 | 121 | 0 | 199 | 217 | 199 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 199 and ends at 217. It contains 19 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [199.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | update | def update(self, input_pos, k_val, v_val):# quantize current k_val and store it in the cacheq_k_val, k_scale = _quantize_activation_per_token_absmax(k_val)self.k_cache[:, :, input_pos] = q_k_valself.k_cache_scale[:, :, input_pos] = k_scale.unsqueeze(-1)k_out = self.k_cache * self.k_cache_scalek_out[:, :, input_pos] = k... | 1 | 12 | 4 | 129 | 0 | 219 | 233 | 219 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (update) defined within the public class called public.The function start at line 219 and ends at 233. It contains 12 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [219.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | from_float | def from_float(cls, kv_cache):cache_shape = kv_cache.k_cache.shapemax_batch_size, n_heads, max_seq_length, head_dim = cache_shapescale_dtype = kv_cache.k_cache.dtypereturn cls(max_batch_size, max_seq_length, n_heads, head_dim, scale_dtype) | 1 | 5 | 2 | 43 | 0 | 236 | 240 | 236 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (from_float) defined within the public class called public.The function start at line 236 and ends at 240. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [236.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, config: ModelArgs) -> None:super().__init__()self.config = configself.tok_embeddings = nn.Embedding(config.vocab_size, config.dim)self.layers = nn.ModuleList(TransformerBlock(config) for _ in range(config.n_layer))self.norm = RMSNorm(config.dim, eps=config.norm_eps)self.output = nn.Linear(config.dim,... | 2 | 13 | 2 | 129 | 0 | 244 | 258 | 244 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 244 and ends at 258. It contains 13 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [244.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | setup_caches | def setup_caches(self,max_batch_size,max_seq_length,training: bool = False,kv_cache_quantization=None,linear_causal_mask=False,prompt_length=None,):if (self.max_seq_length >= max_seq_lengthand self.max_batch_size >= max_batch_size):returnhead_dim = self.config.dim // self.config.n_headmax_seq_length = find_multiple(max... | 11 | 67 | 7 | 343 | 0 | 260 | 330 | 260 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (setup_caches) defined within the public class called public.The function start at line 260 and ends at 330. It contains 67 lines of code and it has a cyclomatic complexity of 11. It takes 7 parameters, represented as [260.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | reset_caches | def reset_caches(self):"""Reset caches.The caches used by training stage and inference stage may be different, reset them before switching."""self.max_batch_size = -1self.max_seq_length = -1self.freqs_cis: Optional[Tensor] = Noneself.mask_cache: Optional[Tensor] = None | 1 | 5 | 1 | 38 | 0 | 332 | 340 | 332 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (reset_caches) defined within the public class called public.The function start at line 332 and ends at 340. 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 | forward | def forward(self, idx: Tensor, input_pos: Optional[Tensor] = None) -> Tensor:"""Forward pass of the model.Args:idx(`torch.LongTensor` of shape `(batch_size, seq_length)`):Indices of input sequence tokens in the vocabulary.input_pos (`torch.LongTensor` of shape `(batch_size, seq_length)`, *optional*):Indices of position... | 6 | 33 | 3 | 210 | 0 | 342 | 390 | 342 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 342 and ends at 390. It contains 33 lines of code and it has a cyclomatic complexity of 6. It takes 3 parameters, represented as [342.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | from_name | def from_name(cls, name: str):return cls(ModelArgs.from_name(name)) | 1 | 2 | 2 | 19 | 0 | 393 | 394 | 393 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (from_name) defined within the public class called public.The function start at line 393 and ends at 394. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [393.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, config: ModelArgs) -> None:super().__init__()self.attention = Attention(config)self.feed_forward = FeedForward(config)self.ffn_norm = RMSNorm(config.dim, config.norm_eps)self.attention_norm = RMSNorm(config.dim, config.norm_eps) | 1 | 6 | 2 | 62 | 0 | 398 | 403 | 398 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 398 and ends at 403. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [398.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(self,x: Tensor,input_pos: Optional[Tensor],freqs_cis: Tensor,mask: Optional[Tensor],) -> Tensor:h = x + self.attention(self.attention_norm(x), freqs_cis, mask, input_pos)out = h + self.feed_forward(self.ffn_norm(h))return out | 1 | 10 | 5 | 68 | 0 | 405 | 414 | 405 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 405 and ends at 414. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [405.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, config: ModelArgs):super().__init__()assert config.dim % config.n_head == 0total_head_dim = (config.n_head + 2 * config.n_local_heads) * config.head_dim# key, query, value projections for all heads, but in a batchself.wqkv = nn.Linear(config.dim, total_head_dim, bias=False)self.wo = nn.Linear(config.... | 1 | 12 | 2 | 122 | 0 | 418 | 432 | 418 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 418 and ends at 432. It contains 12 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [418.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | load_hook | def load_hook(self, state_dict, prefix, *args):if prefix + "wq.weight" in state_dict:wq = state_dict.pop(prefix + "wq.weight")wk = state_dict.pop(prefix + "wk.weight")wv = state_dict.pop(prefix + "wv.weight")state_dict[prefix + "wqkv.weight"] = torch.cat([wq, wk, wv]) | 2 | 6 | 4 | 68 | 0 | 434 | 439 | 434 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (load_hook) defined within the public class called public.The function start at line 434 and ends at 439. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [434.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(self,x: Tensor,freqs_cis: Tensor,mask: Optional[Tensor],input_pos: Optional[Tensor] = None,) -> Tensor:bsz, seqlen, _ = x.shapekv_size = self.n_local_heads * self.head_dimq, k, v = self.wqkv(x).split([self.dim, kv_size, kv_size], dim=-1)q = q.view(bsz, seqlen, self.n_head, self.head_dim)k = k.view(bsz, seql... | 3 | 27 | 5 | 309 | 0 | 441 | 475 | 441 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 441 and ends at 475. It contains 27 lines of code and it has a cyclomatic complexity of 3. It takes 5 parameters, represented as [441.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, config: ModelArgs) -> None:super().__init__()self.w1 = nn.Linear(config.dim, config.intermediate_size, bias=False)self.w3 = nn.Linear(config.dim, config.intermediate_size, bias=False)self.w2 = nn.Linear(config.intermediate_size, config.dim, bias=False) | 1 | 5 | 2 | 78 | 0 | 479 | 483 | 479 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 479 and ends at 483. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [479.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(self, x: Tensor) -> Tensor:return self.w2(F.silu(self.w1(x)) * self.w3(x)) | 1 | 2 | 2 | 35 | 0 | 485 | 486 | 485 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 485 and ends at 486. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [485.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, dim: int, eps: float = 1e-5):super().__init__()self.eps = epsself.weight = nn.Parameter(torch.ones(dim)) | 1 | 4 | 3 | 44 | 0 | 490 | 493 | 490 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 490 and ends at 493. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [490.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _norm | def _norm(self, x):return x * torch.rsqrt(torch.mean(x * x, dim=-1, keepdim=True) + self.eps) | 1 | 2 | 2 | 36 | 0 | 495 | 496 | 495 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_norm) defined within the public class called public.The function start at line 495 and ends at 496. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [495.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(self, x: Tensor) -> Tensor:output = self._norm(x.float()).type_as(x)return output * self.weight | 1 | 3 | 2 | 34 | 0 | 498 | 500 | 498 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 498 and ends at 500. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [498.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | apply_scaling | def apply_scaling(freqs: torch.Tensor):# Values obtained from grid searchscale_factor = 8low_freq_factor = 1high_freq_factor = 4old_context_len = 8192# original llama3 lengthlow_freq_wavelen = old_context_len / low_freq_factorhigh_freq_wavelen = old_context_len / high_freq_factornew_freqs = []for freq in freqs:wavelen ... | 4 | 21 | 1 | 131 | 9 | 503 | 525 | 503 | null | ['old_context_len', 'low_freq_factor', 'low_freq_wavelen', 'new_freqs', 'wavelen', 'scale_factor', 'high_freq_factor', 'smooth', 'high_freq_wavelen'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (apply_scaling) defined within the public class called public.The function start at line 503 and ends at 525. It contains 21 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 | precompute_freqs_cis | def precompute_freqs_cis(seq_len: int,n_elem: int,base: int = 10000,dtype: torch.dtype = torch.bfloat16,use_scaled: bool = False,) -> Tensor:freqs = 1.0 / (base ** (torch.arange(0, n_elem, 2)[: (n_elem // 2)].float() / n_elem))t = torch.arange(seq_len, device=freqs.device)if use_scaled:freqs = apply_scaling(freqs)freqs... | 2 | 17 | 5 | 140 | 4 | 528 | 544 | 528 | null | ['cache', 't', 'freqs', 'freqs_cis'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (precompute_freqs_cis) defined within the public class called public.The function start at line 528 and ends at 544. It contains 17 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [528.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | apply_rotary_emb | def apply_rotary_emb(x: Tensor, freqs_cis: Tensor) -> Tensor:xshaped = x.float().reshape(*x.shape[:-1], -1, 2)freqs_cis = freqs_cis.view(1, xshaped.size(1), 1, xshaped.size(3), 2)x_out2 = torch.stack([xshaped[..., 0] * freqs_cis[..., 0] - xshaped[..., 1] * freqs_cis[..., 1],xshaped[..., 1] * freqs_cis[..., 0] + xshaped... | 1 | 12 | 2 | 148 | 3 | 547 | 559 | 547 | null | ['xshaped', 'x_out2', 'freqs_cis'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (apply_rotary_emb) defined within the public class called public.The function start at line 547 and ends at 559. It contains 12 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [547.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, model_path):self.model_path = model_path | 1 | 2 | 2 | 12 | 0 | 13 | 14 | 13 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 13 and ends at 14. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [13.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | encode | def encode(self, text):raise NotImplementedError("This method should be overridden by subclasses.") | 1 | 2 | 2 | 12 | 0 | 16 | 17 | 16 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (encode) 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 | decode | def decode(self, tokens):raise NotImplementedError("This method should be overridden by subclasses.") | 1 | 2 | 2 | 12 | 0 | 19 | 20 | 19 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (decode) defined within the public class called public.The function start at line 19 and ends at 20. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [19.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | bos_id | def bos_id(self):raise NotImplementedError("This method should be overridden by subclasses.") | 1 | 2 | 1 | 10 | 0 | 22 | 23 | 22 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (bos_id) defined within the public class called public.The function start at line 22 and ends at 23. 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 | eos_id | def eos_id(self):raise NotImplementedError("This method should be overridden by subclasses.") | 1 | 2 | 1 | 10 | 0 | 25 | 26 | 25 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (eos_id) defined within the public class called public.The function start at line 25 and ends at 26. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, model_path):import sentencepiece as spmsuper().__init__(model_path)self.processor = spm.SentencePieceProcessor(str(model_path))self.bos_token_id = self.bos_id()self.eos_token_id = self.eos_id() | 1 | 6 | 2 | 50 | 0 | 30 | 36 | 30 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 30 and ends at 36. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [30.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | encode | def encode(self, text):return self.processor.EncodeAsIds(text) | 1 | 2 | 2 | 16 | 0 | 38 | 39 | 38 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (encode) defined within the public class called public.The function start at line 38 and ends at 39. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [38.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | decode | def decode(self, tokens):return self.processor.DecodeIds(tokens) | 1 | 2 | 2 | 16 | 0 | 41 | 42 | 41 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (decode) defined within the public class called public.The function start at line 41 and ends at 42. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [41.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | bos_id | def bos_id(self):return self.processor.bos_id() | 1 | 2 | 1 | 13 | 0 | 44 | 45 | 44 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (bos_id) defined within the public class called public.The function start at line 44 and ends at 45. 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.. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.