From f043670b4ac383fc070f5b174a4753dfae11d428 Mon Sep 17 00:00:00 2001 From: mouliraj-mcw Date: Thu, 17 Oct 2024 10:13:55 +0000 Subject: [PATCH] #8142: Update sweep tests --- .../sweeps/eltwise/unary/log10/log10.py | 41 +++++++++++-------- .../sweeps/eltwise/unary/log1p/log1p.py | 41 ++++++++++++------- .../sweeps/eltwise/unary/log2/log2.py | 40 +++++++++++------- .../eltwise/unary/log_sigmoid/log_sigmoid.py | 40 +++++++++++------- 4 files changed, 101 insertions(+), 61 deletions(-) diff --git a/tests/sweep_framework/sweeps/eltwise/unary/log10/log10.py b/tests/sweep_framework/sweeps/eltwise/unary/log10/log10.py index 750add6907b..e7ed425f251 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/log10/log10.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/log10/log10.py @@ -22,44 +22,53 @@ "input_shape": gen_shapes([1, 1, 32, 32], [6, 12, 256, 256], [1, 1, 32, 32], 16) + gen_shapes([1, 32, 32], [12, 256, 256], [1, 32, 32], 16) + gen_shapes([32, 32], [256, 256], [32, 32], 32), - "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], - "input_a_layout": [ttnn.TILE_LAYOUT], - "input_a_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + "input_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], + "input_layout": [ttnn.TILE_LAYOUT, ttnn.ROW_MAJOR_LAYOUT], + "input_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], "output_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], }, } +# Invalidate vector is called during the generation phase where each vector will be passed in. +# If invalidated, the vector will still be stored but will be skipped. +# Returns False, None if the vector is valid, and True, str with a reason for invalidation if it is invalid. +def invalidate_vector(test_vector) -> Tuple[bool, Optional[str]]: + if test_vector["input_layout"] == ttnn.ROW_MAJOR_LAYOUT: + return True, "Row Major layout is not supported" + return False, None + + # This is the run instructions for the test, defined by the developer. # The run function must take the above-defined parameters as inputs. # The runner will call this run function with each test vector, and the returned results from this function will be stored. # If you defined a device_mesh_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra. def run( input_shape, - input_a_dtype, - input_a_layout, - input_a_memory_config, + input_dtype, + input_layout, + input_memory_config, output_memory_config, *, device, ) -> list: torch.manual_seed(0) - torch_input_tensor_a = gen_func_with_cast_tt( - partial(torch_random, low=1, high=100, dtype=torch.float32), input_a_dtype + torch_input_tensor = gen_func_with_cast_tt( + partial(torch_random, low=1, high=100, dtype=torch.float32), input_dtype )(input_shape) - torch_output_tensor = torch.log10(torch_input_tensor_a) - - input_tensor_a = ttnn.from_torch( - torch_input_tensor_a, - dtype=input_a_dtype, - layout=input_a_layout, + golden_function = ttnn.get_golden_function(ttnn.log10) + torch_output_tensor = golden_function(torch_input_tensor) + input_tensor = ttnn.from_torch( + torch_input_tensor, + dtype=input_dtype, + layout=input_layout, device=device, - memory_config=input_a_memory_config, + memory_config=input_memory_config, ) start_time = start_measuring_time() - result = ttnn.log10(input_tensor_a, memory_config=output_memory_config) + result = ttnn.log10(input_tensor, memory_config=output_memory_config) output_tensor = ttnn.to_torch(result) e2e_perf = stop_measuring_time(start_time) diff --git a/tests/sweep_framework/sweeps/eltwise/unary/log1p/log1p.py b/tests/sweep_framework/sweeps/eltwise/unary/log1p/log1p.py index b9d50f5ca0d..a188e346f78 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/log1p/log1p.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/log1p/log1p.py @@ -22,44 +22,55 @@ "input_shape": gen_shapes([1, 1, 32, 32], [6, 12, 256, 256], [1, 1, 32, 32], 16) + gen_shapes([1, 32, 32], [12, 256, 256], [1, 32, 32], 16) + gen_shapes([32, 32], [256, 256], [32, 32], 32), - "input_a_dtype": [ttnn.bfloat16], - "input_a_layout": [ttnn.TILE_LAYOUT], - "input_a_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + "input_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], + "input_layout": [ttnn.TILE_LAYOUT, ttnn.ROW_MAJOR_LAYOUT], + "input_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], "output_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], }, } +# Invalidate vector is called during the generation phase where each vector will be passed in. +# If invalidated, the vector will still be stored but will be skipped. +# Returns False, None if the vector is valid, and True, str with a reason for invalidation if it is invalid. +def invalidate_vector(test_vector) -> Tuple[bool, Optional[str]]: + if test_vector["input_layout"] == ttnn.ROW_MAJOR_LAYOUT or test_vector["input_dtype"] == ttnn.bfloat8_b: + return True, "Row Major layout and bfloat8_b are not supported" + return False, None + + # This is the run instructions for the test, defined by the developer. # The run function must take the above-defined parameters as inputs. # The runner will call this run function with each test vector, and the returned results from this function will be stored. # If you defined a device_mesh_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra. def run( input_shape, - input_a_dtype, - input_a_layout, - input_a_memory_config, + input_dtype, + input_layout, + input_memory_config, output_memory_config, *, device, ) -> list: torch.manual_seed(0) - torch_input_tensor_a = gen_func_with_cast_tt( - partial(torch_random, low=1, high=100, dtype=torch.float32), input_a_dtype + torch_input_tensor = gen_func_with_cast_tt( + partial(torch_random, low=1, high=100, dtype=torch.float32), input_dtype )(input_shape) - torch_output_tensor = torch.log1p(torch_input_tensor_a) - input_tensor_a = ttnn.from_torch( - torch_input_tensor_a, - dtype=input_a_dtype, - layout=input_a_layout, + golden_function = ttnn.get_golden_function(ttnn.log1p) + torch_output_tensor = golden_function(torch_input_tensor) + + input_tensor = ttnn.from_torch( + torch_input_tensor, + dtype=input_dtype, + layout=input_layout, device=device, - memory_config=input_a_memory_config, + memory_config=input_memory_config, ) start_time = start_measuring_time() - result = ttnn.log1p(input_tensor_a, memory_config=output_memory_config) + result = ttnn.log1p(input_tensor, memory_config=output_memory_config) output_tensor = ttnn.to_torch(result) e2e_perf = stop_measuring_time(start_time) diff --git a/tests/sweep_framework/sweeps/eltwise/unary/log2/log2.py b/tests/sweep_framework/sweeps/eltwise/unary/log2/log2.py index db5762d4d51..b695f39d690 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/log2/log2.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/log2/log2.py @@ -22,44 +22,54 @@ "input_shape": gen_shapes([1, 1, 32, 32], [6, 12, 256, 256], [1, 1, 32, 32], 16) + gen_shapes([1, 32, 32], [12, 256, 256], [1, 32, 32], 16) + gen_shapes([32, 32], [256, 256], [32, 32], 32), - "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], - "input_a_layout": [ttnn.TILE_LAYOUT], - "input_a_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + "input_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], + "input_layout": [ttnn.TILE_LAYOUT, ttnn.ROW_MAJOR_LAYOUT], + "input_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], "output_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], }, } +# Invalidate vector is called during the generation phase where each vector will be passed in. +# If invalidated, the vector will still be stored but will be skipped. +# Returns False, None if the vector is valid, and True, str with a reason for invalidation if it is invalid. +def invalidate_vector(test_vector) -> Tuple[bool, Optional[str]]: + if test_vector["input_layout"] == ttnn.ROW_MAJOR_LAYOUT: + return True, "Row Major layout is not supported" + return False, None + + # This is the run instructions for the test, defined by the developer. # The run function must take the above-defined parameters as inputs. # The runner will call this run function with each test vector, and the returned results from this function will be stored. # If you defined a device_mesh_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra. def run( input_shape, - input_a_dtype, - input_a_layout, - input_a_memory_config, + input_dtype, + input_layout, + input_memory_config, output_memory_config, *, device, ) -> list: torch.manual_seed(0) - torch_input_tensor_a = gen_func_with_cast_tt( - partial(torch_random, low=1, high=100, dtype=torch.float32), input_a_dtype + torch_input_tensor = gen_func_with_cast_tt( + partial(torch_random, low=1, high=100, dtype=torch.float32), input_dtype )(input_shape) - torch_output_tensor = torch.log2(torch_input_tensor_a) + golden_function = ttnn.get_golden_function(ttnn.log2) + torch_output_tensor = golden_function(torch_input_tensor) - input_tensor_a = ttnn.from_torch( - torch_input_tensor_a, - dtype=input_a_dtype, - layout=input_a_layout, + input_tensor = ttnn.from_torch( + torch_input_tensor, + dtype=input_dtype, + layout=input_layout, device=device, - memory_config=input_a_memory_config, + memory_config=input_memory_config, ) start_time = start_measuring_time() - result = ttnn.log2(input_tensor_a, memory_config=output_memory_config) + result = ttnn.log2(input_tensor, memory_config=output_memory_config) output_tensor = ttnn.to_torch(result) e2e_perf = stop_measuring_time(start_time) diff --git a/tests/sweep_framework/sweeps/eltwise/unary/log_sigmoid/log_sigmoid.py b/tests/sweep_framework/sweeps/eltwise/unary/log_sigmoid/log_sigmoid.py index 2600b2da40c..75f73eaed12 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/log_sigmoid/log_sigmoid.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/log_sigmoid/log_sigmoid.py @@ -22,44 +22,54 @@ "input_shape": gen_shapes([1, 1, 32, 32], [6, 12, 256, 256], [1, 1, 32, 32], 16) + gen_shapes([1, 32, 32], [12, 256, 256], [1, 32, 32], 16) + gen_shapes([32, 32], [256, 256], [32, 32], 32), - "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], - "input_a_layout": [ttnn.TILE_LAYOUT], - "input_a_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], + "input_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], + "input_layout": [ttnn.TILE_LAYOUT, ttnn.ROW_MAJOR_LAYOUT], + "input_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], "output_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG], }, } +# Invalidate vector is called during the generation phase where each vector will be passed in. +# If invalidated, the vector will still be stored but will be skipped. +# Returns False, None if the vector is valid, and True, str with a reason for invalidation if it is invalid. +def invalidate_vector(test_vector) -> Tuple[bool, Optional[str]]: + if test_vector["input_layout"] == ttnn.ROW_MAJOR_LAYOUT: + return True, "Row Major layout is not supported" + return False, None + + # This is the run instructions for the test, defined by the developer. # The run function must take the above-defined parameters as inputs. # The runner will call this run function with each test vector, and the returned results from this function will be stored. # If you defined a device_mesh_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra. def run( input_shape, - input_a_dtype, - input_a_layout, - input_a_memory_config, + input_dtype, + input_layout, + input_memory_config, output_memory_config, *, device, ) -> list: torch.manual_seed(0) - torch_input_tensor_a = gen_func_with_cast_tt( - partial(torch_random, low=-4, high=10, dtype=torch.float32), input_a_dtype + torch_input_tensor = gen_func_with_cast_tt( + partial(torch_random, low=-4, high=10, dtype=torch.float32), input_dtype )(input_shape) - torch_output_tensor = torch.nn.functional.logsigmoid(torch_input_tensor_a) + golden_function = ttnn.get_golden_function(ttnn.log_sigmoid) + torch_output_tensor = golden_function(torch_input_tensor) - input_tensor_a = ttnn.from_torch( - torch_input_tensor_a, - dtype=input_a_dtype, - layout=input_a_layout, + input_tensor = ttnn.from_torch( + torch_input_tensor, + dtype=input_dtype, + layout=input_layout, device=device, - memory_config=input_a_memory_config, + memory_config=input_memory_config, ) start_time = start_measuring_time() - result = ttnn.log_sigmoid(input_tensor_a, memory_config=output_memory_config) + result = ttnn.log_sigmoid(input_tensor, memory_config=output_memory_config) output_tensor = ttnn.to_torch(result) e2e_perf = stop_measuring_time(start_time)