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
add_param_group
def add_param_group(self, param_group: dict) -> None:super().add_param_group(param_group)# convert LR to a tensorgroup = self.param_groups[-1]if not isinstance(group["lr"], Tensor):group["lr"] = torch.tensor(group["lr"], dtype=torch.float32)
2
5
2
60
0
53
59
53
null
[]
None
null
0
0
0
null
0
null
The function (add_param_group) defined within the public class called public.The function start at line 53 and ends at 59. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [53.0] and does not return any value..
pytorch_ao
public
public
0
0
__setstate__
def __setstate__(self, state):super().__setstate__(state)for group in self.param_groups:group.setdefault("amsgrad", False)
2
4
2
30
0
61
64
61
null
[]
None
null
0
0
0
null
0
null
The function (__setstate__) defined within the public class called public.The function start at line 61 and ends at 64. It contains 4 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [61.0] and does not return any value..
pytorch_ao
public
public
0
0
_subclass_zeros
def _subclass_zeros(p: Tensor, signed: bool, block_size: int):raise NotImplementedError
1
2
3
17
0
68
69
68
null
[]
None
null
0
0
0
null
0
null
The function (_subclass_zeros) defined within the public class called public.The function start at line 68 and ends at 69. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [68.0] and does not return any value..
pytorch_ao
public
public
0
0
_new_buffer
def _new_buffer(self, p: Tensor, signed: bool):local_p = p.to_local() if isinstance(p, DTensor) else p# follow bitsandbytes, only quantize tensors >= 4096 valuesif local_p.numel() >= 4096 and local_p.numel() % self.block_size == 0:out = self._subclass_zeros(local_p, signed, self.block_size)else:out = torch.zeros_like(l...
5
17
3
135
0
71
99
71
null
[]
None
null
0
0
0
null
0
null
The function (_new_buffer) defined within the public class called public.The function start at line 71 and ends at 99. It contains 17 lines of code and it has a cyclomatic complexity of 5. It takes 3 parameters, represented as [71.0] and does not return any value..
pytorch_ao
public
public
0
0
step
def step(self, closure=None):loss = Noneif closure is not None:with torch.enable_grad():loss = closure()# for a given model, the number of different argument combinations to single_param_adam() is fixed.# thus, it is safe to disable cache limit without the risk of always re-compiling.with torch._dynamo.utils.disable_ca...
10
42
2
274
0
102
158
102
null
[]
None
null
0
0
0
null
0
null
The function (step) defined within the public class called public.The function start at line 102 and ends at 158. It contains 42 lines of code and it has a cyclomatic complexity of 10. It takes 2 parameters, represented as [102.0] and does not return any value..
pytorch_ao
public
public
0
0
single_param_adam
def single_param_adam(p: Tensor,grad: Tensor,step: Tensor,exp_avg: Tensor,exp_avg_sq: Tensor,max_exp_avg_sq: Optional[Tensor],lr: Tensor,beta1: float,beta2: float,weight_decay: float,eps: float,IS_ADAMW: bool,BF16_STOCHASTIC_ROUND: bool,):# compute in FP32 for accurate calculationsp_f32 = p.float()grad_f32 = grad.float...
4
38
13
251
8
163
209
163
null
['bias_correction2', 'exp_avg_sq_f32', 'exp_avg_f32', 'denom', 'bias_correction1', 'grad_f32', 'p_f32', 'max_exp_avg_sq_f32']
None
null
0
0
0
null
0
null
The function (single_param_adam) defined within the public class called public.The function start at line 163 and ends at 209. It contains 38 lines of code and it has a cyclomatic complexity of 4. It takes 13 parameters, represented as [163.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,params,lr=1e-3,betas=(0.9, 0.999),eps=1e-8,weight_decay=0,amsgrad=False,*,block_size=256,bf16_stochastic_round=False,) -> None:super().__init__(params,lr,betas,eps,weight_decay,amsgrad,block_size=block_size,bf16_stochastic_round=bf16_stochastic_round,is_adamw=False,)torch._C._log_api_usage_once("torch...
1
24
5
91
0
213
236
213
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 213 and ends at 236. It contains 24 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [213.0] and does not return any value..
pytorch_ao
public
public
0
0
_subclass_zeros
def _subclass_zeros(p: Tensor, signed: bool, block_size: int):return OptimState8bit.zeros(p.shape, signed, block_size, p.device)
1
2
3
32
0
239
240
239
null
[]
None
null
0
0
0
null
0
null
The function (_subclass_zeros) defined within the public class called public.The function start at line 239 and ends at 240. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [239.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,params,lr=1e-3,betas=(0.9, 0.999),eps=1e-8,weight_decay=0,amsgrad=False,*,block_size=256,bf16_stochastic_round=False,) -> None:super().__init__(params,lr,betas,eps,weight_decay,amsgrad,block_size=block_size,bf16_stochastic_round=bf16_stochastic_round,is_adamw=False,)torch._C._log_api_usage_once("torch...
1
24
5
91
0
244
267
213
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 267. It contains 24 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [213.0] and does not return any value..
pytorch_ao
public
public
0
0
_subclass_zeros
def _subclass_zeros(p: Tensor, signed: bool, block_size: int):return OptimState8bit.zeros(p.shape, signed, block_size, p.device)
1
2
3
32
0
270
271
239
null
[]
None
null
0
0
0
null
0
null
The function (_subclass_zeros) defined within the public class called public.The function start at line 270 and ends at 271. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [239.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,params,lr=1e-3,betas=(0.9, 0.999),eps=1e-8,weight_decay=0,amsgrad=False,*,block_size=256,bf16_stochastic_round=False,) -> None:super().__init__(params,lr,betas,eps,weight_decay,amsgrad,block_size=block_size,bf16_stochastic_round=bf16_stochastic_round,is_adamw=False,)torch._C._log_api_usage_once("torch...
1
24
5
91
0
275
298
213
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 275 and ends at 298. It contains 24 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [213.0] and does not return any value..
pytorch_ao
public
public
0
0
_subclass_zeros
def _subclass_zeros(p: Tensor, signed: bool, block_size: int):return OptimStateFp8.zeros(p.shape, block_size, p.device)
1
2
3
30
0
301
302
301
null
[]
None
null
0
0
0
null
0
null
The function (_subclass_zeros) defined within the public class called public.The function start at line 301 and ends at 302. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [301.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,params,lr=1e-3,betas=(0.9, 0.999),eps=1e-8,weight_decay=1e-2,amsgrad=False,*,block_size=256,bf16_stochastic_round=False,) -> None:super().__init__(params,lr,betas,eps,weight_decay,amsgrad,block_size=block_size,bf16_stochastic_round=bf16_stochastic_round,is_adamw=True,)torch._C._log_api_usage_once("tor...
1
24
5
93
0
306
329
306
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 306 and ends at 329. It contains 24 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [306.0] and does not return any value..
pytorch_ao
public
public
0
0
_subclass_zeros
def _subclass_zeros(p: Tensor, signed: bool, block_size: int):return OptimState8bit.zeros(p.shape, signed, block_size, p.device)
1
2
3
32
0
332
333
239
null
[]
None
null
0
0
0
null
0
null
The function (_subclass_zeros) 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 1. It takes 3 parameters, represented as [239.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,params,lr=1e-3,betas=(0.9, 0.999),eps=1e-8,weight_decay=1e-2,amsgrad=False,*,block_size=256,bf16_stochastic_round=False,) -> None:super().__init__(params,lr,betas,eps,weight_decay,amsgrad,block_size=block_size,bf16_stochastic_round=bf16_stochastic_round,is_adamw=True,)torch._C._log_api_usage_once("tor...
1
24
5
93
0
337
360
306
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 337 and ends at 360. It contains 24 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [306.0] and does not return any value..
pytorch_ao
public
public
0
0
_subclass_zeros
def _subclass_zeros(p: Tensor, signed: bool, block_size: int):return OptimState8bit.zeros(p.shape, signed, block_size, p.device)
1
2
3
32
0
363
364
239
null
[]
None
null
0
0
0
null
0
null
The function (_subclass_zeros) defined within the public class called public.The function start at line 363 and ends at 364. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [239.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,params,lr=1e-3,betas=(0.9, 0.999),eps=1e-8,weight_decay=1e-2,amsgrad=False,*,block_size=256,bf16_stochastic_round=False,) -> None:super().__init__(params,lr,betas,eps,weight_decay,amsgrad,block_size=block_size,bf16_stochastic_round=bf16_stochastic_round,is_adamw=True,)torch._C._log_api_usage_once("tor...
1
24
5
93
0
368
391
306
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 368 and ends at 391. It contains 24 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [306.0] and does not return any value..
pytorch_ao
public
public
0
0
_subclass_zeros
def _subclass_zeros(p: Tensor, signed: bool, block_size: int):return OptimStateFp8.zeros(p.shape, block_size, p.device)
1
2
3
30
0
394
395
301
null
[]
None
null
0
0
0
null
0
null
The function (_subclass_zeros) defined within the public class called public.The function start at line 394 and ends at 395. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [301.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,params,lr=1e-3,betas=(0.9, 0.999),eps=1e-8,weight_decay=1e-2,amsgrad=False,*,bf16_stochastic_round=False,) -> None:"""AdamW optimizer that supports quantized training (parameter is quantized). This optimizer shouldonly be used with torchao's quantized training."""super().__init__(params,lr,betas,eps,w...
1
22
5
85
0
399
422
399
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 399 and ends at 422. It contains 22 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [399.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__.backward_hook
def backward_hook(p_device):if p_device.grad is not None:p_host = self.param_d2h_map[p_device]# make sure backward for this param finishesself.stream.wait_stream(getattr(torch, self.device).current_stream())with getattr(torch, self.device).stream(self.stream):p_host.grad.copy_(p_device.grad, non_blocking=True)# we rely...
4
12
1
117
0
65
84
65
null
[]
None
null
0
0
0
null
0
null
The function (__init__.backward_hook) defined within the public class called public.The function start at line 65 and ends at 84. It contains 12 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,params: ParamsT,optimizer_class: Type[Optimizer] = torch.optim.AdamW,*,offload_gradients: bool = False,minimal_size: int = 4096,**kwargs,) -> None:"""Offload optimizer to CPU for single-GPU training. This will reduce GPU memory by the size of optimizer state.Optimizer step will be done on CPU.Argspara...
11
50
6
358
0
19
114
19
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 19 and ends at 114. It contains 50 lines of code and it has a cyclomatic complexity of 11. It takes 6 parameters, represented as [19.0] and does not return any value..
pytorch_ao
public
public
0
0
step
def step(self, closure=None):loss = Noneif closure is not None:loss = closure()# handle small parameters on the GPU, in parallel with the CPU calls belowif self.d_opt is not None:self.d_opt.step()for p_device, grad_d2h_event in self.queue.items():grad_d2h_event.synchronize()self.optim_dict[p_device].step()# submit more...
4
15
2
117
0
117
140
117
null
[]
None
null
0
0
0
null
0
null
The function (step) defined within the public class called public.The function start at line 117 and ends at 140. It contains 15 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [117.0] and does not return any value..
pytorch_ao
public
public
0
0
zero_grad
def zero_grad(self, set_to_none=True):assert set_to_none# only clear DEVICE grad. CPU grad will always be overwritten by DEVICE grad.for p_device in self.param_d2h_map.keys():p_device.grad = Noneif self.d_opt is not None:self.d_opt.zero_grad(set_to_none=set_to_none)
3
6
2
45
0
142
150
142
null
[]
None
null
0
0
0
null
0
null
The function (zero_grad) defined within the public class called public.The function start at line 142 and ends at 150. It contains 6 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [142.0] and does not return any value..
pytorch_ao
public
public
0
0
param_groups
def param_groups(self):# each param group will only has 1 parameter# TODO: we might want to return the original param_groups instead.return sum((optim.param_groups for optim in self.optim_dict.values()),start=self.d_param_groups,)
2
5
1
31
0
153
159
153
null
[]
None
null
0
0
0
null
0
null
The function (param_groups) defined within the public class called public.The function start at line 153 and ends at 159. 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
state_dict
def state_dict(self):state_dict = {"offloaded": [optim.state_dict() for optim in self.optim_dict.values()]}if self.d_opt:state_dict["on-device"] = self.d_opt.state_dict()return state_dict
3
7
1
47
0
161
167
161
null
[]
None
null
0
0
0
null
0
null
The function (state_dict) defined within the public class called public.The function start at line 161 and ends at 167. It contains 7 lines of code and it has a cyclomatic complexity of 3. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
load_state_dict
def load_state_dict(self, state_dict):for optim, optim_state_dict in zip(self.optim_dict.values(), state_dict["offloaded"]):optim.load_state_dict(optim_state_dict)if self.d_opt:self.d_opt.load_state_dict(state_dict["on-device"])elif "on-device" in state_dict:raise ValueError("loaded state dict has a 'on-device' paramet...
4
11
2
60
0
169
180
169
null
[]
None
null
0
0
0
null
0
null
The function (load_state_dict) defined within the public class called public.The function start at line 169 and ends at 180. It contains 11 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [169.0] and does not return any value..
pytorch_ao
public
public
0
0
create_dynamic_map
def create_dynamic_map(signed=True, max_exponent_bits=7, total_bits=8):"""Creates the dynamic quantiztion map.The dynamic data type is made up of a dynamic exponent andfraction. As the exponent increase from 0 to -7 the numberof bits available for the fraction shrinks.This is a generalization of the dynamic type where ...
7
26
3
292
6
12
60
12
null
['additional_items', 'fraction_items', 'boundaries', 'means', 'non_sign_bits', 'data']
None
null
0
0
0
null
0
null
The function (create_dynamic_map) defined within the public class called public.The function start at line 12 and ends at 60. It contains 26 lines of code and it has a cyclomatic complexity of 7. It takes 3 parameters, represented as [12.0] and does not return any value..
pytorch_ao
public
public
0
0
scale_tensor
def scale_tensor(input: Tensor, block_size: int):"""Scale tensor so that max(abs(input)) = 1"""shape = input.shape# section 2.1 from https://arxiv.org/abs/2110.02861input = input.view(-1, block_size)scale = input.abs().amax(-1).clip(1e-12)input = input / scale.view(-1, 1)return input.view(shape), scale
1
6
2
70
3
63
71
63
null
['scale', 'input', 'shape']
None
null
0
0
0
null
0
null
The function (scale_tensor) defined within the public class called public.The function start at line 63 and ends at 71. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [63.0] and does not return any value..
pytorch_ao
public
public
0
0
quantize_8bit_with_qmap
def quantize_8bit_with_qmap(input: Tensor, qmap: Tensor):# GPU-friendly binary search# https://blog.demofox.org/2017/06/20/simd-gpu-friendly-branchless-binary-search/codes = torch.where(input >= qmap[128], 128, 0)codes += torch.where(input >= qmap[codes + 64], 64, 0)codes += torch.where(input >= qmap[codes + 32], 32, 0...
1
15
2
223
5
74
93
74
null
['val_up', 'residual', 'codes_up', 'val_down', 'codes']
None
null
0
0
0
null
0
null
The function (quantize_8bit_with_qmap) defined within the public class called public.The function start at line 74 and ends at 93. It contains 15 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [74.0] and does not return any value..
pytorch_ao
public
public
0
0
quantize_4bit_with_qmap
def quantize_4bit_with_qmap(input: Tensor, qmap: Tensor):# GPU-friendly binary search# https://blog.demofox.org/2017/06/20/simd-gpu-friendly-branchless-binary-search/codes = torch.where(input >= qmap[8], 8, 0)codes += torch.where(input >= qmap[codes + 4], 4, 0)codes += torch.where(input >= qmap[codes + 2], 2, 0)codes +...
1
11
2
147
5
96
111
96
null
['val_up', 'residual', 'codes_up', 'val_down', 'codes']
None
null
0
0
0
null
0
null
The function (quantize_4bit_with_qmap) defined within the public class called public.The function start at line 96 and ends at 111. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [96.0] and does not return any value..
pytorch_ao
public
public
0
0
dequant_with_qmap
def dequant_with_qmap(codes: Tensor, qmap: Tensor, scale: Tensor):# torch.compile() cannot use uint8 as indexout = qmap[codes.int()].view(scale.shape[0], -1) * scale.view(-1, 1)return out.view(codes.shape)
1
3
3
57
1
114
117
114
null
['out']
None
null
0
0
0
null
0
null
The function (dequant_with_qmap) defined within the public class called public.The function start at line 114 and ends at 117. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [114.0] and does not return any value..
pytorch_ao
public
public
0
0
_fp32_to_bf16_sr
def _fp32_to_bf16_sr(x_f32: Tensor) -> Tensor:# For an FP32 number[a31, ..., a16, a15, ..., a0] to be converted to BF16# - Round towards zero: [a31, ..., a16, 0, ...,0]# - Round away from zero: [a31, ..., a16+1, 0, ...,0]# (since the value can be negative, we use round towards/away from zero instead of round up/down)##...
1
14
1
88
4
120
145
120
null
['x_fraction', 'x_bf16_towards_zero', 'x_f32_bits', 'rand_16bit']
None
null
0
0
0
null
0
null
The function (_fp32_to_bf16_sr) defined within the public class called public.The function start at line 120 and ends at 145. It contains 14 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_qmap_signed
def get_qmap_signed():return create_dynamic_map(True, 3, 4)
1
2
0
13
0
35
36
35
null
[]
None
null
0
0
0
null
0
null
The function (get_qmap_signed) defined within the public class called public.The function start at line 35 and ends at 36. 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_qmap_unsigned
def get_qmap_unsigned():return torch.linspace(0, 1, 17, device="cpu")[1:].tolist()# no zero
1
2
0
27
0
40
41
40
null
[]
None
null
0
0
0
null
0
null
The function (get_qmap_unsigned) defined within the public class called public.The function start at line 40 and ends at 41. 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
__new__
def __new__(cls, codes: Tensor, scale: Tensor, qmap: Tensor, signed: bool, shape):return Tensor._make_wrapper_subclass(cls, shape, device=codes.device)
1
2
6
38
0
48
49
48
null
[]
None
null
0
0
0
null
0
null
The function (__new__) defined within the public class called public.The function start at line 48 and ends at 49. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [48.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, codes: Tensor, scale: Tensor, qmap: Tensor, signed: bool, shape):"""Create quantized 4-bit optimizer state as proposed in https://arxiv.org/abs/2309.01507Argscodes: quantized and packed 4-bit data stored as uint8.scale: scale data for block-wise quantization.qmap: lookup table that maps between quant...
1
11
6
89
0
51
75
51
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 51 and ends at 75. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [51.0] and does not return any value..
pytorch_ao
public
public
0
0
__tensor_flatten__
def __tensor_flatten__(self):return self.tensor_attrs, [self.signed, self._shape]
1
2
1
19
0
77
78
77
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 77 and ends at 78. 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=None, outer_stride=None):return cls(*[tensor_data_dict[name] for name in cls.tensor_attrs], *tensor_attributes)
2
6
5
37
0
81
86
81
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 81 and ends at 86. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [81.0] and does not return any value..
pytorch_ao
public
public
0
0
dequantize
def dequantize(self, output_dtype=None):codes = torch.stack([self.codes >> 4, self.codes & 0b1111], dim=-1)# unpackfloat_data = dequant_with_qmap(codes, self.qmap, self.scale)if output_dtype is not None:float_data = float_data.to(output_dtype)return float_data.view(self._shape)
2
6
2
72
0
88
93
88
null
[]
None
null
0
0
0
null
0
null
The function (dequantize) defined within the public class called public.The function start at line 88 and ends at 93. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [88.0] and does not return any value..
pytorch_ao
public
public
0
0
zeros
def zeros(cls, shape, signed: bool = True, block_size: int = 128, device=None):shape = (shape,) if isinstance(shape, int) else shapen_elems = math.prod(shape)codes = torch.zeros(n_elems // 2, dtype=torch.uint8, device=device)scale = torch.zeros(n_elems // block_size, device=device)qmap_list = get_qmap_signed() if signe...
3
8
5
104
0
96
104
96
null
[]
None
null
0
0
0
null
0
null
The function (zeros) defined within the public class called public.The function start at line 96 and ends at 104. It contains 8 lines of code and it has a cyclomatic complexity of 3. It takes 5 parameters, represented as [96.0] and does not return any value..
pytorch_ao
public
public
0
0
__repr__
def __repr__(self):return (f"{self.__class__.__name__}(signed={self.signed}, block_size={self.block_size}, "f"shape={tuple(self.shape)}, device={self.device}, requires_grad={self.requires_grad})")
1
5
1
12
0
106
110
106
null
[]
None
null
0
0
0
null
0
null
The function (__repr__) defined within the public class called public.The function start at line 106 and ends at 110. 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
_
def _(func, types, args, kwargs):dst = args[0]src = args[1]if isinstance(dst, OptimState4bit) and isinstance(src, OptimState4bit):assert (dst.signed == src.signedand dst.block_size == src.block_sizeand dst._shape == src._shape)dst.codes.copy_(src.codes)dst.scale.copy_(src.scale)# qmap should be the same, don't need to ...
6
19
4
166
3
114
137
114
null
['dst', 'codes', 'src']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 114 and ends at 137. It contains 19 lines of code and it has a cyclomatic complexity of 6. It takes 4 parameters, represented as [114.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):# ignore dtypedevice = kwargs.get("device", None)out = OptimState4bit(args[0].codes.to(device=device),args[0].scale.to(device=device),args[0].qmap.to(device=device),args[0].signed,args[0].shape,)return return_and_correct_aliasing(func, args, kwargs, out)
1
10
4
93
2
141
151
141
null
['out', 'device']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 141 and ends at 151. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [141.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):args = [x.dequantize() if isinstance(x, OptimState4bit) else x for x in args]return func(*args, **kwargs)
3
3
4
42
1
155
157
155
null
['args']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 155 and ends at 157. It contains 3 lines of code and it has a cyclomatic complexity of 3. It takes 4 parameters, represented as [155.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):x, shape = argsif tuple(x.shape) == tuple(shape):return OptimState4bit(x.codes, x.scale, x.qmap, x.signed, x._shape)if len(shape) == 1 and shape[0] == -1:return OptimState4bit(x.codes, x.scale, x.qmap, x.signed, (x.numel(),))raise ValueError(f"{x.__class__.__name__} only supports .view(...
4
9
4
102
0
162
173
162
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 162 and ends at 173. It contains 9 lines of code and it has a cyclomatic complexity of 4. It takes 4 parameters, represented as [162.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):x = args[0]if not isinstance(x, OptimState4bit):raise ValueError(f"expecting a OptimState4bit but found {type(x)}")codes = func(x.codes, *args[1:], **kwargs)scale = func(x.scale, *args[1:], **kwargs)# adjust the first dimshape = (x._shape[0] * codes.numel() // x.codes.numel(),) + x._sha...
2
8
4
105
4
187
199
187
null
['x', 'codes', 'shape', 'scale']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 187 and ends at 199. It contains 8 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [187.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return (args[0].codes.is_pinned()and args[0].scale.is_pinned()and args[0].qmap.is_pinned())
3
6
4
46
0
206
211
206
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 206 and ends at 211. It contains 6 lines of code and it has a cyclomatic complexity of 3. It takes 4 parameters, represented as [206.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):dst = args[0]src = args[1]if isinstance(dst, OptimState4bit) and isinstance(src, OptimState4bit):assert (dst.signed == src.signedand dst.block_size == src.block_sizeand dst._shape == src._shape)dst.codes.copy_(src.codes)dst.scale.copy_(src.scale)# qmap should be the same, don't need to ...
6
19
4
166
3
216
246
114
null
['dst', 'codes', 'src']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 216 and ends at 246. It contains 19 lines of code and it has a cyclomatic complexity of 6. It takes 4 parameters, represented as [114.0] and does not return any value..
pytorch_ao
public
public
0
0
get_qmap_signed
def get_qmap_signed():return create_dynamic_map(signed=True)
1
2
0
11
0
31
32
31
null
[]
None
null
0
0
0
null
0
null
The function (get_qmap_signed) defined within the public class called public.The function start at line 31 and ends at 32. 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_qmap_unsigned
def get_qmap_unsigned():return create_dynamic_map(signed=False)
1
2
0
11
0
36
37
36
null
[]
None
null
0
0
0
null
0
null
The function (get_qmap_unsigned) defined within the public class called public.The function start at line 36 and ends at 37. 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
__new__
def __new__(cls, codes: Tensor, scale: Tensor, qmap: Tensor, signed: bool):return Tensor._make_wrapper_subclass(cls, codes.shape, device=codes.device)
1
2
5
38
0
44
45
44
null
[]
None
null
0
0
0
null
0
null
The function (__new__) 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. It takes 5 parameters, represented as [44.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, codes: Tensor, scale: Tensor, qmap: Tensor, signed: bool):"""Create quantized 8-bit optimizer state as proposed in https://arxiv.org/abs/2110.02861Argscodes: quantized 8-bit data stored as uint8. Has the same shape as the original float tensor.scale: scale data for block-wise quantization.qmap: looku...
1
9
5
74
0
47
67
47
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 47 and ends at 67. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [47.0] and does not return any value..
pytorch_ao
public
public
0
0
__tensor_flatten__
def __tensor_flatten__(self):return self.tensor_attrs, [self.signed]
1
2
1
15
0
69
70
69
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 69 and ends at 70. 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=None, outer_stride=None):return cls(*[tensor_data_dict[name] for name in cls.tensor_attrs], *tensor_attributes)
2
6
5
37
0
73
78
73
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 73 and ends at 78. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [73.0] and does not return any value..
pytorch_ao
public
public
0
0
dequantize
def dequantize(self, output_dtype=None):float_data = dequant_with_qmap(self.codes, self.qmap, self.scale)if output_dtype is not None:float_data = float_data.to(output_dtype)return float_data
2
5
2
41
0
80
84
80
null
[]
None
null
0
0
0
null
0
null
The function (dequantize) defined within the public class called public.The function start at line 80 and ends at 84. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [80.0] and does not return any value..
pytorch_ao
public
public
0
0
zeros
def zeros(cls, shape, signed: bool = True, block_size: int = 256, device=None):codes = torch.zeros(shape, dtype=torch.uint8, device=device)scale = torch.zeros(codes.numel() // block_size, device=device)qmap_list = get_qmap_signed() if signed else get_qmap_unsigned()qmap = torch.tensor(qmap_list, dtype=torch.float32, de...
2
6
5
93
0
87
92
87
null
[]
None
null
0
0
0
null
0
null
The function (zeros) defined within the public class called public.The function start at line 87 and ends at 92. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [87.0] and does not return any value..
pytorch_ao
public
public
0
0
__repr__
def __repr__(self):return (f"{self.__class__.__name__}(signed={self.signed}, block_size={self.block_size}, "f"shape={tuple(self.shape)}, device={self.device}, requires_grad={self.requires_grad})")
1
5
1
12
0
94
98
94
null
[]
None
null
0
0
0
null
0
null
The function (__repr__) defined within the public class called public.The function start at line 94 and ends at 98. 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
_
def _(func, types, args, kwargs):dst = args[0]src = args[1]if isinstance(dst, OptimState8bit) and isinstance(src, OptimState8bit):assert dst.signed == src.signed and dst.block_size == src.block_sizedst.codes.copy_(src.codes)dst.scale.copy_(src.scale)# qmap should be the same, don't need to copyelif isinstance(dst, Opti...
5
15
4
134
3
102
121
102
null
['dst', 'codes', 'src']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 102 and ends at 121. It contains 15 lines of code and it has a cyclomatic complexity of 5. It takes 4 parameters, represented as [102.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):# ignore dtypedevice = kwargs.get("device", None)out = OptimState8bit(args[0].codes.to(device=device),args[0].scale.to(device=device),args[0].qmap.to(device=device),args[0].signed,)return return_and_correct_aliasing(func, args, kwargs, out)
1
9
4
86
2
125
134
125
null
['out', 'device']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 125 and ends at 134. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [125.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):args = [x.dequantize() if isinstance(x, OptimState8bit) else x for x in args]return func(*args, **kwargs)
3
3
4
42
1
138
140
138
null
['args']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 138 and ends at 140. It contains 3 lines of code and it has a cyclomatic complexity of 3. It takes 4 parameters, represented as [138.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):x, shape = argsreturn OptimState8bit(x.codes.view(shape), x.scale, x.qmap, x.signed)
1
3
4
40
0
145
147
145
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 145 and ends at 147. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [145.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):x = args[0]if not isinstance(x, OptimState8bit):raise ValueError(f"expecting a OptimState8bit but found {type(x)}")# assume tensors from all ranks have the same signednessreturn OptimState8bit(func(x.codes, *args[1:], **kwargs),func(x.scale, *args[1:], **kwargs),x.qmap.clone(),x.signed,...
2
10
4
82
1
161
172
161
null
['x']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 161 and ends at 172. It contains 10 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [161.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return (args[0].codes.is_pinned()and args[0].scale.is_pinned()and args[0].qmap.is_pinned())
3
6
4
46
0
179
184
179
null
[]
None
null
0
0
0
null
0
null
The function (_) 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 3. It takes 4 parameters, represented as [179.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):x, dim, start, end = args[:4]step = args[4] if len(args) > 4 else 1# input validationif dim != 0:raise ValueError("Only support aten.slice along the first dim")if step != 1:raise ValueError("Only support aten.slice with step=1")block_size = x.block_sizestride = math.prod(x.shape[1:])# f...
6
21
4
142
3
189
216
189
null
['stride', 'block_size', 'step']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 189 and ends at 216. It contains 21 lines of code and it has a cyclomatic complexity of 6. It takes 4 parameters, represented as [189.0] and does not return any value..
pytorch_ao
public
public
0
0
quantize_fp8
def quantize_fp8(input: Tensor, block_size: int):shape = input.shapeinput = input.view(-1, block_size)scale = input.abs().amax(-1).clip(1e-12) / torch.finfo(DTYPE).maxinput = input / scale.view(-1, 1)codes = input.to(DTYPE).view(-1)return codes.view(shape), scale
1
7
2
92
4
22
28
22
null
['scale', 'input', 'shape', 'codes']
None
null
0
0
0
null
0
null
The function (quantize_fp8) defined within the public class called public.The function start at line 22 and ends at 28. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [22.0] and does not return any value..
pytorch_ao
public
public
0
0
__new__
def __new__(cls, codes: Tensor, scale: Tensor):return Tensor._make_wrapper_subclass(cls, codes.shape, device=codes.device)
1
2
3
30
0
38
39
38
null
[]
None
null
0
0
0
null
0
null
The function (__new__) 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 3 parameters, represented as [38.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, codes: Tensor, scale: Tensor):"""Create quantized FP8 optimizer state.Argscodes: quantized FP8 E4M3FN data. Has the same shape as the original float tensor.scale: scale data for block-wise quantization.NOTE: To get block-wise scale, the original float tensor is first reshape to (-1, block_size).Thus,...
1
6
3
46
0
41
56
41
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 41 and ends at 56. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [41.0] and does not return any value..
pytorch_ao
public
public
0
0
__tensor_flatten__
def __tensor_flatten__(self):return self.tensor_attrs, []
1
2
1
12
0
58
59
58
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 58 and ends at 59. 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=None, outer_stride=None):return cls(*[tensor_data_dict[name] for name in cls.tensor_attrs], *tensor_attributes)
2
6
5
37
0
62
67
62
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 62 and ends at 67. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [62.0] and does not return any value..
pytorch_ao
public
public
0
0
dequantize
def dequantize(self, output_dtype=None):float_data = self.codes.float()float_data = float_data.view(-1, self.block_size) * self.scale.view(-1, 1)if output_dtype is not None:float_data = float_data.to(output_dtype)return float_data.view(self.codes.shape)
2
6
2
68
0
69
75
69
null
[]
None
null
0
0
0
null
0
null
The function (dequantize) defined within the public class called public.The function start at line 69 and ends at 75. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [69.0] and does not return any value..
pytorch_ao
public
public
0
0
zeros
def zeros(cls, shape, block_size: int = 256, device=None):codes = torch.zeros(shape, dtype=DTYPE, device=device)scale = torch.zeros(codes.numel() // block_size, device=device)return cls(codes, scale)
1
4
4
52
0
78
81
78
null
[]
None
null
0
0
0
null
0
null
The function (zeros) defined within the public class called public.The function start at line 78 and ends at 81. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [78.0] and does not return any value..
pytorch_ao
public
public
0
0
__repr__
def __repr__(self):return (f"{self.__class__.__name__}(block_size={self.block_size}, "f"shape={tuple(self.shape)}, device={self.device}, requires_grad={self.requires_grad})")
1
5
1
12
0
83
87
83
null
[]
None
null
0
0
0
null
0
null
The function (__repr__) defined within the public class called public.The function start at line 83 and ends at 87. 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
_
def _(func, types, args, kwargs):dst = args[0]src = args[1]if isinstance(dst, OptimStateFp8) and isinstance(src, OptimStateFp8):assert dst.block_size == src.block_sizedst.codes.copy_(src.codes)dst.scale.copy_(src.scale)elif isinstance(dst, OptimStateFp8):codes, scale = quantize_fp8(src, dst.block_size)dst.codes.copy_(c...
4
14
4
116
2
91
108
91
null
['dst', 'src']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 91 and ends at 108. It contains 14 lines of code and it has a cyclomatic complexity of 4. It takes 4 parameters, represented as [91.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):# ignore dtypedevice = kwargs.get("device", None)out = OptimStateFp8(args[0].codes.to(device=device),args[0].scale.to(device=device),)return return_and_correct_aliasing(func, args, kwargs, out)
1
7
4
65
2
112
119
112
null
['out', 'device']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 112 and ends at 119. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [112.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):args = [x.dequantize() if isinstance(x, OptimStateFp8) else x for x in args]return func(*args, **kwargs)
3
3
4
42
1
123
125
123
null
['args']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 123 and ends at 125. It contains 3 lines of code and it has a cyclomatic complexity of 3. It takes 4 parameters, represented as [123.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):x, shape = argsreturn OptimStateFp8(x.codes.view(shape), x.scale)
1
3
4
32
0
130
132
130
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 130 and ends at 132. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [130.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):x = args[0]if not isinstance(x, OptimStateFp8):raise ValueError(f"expecting a OptimStateFp8 but found {type(x)}")# assume tensors from all ranks have the same signednessreturn OptimStateFp8(func(x.codes, *args[1:], **kwargs),func(x.scale, *args[1:], **kwargs),)
2
8
4
70
1
146
155
146
null
['x']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 146 and ends at 155. It contains 8 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [146.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return args[0].codes.is_pinned() and args[0].scale.is_pinned()
2
2
4
33
0
162
163
162
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 162 and ends at 163. It contains 2 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [162.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):x, dim, start, end = args[:4]step = args[4] if len(args) > 4 else 1# input validationif dim != 0:raise ValueError("Only support aten.slice along the first dim")if step != 1:raise ValueError("Only support aten.slice with step=1")block_size = x.block_sizestride = math.prod(x.shape[1:])# f...
6
19
4
130
3
168
193
168
null
['stride', 'block_size', 'step']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 168 and ends at 193. It contains 19 lines of code and it has a cyclomatic complexity of 6. It takes 4 parameters, represented as [168.0] and does not return any value..
pytorch_ao
public
public
0
0
_n_ones
def _n_ones(n: int) -> int:return (1 << n) - 1
1
2
1
18
0
19
20
19
null
[]
None
null
0
0
0
null
0
null
The function (_n_ones) defined within the public class called public.The function start at line 19 and ends at 20. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_f32_to_floatx_unpacked
def _f32_to_floatx_unpacked(x: Tensor, ebits: int, mbits: int) -> Tensor:"""Convert FP32 numbers to sub-byte floating point numbers with the givennumber of exponent and mantissa bits.Input: torch.Tensor of dtype torch.floatOutput: torch.Tensor of dtype torch.uint8, where the bit encoding is storedin the least significa...
1
44
3
392
19
27
142
27
null
['saturate_mask', 'max_int', 'min_normal', 'denorm_mask_float', 'sign', 'sign_mask', 'exp_bias', 'denormal_mask', 'normal_mask', 'denorm_mask_int', 'mant_odd', 'denorm_exp', 'max_normal', 'val_to_add', 'sign_lp', 'denormal_x', 'normal_x', 'x', 'magic_adder']
None
null
0
0
0
null
0
null
The function (_f32_to_floatx_unpacked) defined within the public class called public.The function start at line 27 and ends at 142. It contains 44 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [27.0] and does not return any value..
pytorch_ao
public
public
0
0
_floatx_unpacked_to_f32
def _floatx_unpacked_to_f32(x: Tensor, ebits: int, mbits: int) -> Tensor:"""Convert sub-byte floating point numbers with the given number of exponentand mantissa bits to FP32.Input: torch.Tensor of dtype uint8, where the bit encoding is storedin the least significant bits. e.g.fp4: bits 0-3 empty and bits 4-7 in fp4_e2...
4
35
3
307
15
147
235
147
null
['mantissa_lp_int32', 'sign_mask', 'mantissa_f32', 'sign_lp', 'left_shift', 'exp_bias', 'denormal_mask', 'denormal_exp_biased', 'exp_biased_lp', 'sign_f32', 'x_pos', 'result', 'zero_mask', 'exp_biased_f32', 'mantissa_mask']
None
null
0
0
0
null
0
null
The function (_floatx_unpacked_to_f32) defined within the public class called public.The function start at line 147 and ends at 235. It contains 35 lines of code and it has a cyclomatic complexity of 4. It takes 3 parameters, represented as [147.0] and does not return any value..
pytorch_ao
public
public
0
0
quantize_model_with_autoround_
def quantize_model_with_autoround_(model,tokenizer,is_target_module,bits: int = 4,group_size: int = 128,iters: int = 200,seqlen: int = 2048,dataset_name: str = "NeelNanda/pile-10k",batch_size: int = 8,nsamples: int = 128,use_optimized_layer_output: bool = False,gradient_accumulate_steps: Optional[int] = 1,compile_optim...
3
49
13
224
6
24
84
24
null
['dataloader', 'input_ids_lst', 'num_quantized_weight', 'model_device', 'device', 'multi_t_input_ids']
None
null
0
0
0
null
0
null
The function (quantize_model_with_autoround_) defined within the public class called public.The function start at line 24 and ends at 84. It contains 49 lines of code and it has a cyclomatic complexity of 3. It takes 13 parameters, represented as [24.0] and does not return any value..
pytorch_ao
public
public
0
0
main
def main(args):# Get the model, tokenizer, and decoder_clsmodel_name_or_path = args.model_name_or_pathmodel, tokenizer, decoder_cls = ar_utils.get_float_model_info(model_name_or_path, dtype=torch.bfloat16)# Disable the `use_cache` for calibration stage.model.config.use_cache = Falsear_utils.gen_text(model, tokenizer, "...
3
30
1
188
3
87
125
87
null
['model_name_or_path', 'is_target_module', 'model']
None
null
0
0
0
null
0
null
The function (main) defined within the public class called public.The function start at line 87 and ends at 125. It contains 30 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
reset
def reset(self):self.num_layers = 0self.optimized_layers = 0
1
3
1
15
0
40
42
40
null
[]
None
null
0
0
0
null
0
null
The function (reset) defined within the public class called public.The function start at line 40 and ends at 42. 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
_replace_model_buffers_and_params
def _replace_model_buffers_and_params(model, replacement_fn):model = replacement_fn(model)for name, child in model.named_children():new_child = _replace_model_buffers_and_params(child, replacement_fn)if new_child is not child:setattr(model, name, new_child)return model
3
7
2
48
2
48
54
48
null
['new_child', 'model']
None
null
0
0
0
null
0
null
The function (_replace_model_buffers_and_params) defined within the public class called public.The function start at line 48 and ends at 54. It contains 7 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [48.0] and does not return any value..
pytorch_ao
public
public
0
0
_tensor_to_multi_tensor
def _tensor_to_multi_tensor(model):for name, buf in model.named_buffers(recurse=False):setattr(model, name, MultiTensor([buf]))for name, param in model.named_parameters(recurse=False):setattr(model, name, torch.nn.Parameter(MultiTensor([param]), False))return model
3
6
1
70
0
57
62
57
null
[]
None
null
0
0
0
null
0
null
The function (_tensor_to_multi_tensor) defined within the public class called public.The function start at line 57 and ends at 62. 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
_multi_tensor_to_tensor
def _multi_tensor_to_tensor(model):for name, buf in model.named_buffers(recurse=False):if isinstance(buf, MultiTensor):assert len(buf.values) == 1, (f"The buffer should only have one tensor, but got {buf.count}.")model.register_buffer(name, buf.values[0])for name, param in model.named_parameters(recurse=False):if isins...
5
16
1
116
0
65
80
65
null
[]
None
null
0
0
0
null
0
null
The function (_multi_tensor_to_tensor) defined within the public class called public.The function start at line 65 and ends at 80. It contains 16 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
prepare_model_for_applying_auto_round_._revert_buffers_and_params_fn
def _revert_buffers_and_params_fn(module,input: Tuple[MultiTensor],output: Tuple[MultiTensor],):module._forward_hook_handle_for_revert_buffers_and_params.remove()_replace_model_buffers_and_params(module, _multi_tensor_to_tensor)return output
1
8
3
35
0
127
134
127
null
[]
None
null
0
0
0
null
0
null
The function (prepare_model_for_applying_auto_round_._revert_buffers_and_params_fn) defined within the public class called public.The function start at line 127 and ends at 134. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [127.0] and does not return any val...
pytorch_ao
public
public
0
0
prepare_model_for_applying_auto_round_.auto_round_optimization_hook
def auto_round_optimization_hook(module,args: Tuple[MultiTensor],kwargs: Dict[str, MultiTensor],output: Tuple[MultiTensor],):apply_auto_round_optimization(module, args, kwargs, output, config=_auto_round_config)return output
1
10
4
45
0
142
151
142
null
[]
None
null
0
0
0
null
0
null
The function (prepare_model_for_applying_auto_round_.auto_round_optimization_hook) defined within the public class called public.The function start at line 142 and ends at 151. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [142.0] and does not return any val...
pytorch_ao
public
public
0
0
prepare_model_for_applying_auto_round_._register_forward_hook
def _register_forward_hook(module: torch.nn.Module):forward_hook_handle = module.register_forward_hook(auto_round_optimization_hook, with_kwargs=True)module._forward_hook_handle_for_auto_round = forward_hook_handle_optimization_tracker.num_layers += 1return module
1
7
1
35
0
153
159
153
null
[]
None
null
0
0
0
null
0
null
The function (prepare_model_for_applying_auto_round_._register_forward_hook) defined within the public class called public.The function start at line 153 and ends at 159. It contains 7 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
prepare_model_for_applying_auto_round_
def prepare_model_for_applying_auto_round_(model: torch.nn.Module,is_target_module: Callable[[torch.nn.Module, str], bool],bits: int = 4,group_size: int = 128,iters: int = 200,use_optimized_layer_output: bool = False,gradient_accumulate_steps: Optional[int] = 1,compile_optimization_process: Optional[bool] = False,devic...
1
32
9
193
2
84
164
84
null
['forward_hook_handle', 'model']
None
null
0
0
0
null
0
null
The function (prepare_model_for_applying_auto_round_) defined within the public class called public.The function start at line 84 and ends at 164. It contains 32 lines of code and it has a cyclomatic complexity of 1. It takes 9 parameters, represented as [84.0] and does not return any value..
pytorch_ao
public
public
0
0
apply_auto_round.apply_auto_round._apply_auto_round.apply_auto_round.apply_auto_round._apply_auto_round.convert_weight_to_affine_quantized_tensor.to_uintx_weight
def to_uintx_weight(input_float):quant_min = 0quant_max = _auto_round_config.bits**2 - 1block_size = (1, observed_linear.group_size)from torchao.dtypes.uintx.uintx import (_BIT_WIDTH_TO_DTYPE,UintxLayout,)from torchao.quantization.quant_primitives import ZeroPointDomainassert _auto_round_config.bits in _BIT_WIDTH_TO_DT...
1
26
1
135
0
188
214
188
null
[]
None
null
0
0
0
null
0
null
The function (apply_auto_round.apply_auto_round._apply_auto_round.apply_auto_round.apply_auto_round._apply_auto_round.convert_weight_to_affine_quantized_tensor.to_uintx_weight) defined within the public class called public.The function start at line 188 and ends at 214. It contains 26 lines of code and it has a cycloma...
pytorch_ao
public
public
0
0
apply_auto_round.apply_auto_round._apply_auto_round.apply_auto_round.apply_auto_round._apply_auto_round.convert_weight_to_affine_quantized_tensor.to_int4_tinygemm_weight
def to_int4_tinygemm_weight(input_float):# TODO(Yi): check the weight shape, `group_size`, and `inner_k_tiles` to make sure the tinygemm can handle itinner_k_tiles = 8quant_min = 0quant_max = _auto_round_config.bits**2 - 1# Shift the `zero_point` to align with tiny gemm.# The dequantization process in tiny gemm:# tiny_...
1
41
1
199
0
216
268
216
null
[]
None
null
0
0
0
null
0
null
The function (apply_auto_round.apply_auto_round._apply_auto_round.apply_auto_round.apply_auto_round._apply_auto_round.convert_weight_to_affine_quantized_tensor.to_int4_tinygemm_weight) defined within the public class called public.The function start at line 216 and ends at 268. It contains 41 lines of code and it has a...
pytorch_ao
public
public
0
0
apply_auto_round.apply_auto_round._apply_auto_round.convert_weight_to_affine_quantized_tensor
def convert_weight_to_affine_quantized_tensor(observed_linear: torch.nn.Module):device = observed_linear.weight.devicescale = observed_linear.scale.to(device)zero_point = observed_linear.zp.to(device)def to_uintx_weight(input_float):quant_min = 0quant_max = _auto_round_config.bits**2 - 1block_size = (1, observed_linear...
3
19
1
100
0
183
284
183
null
[]
None
null
0
0
0
null
0
null
The function (apply_auto_round.apply_auto_round._apply_auto_round.convert_weight_to_affine_quantized_tensor) defined within the public class called public.The function start at line 183 and ends at 284. It contains 19 lines of code and it has a cyclomatic complexity of 3. The function does not take any parameters and d...
pytorch_ao
public
public
0
0
apply_auto_round.apply_auto_round._apply_auto_round._is_observed_linear
def _is_observed_linear(mod: torch.nn.Module, fqn: str):return hasattr(mod, "scale")
1
2
2
22
0
286
287
286
null
[]
None
null
0
0
0
null
0
null
The function (apply_auto_round.apply_auto_round._apply_auto_round._is_observed_linear) defined within the public class called public.The function start at line 286 and ends at 287. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [286.0] and does not return any ...
pytorch_ao
public
public
0
0
apply_auto_round._apply_auto_round
def _apply_auto_round(optimized_model: torch.nn.Module):"""The `optimized_model` includes `Linear` layers optimized by auto-round, which includes `qdq_weight`, `scale`, `zp`."""@torch.no_grad()def convert_weight_to_affine_quantized_tensor(observed_linear: torch.nn.Module):device = observed_linear.weight.devicescale = o...
1
10
1
39
0
177
294
177
null
[]
None
null
0
0
0
null
0
null
The function (apply_auto_round._apply_auto_round) defined within the public class called public.The function start at line 177 and ends at 294. It contains 10 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
apply_auto_round
def apply_auto_round():"""Create the quantized model from the model optimized by auto-round.More details about the auto-round can be found at https://arxiv.org/abs/2309.05516."""raise AssertionError("Please migrate this function to direct configuration, see https://github.com/pytorch/ao/issues/1690 for details")def _ap...
1
6
0
14
20
167
296
167
null
['pad_scale', 'shifted_zero_point', 'quant_max', 'out_features', 'qmodel', 'zero_point', 'device', 'mid_point', 'scale', 'in_features', 'new_num_groups', 'block_size', 'dtype', 'pack_dim', 'inner_k_tiles', 'weight_func', '_layout', 'pad_shifted_zero_point', 'quant_min', 'orig_num_groups']
None
null
0
0
0
null
0
null
The function (apply_auto_round) defined within the public class called public.The function start at line 167 and ends at 296. It contains 6 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_apply_auto_round_optimization
def _apply_auto_round_optimization(block, block_inputs, block_outputs, config: _AutoRoundConfig):# Call the auto-round to execute the optimization process.# https://github.com/intel/auto-round/tree/patch-for-ao-2# TODO(Yi), make the branch more stableif ar_utils.is_auto_round_available():import auto_roundelse:raise Imp...
3
41
4
185
3
300
346
300
null
['block', 'rounder', 'orig_device']
None
null
0
0
0
null
0
null
The function (_apply_auto_round_optimization) defined within the public class called public.The function start at line 300 and ends at 346. It contains 41 lines of code and it has a cyclomatic complexity of 3. It takes 4 parameters, represented as [300.0] and does not return any value..
pytorch_ao
public
public
0
0
apply_auto_round_optimization
def apply_auto_round_optimization(module: torch.nn.Module,args: Tuple[MultiTensor],kwargs: Dict[str, Any],output: Any,config: _AutoRoundConfig,):# Remove the hook to avoid recursive callsmodule._forward_hook_handle_for_auto_round.remove()# Revert the model to the original state for applying auto-round optimizationmodul...
2
16
5
102
4
351
372
351
null
['block_inputs', 'output', 'module', 'block_outputs']
None
null
0
0
0
null
0
null
The function (apply_auto_round_optimization) defined within the public class called public.The function start at line 351 and ends at 372. It contains 16 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [351.0] and does not return any value..