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
test_aot_eager
def test_aot_eager(fullgraph,emulate: bool,scaling_type_input: ScalingType,scaling_type_weight: ScalingType,scaling_type_grad_output: ScalingType,dtype: torch.dtype,):torch._dynamo.reset()config = get_test_float8_linear_config(scaling_type_input,scaling_type_weight,scaling_type_grad_output,emulate,)_test_compile_base("...
1
21
6
59
1
126
146
126
null
['config']
None
null
0
0
0
null
0
null
The function (test_aot_eager) defined within the public class called public.The function start at line 126 and ends at 146. It contains 21 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [126.0] and does not return any value..
pytorch_ao
public
public
0
0
test_inductor_from_config_params
def test_inductor_from_config_params(fullgraph,emulate: bool,scaling_type_input: ScalingType,scaling_type_weight: ScalingType,scaling_type_grad_output: ScalingType,dtype: torch.dtype,):torch._dynamo.reset()config = get_test_float8_linear_config(scaling_type_input,scaling_type_weight,scaling_type_grad_output,emulate,)_t...
1
21
6
59
1
165
185
165
null
['config']
None
null
0
0
0
null
0
null
The function (test_inductor_from_config_params) defined within the public class called public.The function start at line 165 and ends at 185. It contains 21 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [165.0] and does not return any value..
pytorch_ao
public
public
0
0
test_inductor_from_recipe
def test_inductor_from_recipe(recipe_name):torch._dynamo.reset()config = Float8LinearConfig.from_recipe_name(recipe_name)fullgraph = Truedtype = torch.bfloat16_test_compile_base("inductor",fullgraph,config,dtype,)
1
11
1
39
3
202
212
202
null
['fullgraph', 'config', 'dtype']
None
null
0
0
0
null
0
null
The function (test_inductor_from_recipe) defined within the public class called public.The function start at line 202 and ends at 212. It contains 11 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, graph_break: bool):super().__init__()self.graph_break = graph_break
1
3
2
21
0
217
219
217
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 217 and ends at 219. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [217.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, x):x_fp8 = hp_tensor_to_float8_dynamic(x,e4m3_dtype,LinearMMConfig(),)if self.graph_break:torch._dynamo.graph_break()x_hp = x_fp8.to_original_precision()return x_hpreturn x_fp8
2
11
2
43
0
221
231
221
null
[]
None
null
0
0
0
null
0
null
The function (forward) defined within the public class called public.The function start at line 221 and ends at 231. It contains 11 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [221.0] and does not return any value..
pytorch_ao
public
public
0
0
test_float8_with_graph_break_in_the_middle
def test_float8_with_graph_break_in_the_middle(self):"""Test that having Float8TrainingTensor object at the boundary of a subgraph"""cnts = CompileCounterWithBackend("inductor")mod = self.MockLinear(graph_break=True).cuda()compiled_mod = copy.deepcopy(mod)compiled_mod = torch.compile(compiled_mod, backend=cnts)x = torc...
1
10
1
94
0
238
248
238
null
[]
None
null
0
0
0
null
0
null
The function (test_float8_with_graph_break_in_the_middle) defined within the public class called public.The function start at line 238 and ends at 248. 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
test_float8_graph_input.to_float
def to_float(x):return x.to_original_precision()
1
2
1
11
0
257
258
257
null
[]
None
null
0
0
0
null
0
null
The function (test_float8_graph_input.to_float) defined within the public class called public.The function start at line 257 and ends at 258. 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
test_float8_graph_input
def test_float8_graph_input(self):"""Test that having Float8TrainingTensor object as a graph input"""def to_float(x):return x.to_original_precision()cnts = CompileCounterWithBackend("inductor")mod = self.MockLinear(graph_break=False).cuda()x = torch.randn(2, 2, device="cuda")compiled_to_float = torch.compile(to_float, ...
1
15
1
95
0
254
272
254
null
[]
None
null
0
0
0
null
0
null
The function (test_float8_graph_input) defined within the public class called public.The function start at line 254 and ends at 272. It contains 15 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
test_float8_graph_output
def test_float8_graph_output(self):"""Test that having Float8TrainingTensor object as a graph output works"""cnts = CompileCounterWithBackend("inductor")mod = self.MockLinear(graph_break=False).cuda()compiled_mod = torch.compile(mod, backend=cnts)x = torch.randn(16, 16, device="cuda")y_compiled = compiled_mod(x)self.as...
2
22
1
161
0
278
301
278
null
[]
None
null
0
0
0
null
0
null
The function (test_float8_graph_output) defined within the public class called public.The function start at line 278 and ends at 301. It contains 22 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
__enter__
def __enter__(self):self.sys_stderr = sys.stderrself.stringio = StringIO()sys.stderr = self.stringioreturn self
1
5
1
28
0
309
313
309
null
[]
None
null
0
0
0
null
0
null
The function (__enter__) defined within the public class called public.The function start at line 309 and ends at 313. 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
__exit__
def __exit__(self, *args):self.append(str(self.stringio.getvalue()))del self.stringiosys.stderr = self.sys_stderr
1
4
2
34
0
315
318
315
null
[]
None
null
0
0
0
null
0
null
The function (__exit__) defined within the public class called public.The function start at line 315 and ends at 318. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [315.0] and does not return any value..
pytorch_ao
public
public
0
0
test_dynamic_scale_numeric_parity
def test_dynamic_scale_numeric_parity(dtype: torch.dtype, round_scales_to_power_of_2: bool):scaling_type_weight = ScalingType.DYNAMICtorch.manual_seed(42)hp_tensor1 = torch.randn(16, 16, device="cuda", dtype=dtype)hp_tensor2 = hp_tensor1.detach().clone()float8_config = Float8LinearConfig(cast_config_weight=CastConfig(s...
1
48
2
214
7
340
390
340
null
['float8_config', 'float8_compile', 'float8_eager', 'hp_tensor2', 'scaling_type_weight', 'linear_mm_config', 'hp_tensor1']
None
null
0
0
0
null
0
null
The function (test_dynamic_scale_numeric_parity) defined within the public class called public.The function start at line 340 and ends at 390. It contains 48 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [340.0] and does not return any value..
pytorch_ao
public
public
0
0
setup_distributed
def setup_distributed():world_size = int(os.environ.get("WORLD_SIZE", -1))device_mesh = init_device_mesh("cuda", (world_size,))# seed must be the same in all processestorch.manual_seed(1)local_rank = torch.distributed.get_rank()torch.cuda.set_device(local_rank)return device_mesh
1
7
0
56
3
48
55
48
null
['local_rank', 'device_mesh', 'world_size']
None
null
0
0
0
null
0
null
The function (setup_distributed) defined within the public class called public.The function start at line 48 and ends at 55. 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
_test_scaled_mm
def _test_scaled_mm(mesh: DeviceMesh, size=16):device = mesh.device_typefp8_dtype = e4m3_dtypeworld_size = mesh.size()x_fp32 = torch.rand(size, size, device=device)y_fp32 = torch.eye(size, device=device).t()placement_combs = ((Shard(0), Replicate()),(Replicate(), Shard(1)),(Shard(1), Shard(0)),)expected_dt_out_shape = ...
2
34
2
302
15
58
98
58
null
['x_fp8', 'expected_dt_out_shape', 'dist_y_fp8', 'device', 'world_size', 'fp8_dtype', 'y_scale', 'out_fp8', 'y_fp8', 'x_scale', 'placement_combs', 'y_fp32', 'dist_x_fp8', 'x_fp32', 'local_fp8_out']
None
null
0
0
0
null
0
null
The function (_test_scaled_mm) defined within the public class called public.The function start at line 58 and ends at 98. It contains 34 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [58.0] and does not return any value..
pytorch_ao
public
public
0
0
_test_fp8_redistribute
def _test_fp8_redistribute(mesh: DeviceMesh, size=16):device = mesh.device_typefp8_dtype = e4m3_dtypeworld_size = mesh.size()x_fp32 = torch.rand(size, size, device=device)x_scale = tensor_to_scale(x_fp32, fp8_dtype).float()x_fp8 = hp_tensor_and_scale_to_float8(x_fp32, x_scale, fp8_dtype)dist_x_fp8 = DTensor.from_local(...
2
18
2
177
9
101
125
101
null
['x_fp8', 'out_local', 'device', 'world_size', 'fp8_dtype', 'out_dist', 'x_scale', 'dist_x_fp8', 'x_fp32']
None
null
0
0
0
null
0
null
The function (_test_fp8_redistribute) defined within the public class called public.The function start at line 101 and ends at 125. It contains 18 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [101.0] and does not return any value..
pytorch_ao
public
public
0
0
_test_dtensor_cast_to_fp8
def _test_dtensor_cast_to_fp8(mesh: DeviceMesh, size=16):device = mesh.device_typefp8_dtype = e4m3_dtypex_fp32 = torch.rand(size, size, device=device)dist_x_fp32 = distribute_tensor(x_fp32, mesh, [Shard(0)])dist_x_scale = tensor_to_scale(dist_x_fp32, fp8_dtype).float()assert isinstance(dist_x_scale, DTensor)dist_x_fp8 ...
1
9
2
84
6
128
139
128
null
['dist_x_fp32', 'dist_x_scale', 'device', 'fp8_dtype', 'dist_x_fp8', 'x_fp32']
None
null
0
0
0
null
0
null
The function (_test_dtensor_cast_to_fp8) defined within the public class called public.The function start at line 128 and ends at 139. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [128.0] and does not return any value..
pytorch_ao
public
public
0
0
_test_dtensor_fp8_autograd
def _test_dtensor_fp8_autograd(mesh: DeviceMesh, size=16):device = mesh.device_typefp8_dtype = e4m3_dtypex_fp32 = torch.rand(size, size, device=device, requires_grad=True)local_weight = torch.rand(2 * size, size, device=device, requires_grad=True)target = torch.rand(size, 2 * size, device=device)dist_x_fp32 = distribut...
1
30
2
234
14
142
176
142
null
['dist_x_fp32', 'target', 'out', 'dist_weight_scale', 'device', 'fp8_dtype', 'dist_x_scale', 'dist_target', 'dist_weight_fp8', 'loss', 'local_weight', 'dist_x_fp8', 'x_fp32', 'dist_wight_fp32']
None
null
0
0
0
null
0
null
The function (_test_dtensor_fp8_autograd) defined within the public class called public.The function start at line 142 and ends at 176. It contains 30 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [142.0] and does not return any value..
pytorch_ao
public
public
0
0
_test_fp8_mlp_tensor_parallelism_eager
def _test_fp8_mlp_tensor_parallelism_eager(mesh: DeviceMesh, size=32):tensorwise_config = Float8LinearConfig(emulate=True)_test_lowp_mlp_tensor_parallelism_base(mesh, tensorwise_config, size, compile=False, allgather_in_lowp=True)rowwise_config = Float8LinearConfig.from_recipe_name(Float8LinearRecipeName.ROWWISE)# hack...
1
10
2
71
2
179
191
179
null
['tensorwise_config', 'rowwise_config']
None
null
0
0
0
null
0
null
The function (_test_fp8_mlp_tensor_parallelism_eager) defined within the public class called public.The function start at line 179 and ends at 191. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [179.0] and does not return any value..
pytorch_ao
public
public
0
0
_test_fp8_mlp_tensor_parallelism_compile
def _test_fp8_mlp_tensor_parallelism_compile(mesh: DeviceMesh, size=32):tensorwise_config = Float8LinearConfig(emulate=True)_test_lowp_mlp_tensor_parallelism_base(mesh, tensorwise_config, size, compile=True, allgather_in_lowp=True)rowwise_config = Float8LinearConfig.from_recipe_name(Float8LinearRecipeName.ROWWISE)# hac...
1
10
2
71
2
194
206
194
null
['tensorwise_config', 'rowwise_config']
None
null
0
0
0
null
0
null
The function (_test_fp8_mlp_tensor_parallelism_compile) defined within the public class called public.The function start at line 194 and ends at 206. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [194.0] and does not return any value..
pytorch_ao
public
public
0
0
_test_distribute_fsdp_tensor_subclass
def _test_distribute_fsdp_tensor_subclass(tp_mesh: DeviceMesh):torch.manual_seed(42)model = Transformer(ModelArgs(dropout_p=0.0, weight_tying=False)).cuda()convert_to_float8_training(model,config=Float8LinearConfig(enable_fsdp_float8_all_gather=True,cast_config_weight=CastConfig(scaling_type=ScalingType.DYNAMIC),),)# t...
3
26
1
154
3
209
236
209
null
['colwise_param', 'rowwise_param', 'model']
None
null
0
0
0
null
0
null
The function (_test_distribute_fsdp_tensor_subclass) defined within the public class called public.The function start at line 209 and ends at 236. It contains 26 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
test_round_scale_down_to_power_of_2_valid_inputs
def test_round_scale_down_to_power_of_2_valid_inputs(test_case: dict,):test_case_name, input, expected_result = test_caseinput_tensor, expected_tensor = (torch.tensor(input, dtype=torch.float32).cuda(),torch.tensor(expected_result, dtype=torch.float32).cuda(),)result = _round_scale_down_to_power_of_2(input_tensor)asser...
3
14
1
89
1
36
50
36
null
['result']
None
null
0
0
0
null
0
null
The function (test_round_scale_down_to_power_of_2_valid_inputs) defined within the public class called public.The function start at line 36 and ends at 50. It contains 14 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
test_non_float32_input
def test_non_float32_input(invalid_dtype: torch.dtype):non_float32_tensor = torch.tensor([3.0], dtype=invalid_dtype)with pytest.raises(AssertionError, match="scale must be float32 tensor"):_round_scale_down_to_power_of_2(non_float32_tensor)
1
4
1
41
1
66
69
66
null
['non_float32_tensor']
None
null
0
0
0
null
0
null
The function (test_non_float32_input) defined within the public class called public.The function start at line 66 and ends at 69. 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
setup
def setup(rank, world_size):os.environ["MASTER_ADDR"] = "localhost"os.environ["MASTER_PORT"] = "12355"# initialize the process groupdist.init_process_group("nccl", rank=rank, world_size=world_size)
1
4
2
37
0
44
49
44
null
[]
None
null
0
0
0
null
0
null
The function (setup) defined within the public class called public.The function start at line 44 and ends at 49. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [44.0] and does not return any value..
pytorch_ao
public
public
0
0
cleanup
def cleanup():dist.destroy_process_group()
1
2
0
9
0
52
53
52
null
[]
None
null
0
0
0
null
0
null
The function (cleanup) defined within the public class called public.The function start at line 52 and ends at 53. 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_model
def get_model(K, N, base_dtype=torch.float32):m = nn.Sequential(nn.Linear(K, N, dtype=base_dtype),nn.ReLU(),nn.Linear(N, N, dtype=base_dtype),nn.ReLU(),)return m
1
8
3
60
1
56
63
56
null
['m']
None
null
0
0
0
null
0
null
The function (get_model) defined within the public class called public.The function start at line 56 and ends at 63. It contains 8 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [56.0] and does not return any value..
pytorch_ao
public
public
0
0
fsdp_main.forward_backward
def forward_backward(model, optim, is_fp8, i):optim.zero_grad()y_local = model(ref_input_local[i])y_local.backward(ref_grad_local[i])optim.step()return y_local
1
6
4
41
0
122
127
122
null
[]
None
null
0
0
0
null
0
null
The function (fsdp_main.forward_backward) defined within the public class called public.The function start at line 122 and ends at 127. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [122.0] and does not return any value..
pytorch_ao
public
public
0
0
fsdp_main
def fsdp_main(rank, world_size, args):setup(rank, world_size)torch.cuda.set_device(rank)print("args", args)emulate, base_dtype, compile = argsmodel = get_model(K, N, base_dtype=base_dtype).to(rank)model_fp8 = copy.deepcopy(model)config = Float8LinearConfig()# Note: we only iterate over `scaling_type_weight` because FSD...
10
72
3
612
21
68
173
68
null
['config', 'bsz_local_start', 'bsz_local_end', 'y_local', 'model_fp8', 'ref_grad_local', 'local_sqnr', 'sqnr', 'ref_input_local', 'cpu_state', 'optimizer_fp8', 'optimizer', 'y_global', 'y_local_fp8', 'v2', 'save_policy', 'ref_grad_global', 'cpu_state_fp8', 'model', 'ref_input_global', 'y_global_fp8']
None
null
0
0
0
null
0
null
The function (fsdp_main) defined within the public class called public.The function start at line 68 and ends at 173. It contains 72 lines of code and it has a cyclomatic complexity of 10. It takes 3 parameters, represented as [68.0] and does not return any value..
pytorch_ao
public
public
0
0
run
def run(compile_fsdp: bool = False):base_dtype = torch.bfloat16emulate = Falseif not torch.cuda.is_available():warnings.warn("CUDA not available, running in emulation_mode")emulate = Trueelif torch.cuda.get_device_capability() < (8, 9):warnings.warn(f"CUDA capability {torch.cuda.get_device_capability()} < (8.9), runnin...
3
14
1
101
4
176
191
176
null
['base_dtype', 'WORLD_SIZE', 'emulate', 'args']
None
null
0
0
0
null
0
null
The function (run) defined within the public class called public.The function start at line 176 and ends at 191. It contains 14 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
setup_distributed
def setup_distributed():world_size = int(os.environ.get("WORLD_SIZE", -1))# https://pytorch.org/tutorials/recipes/distributed_device_mesh.htmldevice_mesh = init_device_mesh("cuda",(world_size // 2, 2),mesh_dim_names=("dp", "tp"),)# seed must be the same in all processestorch.manual_seed(1)local_rank = torch.distributed...
1
11
0
63
3
33
46
33
null
['local_rank', 'device_mesh', 'world_size']
None
null
0
0
0
null
0
null
The function (setup_distributed) defined within the public class called public.The function start at line 33 and ends at 46. It contains 11 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_test_fp8_mlp_tensor_parallelism_base
def _test_fp8_mlp_tensor_parallelism_base(mesh: DeviceMesh, size=16, compile: bool = False):device = mesh.device_typeconfig = Float8LinearConfig(emulate=True,enable_fsdp_float8_all_gather=True,)toy_model = ToyModel(size).to(device)tp_model = copy.deepcopy(toy_model)tp_model = convert_to_float8_training(tp_model, config...
2
29
3
178
8
49
87
49
null
['toy_model', 'config', 'fsdp_config', 'tp_out', 'device', 'tp_model', 'x_fp32_tp_input', 'x_fp32']
None
null
0
0
0
null
0
null
The function (_test_fp8_mlp_tensor_parallelism_base) defined within the public class called public.The function start at line 49 and ends at 87. It contains 29 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [49.0] and does not return any value..
pytorch_ao
public
public
0
0
_test_fp8_mlp_tensor_parallelism_eager
def _test_fp8_mlp_tensor_parallelism_eager(mesh: DeviceMesh, size=32):_test_fp8_mlp_tensor_parallelism_base(mesh, size, compile=False)
1
2
2
21
0
92
93
92
null
[]
None
null
0
0
0
null
0
null
The function (_test_fp8_mlp_tensor_parallelism_eager) defined within the public class called public.The function start at line 92 and ends at 93. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [92.0] and does not return any value..
pytorch_ao
public
public
0
0
_test_fp8_mlp_tensor_parallelism_compile
def _test_fp8_mlp_tensor_parallelism_compile(mesh: DeviceMesh, size=32):_test_fp8_mlp_tensor_parallelism_base(mesh, size, compile=True)
1
2
2
21
0
96
97
96
null
[]
None
null
0
0
0
null
0
null
The function (_test_fp8_mlp_tensor_parallelism_compile) defined within the public class called public.The function start at line 96 and ends at 97. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [96.0] and does not return any value..
pytorch_ao
public
public
0
0
setup
def setup(rank, world_size):os.environ["MASTER_ADDR"] = "localhost"os.environ["MASTER_PORT"] = "12355"# initialize the process groupdist.init_process_group("nccl", rank=rank, world_size=world_size)
1
4
2
37
0
33
38
33
null
[]
None
null
0
0
0
null
0
null
The function (setup) defined within the public class called public.The function start at line 33 and ends at 38. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [33.0] and does not return any value..
pytorch_ao
public
public
0
0
cleanup
def cleanup():dist.destroy_process_group()
1
2
0
9
0
41
42
41
null
[]
None
null
0
0
0
null
0
null
The function (cleanup) defined within the public class called public.The function start at line 41 and ends at 42. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
get_model
def get_model(K, N, is_fp8, emulate, base_dtype=torch.float32):# composability of torch.compile + FSDP + autocast + Float8Linear# as fo 2023-12-30# without any changes to the Float8Linear, we get this error:# https://gist.github.com/vkuzo/3bcb81806cc92f99ac0b9c5fdf287730# if we initialize Float8Linear with is_amax_init...
1
13
5
63
2
45
68
45
null
['m', 'config']
None
null
0
0
0
null
0
null
The function (get_model) defined within the public class called public.The function start at line 45 and ends at 68. It contains 13 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [45.0] and does not return any value..
pytorch_ao
public
public
0
0
fsdp_main
def fsdp_main(rank, world_size, args):setup(rank, world_size)torch.cuda.set_device(rank)(emulate,) = args# finally, if we remove the usage of self.bias_dtype, then# things work e2e. Note that FSDP does not support full-graph compile# regardless of float8.model = get_model(K, N, is_fp8=True, emulate=emulate, base_dtype=...
2
19
3
160
4
73
103
73
null
['y_local', 'optimizer', 'input_local', 'model']
None
null
0
0
0
null
0
null
The function (fsdp_main) defined within the public class called public.The function start at line 73 and ends at 103. It contains 19 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [73.0] and does not return any value..
pytorch_ao
public
public
0
0
run
def run():emulate = Falseif not torch.cuda.is_available():warnings.warn("CUDA not available, running in emulation_mode", stacklevel=2)emulate = Trueelif torch.cuda.get_device_capability() < (9, 0):warnings.warn(f"CUDA capability {torch.cuda.get_device_capability()} < (9.0), running in emulation mode",stacklevel=2,)emul...
3
14
0
97
3
106
120
106
null
['WORLD_SIZE', 'emulate', 'args']
None
null
0
0
0
null
0
null
The function (run) defined within the public class called public.The function start at line 106 and ends at 120. It contains 14 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
__init__
def __init__(self,dim: int,hidden_dim: int,multiple_of: int,ffn_dim_multiplier: Optional[float],):super().__init__()hidden_dim = int(2 * hidden_dim / 3)# custom dim factor multiplierif ffn_dim_multiplier is not None:hidden_dim = int(ffn_dim_multiplier * hidden_dim)hidden_dim = multiple_of * ((hidden_dim + multiple_of -...
2
15
5
117
0
53
69
53
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 53 and ends at 69. It contains 15 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [53.0] and does not return any value..
pytorch_ao
public
public
0
0
forward
def forward(self, x):return self.w2(F.silu(self.w1(x)) * self.w3(x))
1
2
2
31
0
71
72
71
null
[]
None
null
0
0
0
null
0
null
The function (forward) 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. It takes 2 parameters, represented as [71.0] and does not return any value..
pytorch_ao
public
public
0
0
init_weights
def init_weights(self, init_std: float):nn.init.trunc_normal_(self.w1.weight, mean=0.0, std=0.02)for linear in (self.w2, self.w3):nn.init.trunc_normal_(linear.weight, mean=0.0, std=init_std)
2
4
2
66
0
74
77
74
null
[]
None
null
0
0
0
null
0
null
The function (init_weights) defined within the public class called public.The function start at line 74 and ends at 77. It contains 4 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [74.0] and does not return any value..
pytorch_ao
public
public
0
0
_test_impl
def _test_impl(self, config: Float8LinearConfig) -> None:data_dtype = torch.bfloat16# LLaMa 3 70B shapesmodel_ref = (FeedForward(dim=4096,hidden_dim=16384,multiple_of=1024,ffn_dim_multiplier=1.3,).cuda().to(data_dtype))# for now just test the encoder to simplify thingsmodel_fp8 = copy.deepcopy(model_ref)convert_to_floa...
3
42
2
287
0
81
142
81
null
[]
None
null
0
0
0
null
0
null
The function (_test_impl) defined within the public class called public.The function start at line 81 and ends at 142. It contains 42 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
test_encoder_fw_bw_from_config_params
def test_encoder_fw_bw_from_config_params(self,scaling_type_input: ScalingType,scaling_type_weight: ScalingType,scaling_type_grad_output: ScalingType,):config = get_test_float8_linear_config(scaling_type_input,scaling_type_weight,scaling_type_grad_output,emulate=False,)self._test_impl(config)
1
13
4
39
0
160
172
160
null
[]
None
null
0
0
0
null
0
null
The function (test_encoder_fw_bw_from_config_params) defined within the public class called public.The function start at line 160 and ends at 172. It contains 13 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [160.0] and does not return any value..
pytorch_ao
public
public
0
0
test_encoder_fw_bw_from_recipe
def test_encoder_fw_bw_from_recipe(self,recipe_name: str,):config = Float8LinearConfig.from_recipe_name(recipe_name)self._test_impl(config)
1
6
2
24
0
185
190
185
null
[]
None
null
0
0
0
null
0
null
The function (test_encoder_fw_bw_from_recipe) defined within the public class called public.The function start at line 185 and ends at 190. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [185.0] and does not return any value..
pytorch_ao
public
public
0
0
broadcast_module
def broadcast_module(self, module: nn.Module) -> None:# Broadcast for multi-threaded process group tests since seed is per# process, not per threadfor param in module.parameters():dist.broadcast(param, src=0)
2
3
2
32
0
53
57
53
null
[]
None
null
0
0
0
null
0
null
The function (broadcast_module) defined within the public class called public.The function start at line 53 and ends at 57. It contains 3 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
init_single_module
def init_single_module(self) -> nn.Module:torch.manual_seed(42)module = nn.Linear(16, 16, device="cuda")self.broadcast_module(module)return module
1
5
1
37
0
59
63
59
null
[]
None
null
0
0
0
null
0
null
The function (init_single_module) defined within the public class called public.The function start at line 59 and ends at 63. 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
init_multi_module
def init_multi_module(self) -> nn.Module:torch.manual_seed(42)module = nn.Sequential(*[MLP(16, device="cuda") for _ in range(3)])self.broadcast_module(module)return module
2
5
1
48
0
65
69
65
null
[]
None
null
0
0
0
null
0
null
The function (init_multi_module) defined within the public class called public.The function start at line 65 and ends at 69. 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
init_transformer
def init_transformer(self,weight_tying: bool,dtype: Optional[torch.dtype] = None,requires_grad: bool = True,) -> nn.Module:torch.manual_seed(42)args = ModelArgs(n_layers=3,dim=768,n_heads=12,dropout_p=0.0,weight_tying=weight_tying,vocab_size=32,)module = Transformer(args).cuda()if dtype is not None:module = module.to(d...
4
23
4
126
0
71
97
71
null
[]
None
null
0
0
0
null
0
null
The function (init_transformer) defined within the public class called public.The function start at line 71 and ends at 97. It contains 23 lines of code and it has a cyclomatic complexity of 4. It takes 4 parameters, represented as [71.0] and does not return any value..
pytorch_ao
public
public
0
0
get_local_inp
def get_local_inp(self, dtype: torch.dtype = torch.float32):torch.manual_seed(42)global_inp = torch.randn((16 * self.world_size, 16), device="cuda", dtype=dtype)dist.broadcast(global_inp, src=0)return global_inp.view(self.world_size, -1)[self.rank].view(16, 16)
1
5
2
79
0
99
103
99
null
[]
None
null
0
0
0
null
0
null
The function (get_local_inp) defined within the public class called public.The function start at line 99 and ends at 103. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [99.0] and does not return any value..
pytorch_ao
public
public
0
0
world_size
def world_size(self) -> int:return min(torch.cuda.device_count(), 2)
1
2
1
20
0
108
109
108
null
[]
None
null
0
0
0
null
0
null
The function (world_size) defined within the public class called public.The function start at line 108 and ends at 109. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_transformer_parity
def test_transformer_parity(self):self.run_subtests({"enable_fsdp_float8_all_gather": [False, True],"precompute": [False, True],"scaling_type_weight": [ScalingType.DYNAMIC,],"compile_transformer_block": [False, True],"dtype": [torch.float32, torch.bfloat16],"requires_grad": [True, False],},self._test_transformer_parity...
1
14
1
70
0
112
125
112
null
[]
None
null
0
0
0
null
0
null
The function (test_transformer_parity) defined within the public class called public.The function start at line 112 and ends at 125. 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
_test_transformer_parity
def _test_transformer_parity(self,enable_fsdp_float8_all_gather: bool,precompute: bool,scaling_type_weight: ScalingType,compile_transformer_block: bool,requires_grad: bool,dtype: Optional[torch.dtype] = None,):if not enable_fsdp_float8_all_gather and precompute:return# NOTE: Weight-tying does not compose with fp8 all-g...
7
57
7
308
0
127
189
127
null
[]
None
null
0
0
0
null
0
null
The function (_test_transformer_parity) defined within the public class called public.The function start at line 127 and ends at 189. It contains 57 lines of code and it has a cyclomatic complexity of 7. It takes 7 parameters, represented as [127.0] and does not return any value..
pytorch_ao
public
public
0
0
test_transformer_memory
def test_transformer_memory(self):"""Tests peak active memory in the forward and backward passes."""for enable_fsdp_float8_all_gather in [False, True]:self._test_transformer_memory(enable_fsdp_float8_all_gather)
2
3
1
21
0
192
195
192
null
[]
None
null
0
0
0
null
0
null
The function (test_transformer_memory) defined within the public class called public.The function start at line 192 and ends at 195. It contains 3 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_test_transformer_memory
def _test_transformer_memory(self, enable_fsdp_float8_all_gather: bool):torch.manual_seed(42)# Pre-run a linear forward (gemm and bias) and backward (gemm) to# allocate the cuBLAS workspaces before measuring the memory usage# since the workspace size can differ between hardwareslin = torch.nn.Linear(768, 768, device="c...
13
79
2
571
0
197
308
197
null
[]
None
null
0
0
0
null
0
null
The function (_test_transformer_memory) defined within the public class called public.The function start at line 197 and ends at 308. It contains 79 lines of code and it has a cyclomatic complexity of 13. It takes 2 parameters, represented as [197.0] and does not return any value..
pytorch_ao
public
public
0
0
_get_peak_active_memory_mb
def _get_peak_active_memory_mb(self) -> int:mem_stats = torch.cuda.memory_stats()return round(mem_stats["active_bytes.all.peak"] / 1e6)
1
3
1
26
0
310
312
310
null
[]
None
null
0
0
0
null
0
null
The function (_get_peak_active_memory_mb) defined within the public class called public.The function start at line 310 and ends at 312. It contains 3 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_get_curr_active_memory_mb
def _get_curr_active_memory_mb(self) -> int:mem_stats = torch.cuda.memory_stats()return round(mem_stats["active_bytes.all.current"] / 1e6)
1
3
1
26
0
314
316
314
null
[]
None
null
0
0
0
null
0
null
The function (_get_curr_active_memory_mb) defined within the public class called public.The function start at line 314 and ends at 316. 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
world_size
def world_size(self) -> int:return 4
1
2
1
9
0
321
322
321
null
[]
None
null
0
0
0
null
0
null
The function (world_size) defined within the public class called public.The function start at line 321 and ends at 322. 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
test_amax_allreduce_device_mesh
def test_amax_allreduce_device_mesh(self):dp_size = 2pp_size = self.world_size // dp_sizeglobal_mesh = init_device_mesh("cuda", (pp_size, dp_size), mesh_dim_names=("pp", "dp"))dp_mesh = global_mesh["dp"]if self.rank in [0, 1]:# rank 0 and 1 are the 1st stage in the pipeline# rank 2 and 4 are doing nothing but waiting f...
2
20
1
113
0
324
346
324
null
[]
None
null
0
0
0
null
0
null
The function (test_amax_allreduce_device_mesh) defined within the public class called public.The function start at line 324 and ends at 346. It contains 20 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
world_size
def world_size(self) -> int:return 4
1
2
1
9
0
351
352
321
null
[]
None
null
0
0
0
null
0
null
The function (world_size) defined within the public class called public.The function start at line 351 and ends at 352. 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
test_weight_subclass_dynamic
def test_weight_subclass_dynamic(self):tensor_cls = WeightWithDynamicFloat8CastTensor# Check for a single FSDP paramter groupmodule_fp32 = self.init_single_module()float8_linear_config = Float8LinearConfig(enable_fsdp_float8_all_gather=True,emulate=True,)module = convert_to_float8_training(module_fp32,config=float8_lin...
8
32
1
180
0
355
389
355
null
[]
None
null
0
0
0
null
0
null
The function (test_weight_subclass_dynamic) defined within the public class called public.The function start at line 355 and ends at 389. It contains 32 lines of code and it has a cyclomatic complexity of 8. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_fp8_fp32_all_gather_dynamic_comm_size.all_gather
def all_gather(*args: Any, **kwargs: Any):nonlocal all_gather_sizesif len(args) > 0:output = args[0]elif "output_tensor" in kwargs:output = kwargs["output_tensor"]else:raise AssertionError(f"Cannot get all-gather output from\nargs: {args}\nkwargs: {kwargs}")with lock:all_gather_sizes.append(output.numel() * output.item...
3
13
2
74
0
401
413
401
null
[]
None
null
0
0
0
null
0
null
The function (test_fp8_fp32_all_gather_dynamic_comm_size.all_gather) defined within the public class called public.The function start at line 401 and ends at 413. It contains 13 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [401.0] and does not return any value..
pytorch_ao
public
public
0
0
test_fp8_fp32_all_gather_dynamic_comm_size.get_expected_all_gather_size
def get_expected_all_gather_size(module: nn.Module):size = 0for param_name, param in module.named_parameters():bytes_per_numel = 1 if "weight" in param_name else param.itemsizesize += param.numel() * bytes_per_numelreturn size
3
6
1
45
0
415
420
415
null
[]
None
null
0
0
0
null
0
null
The function (test_fp8_fp32_all_gather_dynamic_comm_size.get_expected_all_gather_size) defined within the public class called public.The function start at line 415 and ends at 420. 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 valu...
pytorch_ao
public
public
0
0
test_fp8_fp32_all_gather_dynamic_comm_size
def test_fp8_fp32_all_gather_dynamic_comm_size(self):"""Tests that fp8 all-gather with dynamic scaling communicates theexpected number of bytes."""orig_all_gather = dist.all_gather_into_tensorall_gather_sizes: List[int] = []lock = threading.Lock()def all_gather(*args: Any, **kwargs: Any):nonlocal all_gather_sizesif len...
8
52
1
294
0
392
472
392
null
[]
None
null
0
0
0
null
0
null
The function (test_fp8_fp32_all_gather_dynamic_comm_size) defined within the public class called public.The function start at line 392 and ends at 472. It contains 52 lines of code and it has a cyclomatic complexity of 8. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
test_fp32_fp8_single_module_parity
def test_fp32_fp8_single_module_parity(self):"""Tests numeric parity for fp32 parameters with fp8 computation with asingle module/FSDP communication group."""choices = itertools.product([False, True],[ScalingType.DYNAMIC],)for enable_fsdp_float8_all_gather, scaling_type_weight in choices:cast_config_weight = CastConfig...
2
39
1
184
0
475
518
475
null
[]
None
null
0
0
0
null
0
null
The function (test_fp32_fp8_single_module_parity) defined within the public class called public.The function start at line 475 and ends at 518. It contains 39 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
test_fp32_fp8_multi_module_parity
def test_fp32_fp8_multi_module_parity(self):"""Tests numeric parity for fp32 parameters with fp8 computation withmultiple modules/FSDP communication groups."""choices = itertools.product([False, True],[ScalingType.DYNAMIC],)for enable_fsdp_float8_all_gather, scaling_type_weight in choices:float8_linear_config1 = Float8...
3
39
1
192
0
521
563
521
null
[]
None
null
0
0
0
null
0
null
The function (test_fp32_fp8_multi_module_parity) defined within the public class called public.The function start at line 521 and ends at 563. It contains 39 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
test_bf16_mp_fp8_dynamic_multi_parity
def test_bf16_mp_fp8_dynamic_multi_parity(self):"""Tests numeric parity for fp32 parameters with FSDP's bf16 mixedprecision and fp8 computation with multiple modules/FSDP communicationgroups. Parameters are all-gathered in bf16 before being cast to fp8."""# NOTE: We cannot test easily with fp8 all-gather because then t...
2
23
1
162
0
566
596
566
null
[]
None
null
0
0
0
null
0
null
The function (test_bf16_mp_fp8_dynamic_multi_parity) defined within the public class called public.The function start at line 566 and ends at 596. It contains 23 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
_init_data
def _init_data(in_features, out_features, compute_dtype, device, torch_seed):torch.random.manual_seed(torch_seed)linear_layer = torch.nn.Linear(in_features, out_features, bias=False).to(device)x = (torch.randn((1, linear_layer.in_features), dtype=torch.float, device=device)/ 20.0)y_ref = linear_layer(x)W = linear_layer...
1
10
5
106
4
36
45
36
null
['x', 'W', 'linear_layer', 'y_ref']
None
null
0
0
0
null
0
null
The function (_init_data) defined within the public class called public.The function start at line 36 and ends at 45. It contains 10 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [36.0] and does not return any value..
pytorch_ao
public
public
0
0
_eval_hqq
def _eval_hqq(dtype):W, x, y_ref = _init_data(in_features, out_features, compute_dtype, device, torch_seed)dummy_linear = torch.nn.Linear(in_features=in_features, out_features=out_features, bias=False)dummy_linear.weight.data = Wif dtype == torch.uint4:config = Int4WeightOnlyConfig(group_size=max(block_size), use_hqq=T...
2
26
1
203
6
48
76
48
null
['q_tensor_hqq', 'config', 'dot_product_error', 'quant_linear_layer', 'dummy_linear', 'dequantize_error']
None
null
0
0
0
null
0
null
The function (_eval_hqq) defined within the public class called public.The function start at line 48 and ends at 76. It contains 26 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
_test_hqq
def _test_hqq(self, dtype=None, ref_dequantize_error=None, ref_dot_product_error=None):if dtype is None:returndequantize_error, dot_product_error = _eval_hqq(dtype)self.assertTrue(dequantize_error < ref_dequantize_error)self.assertTrue(dot_product_error < ref_dot_product_error)
2
8
4
47
0
81
88
81
null
[]
None
null
0
0
0
null
0
null
The function (_test_hqq) defined within the public class called public.The function start at line 81 and ends at 88. It contains 8 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [81.0] and does not return any value..
pytorch_ao
public
public
0
0
test_hqq_plain_8bit
def test_hqq_plain_8bit(self):self._test_hqq(dtype=torch.uint8, ref_dequantize_error=5e-5, ref_dot_product_error=0.00013)
1
4
1
27
0
90
93
90
null
[]
None
null
0
0
0
null
0
null
The function (test_hqq_plain_8bit) defined within the public class called public.The function start at line 90 and ends at 93. 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
test_hqq_plain_7bit
def test_hqq_plain_7bit(self):self._test_hqq(dtype=torch.uint7,ref_dequantize_error=6e-05,ref_dot_product_error=0.000193,)
1
6
1
28
0
95
100
95
null
[]
None
null
0
0
0
null
0
null
The function (test_hqq_plain_7bit) defined within the public class called public.The function start at line 95 and ends at 100. 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
test_hqq_plain_6bit
def test_hqq_plain_6bit(self):self._test_hqq(dtype=torch.uint6,ref_dequantize_error=0.0001131,ref_dot_product_error=0.000353,)
1
6
1
28
0
102
107
102
null
[]
None
null
0
0
0
null
0
null
The function (test_hqq_plain_6bit) defined within the public class called public.The function start at line 102 and ends at 107. 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
test_hqq_plain_5bit
def test_hqq_plain_5bit(self):self._test_hqq(dtype=torch.uint5,ref_dequantize_error=0.00023,ref_dot_product_error=0.000704,)
1
6
1
28
0
109
114
109
null
[]
None
null
0
0
0
null
0
null
The function (test_hqq_plain_5bit) defined within the public class called public.The function start at line 109 and ends at 114. 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
test_hqq_plain_4bit
def test_hqq_plain_4bit(self):self._test_hqq(dtype=torch.uint4,ref_dequantize_error=0.000487,ref_dot_product_error=0.001472,)
1
6
1
28
0
117
122
117
null
[]
None
null
0
0
0
null
0
null
The function (test_hqq_plain_4bit) defined within the public class called public.The function start at line 117 and ends at 122. 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
test_hqq_plain_3bit
def test_hqq_plain_3bit(self):self._test_hqq(dtype=torch.uint3,ref_dequantize_error=0.00101,ref_dot_product_error=0.003047,)
1
6
1
28
0
124
129
124
null
[]
None
null
0
0
0
null
0
null
The function (test_hqq_plain_3bit) defined within the public class called public.The function start at line 124 and ends at 129. 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
test_hqq_plain_2bit
def test_hqq_plain_2bit(self):self._test_hqq(dtype=torch.uint2,ref_dequantize_error=0.002366,ref_dot_product_error=0.007255,)
1
6
1
28
0
131
136
131
null
[]
None
null
0
0
0
null
0
null
The function (test_hqq_plain_2bit) defined within the public class called public.The function start at line 131 and ends at 136. 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
check
def check(expected, actual, msg="", max_diff=1e-3, verbose=False):passed = torch.allclose(expected, actual, atol=max_diff, rtol=max_diff)if verbose:max_err = (expected - actual).abs().max()if not passed:print_msg = f"{msg}:\nFailed! Max error: {max_err}"try:from termcolor import coloredexcept ImportError:print(print_ms...
5
21
5
133
3
50
72
50
null
['passed', 'max_err', 'print_msg']
None
null
0
0
0
null
0
null
The function (check) defined within the public class called public.The function start at line 50 and ends at 72. It contains 21 lines of code and it has a cyclomatic complexity of 5. It takes 5 parameters, represented as [50.0] and does not return any value..
pytorch_ao
public
public
0
0
_arg_to_id
def _arg_to_id(arg):if isinstance(arg, list):return "x".join([str(x) for x in arg])return str(arg)
3
4
1
34
0
75
78
75
null
[]
None
null
0
0
0
null
0
null
The function (_arg_to_id) defined within the public class called public.The function start at line 75 and ends at 78. 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
test_mixed_mm
def test_mixed_mm(shape, group_size, axis, dtype, transposed, kernel_type, quant_dtype=torch.uint8):qcfg = {**BASE_QUANT_CONFIG,**dict(group_size=group_size, axis=axis),}M, N, K = shapelinear = torch.nn.Linear(K, N, bias=False, dtype=dtype, device="cuda")quant_config = BaseQuantizeConfig(quant_zero=False, quant_scale=F...
4
58
7
360
12
86
151
86
null
['tt_out', 'zeros', 'scales', 'hqq_out', 'hqq_linear', 'x', 'W_q', 'W_dq', 'packed_w', 'quant_config', 'linear', 'qcfg']
None
null
0
0
0
null
0
null
The function (test_mixed_mm) defined within the public class called public.The function start at line 86 and ends at 151. It contains 58 lines of code and it has a cyclomatic complexity of 4. It takes 7 parameters, represented as [86.0] and does not return any value..
pytorch_ao
public
public
0
0
_test_mixed_mm
def _test_mixed_mm(shape,group_size,BLOCK_M,BLOCK_N,BLOCK_K,axis=1,dtype=torch.float16,transposed=True,kernel_type="debug",quant_dtype=torch.uint8,):qcfg = {**BASE_QUANT_CONFIG,**dict(group_size=group_size, axis=axis),}M, N, K = shapequant_config = BaseQuantizeConfig(quant_zero=False, quant_scale=False, offload_meta=Fa...
3
68
10
379
11
155
230
155
null
['tt_out', 'zeros', 'scales', 'hqq_out', 'x', 'W_q', 'W_dq', 'packed_w', 'quant_config', 'msg', 'qcfg']
None
null
0
0
0
null
0
null
The function (_test_mixed_mm) defined within the public class called public.The function start at line 155 and ends at 230. It contains 68 lines of code and it has a cyclomatic complexity of 3. It takes 10 parameters, represented as [155.0] and does not return any value..
pytorch_ao
public
public
0
0
_arg_to_id
def _arg_to_id(arg):if isinstance(arg, list):return "x".join([str(x) for x in arg])return str(arg)
3
4
1
34
0
50
53
50
null
[]
None
null
0
0
0
null
0
null
The function (_arg_to_id) defined within the public class called public.The function start at line 50 and ends at 53. 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
quantize_helper
def quantize_helper(weight_shape, quant_config, dtype, device="cuda", quant_dtype=torch.uint8):N, K = weight_shapelinear = torch.nn.Linear(K, N, bias=False, dtype=dtype, device=device)hqq_linear = HQQLinear(linear, quant_config, compute_dtype=dtype, del_orig=False)W_q, meta = hqq_linear.W_q, hqq_linear.metaW_q = W_q.to...
2
17
5
151
5
56
75
56
null
['zero', 'hqq_linear', 'scale', 'W_q', 'linear']
None
null
0
0
0
null
0
null
The function (quantize_helper) defined within the public class called public.The function start at line 56 and ends at 75. It contains 17 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [56.0] and does not return any value..
pytorch_ao
public
public
0
0
fuse_qkv
def fuse_qkv(W_qs, scales, zeros):"""Args:W_qs (list[torch.Tensor]): len 3 list of tensors with shapes Nq x K, Nk x K, Nv x K where Nk == Nvscales (list[torch.Tensor]): each is N x (K // group_size), with same N requirements per W_qszeros (list[torch.Tensor]): same as scalesReturns:qkv (torch.Tensor): (N_qkv x K) where...
3
5
3
64
3
78
93
78
null
['fused_zeros', 'fused_scales', 'qkv']
None
null
0
0
0
null
0
null
The function (fuse_qkv) defined within the public class called public.The function start at line 78 and ends at 93. It contains 5 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [78.0] and does not return any value..
pytorch_ao
public
public
0
0
ref_proj
def ref_proj(x, packed_w, scale, zero, group_size, kernel_type, transposed=False):return triton_mixed_mm(x,packed_w,scale.T,zero.T,transposed=transposed,group_size=group_size,fp8_fast_accum=False,kernel_type=kernel_type,)
1
11
7
51
0
96
106
96
null
[]
None
null
0
0
0
null
0
null
The function (ref_proj) defined within the public class called public.The function start at line 96 and ends at 106. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 7 parameters, represented as [96.0] and does not return any value..
pytorch_ao
public
public
0
0
test_mixed_mm
def test_mixed_mm(q_shape,kv_shape,group_size,axis,dtype,transposed,kernel_type,seqlen=16,device="cuda",quant_dtype=torch.uint8,):"""Note we test with dtype float32 in the transposed case, since fused and non-fused ops are not exactly equivalent in this case.More specifically when running transposed matmul:- fused: we ...
10
77
10
567
12
114
216
114
null
['tt_ref', 'Ks', 'x_fused', 'x', 'tt_fused', 'dtype', 'xs', 'quant_config', 'K', 'qkv_fused_packed', 'Ns', 'qcfg']
None
null
0
0
0
null
0
null
The function (test_mixed_mm) defined within the public class called public.The function start at line 114 and ends at 216. It contains 77 lines of code and it has a cyclomatic complexity of 10. It takes 10 parameters, represented as [114.0] and does not return any value..
pytorch_ao
public
public
0
0
_int8wo_api
def _int8wo_api(mod):quantize_(mod, Int8WeightOnlyConfig(set_inductor_config=False))
1
2
1
16
0
111
112
111
null
[]
None
null
0
0
0
null
0
null
The function (_int8wo_api) defined within the public class called public.The function start at line 111 and ends at 112. 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
_int8wo_groupwise_api
def _int8wo_groupwise_api(mod):group_size = 32quantize_(mod, Int8WeightOnlyConfig(group_size=group_size, set_inductor_config=False))
1
5
1
23
1
115
119
115
null
['group_size']
None
null
0
0
0
null
0
null
The function (_int8wo_groupwise_api) defined within the public class called public.The function start at line 115 and ends at 119. 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
_int8da_int8w_api
def _int8da_int8w_api(mod,act_mapping_type=MappingType.SYMMETRIC,):quantize_(mod,Int8DynamicActivationInt8WeightConfig(act_mapping_type=act_mapping_type,set_inductor_config=False,),)
1
11
2
29
0
122
132
122
null
[]
None
null
0
0
0
null
0
null
The function (_int8da_int8w_api) defined within the public class called public.The function start at line 122 and ends at 132. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [122.0] and does not return any value..
pytorch_ao
public
public
0
0
_int4wo_api
def _int4wo_api(mod, use_hqq=False):if check_cpu_version(next(mod.parameters()).device):quantize_(mod,Int4WeightOnlyConfig(layout=Int4CPULayout(),use_hqq=use_hqq,set_inductor_config=False,version=1,),)unwrap_tensor_subclass(mod)elif check_xpu_version(next(mod.parameters()).device):quantize_(mod,Int4WeightOnlyConfig(lay...
3
22
2
113
0
135
156
135
null
[]
None
null
0
0
0
null
0
null
The function (_int4wo_api) defined within the public class called public.The function start at line 135 and ends at 156. It contains 22 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [135.0] and does not return any value..
pytorch_ao
public
public
0
0
_int8da_int4w_api
def _int8da_int4w_api(mod):quantize_(mod, Int8DynamicActivationInt4WeightConfig(set_inductor_config=False))
1
2
1
16
0
159
160
159
null
[]
None
null
0
0
0
null
0
null
The function (_int8da_int4w_api) defined within the public class called public.The function start at line 159 and ends at 160. 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
undo_recommended_configs
def undo_recommended_configs():torch._inductor.config.coordinate_descent_tuning = Falsetorch._inductor.config.coordinate_descent_check_all_directions = Falsetorch._inductor.config.force_fuse_int_mm_with_mul = Falsetorch._inductor.config.fx_graph_cache = Falsetorch._inductor.config.triton.unique_kernel_names = Falsetorc...
1
7
0
57
0
171
177
171
null
[]
None
null
0
0
0
null
0
null
The function (undo_recommended_configs) defined within the public class called public.The function start at line 171 and ends at 177. 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
combine_parameters
def combine_parameters(a, b):new_tuples = []for tuple1, tuple2 in itertools.product(a, b):new_tuples.append(tuple1 + tuple2)return new_tuples
2
5
2
35
1
180
184
180
null
['new_tuples']
None
null
0
0
0
null
0
null
The function (combine_parameters) defined within the public class called public.The function start at line 180 and ends at 184. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [180.0] and does not return any value..
pytorch_ao
public
public
0
0
run_supported_device_dtype.wrapper
def wrapper(*args, **kwargs):if len(args) < 3:raise unittest.SkipTest(f"Not enough args. Expected more than or equal to 3, but got {len(args)}")device = args[2]dtype = kwargs["test_dtype"] if "test_dtype" in kwargs else args[3]if device == "cuda" and not torch.cuda.is_available():raise unittest.SkipTest("Need CUDA avai...
9
17
2
118
0
192
208
192
null
[]
None
null
0
0
0
null
0
null
The function (run_supported_device_dtype.wrapper) defined within the public class called public.The function start at line 192 and ends at 208. It contains 17 lines of code and it has a cyclomatic complexity of 9. It takes 2 parameters, represented as [192.0] and does not return any value..
pytorch_ao
public
public
0
0
run_supported_device_dtype
def run_supported_device_dtype(test_method):"""Assumes that the 3rd arg (args[2]) of the decorated method is device andthere is a `test_dtype` kwarg or the 4th arg (args[3]) that indicates the dtype for testing"""def wrapper(*args, **kwargs):if len(args) < 3:raise unittest.SkipTest(f"Not enough args. Expected more than...
1
3
1
10
2
187
210
187
null
['dtype', 'device']
None
null
0
0
0
null
0
null
The function (run_supported_device_dtype) defined within the public class called public.The function start at line 187 and ends at 210. 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
test_figure_4
def test_figure_4(self):X = torch.FloatTensor([1, -16, 2, 6, -2, 8, -1, -9]).reshape(1, 2, 4)W = torch.FloatTensor([2, 1, -2, 1, -1, -1, 2, -1, -2, -1, -1, 1]).reshape(4, 3)X_mul_W = torch.matmul(X, W)smoothquant_scale = get_scale(torch.amax(torch.abs(X), dim=(0, 1)),torch.amax(torch.abs(W), dim=1),alpha=0.5,)# reprodu...
1
14
1
204
0
216
232
216
null
[]
None
null
0
0
0
null
0
null
The function (test_figure_4) defined within the public class called public.The function start at line 216 and ends at 232. 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
test_tensors
def test_tensors(self):x_shape = (1, 5, 7)w_shape = (7, 9)for i in range(3):X = torch.randn(x_shape) * 10W = torch.randn(w_shape)s = get_scale(torch.amax(torch.abs(X), dim=(0, 1)),torch.amax(torch.abs(W), dim=1),alpha=0.5,)Y = torch.matmul(X, W)Y_ref = torch.matmul(X / s.reshape(1, 1, -1),torch.matmul(torch.diag(s), W)...
2
17
1
162
0
235
252
235
null
[]
None
null
0
0
0
null
0
null
The function (test_tensors) defined within the public class called public.The function start at line 235 and ends at 252. It contains 17 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
_test_smooth_linear_impl
def _test_smooth_linear_impl(self, x_shape, lin_shape, device):orig_backend = torch.backends.quantized.engine# so we can use the full rangetorch.backends.quantized.engine = "qnnpack"x = torch.randn(*x_shape, device=device) * 9 + 10lin_fp32 = nn.Linear(*lin_shape, device=device)# misc: ignorelin_smooth = SmoothFakeDynam...
1
38
4
311
0
254
320
254
null
[]
None
null
0
0
0
null
0
null
The function (_test_smooth_linear_impl) defined within the public class called public.The function start at line 254 and ends at 320. It contains 38 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [254.0] and does not return any value..
pytorch_ao
public
public
0
0
test_smooth_linear_cpu
def test_smooth_linear_cpu(self):self._test_smooth_linear_impl((1, 5, 3), (3, 4), "cpu")
1
2
1
25
0
322
323
322
null
[]
None
null
0
0
0
null
0
null
The function (test_smooth_linear_cpu) defined within the public class called public.The function start at line 322 and ends at 323. 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
test_smooth_linear_cuda
def test_smooth_linear_cuda(self):self._test_smooth_linear_impl((1, 32, 32), (32, 16), "cuda")
1
2
1
25
0
326
327
326
null
[]
None
null
0
0
0
null
0
null
The function (test_smooth_linear_cuda) defined within the public class called public.The function start at line 326 and ends at 327. 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
test_smooth_linear_edge_cases
def test_smooth_linear_edge_cases(self):orig_backend = torch.backends.quantized.engine# so we can use the full rangetorch.backends.quantized.engine = "qnnpack"lin_fp32 = nn.Linear(3, 4)lin_smooth = SmoothFakeDynamicallyQuantizedLinear.from_float(lin_fp32, alpha=0.25)# test different ranksx0 = torch.randn(4, 5, 3)x1 = t...
1
18
1
139
0
329
355
329
null
[]
None
null
0
0
0
null
0
null
The function (test_smooth_linear_edge_cases) defined within the public class called public.The function start at line 329 and ends at 355. It contains 18 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
test_swap
def test_swap(self):m = nn.Sequential(nn.Sequential(nn.Linear(4, 4), nn.ReLU(), nn.Linear(4, 4)),nn.Linear(4, 4),)m_copy = copy.deepcopy(m)swap_linear_with_smooth_fq_linear(m_copy, skip_fqn_list=["0.2"])# verify all linears are swappedassert isinstance(m_copy[0][0], SmoothFakeDynamicallyQuantizedLinear)assert isinstanc...
1
15
1
152
0
357
376
357
null
[]
None
null
0
0
0
null
0
null
The function (test_swap) defined within the public class called public.The function start at line 357 and ends at 376. It contains 15 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..