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
_use_deterministic
def _use_deterministic():torch.backends.cudnn.deterministic = Truetorch.backends.cudnn.benchmark = Falsetorch.use_deterministic_algorithms(True, warn_only=False)os.environ["CUBLAS_WORKSPACE_CONFIG"] = ":4096:8"logger.warning(("Reproducibility is enabled with `AO_USE_DETERMINISTIC_ALGORITHMS=1`, which sets ""`torch.use_...
1
13
0
51
0
21
33
21
null
[]
None
null
0
0
0
null
0
null
The function (_use_deterministic) defined within the public class called public.The function start at line 21 and ends at 33. It contains 13 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
run_evaluation
def run_evaluation(model, tokenizer, tasks, compile=False, batch_size=4):try:from lm_eval.evaluator import evaluatefrom lm_eval.models.huggingface import HFLMfrom lm_eval.tasks import get_task_dictexcept ImportError:print("""Error: The 'lm_eval' module was not found.To install, follow these steps:pip install git+https:...
2
22
5
99
1
44
67
44
null
['result']
None
null
0
0
0
null
0
null
The function (run_evaluation) defined within the public class called public.The function start at line 44 and ends at 67. It contains 22 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [44.0] and does not return any value..
pytorch_ao
public
public
0
0
bench_accuracy
def bench_accuracy(model, tokenizer, tasks, msg=""):with torch.no_grad():print(f"==================== {msg} ====================")print(f"tasks: {tasks}")from torchao.prototype.autoround.hf_eval_utils import run_evaluationtorch.cuda.empty_cache()run_evaluation(model, tokenizer, tasks=tasks)torch.cuda.empty_cache()
1
8
4
64
0
70
78
70
null
[]
None
null
0
0
0
null
0
null
The function (bench_accuracy) defined within the public class called public.The function start at line 70 and ends at 78. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [70.0] and does not return any value..
pytorch_ao
public
public
0
0
_is_linear_but_not_lm_head
def _is_linear_but_not_lm_head(mod, fqn):return isinstance(mod, torch.nn.Linear) and "lm_head" not in fqn
2
2
2
23
0
81
82
81
null
[]
None
null
0
0
0
null
0
null
The function (_is_linear_but_not_lm_head) defined within the public class called public.The function start at line 81 and ends at 82. It contains 2 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [81.0] and does not return any value..
pytorch_ao
public
public
0
0
main
def main(args):with torch.no_grad():model_name_or_path = args.model_name_or_pathmodel, tokenizer, decoder_cls = ar_utils.get_float_model_info(model_name_or_path, dtype=torch.bfloat16)model.eval()model_device = args.model_device# `sorted_logits` does not have a deterministic implementationif not AO_USE_DETERMINISTIC_ALG...
10
74
1
408
9
85
167
85
null
['is_target_module', 'filter_fn', 'model_name_or_path', 'model_device', 'model', 'dtype', 'bits', 'quantized_layer_cnt', 'msg']
None
null
0
0
0
null
0
null
The function (main) defined within the public class called public.The function start at line 85 and ends at 167. It contains 74 lines of code and it has a cyclomatic complexity of 10. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
__new__
def __new__(cls, input, **kwargs):if isinstance(input, (list, tuple)):input = input[0]kwargs["dtype"] = kwargs.get("dtype", input.dtype)shape = kwargs.pop("shape", input.shape)return torch.Tensor._make_wrapper_subclass(cls, shape, **kwargs)
2
6
3
69
0
37
42
37
null
[]
None
null
0
0
0
null
0
null
The function (__new__) defined within the public class called public.The function start at line 37 and ends at 42. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [37.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, input, **kwargs):self.values = []self.count = 0self.add_tensors(input)self.debug = True
1
5
3
32
0
44
48
44
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 44 and ends at 48. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [44.0] and does not return any value..
pytorch_ao
public
public
0
0
__repr__
def __repr__(self):return f"{self.__class__.__name__}(data={self.values})"
1
2
1
8
0
50
51
50
null
[]
None
null
0
0
0
null
0
null
The function (__repr__) defined within the public class called public.The function start at line 50 and ends at 51. 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
add_tensors
def add_tensors(self, input):if isinstance(input, (tuple, list)):for inp in input:self.add_tensors(inp)else:assert isinstance(input, torch.Tensor), (f"MultiTensor can only use add_tensors for Tensors or lists of tensors but got {type(input)}")self.count += 1self.values.append(input)return self
3
11
2
61
0
53
63
53
null
[]
None
null
0
0
0
null
0
null
The function (add_tensors) defined within the public class called public.The function start at line 53 and ends at 63. It contains 11 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [53.0] and does not return any value..
pytorch_ao
public
public
0
0
get_value
def get_value(self, i):# Instead of copy the last tensor to pad the MultiTensor, we use this function to do fake padding# to avoid introducing extra memory usage.if i + 1 <= self.count:return self.values[i]else:return self.values[-1]
2
5
2
33
0
65
71
65
null
[]
None
null
0
0
0
null
0
null
The function (get_value) defined within the public class called public.The function start at line 65 and ends at 71. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [65.0] and does not return any value..
pytorch_ao
public
public
0
0
flat_to_grouped
def flat_to_grouped(cls, flat):# size of biggest MultiTensormulti_tensor_size = max([x.count if isinstance(x, MultiTensor) else 1 for x in flat])grouped = []for i in range(multi_tensor_size):sub_group = []for x in flat:if isinstance(x, MultiTensor):sub_group.append(x.get_value(i))else:sub_group.append(x)grouped.append(...
6
14
2
86
0
74
89
74
null
[]
None
null
0
0
0
null
0
null
The function (flat_to_grouped) defined within the public class called public.The function start at line 74 and ends at 89. It contains 14 lines of code and it has a cyclomatic complexity of 6. It takes 2 parameters, represented as [74.0] and does not return any value..
pytorch_ao
public
public
0
0
grouped_to_flat
def grouped_to_flat(cls, grouped):# convert [[A,b1,c1], [A,b2,c2] [A,b3,c3]] => [A, MultiTensor(b1,b2,b3), MultiTensor(c1,c2,c3)]# where A is nontensor, b's,c's are tensors# convert [[A,b1,c1], [A,b2,c2] [A,b3,c3]] => [(A,A,A), (b1,b2,b3), (c1,c2,c3)]flat_tups = list(zip(*grouped))# convert [(A,A,A), (b1,b2,b3), (c1,c2...
6
21
2
97
0
92
117
92
null
[]
None
null
0
0
0
null
0
null
The function (grouped_to_flat) defined within the public class called public.The function start at line 92 and ends at 117. It contains 21 lines of code and it has a cyclomatic complexity of 6. It takes 2 parameters, represented as [92.0] and does not return any value..
pytorch_ao
public
public
0
0
revert_to_tensor_pairs
def revert_to_tensor_pairs(cls, args, kwargs=None):if kwargs is None:kwargs = {}# combine args and kwargs and remove lists and tuplesflat_args, spec = tree_flatten((args, kwargs))# convert [A, MultiTensor(b1,b2,b3), MultiTensor(c1,c2,c3)] => [[A,b1,c1], [A,b2,c2] [A,b3,c3]]grouped_args = cls.flat_to_grouped(flat_args)a...
3
10
3
76
0
120
131
120
null
[]
None
null
0
0
0
null
0
null
The function (revert_to_tensor_pairs) defined within the public class called public.The function start at line 120 and ends at 131. It contains 10 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [120.0] and does not return any value..
pytorch_ao
public
public
0
0
__torch_function__
def __torch_function__(cls, func, types, args=(), kwargs=None):args_kwargs_pairs = cls.revert_to_tensor_pairs(args, kwargs)# run function for each of the multitensors and return a multitensoroutputs = []with torch._C.DisableTorchFunctionSubclass():for cur_args, cur_kwargs in args_kwargs_pairs:if func in _multi_tensor_c...
10
29
4
214
0
134
164
134
null
[]
None
null
0
0
0
null
0
null
The function (__torch_function__) defined within the public class called public.The function start at line 134 and ends at 164. It contains 29 lines of code and it has a cyclomatic complexity of 10. It takes 4 parameters, represented as [134.0] and does not return any value..
pytorch_ao
public
public
0
0
__torch_dispatch__
def __torch_dispatch__(cls, func, types, args=(), kwargs={}):pass
1
2
4
20
0
167
168
167
null
[]
None
null
0
0
0
null
0
null
The function (__torch_dispatch__) defined within the public class called public.The function start at line 167 and ends at 168. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [167.0] and does not return any value..
pytorch_ao
public
public
0
0
__tensor_flatten__
def __tensor_flatten__(self):return ["values"], None
1
2
1
11
0
170
171
170
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 170 and ends at 171. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
__tensor_unflatten__
def __tensor_unflatten__(cls, tensor_data_dict, tensor_attributes, outer_size, outer_stride):return cls(tensor_data_dict["values"])
1
4
5
21
0
174
177
174
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 174 and ends at 177. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [174.0] and does not return any value..
pytorch_ao
public
public
0
0
_is_package_available
def _is_package_available(pkg_name, metadata_name=None):# Copied from Accelerate https://github.com/huggingface/accelerateimport importlib# Check we're not importing a "pkg_name" directory somewhere but the actual library by trying to grab the versionpackage_exists = importlib.util.find_spec(pkg_name) is not Noneif pac...
4
11
2
56
2
17
31
17
null
['_', 'package_exists']
None
null
0
0
0
null
0
null
The function (_is_package_available) defined within the public class called public.The function start at line 17 and ends at 31. It contains 11 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [17.0] and does not return any value..
pytorch_ao
public
public
0
0
is_auto_round_available
def is_auto_round_available() -> bool:return _is_package_available("auto_round")
1
2
0
11
0
34
35
34
null
[]
None
null
0
0
0
null
0
null
The function (is_auto_round_available) defined within the public class called public.The function start at line 34 and ends at 35. 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
import_dataloader
def import_dataloader():if is_auto_round_available():import auto_roundget_dataloader = auto_round.calib_dataset.get_dataloaderreturn get_dataloaderelse:raise ImportError(("This example requires the `auto-round` library.""Please install it with `pip install git+https://github.com/intel/auto-round.git@patch-for-ao-2`"))
2
12
0
30
1
38
50
38
null
['get_dataloader']
None
null
0
0
0
null
0
null
The function (import_dataloader) defined within the public class called public.The function start at line 38 and ends at 50. It contains 12 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
singleton._singleton
def _singleton(*args, **kw):"""Create a singleton object."""if cls not in instances:instances[cls] = cls(*args, **kw)return instances[cls]
2
4
2
34
0
57
61
57
null
[]
None
null
0
0
0
null
0
null
The function (singleton._singleton) defined within the public class called public.The function start at line 57 and ends at 61. It contains 4 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [57.0] and does not return any value..
pytorch_ao
public
public
0
0
singleton
def singleton(cls):"""Singleton decorator."""instances = {}def _singleton(*args, **kw):"""Create a singleton object."""if cls not in instances:instances[cls] = cls(*args, **kw)return instances[cls]return _singleton
1
4
1
14
1
53
63
53
null
['instances']
None
null
0
0
0
null
0
null
The function (singleton) defined within the public class called public.The function start at line 53 and ends at 63. It contains 4 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
freeze_random
def freeze_random(seed=0):random.seed(seed)torch.manual_seed(seed)np.random.seed(seed)g = torch.Generator()g.manual_seed(seed)if torch.cuda.is_available():torch.cuda.manual_seed(seed)torch.cuda.manual_seed_all(seed)
2
9
1
65
1
66
78
66
null
['g']
None
null
0
0
0
null
0
null
The function (freeze_random) defined within the public class called public.The function start at line 66 and ends at 78. It contains 9 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
count_tensor_of_type
def count_tensor_of_type(mod, cls):res = 0for name, param in mod.named_parameters():if isinstance(param, cls):res += 1return res
3
6
2
34
1
81
86
81
null
['res']
None
null
0
0
0
null
0
null
The function (count_tensor_of_type) defined within the public class called public.The function start at line 81 and ends at 86. It contains 6 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [81.0] and does not return any value..
pytorch_ao
public
public
0
0
see_memory_usage
def see_memory_usage(message: str = "", force=True):# Modified from DeepSpeed https://github.com/microsoft/DeepSpeedimport gcimport loggingimport torch.distributed as distif not force:returnif dist.is_initialized() and not dist.get_rank() == 0:returngc.collect()# Print message except when distributed but not rank 0logg...
4
18
2
77
1
89
114
89
null
['bytes_to_gb']
None
null
0
0
0
null
0
null
The function (see_memory_usage) defined within the public class called public.The function start at line 89 and ends at 114. It contains 18 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [89.0] and does not return any value..
pytorch_ao
public
public
0
0
gen_text
def gen_text(model, tokenizer, msg="", device=None, prompt="What's AI?", max_length=20):if device is None:device = "cuda" if torch.cuda.is_available() else "cpu"inputs = tokenizer(prompt, return_tensors="pt")model = model.to(device)new_tokens = model.generate(**inputs.to(device), max_length=max_length)text = tokenizer....
3
8
6
97
5
118
125
118
null
['device', 'model', 'text', 'new_tokens', 'inputs']
None
null
0
0
0
null
0
null
The function (gen_text) defined within the public class called public.The function start at line 118 and ends at 125. It contains 8 lines of code and it has a cyclomatic complexity of 3. It takes 6 parameters, represented as [118.0] and does not return any value..
pytorch_ao
public
public
0
0
gen_example_inputs
def gen_example_inputs(tokenizer, device, max_length=20):inputs = tokenizer("What's AI?", return_tensors="pt", padding="max_length", max_length=max_length)input_ids = inputs["input_ids"].to(device)return (input_ids,)
1
6
3
45
2
128
133
128
null
['input_ids', 'inputs']
None
null
0
0
0
null
0
null
The function (gen_example_inputs) defined within the public class called public.The function start at line 128 and ends at 133. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [128.0] and does not return any value..
pytorch_ao
public
public
0
0
_auto_detect_decoder_cls
def _auto_detect_decoder_cls(model):for name, module in model.named_modules():if isinstance(module, torch.nn.ModuleList):first_module = module[0]return type(first_module)
3
5
1
39
1
136
140
136
null
['first_module']
None
null
0
0
0
null
0
null
The function (_auto_detect_decoder_cls) defined within the public class called public.The function start at line 136 and ends at 140. It contains 5 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_float_model_info
def get_float_model_info(model_name_or_path, dtype=torch.float32):import transformersmodel = transformers.AutoModelForCausalLM.from_pretrained(model_name_or_path, dtype=dtype)tokenizer = transformers.AutoTokenizer.from_pretrained(model_name_or_path)decoder_cls = _auto_detect_decoder_cls(model)logging.warning(f"Detected...
2
13
2
66
3
143
156
143
null
['decoder_cls', 'tokenizer', 'model']
None
null
0
0
0
null
0
null
The function (get_float_model_info) defined within the public class called public.The function start at line 143 and ends at 156. It contains 13 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [143.0] and does not return any value..
pytorch_ao
public
public
0
0
dump_elapsed_time.dump_elapsed_time.f.fi
def fi(*args, **kwargs):start = time.time()res = func(*args, **kwargs)end = time.time()dur = round((end - start) * 1000, 2)if record:execution_records[func.__qualname__].append(dur)logging.warning("%s elapsed time: %s ms"% (customized_msg if customized_msg else func.__qualname__,dur,))if record:avg_time = sum(execution...
4
23
2
126
0
172
194
172
null
[]
None
null
0
0
0
null
0
null
The function (dump_elapsed_time.dump_elapsed_time.f.fi) defined within the public class called public.The function start at line 172 and ends at 194. It contains 23 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [172.0] and does not return any value..
pytorch_ao
public
public
0
0
dump_elapsed_time.f
def f(func):def fi(*args, **kwargs):start = time.time()res = func(*args, **kwargs)end = time.time()dur = round((end - start) * 1000, 2)if record:execution_records[func.__qualname__].append(dur)logging.warning("%s elapsed time: %s ms"% (customized_msg if customized_msg else func.__qualname__,dur,))if record:avg_time = s...
1
3
1
9
0
171
196
171
null
[]
None
null
0
0
0
null
0
null
The function (dump_elapsed_time.f) defined within the public class called public.The function start at line 171 and ends at 196. 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
dump_elapsed_time
def dump_elapsed_time(customized_msg="", record=False):"""Get the elapsed time for decorated functions.Args:customized_msg (string, optional): The parameter passed to decorator. Defaults to None."""import loggingimport timedef f(func):def fi(*args, **kwargs):start = time.time()res = func(*args, **kwargs)end = time.time...
1
5
2
20
6
162
198
162
null
['end', 'res', 'start', 'avg_time', 'dur', 'std_time']
None
null
0
0
0
null
0
null
The function (dump_elapsed_time) defined within the public class called public.The function start at line 162 and ends at 198. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [162.0] and does not return any value..
pytorch_ao
public
public
0
0
__post_init__
def __post_init__(self):self.step = self.step.lower()all_step_values = [s.value for s in AWQStep]if self.step not in all_step_values:raise ValueError(f"{self.step} is not one of {all_step_values}")
3
5
1
41
0
52
56
52
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 52 and ends at 56. It contains 5 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
_awq_transform
def _awq_transform(module: torch.nn.Module,config: AWQConfig,) -> torch.nn.Module:step = config.stepscale_search_space_size = config.scale_search_space_sizeobserved_linear = Nonebase_config = config.base_configif step == AWQStep.PREPARE:observer = AWQObserver(module.weight,module.bias,base_config,scale_search_space_siz...
4
59
2
325
12
60
125
60
null
['equalization_scale', 'observed_linear', 'base_config', 'dummy_mod', 'example_input', 'step', 'qw', 'quant_mod', 'observer', 'scale_search_space_size', 'base_config_handler', 'linear']
None
null
0
0
0
null
0
null
The function (_awq_transform) defined within the public class called public.The function start at line 60 and ends at 125. It contains 59 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [60.0] and does not return any value..
pytorch_ao
public
public
0
0
get_act_scale
def get_act_scale(x):return x.abs().view(-1, x.shape[-1]).mean(0)
1
2
1
30
0
28
29
28
null
[]
None
null
0
0
0
null
0
null
The function (get_act_scale) defined within the public class called public.The function start at line 28 and ends at 29. 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,weight: torch.Tensor,bias: Optional[torch.Tensor],base_config: AOBaseConfig,scale_search_space_size: int = 20,):"""A custom observer for Activation aware Weight Quantization (AWQ)Note: this only applies to weight only quantization: https://github.com/pytorch/ao/issues/2388#issuecomment-3062863647Args:...
2
16
5
92
0
33
58
33
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 33 and ends at 58. It contains 16 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [33.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, input: torch.Tensor, output: torch.Tensor):self.inputs.append(input.to("cpu"))
1
2
3
30
0
61
62
61
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 61 and ends at 62. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [61.0] and does not return any value..
pytorch_ao
public
public
0
0
calculate_qparams
def calculate_qparams(self):assert self.inputs != None, ("calibrate observer first by running model on exemplar data")for i in range(len(self.inputs)):self.inputs[i] = self.inputs[i].to(self.device)if self.bias is not None:self.bias = self.bias.to(self.device)acc = torch.cat(self.inputs, dim=-2)x_max = get_act_scale(ac...
6
29
1
290
0
64
96
64
null
[]
None
null
0
0
0
null
0
null
The function (calculate_qparams) defined within the public class called public.The function start at line 64 and ends at 96. It contains 29 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
__init__
def __init__(self,in_features: int,out_features: int,act_obs: torch.nn.Module,bias: bool = True,device=None,dtype=None,):super().__init__(in_features, out_features, bias, device, dtype)self.act_obs = act_obs
1
11
7
57
0
100
110
100
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 100 and ends at 110. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 7 parameters, represented as [100.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, input: torch.Tensor):output = F.linear(input, self.weight, self.bias)self.act_obs(input, output)return output
1
4
2
37
0
112
115
112
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 112 and ends at 115. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [112.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls, float_linear: torch.nn.Linear, act_obs: AWQObserver):observed_linear = cls(float_linear.in_features,float_linear.out_features,act_obs,False,device=float_linear.weight.device,dtype=float_linear.weight.dtype,)observed_linear.weight = float_linear.weightobserved_linear.bias = float_linear.biasreturn ob...
1
12
3
66
0
118
129
118
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 118 and ends at 129. It contains 12 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [118.0] and does not return any value..
pytorch_ao
public
public
0
0
get_calib_dataset
def get_calib_dataset(tokenizer=None, n_samples=100, block_size=512):dataset = load_dataset("mit-han-lab/pile-val-backup", split="validation")samples = []n_tokens = n_samples * block_sizen_run = n_tokensfor data in dataset:line = data["text"]line = line.strip()line_encoded = tokenizer.encode(line)if len(line_encoded) >...
6
22
3
148
8
24
46
24
null
['line', 'samples', 'n_run', 'line_encoded', 'sample', 'dataset', 'cat_samples', 'n_tokens']
None
null
0
0
0
null
0
null
The function (get_calib_dataset) defined within the public class called public.The function start at line 24 and ends at 46. It contains 22 lines of code and it has a cyclomatic complexity of 6. It takes 3 parameters, represented as [24.0] and does not return any value..
pytorch_ao
public
public
0
0
wiki2_eval
def wiki2_eval(model, tokenizer, sequence_length, stride=512, verbose=True, device="cuda"):model.eval()tokenizer.pad_token = tokenizer.eos_tokentokenizer.padding_side = "right"tokenizer.add_eos_token = Falsedataset = load_dataset("wikitext", "wikitext-2-raw-v1", split="test")encodings = tokenizer("\n\n".join(dataset["t...
5
37
6
338
12
50
93
50
null
['t1', 'pred_time', 'begin_loc', 'end_loc', 'ppl', 'input_ids', 'target_ids', 'encodings', 'dataset', 'trg_len', 't2', 'log_likelihood']
None
null
0
0
0
null
0
null
The function (wiki2_eval) defined within the public class called public.The function start at line 50 and ends at 93. It contains 37 lines of code and it has a cyclomatic complexity of 5. It takes 6 parameters, represented as [50.0] and does not return any value..
pytorch_ao
public
public
0
0
benchmark
def benchmark(model, tokenizer, max_length, tasks=None, evaluation_limit=None, device="cuda"):import numpy as npmodel.eval()model.config.use_cache = Falsetry:lm_eval.tasks.initialize_tasks()except:passmodel_eval = HFLM(pretrained=model, tokenizer=tokenizer)eval_batch_size = 1# 8if tasks is None:tasks = ["PPL","truthful...
22
118
6
673
7
97
226
97
null
['mmlu_list', 'results_mmlu', 'results', 'k', 'eval_batch_size', 'tasks', 'model_eval']
None
null
0
0
0
null
0
null
The function (benchmark) defined within the public class called public.The function start at line 97 and ends at 226. It contains 118 lines of code and it has a cyclomatic complexity of 22. It takes 6 parameters, represented as [97.0] and does not return any value..
pytorch_ao
public
public
0
0
quantize_and_eval
def quantize_and_eval(repo_id: str,quant: str,tasks: list[str],max_seq_length: int,calibration_limit: int,evaluation_limit: int,device: str,precision: torch.dtype,compile: bool,model_save_path: str,model_save_hf_hub_path: str,):print(f"Loading model on {device}...")torch.manual_seed(34)t0 = time.time()# load any model ...
11
90
11
477
6
229
330
229
null
['base_config', 't0', 'group_size', 'tokenizer', 'model', 'quant_config']
None
null
0
0
0
null
0
null
The function (quantize_and_eval) defined within the public class called public.The function start at line 229 and ends at 330. It contains 90 lines of code and it has a cyclomatic complexity of 11. It takes 11 parameters, represented as [229.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,block_size: int = 128,dtype: torch.dtype = torch.float8_e4m3fn,):super().__init__()supported_dtypes = [torch.float8_e4m3fn,torch.float8_e5m2,]assert dtype in supported_dtypes, (f"Unsupported dtype: {dtype}. Supported dtypes: {supported_dtypes}")sca...
2
28
6
170
0
30
58
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 58. It contains 28 lines of code and it has a cyclomatic complexity of 2. It takes 6 parameters, represented as [30.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, x: torch.Tensor) -> torch.Tensor:"""Forward pass for the custom linear layer.Args:x (torch.Tensor): Input tensor.Returns:torch.Tensor: Transformed tensor after linear computation."""x, scale = fp8_blockwise_act_quant(x, self.block_size, self.dtype)y = blockwise_fp8_gemm(x, scale, self.weight, self.wei...
2
8
2
69
0
60
77
60
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 60 and ends at 77. It contains 8 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [60.0] and does not return any value..
pytorch_ao
public
public
0
0
blockwise_fp8_gemm_kernel
def blockwise_fp8_gemm_kernel(a_ptr,b_ptr,c_ptr,a_s_ptr,b_s_ptr,M,N: tl.constexpr,K: tl.constexpr,M_BUCKET: tl.constexpr,BLOCK_SIZE_M: tl.constexpr,BLOCK_SIZE_N: tl.constexpr,BLOCK_SIZE_K: tl.constexpr,):pid_m = tl.program_id(axis=0)pid_n = tl.program_id(axis=1)k = tl.cdiv(K, BLOCK_SIZE_K)offs_m = (pid_m * BLOCK_SIZE_M...
2
41
12
410
18
31
73
31
null
['offs_k', 'a_ptrs', 'a_s_ptrs', 'accumulator', 'offs_m', 'k', 'offs_n', 'a', 'b', 'a_s', 'c', 'pid_m', 'mask', 'b_s_ptrs', 'b_s', 'c_ptrs', 'pid_n', 'b_ptrs']
None
null
0
0
0
null
0
null
The function (blockwise_fp8_gemm_kernel) defined within the public class called public.The function start at line 31 and ends at 73. It contains 41 lines of code and it has a cyclomatic complexity of 2. It takes 12 parameters, represented as [31.0] and does not return any value..
pytorch_ao
public
public
0
0
blockwise_fp8_gemm
def blockwise_fp8_gemm(a: torch.Tensor,a_s: torch.Tensor,b: torch.Tensor,b_s: torch.Tensor,block_size: int = 128,):assert a.is_contiguous() and b.is_contiguous()assert a_s.is_contiguous() and b_s.is_contiguous()K = a.size(-1)M = a.numel() // KN = b.size(0)M_BUCKET = math.ceil(math.log2(M))c = a.new_empty(*a.size()[:-1]...
3
22
5
184
6
76
97
76
null
['M_BUCKET', 'c', 'grid', 'N', 'M', 'K']
None
null
0
0
0
null
0
null
The function (blockwise_fp8_gemm) defined within the public class called public.The function start at line 76 and ends at 97. It contains 22 lines of code and it has a cyclomatic complexity of 3. It takes 5 parameters, represented as [76.0] and does not return any value..
pytorch_ao
public
public
0
0
fp8_blockwise_act_quant_kernel
def fp8_blockwise_act_quant_kernel(x_ptr, y_ptr, s_ptr, BLOCK_SIZE: tl.constexpr):"""Quantizes the input tensor `x_ptr` and stores the result in `y_ptr` and the scaling factor in `s_ptr`.Args:x_ptr (triton.Pointer): Pointer to the input tensor.y_ptr (triton.Pointer): Pointer to the output tensor where quantized values ...
1
9
4
111
5
101
121
101
null
['pid', 'x', 'offs', 'y', 's']
None
null
0
0
0
null
0
null
The function (fp8_blockwise_act_quant_kernel) defined within the public class called public.The function start at line 101 and ends at 121. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [101.0] and does not return any value..
pytorch_ao
public
public
0
0
fp8_blockwise_act_quant
def fp8_blockwise_act_quant(x: torch.Tensor, block_size: int = 128, dtype: torch.dtype = torch.float8_e4m3fn) -> Tuple[torch.Tensor, torch.Tensor]:"""Quantizes the input tensor `x` using block-wise quantization with block size being BLOCK_SIZEx1.Args:x (torch.Tensor): The input tensor to be quantized. Must be contiguou...
1
16
3
157
3
124
153
124
null
['s', 'grid', 'y']
None
null
0
0
0
null
0
null
The function (fp8_blockwise_act_quant) defined within the public class called public.The function start at line 124 and ends at 153. It contains 16 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [124.0] and does not return any value..
pytorch_ao
public
public
0
0
fp8_blockwise_weight_quant_kernel
def fp8_blockwise_weight_quant_kernel(x_ptr, y_ptr, s_ptr, M, N, BLOCK_SIZE: tl.constexpr):"""Quantizes the input tensor `x_ptr` and stores the result in `y_ptr` and the scaling factors in `s_ptr`.Args:x_ptr (tl.pointer): Pointer to the input tensor.y_ptr (tl.pointer): Pointer to the output tensor where quantized value...
1
16
6
201
10
157
183
157
null
['n', 'offs_m', 'offs_n', 'x', 'mask', 'offs', 'pid_m', 'y', 's', 'pid_n']
None
null
0
0
0
null
0
null
The function (fp8_blockwise_weight_quant_kernel) defined within the public class called public.The function start at line 157 and ends at 183. It contains 16 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [157.0] and does not return any value..
pytorch_ao
public
public
0
0
fp8_blockwise_weight_quant
def fp8_blockwise_weight_quant(x: torch.Tensor, block_size: int = 128, dtype=torch.float8_e4m3fn) -> Tuple[torch.Tensor, torch.Tensor]:"""Quantizes the given weight tensor using block-wise quantization with block size being BLOCK_SIZExBLOCK_SIZE.Args:x (torch.Tensor): The weight tensor to be quantized.block_size (int, ...
2
21
3
176
3
186
219
186
null
['s', 'grid', 'y']
None
null
0
0
0
null
0
null
The function (fp8_blockwise_weight_quant) defined within the public class called public.The function start at line 186 and ends at 219. It contains 21 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [186.0] and does not return any value..
pytorch_ao
public
public
0
0
fp8_blockwise_weight_dequant_kernel
def fp8_blockwise_weight_dequant_kernel(x_ptr, s_ptr, y_ptr, M, N, BLOCK_SIZE: tl.constexpr):"""Dequantizes weights using the provided scaling factors and stores the result.Args:x_ptr (tl.pointer): Pointer to the quantized weights.s_ptr (tl.pointer): Pointer to the scaling factors.y_ptr (tl.pointer): Pointer to the out...
1
14
6
172
10
223
250
223
null
['n', 'offs_m', 'offs_n', 'x', 'mask', 'offs', 'pid_m', 'y', 's', 'pid_n']
None
null
0
0
0
null
0
null
The function (fp8_blockwise_weight_dequant_kernel) defined within the public class called public.The function start at line 223 and ends at 250. It contains 14 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [223.0] and does not return any value..
pytorch_ao
public
public
0
0
fp8_blockwise_weight_dequant
def fp8_blockwise_weight_dequant(x: torch.Tensor, s: torch.Tensor, block_size: int = 128) -> torch.Tensor:"""Dequantizes the given weight tensor using the provided scale tensor.Args:x (torch.Tensor): The quantized weight tensor of shape (M, N).s (torch.Tensor): The scale tensor of shape (M, N).block_size (int, optional...
3
13
3
135
2
253
279
253
null
['grid', 'y']
None
null
0
0
0
null
0
null
The function (fp8_blockwise_weight_dequant) defined within the public class called public.The function start at line 253 and ends at 279. It contains 13 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [253.0] and does not return any value..
pytorch_ao
public
public
0
0
triton_fp8_gemm_1x128_128x128_kernel
def triton_fp8_gemm_1x128_128x128_kernel(a_ptr,# (M, K)a_stride_dim_0,a_stride_dim_1,b_ptr,# (K, N)b_stride_dim_0,b_stride_dim_1,c_ptr,c_stride_dim_0,c_stride_dim_1,a_s_ptr,# (M, K // block_size) reciprocals of scalesa_s_stride_dim_0,a_s_stride_dim_1,b_s_ptr,# (K // block_size, N // block_size) reciprocals of scalesb_s...
2
53
22
431
20
35
96
35
null
['offs_k', 'accumulator', 'offs_n', 'pid_m', 'b_mask', 'a_ptrs', 'offs_m', 'a_s', 'b_ptrs', 'a_s_base_ptr', 'b_s_base_ptr', 'a', 'b', 'k_num_blocks', 'b_s', 'pid_n', 'c_mask', 'a_mask', 'c', 'c_ptrs']
None
null
0
0
0
null
0
null
The function (triton_fp8_gemm_1x128_128x128_kernel) defined within the public class called public.The function start at line 35 and ends at 96. It contains 53 lines of code and it has a cyclomatic complexity of 2. It takes 22 parameters, represented as [35.0] and does not return any value..
pytorch_ao
public
public
0
0
triton_fp8_gemm_1x128_128x128
def triton_fp8_gemm_1x128_128x128(a: torch.Tensor,# (M, K)b: torch.Tensor,# (K, N)a_s: torch.Tensor,# (M, K // block_size)b_s: torch.Tensor,# (K // block_size, N // block_size)block_size: int = 128,out_dtype: torch.dtype = torch.float32,):# 'a' must be in row-major layout, 'b' must be in column-major layoutassert _is_r...
1
43
6
246
5
99
145
99
null
['c', 'grid', 'N', 'M', 'K']
None
null
0
0
0
null
0
null
The function (triton_fp8_gemm_1x128_128x128) defined within the public class called public.The function start at line 99 and ends at 145. It contains 43 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [99.0] and does not return any value..
pytorch_ao
public
public
0
0
triton_fp8_gemm_1x128_128x1_kernel
def triton_fp8_gemm_1x128_128x1_kernel(a_ptr,# (M, K)a_stride_dim_0,a_stride_dim_1,b_ptr,# (K, N)b_stride_dim_0,b_stride_dim_1,c_ptr,a_s_ptr,# (M, K // block_size)a_s_stride_dim_0,a_s_stride_dim_1,b_s_ptr,# (K // block_size, N)b_s_stride_dim_0,b_s_stride_dim_1,M,N: tl.constexpr,K: tl.constexpr,BLOCK_SIZE_M: tl.constexp...
2
50
19
424
20
152
211
152
null
['offs_k', 'accumulator', 'offs_n', 'pid_m', 'b_mask', 'a_ptrs', 'offs_m', 'a_s', 'b_ptrs', 'a_s_base_ptr', 'b_s_base_ptr', 'a', 'b', 'k_num_blocks', 'b_s', 'pid_n', 'c_mask', 'a_mask', 'c', 'c_ptrs']
None
null
0
0
0
null
0
null
The function (triton_fp8_gemm_1x128_128x1_kernel) defined within the public class called public.The function start at line 152 and ends at 211. It contains 50 lines of code and it has a cyclomatic complexity of 2. It takes 19 parameters, represented as [152.0] and does not return any value..
pytorch_ao
public
public
0
0
triton_fp8_gemm_1x128_128x1
def triton_fp8_gemm_1x128_128x1(a: torch.Tensor,# (M, K)b: torch.Tensor,# (K, N)a_s: torch.Tensor,# (M, K // block_size) reciprocals of scalesb_s: torch.Tensor,# (K // block_size, N) reciprocals of scalesblock_size: int = 128,out_dtype: torch.dtype = torch.float32,):# 'a' must be in row-major layout, 'b' must be in col...
1
40
6
228
5
214
257
214
null
['c', 'grid', 'N', 'M', 'K']
None
null
0
0
0
null
0
null
The function (triton_fp8_gemm_1x128_128x1) defined within the public class called public.The function start at line 214 and ends at 257. It contains 40 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [214.0] and does not return any value..
pytorch_ao
public
public
0
0
triton_fp8_blockwise_act_quant_lhs_kernel
def triton_fp8_blockwise_act_quant_lhs_kernel(x_ptr,x_stride_dim_0,x_stride_dim_1,y_ptr,y_stride_dim_0,y_stride_dim_1,s_ptr,s_stride_dim_0,s_stride_dim_1,M,K: tl.constexpr,BLOCK_SIZE: tl.constexpr,NUM_GROUPS: tl.constexpr,EPS: tl.constexpr,):pid_m = tl.program_id(axis=0)pid_k = tl.program_id(axis=1)# Load (num_groups x...
1
34
14
341
15
285
328
285
null
['y_mask', 'y_offs', 'm_offs', 'x_mask', 'scale_offs', 'x', 'scale', 'amax', 'pid_k', 'pid_m', 'k_offs', 'max_fp8_e4m3', 'min_fp8_e4m3', 'x_offs', 'y']
None
null
0
0
0
null
0
null
The function (triton_fp8_blockwise_act_quant_lhs_kernel) defined within the public class called public.The function start at line 285 and ends at 328. It contains 34 lines of code and it has a cyclomatic complexity of 1. It takes 14 parameters, represented as [285.0] and does not return any value..
pytorch_ao
public
public
0
0
triton_fp8_blockwise_act_quant_lhs
def triton_fp8_blockwise_act_quant_lhs(x: torch.Tensor, block_size: int = 128, dtype: torch.dtype = torch.float8_e4m3fn) -> Tuple[torch.Tensor, torch.Tensor]:"""Input: row-major high-precision tensorOutput: row-major, with reciprocal scales for (1 x block_size) groups stored in col-major."""assert x.is_contiguous(), "I...
1
36
3
222
3
332
372
332
null
['s', 'grid', 'y']
None
null
0
0
0
null
0
null
The function (triton_fp8_blockwise_act_quant_lhs) defined within the public class called public.The function start at line 332 and ends at 372. It contains 36 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [332.0] and does not return any value..
pytorch_ao
public
public
0
0
triton_fp8_blockwise_act_quant_rhs_kernel
def triton_fp8_blockwise_act_quant_rhs_kernel(x_ptr,x_stride_dim_0,x_stride_dim_1,y_ptr,y_stride_dim_0,y_stride_dim_1,s_ptr,s_stride_dim_0,s_stride_dim_1,M,K: tl.constexpr,BLOCK_SIZE: tl.constexpr,NUM_GROUPS: tl.constexpr,EPS: tl.constexpr,):pid_m = tl.program_id(axis=0)pid_k = tl.program_id(axis=1)# Load (block_size x...
1
34
14
341
15
377
422
377
null
['y_mask', 'y_offs', 'm_offs', 'x_mask', 'scale_offs', 'x', 'scale', 'amax', 'pid_k', 'pid_m', 'k_offs', 'max_fp8_e4m3', 'min_fp8_e4m3', 'x_offs', 'y']
None
null
0
0
0
null
0
null
The function (triton_fp8_blockwise_act_quant_rhs_kernel) defined within the public class called public.The function start at line 377 and ends at 422. It contains 34 lines of code and it has a cyclomatic complexity of 1. It takes 14 parameters, represented as [377.0] and does not return any value..
pytorch_ao
public
public
0
0
triton_fp8_blockwise_act_quant_rhs
def triton_fp8_blockwise_act_quant_rhs(x: torch.Tensor, block_size: int = 128, dtype: torch.dtype = torch.float8_e4m3fn) -> Tuple[torch.Tensor, torch.Tensor]:"""Input: row-majorOutput: column-major, with scales for (block_size x 1) groups stored in row-major."""assert x.is_contiguous(), "Input tensor must be contiguous...
1
35
3
251
4
426
465
426
null
['s', 'grid', 'y', 'M_blocks']
None
null
0
0
0
null
0
null
The function (triton_fp8_blockwise_act_quant_rhs) defined within the public class called public.The function start at line 426 and ends at 465. It contains 35 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [426.0] and does not return any value..
pytorch_ao
public
public
0
0
triton_fp8_blockwise_act_quant_transposed_lhs_kernel
def triton_fp8_blockwise_act_quant_transposed_lhs_kernel(x_ptr,x_stride_dim_0,x_stride_dim_1,y_ptr,y_stride_dim_0,y_stride_dim_1,s_ptr,s_stride_dim_0,s_stride_dim_1,M,K: tl.constexpr,BLOCK_SIZE: tl.constexpr,# For scaling groups, not for grid/parallelizationNUM_GROUPS: tl.constexpr,# For grid/parallelization, not for s...
1
37
14
361
18
470
527
470
null
['y_mask', 'y_offs', 'm_offs', 'x_mask', 'scale_m_off', 'scale_offs', 'x', 'scale', 'scale_k_offs', 'amax', 'pid_k', 'pid_m', 'k_offs', 'max_fp8_e4m3', 'min_fp8_e4m3', 'x_offs', 'y', 'scale_mask']
None
null
0
0
0
null
0
null
The function (triton_fp8_blockwise_act_quant_transposed_lhs_kernel) defined within the public class called public.The function start at line 470 and ends at 527. It contains 37 lines of code and it has a cyclomatic complexity of 1. It takes 14 parameters, represented as [470.0] and does not return any value..
pytorch_ao
public
public
0
0
triton_fp8_blockwise_act_quant_transposed_lhs
def triton_fp8_blockwise_act_quant_transposed_lhs(x: torch.Tensor, block_size: int = 128, dtype: torch.dtype = torch.float8_e4m3fn) -> Tuple[torch.Tensor, torch.Tensor]:assert x.is_contiguous(), "Input tensor must be contiguous"assert x.size(0) % block_size == 0, (f"First dimension size must be divisible by block_size ...
1
37
3
246
4
531
572
531
null
['s', 'grid', 'y', 'M_blocks']
None
null
0
0
0
null
0
null
The function (triton_fp8_blockwise_act_quant_transposed_lhs) defined within the public class called public.The function start at line 531 and ends at 572. It contains 37 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [531.0] and does not return any value..
pytorch_ao
public
public
0
0
triton_fp8_blockwise_weight_quant_rhs_kernel
def triton_fp8_blockwise_weight_quant_rhs_kernel(x_ptr,x_stride_dim_0,x_stride_dim_1,y_ptr,y_stride_dim_0,y_stride_dim_1,s_ptr,s_stride_dim_0,s_stride_dim_1,M: tl.constexpr,N: tl.constexpr,BLOCK_SIZE: tl.constexpr,EPS: tl.constexpr,):pid_m = tl.program_id(axis=0)pid_n = tl.program_id(axis=1)offs_m = pid_m * BLOCK_SIZE ...
1
34
13
328
16
577
619
577
null
['y_mask', 'x_mask', 'scale_m_off', 'offs_m', 'offs_n', 'x', 'scale', 'amax', 'pid_m', 'max_fp8_e4m3', 'y', 'y_offs', 'min_fp8_e4m3', 'x_offs', 'pid_n', 'scale_n_off']
None
null
0
0
0
null
0
null
The function (triton_fp8_blockwise_weight_quant_rhs_kernel) defined within the public class called public.The function start at line 577 and ends at 619. It contains 34 lines of code and it has a cyclomatic complexity of 1. It takes 13 parameters, represented as [577.0] and does not return any value..
pytorch_ao
public
public
0
0
triton_fp8_blockwise_weight_quant_rhs
def triton_fp8_blockwise_weight_quant_rhs(x: torch.Tensor, block_size: int = 128, dtype: torch.dtype = torch.float8_e4m3fn) -> Tuple[torch.Tensor, torch.Tensor]:assert x.is_contiguous(), "Input tensor must be contiguous"assert x.dim() == 2, "Input tensor must have 2 dimensions"assert x.size(0) % block_size == 0 and x.s...
2
39
3
293
3
623
661
623
null
['s', 'grid', 'y']
None
null
0
0
0
null
0
null
The function (triton_fp8_blockwise_weight_quant_rhs) defined within the public class called public.The function start at line 623 and ends at 661. It contains 39 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [623.0] and does not return any value..
pytorch_ao
public
public
0
0
triton_fp8_blockwise_weight_quant_transposed_rhs_kernel
def triton_fp8_blockwise_weight_quant_transposed_rhs_kernel(x_ptr,x_stride_dim_0,x_stride_dim_1,y_ptr,y_stride_dim_0,y_stride_dim_1,s_ptr,s_stride_dim_0,s_stride_dim_1,M: tl.constexpr,N: tl.constexpr,BLOCK_SIZE: tl.constexpr,EPS: tl.constexpr,):"""Quantizes the input tensor `x_ptr` and stores the result in `y_ptr` and ...
1
38
13
382
18
666
724
666
null
['y_mask', 'm_offs', 'x_mask', 'scale_k', 'scale_offs', 'scale_m', 'x', 'scale', 'amax', 'pid_m', 'max_fp8_e4m3', 'y', 'y_offs', 'min_fp8_e4m3', 'x_offs', 'scale_mask', 'n_offs', 'pid_n']
None
null
0
0
0
null
0
null
The function (triton_fp8_blockwise_weight_quant_transposed_rhs_kernel) defined within the public class called public.The function start at line 666 and ends at 724. It contains 38 lines of code and it has a cyclomatic complexity of 1. It takes 13 parameters, represented as [666.0] and does not return any value..
pytorch_ao
public
public
0
0
triton_fp8_blockwise_weight_quant_transposed_rhs
def triton_fp8_blockwise_weight_quant_transposed_rhs(x: torch.Tensor, block_size: int = 128, dtype: torch.dtype = torch.float8_e4m3fn) -> Tuple[torch.Tensor, torch.Tensor]:assert x.is_contiguous(), "Input tensor must be contiguous"assert x.dim() == 2, "Input tensor must have 2 dimensions"assert x.size(0) % block_size =...
2
39
3
301
3
728
766
728
null
['s', 'grid', 'y']
None
null
0
0
0
null
0
null
The function (triton_fp8_blockwise_weight_quant_transposed_rhs) defined within the public class called public.The function start at line 728 and ends at 766. It contains 39 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [728.0] and does not return any value..
pytorch_ao
public
public
0
0
torch_blockwise_scale_act_quant_lhs
def torch_blockwise_scale_act_quant_lhs(x, tile_size=128):"""Input: weight tensor in high precisionOutput: weight tensor in float8, and scale, tiled 1 by tile_size"""assert x.is_contiguous(), "input tensor must be contiguous"orig_shape = x.shape# Reshape 2D+ input tensor into 2D tensor with shape (leading_dims, tile_si...
1
15
2
185
4
769
799
769
null
['x', 'orig_shape', 'x_amax', 's']
None
null
0
0
0
null
0
null
The function (torch_blockwise_scale_act_quant_lhs) defined within the public class called public.The function start at line 769 and ends at 799. It contains 15 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [769.0] and does not return any value..
pytorch_ao
public
public
0
0
torch_blockwise_scale_act_quant_rhs
def torch_blockwise_scale_act_quant_rhs(x: torch.Tensor,block_size: int = 128,dtype: torch.dtype = torch.float8_e4m3fn,eps: float = 1e-12,) -> Tuple[torch.Tensor, torch.Tensor]:assert x.is_contiguous(), "Input tensor must be contiguous"assert x.size(-1) % block_size == 0, (f"Last dimension size must be divisible by blo...
2
30
4
313
11
802
859
802
null
['y_col', 'x_col', 'scales', 'y_blocks', 'scale', 'x_blocks', 'amax', 'y', 'max_fp8_e4m3', 'min_fp8_e4m3', 'num_blocks_m']
None
null
0
0
0
null
0
null
The function (torch_blockwise_scale_act_quant_rhs) defined within the public class called public.The function start at line 802 and ends at 859. It contains 30 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [802.0] and does not return any value..
pytorch_ao
public
public
0
0
torch_blockwise_scale_weight_quant
def torch_blockwise_scale_weight_quant(x, tile_size=128):"""Input: weight tensor in high precisionOutput: weight tensor in float8, and scale, tiled tile_size by tile_size"""assert len(x.shape) == 2, "input shape must be 2D"assert x.is_contiguous(), "input tensor must be contiguous"height, width = x.shape# Compute block...
1
22
2
262
5
862
901
862
null
['t_h', 'x_amax', 'x', 't_w', 's']
None
null
0
0
0
null
0
null
The function (torch_blockwise_scale_weight_quant) defined within the public class called public.The function start at line 862 and ends at 901. It contains 22 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [862.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(ctx, x, weight, block_size, out_dtype=torch.bfloat16, use_triton=False):assert block_size == 128, "Only support block_size=128"# Temporarily reshape x to 2D tensorx_orig_shape = x.shapex = x.reshape(-1, x_orig_shape[-1])# Cast inputs to fp8 blockwise using (1, block_size) scaling granularity in row major fo...
2
23
6
143
0
28
58
28
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 28 and ends at 58. It contains 23 lines of code and it has a cyclomatic complexity of 2. It takes 6 parameters, represented as [28.0] and does not return any value..
pytorch_ao
public
public
0
0
backward
def backward(ctx, grad_output):x, weight = ctx.saved_tensorsblock_size = ctx.block_sizeout_dtype = ctx.out_dtypeuse_triton = ctx.use_triton# Reshape input to 2Dx_orig_shape = x.shapex = x.reshape(-1, x_orig_shape[-1])# Reshape grad_output to 2Dgrad_output_orig_shape = grad_output.shapegrad_output = grad_output.reshape(...
3
47
2
221
0
61
129
61
null
[]
None
null
0
0
0
null
0
null
The function (backward) defined within the public class called public.The function start at line 61 and ends at 129. It contains 47 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [61.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,*args,block_size: int = 128,dtype=torch.bfloat16,use_triton=False,**kwargs,):super().__init__(*args, **kwargs)assert dtype in self.supported_dtypes, (f"Unsupported dtype: {dtype}. Supported dtypes: {self.supported_dtypes}")assert is_sm_at_least_90(), "Only support SM90"self.block_size = block_sizeself...
1
16
6
72
0
148
164
148
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 148 and ends at 164. It contains 16 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [148.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, x: torch.Tensor) -> torch.Tensor:"""Forward pass for the custom linear layer.Args:x (torch.Tensor): input tensor.Returns:torch.Tensor: Transformed tensor after linear computation."""return fp8_blockwise_mm.apply(x, self.weight, self.block_size, self.dtype, self.use_triton)
1
4
2
39
0
166
178
166
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 166 and ends at 178. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [166.0] and does not return any value..
pytorch_ao
public
public
0
0
from_float
def from_float(cls,mod,):assert mod.bias is None, "unsupported"assert mod.in_features % 128 == 0, "unsupported"assert mod.out_features % 128 == 0, "unsupported"with torch.device("meta"):new_mod = cls(mod.in_features,mod.out_features,bias=False,)new_mod.weight = mod.weightnew_mod.bias = mod.biasreturn new_mod
1
16
2
77
0
181
196
181
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 181 and ends at 196. It contains 16 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [181.0] and does not return any value..
pytorch_ao
public
public
0
0
_float8_blockwise_transform
def _float8_blockwise_transform(module, config):return Float8BlockwiseLinear.from_float(module)
1
2
2
14
0
204
205
204
null
[]
None
null
0
0
0
null
0
null
The function (_float8_blockwise_transform) defined within the public class called public.The function start at line 204 and ends at 205. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [204.0] and does not return any value..
pytorch_ao
public
public
0
0
simple_bench
def simple_bench(fn, *args, **kwargs):t = do_bench(lambda: fn(*args, **kwargs))return t
1
3
3
28
1
25
27
25
null
['t']
None
null
0
0
0
null
0
null
The function (simple_bench) 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. It takes 3 parameters, represented as [25.0] and does not return any value..
pytorch_ao
public
public
0
0
check
def check(expected, actual, atol=1e-3):diff = (expected - actual).abs().max()print(f"diff: {diff}")
1
3
3
33
1
30
32
30
null
['diff']
None
null
0
0
0
null
0
null
The function (check) defined within the public class called public.The function start at line 30 and ends at 32. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [30.0] and does not return any value..
pytorch_ao
public
public
0
0
benchmark_mm
def benchmark_mm(test_fn, xs, weight, ref_fn=torch.matmul, headers=["M", "K", "N", "test", "ref"]):timings = []for x in xs:M, K = x.shape_, N = weight.shapeassert x.shape[1] == weight.shape[0]print(f"Benchmarking {(M, K, N)}")test_times = do_bench(lambda: test_fn(x, weight))ref_times = do_bench(lambda: ref_fn(x, weight...
2
13
5
124
3
36
48
36
null
['timings', 'ref_times', 'test_times']
None
null
0
0
0
null
0
null
The function (benchmark_mm) defined within the public class called public.The function start at line 36 and ends at 48. It contains 13 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [36.0] and does not return any value..
pytorch_ao
public
public
0
0
run_bench
def run_bench(xs, weight):df = benchmark_mm(xs, weight)print(tabulate(df, headers="keys", floatfmt=".4f"))return df
1
4
2
32
1
51
54
51
null
['df']
None
null
0
0
0
null
0
null
The function (run_bench) defined within the public class called public.The function start at line 51 and ends at 54. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [51.0] and does not return any value..
pytorch_ao
public
public
0
0
__enter__
def __enter__(self):print("Starting cuda profiler")torch.cuda.cudart().cudaProfilerStart()return self
1
4
1
22
0
58
61
58
null
[]
None
null
0
0
0
null
0
null
The function (__enter__) defined within the public class called public.The function start at line 58 and ends at 61. It contains 4 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
__exit__
def __exit__(self, exc_type, exc_value, exc_traceback) -> None:print("Stopping cuda profiler")torch.cuda.cudart().cudaProfilerStop()if exc_type is not None:print(f"Exception occurred: {exc_type}, {exc_value}")# Return True to suppress the exceptionreturn True
2
6
4
41
0
63
69
63
null
[]
None
null
0
0
0
null
0
null
The function (__exit__) defined within the public class called public.The function start at line 63 and ends at 69. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [63.0] and does not return any value..
pytorch_ao
public
public
0
0
step
def step(self):pass
1
2
1
6
0
71
72
71
null
[]
None
null
0
0
0
null
0
null
The function (step) defined within the public class called public.The function start at line 71 and ends at 72. 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
trace_handler
def trace_handler(prof: torch.profiler.profile,group_by_stack: int = 5,group_by_input_shapes: bool = False,prefix="",out_dir=None,export_events=False,export_trace=True,export_memory_timeline=False,):# Prefix for file names.out_dir = out_dir or PROFILE_DIRtimestamp = datetime.now().strftime(TIME_FORMAT_STR)file_prefix =...
5
27
8
135
4
75
107
75
null
['timestamp', 'file_prefix', 'evt_list', 'out_dir']
None
null
0
0
0
null
0
null
The function (trace_handler) defined within the public class called public.The function start at line 75 and ends at 107. It contains 27 lines of code and it has a cyclomatic complexity of 5. It takes 8 parameters, represented as [75.0] and does not return any value..
pytorch_ao
public
public
0
0
get_torch_profiler
def get_torch_profiler(name,with_stack=True,with_flops=True,with_modules=True,record_shapes=False,export_events=False,export_trace=True,export_memory_timeline=False,out_dir=None,warmup=1,active=5,):if not os.path.exists(out_dir):os.makedirs(out_dir)callback = partial(trace_handler,prefix=name,out_dir=out_dir,group_by_i...
3
38
11
176
1
113
150
113
null
['callback']
None
null
0
0
0
null
0
null
The function (get_torch_profiler) defined within the public class called public.The function start at line 113 and ends at 150. It contains 38 lines of code and it has a cyclomatic complexity of 3. It takes 11 parameters, represented as [113.0] and does not return any value..
pytorch_ao
public
public
0
0
profiler
def profiler(name,out_dir,warmup=1,active=5,record_shapes=False,with_stack=True,export_events=False,export_trace=True,export_memory_timeline=False,):return get_torch_profiler(name,with_stack=with_stack,record_shapes=export_memory_timeline or record_shapes,export_events=export_events,export_trace=export_trace,export_mem...
2
22
9
76
0
155
176
155
null
[]
None
null
0
0
0
null
0
null
The function (profiler) defined within the public class called public.The function start at line 155 and ends at 176. It contains 22 lines of code and it has a cyclomatic complexity of 2. It takes 9 parameters, represented as [155.0] and does not return any value..
pytorch_ao
public
public
0
0
get_annotation_ctx
def get_annotation_ctx(profiler_type):assert profiler_type in ["nsys", "torch"]if profiler_type == "nsys":return nvtx_rangeelse:return record_function
2
6
1
24
0
179
184
179
null
[]
None
null
0
0
0
null
0
null
The function (get_annotation_ctx) defined within the public class called public.The function start at line 179 and ends at 184. It contains 6 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
is_function
def is_function(obj):return isinstance(obj, types.FunctionType)
1
2
1
14
0
218
219
218
null
[]
None
null
0
0
0
null
0
null
The function (is_function) defined within the public class called public.The function start at line 218 and ends at 219. 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
is_method
def is_method(obj):return isinstance(obj, types.MethodType)
1
2
1
14
0
222
223
222
null
[]
None
null
0
0
0
null
0
null
The function (is_method) defined within the public class called public.The function start at line 222 and ends at 223. 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
is_private
def is_private(prop):return prop.startswith("_")
1
2
1
12
0
226
227
226
null
[]
None
null
0
0
0
null
0
null
The function (is_private) defined within the public class called public.The function start at line 226 and ends at 227. 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
should_exclude
def should_exclude(obj, prop):return (is_function(getattr(obj, prop))or is_method(getattr(obj, prop))or is_private(prop))
3
6
2
34
0
230
235
230
null
[]
None
null
0
0
0
null
0
null
The function (should_exclude) defined within the public class called public.The function start at line 230 and ends at 235. It contains 6 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [230.0] and does not return any value..
pytorch_ao
public
public
0
0
_get_event_props
def _get_event_props(event: torch.autograd.profiler_util.FunctionEvent):props = [p for p in dir(event) if not should_exclude(event, p)]return props
3
3
1
35
1
238
240
238
null
['props']
None
null
0
0
0
null
0
null
The function (_get_event_props) defined within the public class called public.The function start at line 238 and ends at 240. 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_events_df
def get_events_df(events: torch.autograd.profiler_util.EventList):event_props = _get_event_props(events[0])data = [{p: getattr(e, p) for p in event_props} for e in events]return pd.DataFrame(data)
3
4
1
51
2
243
246
243
null
['event_props', 'data']
None
null
0
0
0
null
0
null
The function (get_events_df) defined within the public class called public.The function start at line 243 and ends at 246. 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
get_perf_df
def get_perf_df(events: torch.autograd.profiler_util.EventList, sort=True):df = get_events_df(events).filter(PERF_COLS_SELECT)if sort:df = df.sort_values(["cpu_time", "cuda_time"], ascending=False)return df
2
5
2
49
1
249
253
249
null
['df']
None
null
0
0
0
null
0
null
The function (get_perf_df) defined within the public class called public.The function start at line 249 and ends at 253. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [249.0] and does not return any value..
pytorch_ao
public
public
0
0
pivot_df
def pivot_df(df,id_cols: str | list[str],columns: str | list[str],values: str | list[str],column_order: list[str] = None,show: bool = True,):df = df.pivot_table(index=id_cols,columns=columns,values=values,).reset_index()if column_order is not None:df = df[column_order]if show:print(df.to_string(index=False))return df
3
18
6
99
1
256
273
256
null
['df']
None
null
0
0
0
null
0
null
The function (pivot_df) defined within the public class called public.The function start at line 256 and ends at 273. It contains 18 lines of code and it has a cyclomatic complexity of 3. It takes 6 parameters, represented as [256.0] and does not return any value..
pytorch_ao
public
public
0
0
upcast_if_fp8
def upcast_if_fp8(a):if "fp8" in str(a):return torch.float16return a
2
4
1
19
0
15
18
15
null
[]
None
null
0
0
0
null
0
null
The function (upcast_if_fp8) defined within the public class called public.The function start at line 15 and ends at 18. 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
get_higher_dtype
def get_higher_dtype(a, b):a = upcast_if_fp8(a)b = upcast_if_fp8(b)if a is b:return aassert a in _ordered_datatypesassert b in _ordered_datatypesfor d in _ordered_datatypes:if a is d:return bif b is d:return a
5
12
2
53
2
21
34
21
null
['b', 'a']
None
null
0
0
0
null
0
null
The function (get_higher_dtype) defined within the public class called public.The function start at line 21 and ends at 34. It contains 12 lines of code and it has a cyclomatic complexity of 5. It takes 2 parameters, represented as [21.0] and does not return any value..
pytorch_ao
public
public
0
0
init_to_zero
def init_to_zero(name):return lambda nargs: nargs[name].zero_()
1
2
1
17
0
37
38
37
null
[]
None
null
0
0
0
null
0
null
The function (init_to_zero) defined within the public class called public.The function start at line 37 and ends at 38. 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..