From c9e37f3d572f6c72384e71acaa40fccd10714ac3 Mon Sep 17 00:00:00 2001 From: ngrujic Date: Wed, 13 Nov 2024 11:07:05 +0000 Subject: [PATCH 01/15] #11512: Added isfinite sharded sweep --- tests/sweep_framework/sweep_utils/utils.py | 12 + .../eltwise/unary/{ => isfinite}/isfinite.py | 0 .../unary/isfinite/isfinite_sharded.py | 242 ++++++++++++++++++ 3 files changed, 254 insertions(+) rename tests/sweep_framework/sweeps/eltwise/unary/{ => isfinite}/isfinite.py (100%) create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite_sharded.py diff --git a/tests/sweep_framework/sweep_utils/utils.py b/tests/sweep_framework/sweep_utils/utils.py index 6f2199055d8..f1bf618d661 100644 --- a/tests/sweep_framework/sweep_utils/utils.py +++ b/tests/sweep_framework/sweep_utils/utils.py @@ -3,6 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 +import os import random from loguru import logger from itertools import product @@ -18,6 +19,17 @@ from models.utility_functions import torch_random +def get_device_grid_size(): + device_name = os.environ.get("ARCH_NAME", os.environ.get("TT_ARCH_NAME", "default")).lower() + assert device_name in ["wormhole_b0", "grayskull"] + if device_name == "grayskull": + y, x = 9, 12 + else: + y, x = 8, 8 + + return y, x + + def sanitize_shape_rm(input_shape): if input_shape[-1] % 2 != 0: input_shape[-1] = input_shape[-1] + 1 diff --git a/tests/sweep_framework/sweeps/eltwise/unary/isfinite.py b/tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite.py similarity index 100% rename from tests/sweep_framework/sweeps/eltwise/unary/isfinite.py rename to tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite.py diff --git a/tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite_sharded.py new file mode 100644 index 00000000000..ef6b1dccbed --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite_sharded.py @@ -0,0 +1,242 @@ +# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. + +# SPDX-License-Identifier: Apache-2.0 + +from typing import Optional, Tuple +from functools import partial +import itertools + +import torch +import random +import ttnn +import math +from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm, get_device_grid_size +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt, gen_rand_inf + +from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time +from models.utility_functions import torch_random + +# Override the default timeout in seconds for hang detection. +TIMEOUT = 120 +Y, X = get_device_grid_size() + +random.seed(0) + + +def gen_sharded_spec(num_shapes, sharding_strategy, y, x, sanitize_args=True): + assert sharding_strategy in ["block", "width", "height"] + + shard_orientation_list = ["col_major", "row_major"] + tensor_hw_as_shard_shape_list = [True, False] + + for shard_orientation, tensor_hw_as_shard_shape in itertools.product( + shard_orientation_list, tensor_hw_as_shard_shape_list + ): + if sharding_strategy == "block": + if not sanitize_args: + interval_1 = 1 + interval_2 = 2 + else: + interval_1 = 32 * y + interval_2 = 32 * x + + input_shape_list = ( + gen_shapes([1, 1, 32 * y, 32 * x], [6, 12, 512, 512], [1, 1, interval_1, interval_2], num_shapes) + + gen_shapes([1, 32 * y, 32 * x], [12, 512, 512], [1, interval_1, interval_2], num_shapes) + + gen_shapes([32 * y, 32 * x], [512, 512], [interval_1, interval_2], num_shapes) + ) + elif sharding_strategy == "width": + if not sanitize_args: + interval = 1 + else: + interval = 32 * x * y + input_shape_list = ( + gen_shapes([1, 1, 32, 32 * x * y], [4, 6, 64, 32 * x * y], [1, 1, 32, interval], num_shapes) + + gen_shapes([1, 32, 32 * x * y], [6, 64, 32 * x * y], [1, 32, interval], num_shapes) + + gen_shapes([32, 32 * x * y], [64, 32 * x * y], [32, interval], num_shapes) + ) + else: + if not sanitize_args: + interval = 1 + else: + interval = 32 * x * y + input_shape_list = ( + gen_shapes([1, 1, 32 * x * y, 32], [4, 6, 32 * x * y, 64], [1, 1, interval, 32], num_shapes) + + gen_shapes([1, 32 * x * y, 32], [6, 32 * x * y, 64], [1, interval, 32], num_shapes) + + gen_shapes([32 * x * y, 32], [32 * x * y, 64], [interval, 32], num_shapes) + ) + + for input_shape in input_shape_list: + yield { + "input_shape": input_shape, + "sharding_strategy": sharding_strategy, + "shard_orientation": shard_orientation, + "tensor_hw_as_shard_shape": tensor_hw_as_shard_shape, + } + + +# Parameters provided to the test vector generator are defined here. +# They are defined as dict-type suites that contain the arguments to the run function as keys, and lists of possible inputs as values. +# Each suite has a key name (in this case "suite_1" and "suite_2") which will associate the test vectors to this specific suite of inputs. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_spec": list(gen_sharded_spec(4, "block", Y, X)) + + list(gen_sharded_spec(4, "height", Y, X)) + + list(gen_sharded_spec(4, "width", Y, X)), + "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], + "input_layout": [ttnn.TILE_LAYOUT, ttnn.ROW_MAJOR_LAYOUT], + }, + "xfail": { + "input_spec": list(gen_sharded_spec(16, "block", Y, X, sanitize_args=False)) + + list(gen_sharded_spec(16, "height", Y, X, sanitize_args=False)) + + list(gen_sharded_spec(16, "width", Y, X, sanitize_args=False)), + "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], + "input_layout": [ttnn.TILE_LAYOUT, ttnn.ROW_MAJOR_LAYOUT], + }, + "test": { + "input_spec": [ + { + "input_shape": [2048, 32], + "sharding_strategy": "height", + "shard_orientation": "row_major", + "tensor_hw_as_shard_shape": False, + } + ], + "input_a_dtype": [ttnn.bfloat16], + "input_layout": [ttnn.TILE_LAYOUT], + }, +} + + +# 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]]: + input_shape, sharding_strategy, _, _ = test_vector["input_spec"].values() + pre_sharded_height = math.prod(input_shape[:-1]) + pre_sharded_width = input_shape[-1] + + if sharding_strategy == "block": + if pre_sharded_height % Y != 0: + return ( + True, + "Prod of all dimensions except the innermost must be divisible by the y coordinate of coregrid when using block sharding", + ) + if pre_sharded_width % X != 0: + return ( + True, + "Innermost dimension must be divisible by the x coordinate of coregrid when using block sharding", + ) + if (pre_sharded_height // Y) // 32 <= 0: + return True, "Shard height must be greater than 32" + if (pre_sharded_width // X) // 32 <= 0: + return True, "Shard wdith must be greater than 32" + + if sharding_strategy == "width": + if pre_sharded_width % (Y * X) != 0: + return True, "Last dimension must be divisible by a total number of cores when using width sharding" + if (pre_sharded_width // (Y * X)) // 32 <= 0: + return True, "Shard wdith must be greater than 32" + + if sharding_strategy == "height": + if pre_sharded_height % (Y * X) != 0: + return ( + True, + "Prod of all dimensions except the innermost must be divisible by a total number of cores when using height sharding", + ) + if (pre_sharded_height // (Y * X)) // 32 <= 0: + return True, "Shard heght must be greater than 32" + + if test_vector["input_layout"] == ttnn.ROW_MAJOR_LAYOUT: + return True, "Input to eltwise binary must be tilized" + if test_vector["input_layout"] == ttnn.ROW_MAJOR_LAYOUT and input_spec["input_a_dtype"] == ttnn.bfloat8_b: + return True, "bfloat8_b is only supported on tiled layout" + + 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 mesh_device_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_spec, + input_a_dtype, + input_layout, + *, + device, +) -> list: + data_seed = random.randint(0, 20000000) + torch.manual_seed(data_seed) + + input_shape, sharding_strategy, shard_orientation, tensor_hw_as_shard_shape = input_spec.values() + if shard_orientation == "col_major": + shard_orientation = ttnn.ShardOrientation.COL_MAJOR + else: + shard_orientation = ttnn.ShardOrientation.ROW_MAJOR + + if sharding_strategy == "block": + sharding_strategy = ttnn.ShardStrategy.BLOCK + elif sharding_strategy == "width": + sharding_strategy = ttnn.ShardStrategy.WIDTH + else: + sharding_strategy = ttnn.ShardStrategy.HEIGHT + + if input_layout == ttnn.ROW_MAJOR_LAYOUT: + input_shape = sanitize_shape_rm(input_shape) + + torch_input_tensor_a = gen_rand_inf(input_shape, low=-100, high=100) + torch_output_tensor = torch.isfinite(torch_input_tensor_a) + + sharded_config = ttnn.create_sharded_memory_config( + shape=input_shape, + core_grid=ttnn.CoreGrid(y=Y, x=X), + strategy=sharding_strategy, + orientation=shard_orientation, + use_height_and_width_as_shard_shape=tensor_hw_as_shard_shape, + ) + + input_tensor_a = ttnn.from_torch( + torch_input_tensor_a, + dtype=input_a_dtype, + layout=input_layout, + device=device, + memory_config=sharded_config, + ) + + start_time = start_measuring_time() + output_tensor = ttnn.isfinite(input_tensor_a, memory_config=sharded_config) + e2e_perf = stop_measuring_time(start_time) + output_tensor = ttnn.to_torch(output_tensor) + + pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) + # print(pcc) + return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] + + +# Run sweeps locally +from tests.sweep_framework.framework.permutations import * + +start_time = start_measuring_time() +for suite in parameters.keys(): + device_id = 0 + device = ttnn.open_device(device_id=device_id) + suite_vectors = list(permutations(parameters[suite])) + print(len(suite_vectors)) + for vector in suite_vectors: + invalidate_res = invalidate_vector(vector) + if invalidate_res[0]: + print(f"Invalidated: {invalidate_res[1]}") + continue + try: + passed, _ = run(**vector, device=device) + if passed[0] != True: + print(passed) + except Exception as e: + print(e) + + ttnn.close_device(device) + +e2e_perf = stop_measuring_time(start_time) +print(f"time {e2e_perf / 1000000000}s") From 34efde316a168bbc29f0c3558ae4165d923f280a Mon Sep 17 00:00:00 2001 From: ngrujic Date: Wed, 20 Nov 2024 07:10:08 +0000 Subject: [PATCH 02/15] #11512: Improve isfinite sharded sweep --- .../unary/isfinite/isfinite_sharded.py | 233 +++++++++--------- .../sweep_tests/generation_funcs.py | 4 + 2 files changed, 117 insertions(+), 120 deletions(-) diff --git a/tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite_sharded.py index ef6b1dccbed..9eb598f989d 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite_sharded.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite_sharded.py @@ -11,7 +11,7 @@ import ttnn import math from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm, get_device_grid_size -from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt, gen_rand_inf +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_rand_inf, _gen_reshape_args_from_volume from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time from models.utility_functions import torch_random @@ -23,56 +23,111 @@ random.seed(0) -def gen_sharded_spec(num_shapes, sharding_strategy, y, x, sanitize_args=True): - assert sharding_strategy in ["block", "width", "height"] +def gen_sharded_spec(num_shapes, y, x, max_tensor_size=8 * 1024 * 1024): + # [ttnn.ShardStrategy.BLOCK, ttnn.ShardStrategy.WIDTH, ttnn.ShardStrategy.HEIGHT, "tensor_wh"] + sharding_strategy_list = ["tensor_wh"] + shard_orientation_list = [ttnn.ShardOrientation.COL_MAJOR, ttnn.ShardOrientation.ROW_MAJOR] + spec_list = [] - shard_orientation_list = ["col_major", "row_major"] - tensor_hw_as_shard_shape_list = [True, False] - - for shard_orientation, tensor_hw_as_shard_shape in itertools.product( - shard_orientation_list, tensor_hw_as_shard_shape_list + for sharding_strategy, shard_orientation, rank, layout in itertools.product( + sharding_strategy_list, shard_orientation_list, [4, 3, 2], [ttnn.TILE_LAYOUT, ttnn.ROW_MAJOR_LAYOUT] ): - if sharding_strategy == "block": - if not sanitize_args: - interval_1 = 1 - interval_2 = 2 - else: - interval_1 = 32 * y - interval_2 = 32 * x - - input_shape_list = ( - gen_shapes([1, 1, 32 * y, 32 * x], [6, 12, 512, 512], [1, 1, interval_1, interval_2], num_shapes) - + gen_shapes([1, 32 * y, 32 * x], [12, 512, 512], [1, interval_1, interval_2], num_shapes) - + gen_shapes([32 * y, 32 * x], [512, 512], [interval_1, interval_2], num_shapes) - ) - elif sharding_strategy == "width": - if not sanitize_args: - interval = 1 - else: - interval = 32 * x * y - input_shape_list = ( - gen_shapes([1, 1, 32, 32 * x * y], [4, 6, 64, 32 * x * y], [1, 1, 32, interval], num_shapes) - + gen_shapes([1, 32, 32 * x * y], [6, 64, 32 * x * y], [1, 32, interval], num_shapes) - + gen_shapes([32, 32 * x * y], [64, 32 * x * y], [32, interval], num_shapes) - ) + if sharding_strategy == "tensor_wh": + tensor_hw_as_shard_shape = True + sharding_strategy = ttnn.ShardStrategy.BLOCK else: - if not sanitize_args: - interval = 1 - else: - interval = 32 * x * y - input_shape_list = ( - gen_shapes([1, 1, 32 * x * y, 32], [4, 6, 32 * x * y, 64], [1, 1, interval, 32], num_shapes) - + gen_shapes([1, 32 * x * y, 32], [6, 32 * x * y, 64], [1, interval, 32], num_shapes) - + gen_shapes([32 * x * y, 32], [32 * x * y, 64], [interval, 32], num_shapes) + tensor_hw_as_shard_shape = False + + for _ in range(num_shapes): + if tensor_hw_as_shard_shape: + # Gets stuck: + # X 8 Y 8 input_shape [1, 17792, 8] DataType.BFLOAT8_B Layout.TILE ShardStrategy.BLOCK ShardOrientation.COL_MAJOR tensor_hw_as_shard_shape True + + if layout == ttnn.TILE_LAYOUT: + # In shard mode ShardMode::PHYSICAL, physical shard shape {12, 13312} is not compatible with alignment Alignment([32, 32])! + min_shard_size_x = 32 + min_shard_size_y = 32 + else: # if layout == ttnn.ROW_MAJOR_LAYOUT: + # Shard Size must be multiple of input_tile_size (width * height is multiple of 1024) + min_shard_size_x = random.choice([1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) + min_shard_size_y = 1024 // min_shard_size_x + + rest_volume = random.randint(1, max_tensor_size // (min_shard_size_x * min_shard_size_y * x * y)) + input_shape = random.choice(_gen_reshape_args_from_volume(rest_volume, step=1, out_dims=rank)) + input_shape = list(input_shape["reshape_dims"]) + input_shape[-2] = input_shape[-2] * min_shard_size_x + input_shape[-1] = input_shape[-1] * min_shard_size_y + + # Shard width should be multiple of 16 to satisfy L1 alignment (width = multiple 8 for bfloat16) + while input_shape[-1] % 16 != 0: + input_shape[-1] *= 2 + input_shape[-2] //= 2 + + if shard_orientation == ttnn.ShardOrientation.COL_MAJOR: + tmp = input_shape[-2] + input_shape[-2] = input_shape[-1] + input_shape[-1] = tmp + + elif sharding_strategy == ttnn.ShardStrategy.BLOCK: + min_shard_size_y = 32 * y + min_shard_size_x = 32 * x + mul_x = random.randint(1, 10) + mul_y = random.randint(1, 64 // mul_x) + + input_shape = random.choice( + _gen_reshape_args_from_volume(mul_y * min_shard_size_y, step=1, out_dims=rank - 1) + ) + input_shape = list(input_shape["reshape_dims"]) + input_shape.append(mul_x * min_shard_size_x) + + elif sharding_strategy == ttnn.ShardStrategy.WIDTH or sharding_strategy == ttnn.ShardStrategy.HEIGHT: + # if shard_width % total_cores != 0: raise RuntimeError("Invalid sharding core_grid") + # Shard Size must be multiple of input_tile_size + + if layout == ttnn.TILE_LAYOUT: + # In shard mode ShardMode::PHYSICAL, physical shard shape {12, 13312} is not compatible with alignment Alignment([32, 32])! + min_shard_size_x = 32 + min_shard_size_y = 32 * x * y + else: # if layout == ttnn.ROW_MAJOR_LAYOUT: + min_shard_size_x = 1 + min_shard_size_y = x * y + + # Shard Size must be multiple of input_tile_size + mul_32_x = random.choice([1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) + mul_32_y = 1024 // mul_32_x + + min_shard_size_x *= mul_32_x + min_shard_size_y *= mul_32_y + + if sharding_strategy == ttnn.ShardStrategy.HEIGHT: + # Shard width should be multiple of 16 to satisfy L1 alignment + while min_shard_size_x % 16 != 0: + min_shard_size_x *= 2 + + rest_volume = random.randint(1, max_tensor_size // (min_shard_size_x * min_shard_size_y)) + input_shape = random.choice(_gen_reshape_args_from_volume(rest_volume, step=1, out_dims=rank)) + input_shape = list(input_shape["reshape_dims"]) + input_shape[-2] = input_shape[-2] * min_shard_size_x + input_shape[-1] = input_shape[-1] * min_shard_size_y + + if sharding_strategy == ttnn.ShardStrategy.HEIGHT: + tmp = input_shape[-2] + input_shape[-2] = input_shape[-1] + input_shape[-1] = tmp + + # print(input_shape) + + spec_list.append( + { + "input_shape": input_shape, + "sharding_strategy": sharding_strategy, + "shard_orientation": shard_orientation, + "tensor_hw_as_shard_shape": tensor_hw_as_shard_shape, + "input_layout": layout, + } ) - for input_shape in input_shape_list: - yield { - "input_shape": input_shape, - "sharding_strategy": sharding_strategy, - "shard_orientation": shard_orientation, - "tensor_hw_as_shard_shape": tensor_hw_as_shard_shape, - } + return spec_list # Parameters provided to the test vector generator are defined here. @@ -81,30 +136,8 @@ def gen_sharded_spec(num_shapes, sharding_strategy, y, x, sanitize_args=True): # Developers can create their own generator functions and pass them to the parameters as inputs. parameters = { "nightly": { - "input_spec": list(gen_sharded_spec(4, "block", Y, X)) - + list(gen_sharded_spec(4, "height", Y, X)) - + list(gen_sharded_spec(4, "width", Y, X)), + "input_spec": gen_sharded_spec(16, Y, X), "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], - "input_layout": [ttnn.TILE_LAYOUT, ttnn.ROW_MAJOR_LAYOUT], - }, - "xfail": { - "input_spec": list(gen_sharded_spec(16, "block", Y, X, sanitize_args=False)) - + list(gen_sharded_spec(16, "height", Y, X, sanitize_args=False)) - + list(gen_sharded_spec(16, "width", Y, X, sanitize_args=False)), - "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], - "input_layout": [ttnn.TILE_LAYOUT, ttnn.ROW_MAJOR_LAYOUT], - }, - "test": { - "input_spec": [ - { - "input_shape": [2048, 32], - "sharding_strategy": "height", - "shard_orientation": "row_major", - "tensor_hw_as_shard_shape": False, - } - ], - "input_a_dtype": [ttnn.bfloat16], - "input_layout": [ttnn.TILE_LAYOUT], }, } @@ -113,44 +146,11 @@ def gen_sharded_spec(num_shapes, sharding_strategy, y, x, sanitize_args=True): # 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]]: - input_shape, sharding_strategy, _, _ = test_vector["input_spec"].values() + input_shape, sharding_strategy, _, _, input_layout = test_vector["input_spec"].values() pre_sharded_height = math.prod(input_shape[:-1]) pre_sharded_width = input_shape[-1] - if sharding_strategy == "block": - if pre_sharded_height % Y != 0: - return ( - True, - "Prod of all dimensions except the innermost must be divisible by the y coordinate of coregrid when using block sharding", - ) - if pre_sharded_width % X != 0: - return ( - True, - "Innermost dimension must be divisible by the x coordinate of coregrid when using block sharding", - ) - if (pre_sharded_height // Y) // 32 <= 0: - return True, "Shard height must be greater than 32" - if (pre_sharded_width // X) // 32 <= 0: - return True, "Shard wdith must be greater than 32" - - if sharding_strategy == "width": - if pre_sharded_width % (Y * X) != 0: - return True, "Last dimension must be divisible by a total number of cores when using width sharding" - if (pre_sharded_width // (Y * X)) // 32 <= 0: - return True, "Shard wdith must be greater than 32" - - if sharding_strategy == "height": - if pre_sharded_height % (Y * X) != 0: - return ( - True, - "Prod of all dimensions except the innermost must be divisible by a total number of cores when using height sharding", - ) - if (pre_sharded_height // (Y * X)) // 32 <= 0: - return True, "Shard heght must be greater than 32" - - if test_vector["input_layout"] == ttnn.ROW_MAJOR_LAYOUT: - return True, "Input to eltwise binary must be tilized" - if test_vector["input_layout"] == ttnn.ROW_MAJOR_LAYOUT and input_spec["input_a_dtype"] == ttnn.bfloat8_b: + if input_layout == ttnn.ROW_MAJOR_LAYOUT and test_vector["input_a_dtype"] == ttnn.bfloat8_b: return True, "bfloat8_b is only supported on tiled layout" return False, None @@ -163,25 +163,16 @@ def invalidate_vector(test_vector) -> Tuple[bool, Optional[str]]: def run( input_spec, input_a_dtype, - input_layout, *, device, ) -> list: data_seed = random.randint(0, 20000000) torch.manual_seed(data_seed) + input_shape, sharding_strategy, shard_orientation, tensor_hw_as_shard_shape, input_layout = input_spec.values() - input_shape, sharding_strategy, shard_orientation, tensor_hw_as_shard_shape = input_spec.values() - if shard_orientation == "col_major": - shard_orientation = ttnn.ShardOrientation.COL_MAJOR - else: - shard_orientation = ttnn.ShardOrientation.ROW_MAJOR - - if sharding_strategy == "block": - sharding_strategy = ttnn.ShardStrategy.BLOCK - elif sharding_strategy == "width": - sharding_strategy = ttnn.ShardStrategy.WIDTH - else: - sharding_strategy = ttnn.ShardStrategy.HEIGHT + print( + f"X {X} Y {Y} input_shape {input_shape} {input_a_dtype} {input_layout} {sharding_strategy} {shard_orientation} tensor_hw_as_shard_shape {tensor_hw_as_shard_shape}" + ) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) @@ -211,7 +202,7 @@ def run( output_tensor = ttnn.to_torch(output_tensor) pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) - # print(pcc) + print(pcc) return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] @@ -231,11 +222,13 @@ def run( continue try: passed, _ = run(**vector, device=device) - if passed[0] != True: - print(passed) + # if passed[0] != True: + # print(passed) except Exception as e: print(e) + # break + ttnn.close_device(device) e2e_perf = stop_measuring_time(start_time) diff --git a/tests/tt_eager/python_api_testing/sweep_tests/generation_funcs.py b/tests/tt_eager/python_api_testing/sweep_tests/generation_funcs.py index c505db14f42..27469ea9087 100644 --- a/tests/tt_eager/python_api_testing/sweep_tests/generation_funcs.py +++ b/tests/tt_eager/python_api_testing/sweep_tests/generation_funcs.py @@ -716,6 +716,10 @@ def _gen_reshape_args_from_volume(volume, step, out_dims=4): for c in _get_factors(volume, 1): b = volume // c shapes.append({"reshape_dims": (b, c)}) + elif out_dims == 1: + shapes.append({"reshape_dims": (volume,)}) + else: + shapes.append({"reshape_dims": []}) return shapes From 58172b2b27adc06c8bdad05756ecaa820e9115e0 Mon Sep 17 00:00:00 2001 From: ngrujic Date: Wed, 20 Nov 2024 11:32:23 +0000 Subject: [PATCH 03/15] #11512: Improve isfinite sharded sweeps --- .../sweep_utils/sharding_utils.py | 137 ++++++++++++++ .../unary/isfinite/isfinite_sharded.py | 179 ++++-------------- 2 files changed, 175 insertions(+), 141 deletions(-) create mode 100644 tests/sweep_framework/sweep_utils/sharding_utils.py diff --git a/tests/sweep_framework/sweep_utils/sharding_utils.py b/tests/sweep_framework/sweep_utils/sharding_utils.py new file mode 100644 index 00000000000..402cf44ca93 --- /dev/null +++ b/tests/sweep_framework/sweep_utils/sharding_utils.py @@ -0,0 +1,137 @@ +import ttnn +import itertools +import random +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import _gen_reshape_args_from_volume + + +def gen_sharded_spec_unary(num_shapes, y, x, max_tensor_size=4 * 1024 * 1024): + # ["BLOCK", "WIDTH", "HEIGHT", "tensor_wh"] + sharding_strategy_list = ["BLOCK", "WIDTH", "HEIGHT", "tensor_wh"] + shard_orientation_list = ["COL_MAJOR", "ROW_MAJOR"] + spec_list = [] + + for sharding_strategy, shard_orientation, rank, layout in itertools.product( + sharding_strategy_list, shard_orientation_list, [4, 3, 2], ["TILE_LAYOUT", "ROW_MAJOR_LAYOUT"] + ): + if sharding_strategy == "tensor_wh": + tensor_hw_as_shard_shape = True + sharding_strategy = "BLOCK" + else: + tensor_hw_as_shard_shape = False + + for _ in range(num_shapes): + if tensor_hw_as_shard_shape: + # Gets stuck: + # X 8 Y 8 input_shape [1, 17792, 8] DataType.BFLOAT8_B Layout.TILE ShardStrategy.BLOCK ShardOrientation.COL_MAJOR tensor_hw_as_shard_shape True + + if layout == "TILE_LAYOUT": + # In shard mode ShardMode::PHYSICAL, physical shard shape {12, 13312} is not compatible with alignment Alignment([32, 32])! + min_shard_size_x = 32 + min_shard_size_y = 32 + else: # if layout == "ROW_MAJOR_LAYOUT": + # Shard Size must be multiple of input_tile_size (width * height is multiple of 1024) + min_shard_size_x = random.choice([1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) + min_shard_size_y = 1024 // min_shard_size_x + + rest_volume = random.randint(1, max_tensor_size // (min_shard_size_x * min_shard_size_y * x * y)) + input_shape = random.choice(_gen_reshape_args_from_volume(rest_volume, step=1, out_dims=rank)) + input_shape = list(input_shape["reshape_dims"]) + input_shape[-2] = input_shape[-2] * min_shard_size_x + input_shape[-1] = input_shape[-1] * min_shard_size_y + + # Shard width should be multiple of 16 to satisfy L1 alignment (width = multiple 8 for bfloat16) + while input_shape[-1] % 16 != 0: + input_shape[-1] *= 2 + input_shape[-2] //= 2 + + if shard_orientation == "COL_MAJOR": + tmp = input_shape[-2] + input_shape[-2] = input_shape[-1] + input_shape[-1] = tmp + + elif sharding_strategy == "BLOCK": + min_shard_size_y = 32 * y + min_shard_size_x = 32 * x + mul_x = random.randint(1, 10) + mul_y = random.randint(1, 64 // mul_x) + + input_shape = random.choice( + _gen_reshape_args_from_volume(mul_y * min_shard_size_y, step=1, out_dims=rank - 1) + ) + input_shape = list(input_shape["reshape_dims"]) + input_shape.append(mul_x * min_shard_size_x) + + elif sharding_strategy == "WIDTH" or sharding_strategy == "HEIGHT": + # if shard_width % total_cores != 0: raise RuntimeError("Invalid sharding core_grid") + # Shard Size must be multiple of input_tile_size + + if layout == "TILE_LAYOUT": + # In shard mode ShardMode::PHYSICAL, physical shard shape {12, 13312} is not compatible with alignment Alignment([32, 32])! + min_shard_size_x = 32 + min_shard_size_y = 32 * x * y + else: # if layout == "ROW_MAJOR_LAYOUT": + # Shard Size must be multiple of input_tile_size + # Shard width should be multiple of 16 to satisfy L1 alignment + mul_32_y = random.choice([16, 32, 64, 128, 256, 512, 1024]) + mul_32_x = 1024 // mul_32_y + + if sharding_strategy == "HEIGHT": + # Shard width should be multiple of 16 to satisfy L1 alignment + while mul_32_x % 16 != 0: + mul_32_x *= 2 + mul_32_y //= 2 + + min_shard_size_x = mul_32_x + min_shard_size_y = mul_32_y * x * y + + rest_volume = random.randint(1, max_tensor_size // (min_shard_size_x * min_shard_size_y)) + input_shape = random.choice(_gen_reshape_args_from_volume(rest_volume, step=1, out_dims=rank)) + input_shape = list(input_shape["reshape_dims"]) + input_shape[-2] = input_shape[-2] * min_shard_size_x + input_shape[-1] = input_shape[-1] * min_shard_size_y + + if sharding_strategy == "HEIGHT": + tmp = input_shape[-2] + input_shape[-2] = input_shape[-1] + input_shape[-1] = tmp + + # print(input_shape) + + spec_list.append( + { + "input_shape": input_shape, + "sharding_strategy": sharding_strategy, + "shard_orientation": shard_orientation, + "tensor_hw_as_shard_shape": tensor_hw_as_shard_shape, + "input_layout": layout, + } + ) + + return spec_list + + +def parse_sharding_spec(input_spec): + input_shape = input_spec["input_shape"] + sharding_strategy = input_spec["sharding_strategy"] + shard_orientation = input_spec["shard_orientation"] + tensor_hw_as_shard_shape = input_spec["tensor_hw_as_shard_shape"] + input_layout = input_spec["input_layout"] + + if sharding_strategy == "HEIGHT": + sharding_strategy = ttnn.ShardStrategy.HEIGHT + elif sharding_strategy == "WIDTH": + sharding_strategy = ttnn.ShardStrategy.WIDTH + else: # sharding_strategy == "BLOCK": + sharding_strategy = ttnn.ShardStrategy.BLOCK + + if shard_orientation == "COL_MAJOR": + shard_orientation = ttnn.ShardOrientation.COL_MAJOR + else: + shard_orientation = ttnn.ShardOrientation.ROW_MAJOR + + if input_layout == "TILE_LAYOUT": + input_layout = ttnn.TILE_LAYOUT + else: + input_layout = ttnn.ROW_MAJOR_LAYOUT + + return input_shape, sharding_strategy, shard_orientation, tensor_hw_as_shard_shape, input_layout diff --git a/tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite_sharded.py index 9eb598f989d..fec93f8f95d 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite_sharded.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite_sharded.py @@ -4,14 +4,15 @@ from typing import Optional, Tuple from functools import partial -import itertools +import json import torch import random import ttnn import math from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm, get_device_grid_size -from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_rand_inf, _gen_reshape_args_from_volume +from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_rand_inf from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time from models.utility_functions import torch_random @@ -23,120 +24,13 @@ random.seed(0) -def gen_sharded_spec(num_shapes, y, x, max_tensor_size=8 * 1024 * 1024): - # [ttnn.ShardStrategy.BLOCK, ttnn.ShardStrategy.WIDTH, ttnn.ShardStrategy.HEIGHT, "tensor_wh"] - sharding_strategy_list = ["tensor_wh"] - shard_orientation_list = [ttnn.ShardOrientation.COL_MAJOR, ttnn.ShardOrientation.ROW_MAJOR] - spec_list = [] - - for sharding_strategy, shard_orientation, rank, layout in itertools.product( - sharding_strategy_list, shard_orientation_list, [4, 3, 2], [ttnn.TILE_LAYOUT, ttnn.ROW_MAJOR_LAYOUT] - ): - if sharding_strategy == "tensor_wh": - tensor_hw_as_shard_shape = True - sharding_strategy = ttnn.ShardStrategy.BLOCK - else: - tensor_hw_as_shard_shape = False - - for _ in range(num_shapes): - if tensor_hw_as_shard_shape: - # Gets stuck: - # X 8 Y 8 input_shape [1, 17792, 8] DataType.BFLOAT8_B Layout.TILE ShardStrategy.BLOCK ShardOrientation.COL_MAJOR tensor_hw_as_shard_shape True - - if layout == ttnn.TILE_LAYOUT: - # In shard mode ShardMode::PHYSICAL, physical shard shape {12, 13312} is not compatible with alignment Alignment([32, 32])! - min_shard_size_x = 32 - min_shard_size_y = 32 - else: # if layout == ttnn.ROW_MAJOR_LAYOUT: - # Shard Size must be multiple of input_tile_size (width * height is multiple of 1024) - min_shard_size_x = random.choice([1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) - min_shard_size_y = 1024 // min_shard_size_x - - rest_volume = random.randint(1, max_tensor_size // (min_shard_size_x * min_shard_size_y * x * y)) - input_shape = random.choice(_gen_reshape_args_from_volume(rest_volume, step=1, out_dims=rank)) - input_shape = list(input_shape["reshape_dims"]) - input_shape[-2] = input_shape[-2] * min_shard_size_x - input_shape[-1] = input_shape[-1] * min_shard_size_y - - # Shard width should be multiple of 16 to satisfy L1 alignment (width = multiple 8 for bfloat16) - while input_shape[-1] % 16 != 0: - input_shape[-1] *= 2 - input_shape[-2] //= 2 - - if shard_orientation == ttnn.ShardOrientation.COL_MAJOR: - tmp = input_shape[-2] - input_shape[-2] = input_shape[-1] - input_shape[-1] = tmp - - elif sharding_strategy == ttnn.ShardStrategy.BLOCK: - min_shard_size_y = 32 * y - min_shard_size_x = 32 * x - mul_x = random.randint(1, 10) - mul_y = random.randint(1, 64 // mul_x) - - input_shape = random.choice( - _gen_reshape_args_from_volume(mul_y * min_shard_size_y, step=1, out_dims=rank - 1) - ) - input_shape = list(input_shape["reshape_dims"]) - input_shape.append(mul_x * min_shard_size_x) - - elif sharding_strategy == ttnn.ShardStrategy.WIDTH or sharding_strategy == ttnn.ShardStrategy.HEIGHT: - # if shard_width % total_cores != 0: raise RuntimeError("Invalid sharding core_grid") - # Shard Size must be multiple of input_tile_size - - if layout == ttnn.TILE_LAYOUT: - # In shard mode ShardMode::PHYSICAL, physical shard shape {12, 13312} is not compatible with alignment Alignment([32, 32])! - min_shard_size_x = 32 - min_shard_size_y = 32 * x * y - else: # if layout == ttnn.ROW_MAJOR_LAYOUT: - min_shard_size_x = 1 - min_shard_size_y = x * y - - # Shard Size must be multiple of input_tile_size - mul_32_x = random.choice([1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) - mul_32_y = 1024 // mul_32_x - - min_shard_size_x *= mul_32_x - min_shard_size_y *= mul_32_y - - if sharding_strategy == ttnn.ShardStrategy.HEIGHT: - # Shard width should be multiple of 16 to satisfy L1 alignment - while min_shard_size_x % 16 != 0: - min_shard_size_x *= 2 - - rest_volume = random.randint(1, max_tensor_size // (min_shard_size_x * min_shard_size_y)) - input_shape = random.choice(_gen_reshape_args_from_volume(rest_volume, step=1, out_dims=rank)) - input_shape = list(input_shape["reshape_dims"]) - input_shape[-2] = input_shape[-2] * min_shard_size_x - input_shape[-1] = input_shape[-1] * min_shard_size_y - - if sharding_strategy == ttnn.ShardStrategy.HEIGHT: - tmp = input_shape[-2] - input_shape[-2] = input_shape[-1] - input_shape[-1] = tmp - - # print(input_shape) - - spec_list.append( - { - "input_shape": input_shape, - "sharding_strategy": sharding_strategy, - "shard_orientation": shard_orientation, - "tensor_hw_as_shard_shape": tensor_hw_as_shard_shape, - "input_layout": layout, - } - ) - - return spec_list - - # Parameters provided to the test vector generator are defined here. # They are defined as dict-type suites that contain the arguments to the run function as keys, and lists of possible inputs as values. # Each suite has a key name (in this case "suite_1" and "suite_2") which will associate the test vectors to this specific suite of inputs. # Developers can create their own generator functions and pass them to the parameters as inputs. parameters = { "nightly": { - "input_spec": gen_sharded_spec(16, Y, X), + "input_spec": gen_sharded_spec_unary(16, Y, X), "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], }, } @@ -168,12 +62,15 @@ def run( ) -> list: data_seed = random.randint(0, 20000000) torch.manual_seed(data_seed) - input_shape, sharding_strategy, shard_orientation, tensor_hw_as_shard_shape, input_layout = input_spec.values() - print( - f"X {X} Y {Y} input_shape {input_shape} {input_a_dtype} {input_layout} {sharding_strategy} {shard_orientation} tensor_hw_as_shard_shape {tensor_hw_as_shard_shape}" + input_shape, sharding_strategy, shard_orientation, tensor_hw_as_shard_shape, input_layout = parse_sharding_spec( + input_spec ) + # print( + # f"X {X} Y {Y} input_shape {input_shape} {input_a_dtype} {input_layout} {sharding_strategy} {shard_orientation} tensor_hw_as_shard_shape {tensor_hw_as_shard_shape}" + # ) + if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) @@ -202,34 +99,34 @@ def run( output_tensor = ttnn.to_torch(output_tensor) pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) - print(pcc) + # print(pcc) return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] -# Run sweeps locally -from tests.sweep_framework.framework.permutations import * - -start_time = start_measuring_time() -for suite in parameters.keys(): - device_id = 0 - device = ttnn.open_device(device_id=device_id) - suite_vectors = list(permutations(parameters[suite])) - print(len(suite_vectors)) - for vector in suite_vectors: - invalidate_res = invalidate_vector(vector) - if invalidate_res[0]: - print(f"Invalidated: {invalidate_res[1]}") - continue - try: - passed, _ = run(**vector, device=device) - # if passed[0] != True: - # print(passed) - except Exception as e: - print(e) - - # break - - ttnn.close_device(device) - -e2e_perf = stop_measuring_time(start_time) -print(f"time {e2e_perf / 1000000000}s") +# # Run sweeps locally +# from tests.sweep_framework.framework.permutations import * + +# start_time = start_measuring_time() +# for suite in parameters.keys(): +# device_id = 0 +# device = ttnn.open_device(device_id=device_id) +# suite_vectors = list(permutations(parameters[suite])) +# print(len(suite_vectors)) +# for vector in suite_vectors: +# invalidate_res = invalidate_vector(vector) +# if invalidate_res[0]: +# print(f"Invalidated: {invalidate_res[1]}") +# continue +# try: +# passed, _ = run(**vector, device=device) +# # if passed[0] != True: +# # print(passed) +# except Exception as e: +# print(e) + +# # break + +# ttnn.close_device(device) + +# e2e_perf = stop_measuring_time(start_time) +# print(f"time {e2e_perf / 1000000000}s") From ab5a950ad249283db6a6f7eeb62e4ba6c1fac428 Mon Sep 17 00:00:00 2001 From: ngrujic Date: Thu, 21 Nov 2024 10:27:48 +0000 Subject: [PATCH 04/15] #11512: Add sweeps for isinf, isnan, isneginf, isposinf sharded --- .github/workflows/ttnn-run-sweeps.yaml | 15 +- .../unary/isfinite/isfinite_sharded.py | 31 +--- .../sweeps/eltwise/unary/{ => isinf}/isinf.py | 0 .../eltwise/unary/isinf/isinf_sharded.py | 103 ++++++++++++++ .../sweeps/eltwise/unary/{ => isnan}/isnan.py | 0 .../eltwise/unary/isnan/isnan_sharded.py | 132 ++++++++++++++++++ .../eltwise/unary/{ => isneginf}/isneginf.py | 0 .../unary/isneginf/isneginf_sharded.py | 103 ++++++++++++++ .../eltwise/unary/{ => isposinf}/isposinf.py | 0 .../unary/isposinf/isposinf_sharded.py | 132 ++++++++++++++++++ 10 files changed, 481 insertions(+), 35 deletions(-) rename tests/sweep_framework/sweeps/eltwise/unary/{ => isinf}/isinf.py (100%) create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/isinf/isinf_sharded.py rename tests/sweep_framework/sweeps/eltwise/unary/{ => isnan}/isnan.py (100%) create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/isnan/isnan_sharded.py rename tests/sweep_framework/sweeps/eltwise/unary/{ => isneginf}/isneginf.py (100%) create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/isneginf/isneginf_sharded.py rename tests/sweep_framework/sweeps/eltwise/unary/{ => isposinf}/isposinf.py (100%) create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/isposinf/isposinf_sharded.py diff --git a/.github/workflows/ttnn-run-sweeps.yaml b/.github/workflows/ttnn-run-sweeps.yaml index 2b8db811e90..442348e8e42 100644 --- a/.github/workflows/ttnn-run-sweeps.yaml +++ b/.github/workflows/ttnn-run-sweeps.yaml @@ -176,11 +176,16 @@ on: - eltwise.unary.logit - eltwise.unary.mish - eltwise.unary.multigammaln - - eltwise.unary.isfinite - - eltwise.unary.isinf - - eltwise.unary.isnan - - eltwise.unary.isneginf - - eltwise.unary.isposinf + - eltwise.unary.isfinite.isfinite + - eltwise.unary.isfinite.isfinite_sharded + - eltwise.unary.isinf.isinf + - eltwise.unary.isinf.isinf_sharded + - eltwise.unary.isnan.isnan + - eltwise.unary.isnan.isnan_sharded + - eltwise.unary.isneginf.isneginf + - eltwise.unary.isneginf.isneginf_sharded + - eltwise.unary.isposinf.isposinf + - eltwise.unary.isposinf.isposinf_sharded - eltwise.binary.add.add_all_pytorch2 - eltwise.binary.add.add_set2_pytorch2 - eltwise.binary.add.add_different_memory_configs diff --git a/tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite_sharded.py index fec93f8f95d..121673c0b63 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite_sharded.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite_sharded.py @@ -44,7 +44,7 @@ def invalidate_vector(test_vector) -> Tuple[bool, Optional[str]]: pre_sharded_height = math.prod(input_shape[:-1]) pre_sharded_width = input_shape[-1] - if input_layout == ttnn.ROW_MAJOR_LAYOUT and test_vector["input_a_dtype"] == ttnn.bfloat8_b: + if input_layout == "ROW_MAJOR_LAYOUT" and test_vector["input_a_dtype"] == ttnn.bfloat8_b: return True, "bfloat8_b is only supported on tiled layout" return False, None @@ -101,32 +101,3 @@ def run( pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) # print(pcc) return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] - - -# # Run sweeps locally -# from tests.sweep_framework.framework.permutations import * - -# start_time = start_measuring_time() -# for suite in parameters.keys(): -# device_id = 0 -# device = ttnn.open_device(device_id=device_id) -# suite_vectors = list(permutations(parameters[suite])) -# print(len(suite_vectors)) -# for vector in suite_vectors: -# invalidate_res = invalidate_vector(vector) -# if invalidate_res[0]: -# print(f"Invalidated: {invalidate_res[1]}") -# continue -# try: -# passed, _ = run(**vector, device=device) -# # if passed[0] != True: -# # print(passed) -# except Exception as e: -# print(e) - -# # break - -# ttnn.close_device(device) - -# e2e_perf = stop_measuring_time(start_time) -# print(f"time {e2e_perf / 1000000000}s") diff --git a/tests/sweep_framework/sweeps/eltwise/unary/isinf.py b/tests/sweep_framework/sweeps/eltwise/unary/isinf/isinf.py similarity index 100% rename from tests/sweep_framework/sweeps/eltwise/unary/isinf.py rename to tests/sweep_framework/sweeps/eltwise/unary/isinf/isinf.py diff --git a/tests/sweep_framework/sweeps/eltwise/unary/isinf/isinf_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/isinf/isinf_sharded.py new file mode 100644 index 00000000000..94b80869dc4 --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/isinf/isinf_sharded.py @@ -0,0 +1,103 @@ +# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. + +# SPDX-License-Identifier: Apache-2.0 + +from typing import Optional, Tuple +from functools import partial + +import json +import torch +import random +import ttnn +import math +from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm, get_device_grid_size +from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_rand_inf + +from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time +from models.utility_functions import torch_random + +# Override the default timeout in seconds for hang detection. +TIMEOUT = 120 +Y, X = get_device_grid_size() + +random.seed(0) + + +# Parameters provided to the test vector generator are defined here. +# They are defined as dict-type suites that contain the arguments to the run function as keys, and lists of possible inputs as values. +# Each suite has a key name (in this case "suite_1" and "suite_2") which will associate the test vectors to this specific suite of inputs. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_spec": gen_sharded_spec_unary(16, Y, X), + "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], + }, +} + + +# 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]]: + input_shape, sharding_strategy, _, _, input_layout = test_vector["input_spec"].values() + pre_sharded_height = math.prod(input_shape[:-1]) + pre_sharded_width = input_shape[-1] + + if input_layout == "ROW_MAJOR_LAYOUT" and test_vector["input_a_dtype"] == ttnn.bfloat8_b: + return True, "bfloat8_b is only supported on tiled layout" + + 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 mesh_device_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_spec, + input_a_dtype, + *, + device, +) -> list: + data_seed = random.randint(0, 20000000) + torch.manual_seed(data_seed) + + input_shape, sharding_strategy, shard_orientation, tensor_hw_as_shard_shape, input_layout = parse_sharding_spec( + input_spec + ) + + # print( + # f"X {X} Y {Y} input_shape {input_shape} {input_a_dtype} {input_layout} {sharding_strategy} {shard_orientation} tensor_hw_as_shard_shape {tensor_hw_as_shard_shape}" + # ) + + if input_layout == ttnn.ROW_MAJOR_LAYOUT: + input_shape = sanitize_shape_rm(input_shape) + + torch_input_tensor_a = gen_rand_inf(input_shape, low=-100, high=100) + torch_output_tensor = torch.isinf(torch_input_tensor_a) + + sharded_config = ttnn.create_sharded_memory_config( + shape=input_shape, + core_grid=ttnn.CoreGrid(y=Y, x=X), + strategy=sharding_strategy, + orientation=shard_orientation, + use_height_and_width_as_shard_shape=tensor_hw_as_shard_shape, + ) + + input_tensor_a = ttnn.from_torch( + torch_input_tensor_a, + dtype=input_a_dtype, + layout=input_layout, + device=device, + memory_config=sharded_config, + ) + + start_time = start_measuring_time() + output_tensor = ttnn.isinf(input_tensor_a, memory_config=sharded_config) + e2e_perf = stop_measuring_time(start_time) + output_tensor = ttnn.to_torch(output_tensor) + + pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) + # print(pcc) + return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/unary/isnan.py b/tests/sweep_framework/sweeps/eltwise/unary/isnan/isnan.py similarity index 100% rename from tests/sweep_framework/sweeps/eltwise/unary/isnan.py rename to tests/sweep_framework/sweeps/eltwise/unary/isnan/isnan.py diff --git a/tests/sweep_framework/sweeps/eltwise/unary/isnan/isnan_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/isnan/isnan_sharded.py new file mode 100644 index 00000000000..d86bd84c2c3 --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/isnan/isnan_sharded.py @@ -0,0 +1,132 @@ +# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. + +# SPDX-License-Identifier: Apache-2.0 + +from typing import Optional, Tuple +from functools import partial + +import json +import torch +import random +import ttnn +import math +from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm, get_device_grid_size +from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_rand_inf + +from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time +from models.utility_functions import torch_random + +# Override the default timeout in seconds for hang detection. +TIMEOUT = 120 +Y, X = get_device_grid_size() + +random.seed(0) + + +# Parameters provided to the test vector generator are defined here. +# They are defined as dict-type suites that contain the arguments to the run function as keys, and lists of possible inputs as values. +# Each suite has a key name (in this case "suite_1" and "suite_2") which will associate the test vectors to this specific suite of inputs. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_spec": gen_sharded_spec_unary(16, Y, X), + "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], + }, +} + + +# 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]]: + input_shape, sharding_strategy, _, _, input_layout = test_vector["input_spec"].values() + pre_sharded_height = math.prod(input_shape[:-1]) + pre_sharded_width = input_shape[-1] + + if input_layout == "ROW_MAJOR_LAYOUT" and test_vector["input_a_dtype"] == ttnn.bfloat8_b: + return True, "bfloat8_b is only supported on tiled layout" + + 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 mesh_device_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_spec, + input_a_dtype, + *, + device, +) -> list: + data_seed = random.randint(0, 20000000) + torch.manual_seed(data_seed) + + input_shape, sharding_strategy, shard_orientation, tensor_hw_as_shard_shape, input_layout = parse_sharding_spec( + input_spec + ) + + # print( + # f"X {X} Y {Y} input_shape {input_shape} {input_a_dtype} {input_layout} {sharding_strategy} {shard_orientation} tensor_hw_as_shard_shape {tensor_hw_as_shard_shape}" + # ) + + if input_layout == ttnn.ROW_MAJOR_LAYOUT: + input_shape = sanitize_shape_rm(input_shape) + + torch_input_tensor_a = gen_rand_inf(input_shape, low=-100, high=100) + torch_output_tensor = torch.isnan(torch_input_tensor_a) + + sharded_config = ttnn.create_sharded_memory_config( + shape=input_shape, + core_grid=ttnn.CoreGrid(y=Y, x=X), + strategy=sharding_strategy, + orientation=shard_orientation, + use_height_and_width_as_shard_shape=tensor_hw_as_shard_shape, + ) + + input_tensor_a = ttnn.from_torch( + torch_input_tensor_a, + dtype=input_a_dtype, + layout=input_layout, + device=device, + memory_config=sharded_config, + ) + + start_time = start_measuring_time() + output_tensor = ttnn.isnan(input_tensor_a, memory_config=sharded_config) + e2e_perf = stop_measuring_time(start_time) + output_tensor = ttnn.to_torch(output_tensor) + + pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) + # print(pcc) + return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] + + +# Run sweeps locally +# from tests.sweep_framework.framework.permutations import * + +# start_time = start_measuring_time() +# for suite in parameters.keys(): +# device_id = 0 +# device = ttnn.open_device(device_id=device_id) +# suite_vectors = list(permutations(parameters[suite])) +# print(len(suite_vectors)) +# for vector in suite_vectors: +# invalidate_res = invalidate_vector(vector) +# if invalidate_res[0]: +# print(f"Invalidated: {invalidate_res[1]}") +# continue +# try: +# passed, _ = run(**vector, device=device) +# # if passed[0] != True: +# # print(passed) +# except Exception as e: +# print(e) + +# # break + +# ttnn.close_device(device) + +# e2e_perf = stop_measuring_time(start_time) +# print(f"time {e2e_perf / 1000000000}s") diff --git a/tests/sweep_framework/sweeps/eltwise/unary/isneginf.py b/tests/sweep_framework/sweeps/eltwise/unary/isneginf/isneginf.py similarity index 100% rename from tests/sweep_framework/sweeps/eltwise/unary/isneginf.py rename to tests/sweep_framework/sweeps/eltwise/unary/isneginf/isneginf.py diff --git a/tests/sweep_framework/sweeps/eltwise/unary/isneginf/isneginf_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/isneginf/isneginf_sharded.py new file mode 100644 index 00000000000..b8bdb32ef66 --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/isneginf/isneginf_sharded.py @@ -0,0 +1,103 @@ +# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. + +# SPDX-License-Identifier: Apache-2.0 + +from typing import Optional, Tuple +from functools import partial + +import json +import torch +import random +import ttnn +import math +from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm, get_device_grid_size +from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_rand_inf + +from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time +from models.utility_functions import torch_random + +# Override the default timeout in seconds for hang detection. +TIMEOUT = 120 +Y, X = get_device_grid_size() + +random.seed(0) + + +# Parameters provided to the test vector generator are defined here. +# They are defined as dict-type suites that contain the arguments to the run function as keys, and lists of possible inputs as values. +# Each suite has a key name (in this case "suite_1" and "suite_2") which will associate the test vectors to this specific suite of inputs. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_spec": gen_sharded_spec_unary(16, Y, X), + "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], + }, +} + + +# 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]]: + input_shape, sharding_strategy, _, _, input_layout = test_vector["input_spec"].values() + pre_sharded_height = math.prod(input_shape[:-1]) + pre_sharded_width = input_shape[-1] + + if input_layout == "ROW_MAJOR_LAYOUT" and test_vector["input_a_dtype"] == ttnn.bfloat8_b: + return True, "bfloat8_b is only supported on tiled layout" + + 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 mesh_device_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_spec, + input_a_dtype, + *, + device, +) -> list: + data_seed = random.randint(0, 20000000) + torch.manual_seed(data_seed) + + input_shape, sharding_strategy, shard_orientation, tensor_hw_as_shard_shape, input_layout = parse_sharding_spec( + input_spec + ) + + # print( + # f"X {X} Y {Y} input_shape {input_shape} {input_a_dtype} {input_layout} {sharding_strategy} {shard_orientation} tensor_hw_as_shard_shape {tensor_hw_as_shard_shape}" + # ) + + if input_layout == ttnn.ROW_MAJOR_LAYOUT: + input_shape = sanitize_shape_rm(input_shape) + + torch_input_tensor_a = gen_rand_inf(input_shape, low=-100, high=100) + torch_output_tensor = torch.isneginf(torch_input_tensor_a) + + sharded_config = ttnn.create_sharded_memory_config( + shape=input_shape, + core_grid=ttnn.CoreGrid(y=Y, x=X), + strategy=sharding_strategy, + orientation=shard_orientation, + use_height_and_width_as_shard_shape=tensor_hw_as_shard_shape, + ) + + input_tensor_a = ttnn.from_torch( + torch_input_tensor_a, + dtype=input_a_dtype, + layout=input_layout, + device=device, + memory_config=sharded_config, + ) + + start_time = start_measuring_time() + output_tensor = ttnn.isneginf(input_tensor_a, memory_config=sharded_config) + e2e_perf = stop_measuring_time(start_time) + output_tensor = ttnn.to_torch(output_tensor) + + pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) + # print(pcc) + return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/unary/isposinf.py b/tests/sweep_framework/sweeps/eltwise/unary/isposinf/isposinf.py similarity index 100% rename from tests/sweep_framework/sweeps/eltwise/unary/isposinf.py rename to tests/sweep_framework/sweeps/eltwise/unary/isposinf/isposinf.py diff --git a/tests/sweep_framework/sweeps/eltwise/unary/isposinf/isposinf_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/isposinf/isposinf_sharded.py new file mode 100644 index 00000000000..63bf5a9610d --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/isposinf/isposinf_sharded.py @@ -0,0 +1,132 @@ +# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. + +# SPDX-License-Identifier: Apache-2.0 + +from typing import Optional, Tuple +from functools import partial + +import json +import torch +import random +import ttnn +import math +from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm, get_device_grid_size +from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_rand_inf + +from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time +from models.utility_functions import torch_random + +# Override the default timeout in seconds for hang detection. +TIMEOUT = 120 +Y, X = get_device_grid_size() + +random.seed(0) + + +# Parameters provided to the test vector generator are defined here. +# They are defined as dict-type suites that contain the arguments to the run function as keys, and lists of possible inputs as values. +# Each suite has a key name (in this case "suite_1" and "suite_2") which will associate the test vectors to this specific suite of inputs. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_spec": gen_sharded_spec_unary(16, Y, X), + "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], + }, +} + + +# 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]]: + input_shape, sharding_strategy, _, _, input_layout = test_vector["input_spec"].values() + pre_sharded_height = math.prod(input_shape[:-1]) + pre_sharded_width = input_shape[-1] + + if input_layout == "ROW_MAJOR_LAYOUT" and test_vector["input_a_dtype"] == ttnn.bfloat8_b: + return True, "bfloat8_b is only supported on tiled layout" + + 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 mesh_device_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_spec, + input_a_dtype, + *, + device, +) -> list: + data_seed = random.randint(0, 20000000) + torch.manual_seed(data_seed) + + input_shape, sharding_strategy, shard_orientation, tensor_hw_as_shard_shape, input_layout = parse_sharding_spec( + input_spec + ) + + # print( + # f"X {X} Y {Y} input_shape {input_shape} {input_a_dtype} {input_layout} {sharding_strategy} {shard_orientation} tensor_hw_as_shard_shape {tensor_hw_as_shard_shape}" + # ) + + if input_layout == ttnn.ROW_MAJOR_LAYOUT: + input_shape = sanitize_shape_rm(input_shape) + + torch_input_tensor_a = gen_rand_inf(input_shape, low=-100, high=100) + torch_output_tensor = torch.isfinite(torch_input_tensor_a) + + sharded_config = ttnn.create_sharded_memory_config( + shape=input_shape, + core_grid=ttnn.CoreGrid(y=Y, x=X), + strategy=sharding_strategy, + orientation=shard_orientation, + use_height_and_width_as_shard_shape=tensor_hw_as_shard_shape, + ) + + input_tensor_a = ttnn.from_torch( + torch_input_tensor_a, + dtype=input_a_dtype, + layout=input_layout, + device=device, + memory_config=sharded_config, + ) + + start_time = start_measuring_time() + output_tensor = ttnn.isfinite(input_tensor_a, memory_config=sharded_config) + e2e_perf = stop_measuring_time(start_time) + output_tensor = ttnn.to_torch(output_tensor) + + pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) + # print(pcc) + return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] + + +# Run sweeps locally +# from tests.sweep_framework.framework.permutations import * + +# start_time = start_measuring_time() +# for suite in parameters.keys(): +# device_id = 0 +# device = ttnn.open_device(device_id=device_id) +# suite_vectors = list(permutations(parameters[suite])) +# print(len(suite_vectors)) +# for vector in suite_vectors: +# invalidate_res = invalidate_vector(vector) +# if invalidate_res[0]: +# print(f"Invalidated: {invalidate_res[1]}") +# continue +# try: +# passed, _ = run(**vector, device=device) +# # if passed[0] != True: +# # print(passed) +# except Exception as e: +# print(e) + +# # break + +# ttnn.close_device(device) + +# e2e_perf = stop_measuring_time(start_time) +# print(f"time {e2e_perf / 1000000000}s") From 3946492d33a1a8f5e34c70f5eb3445ff815a590a Mon Sep 17 00:00:00 2001 From: ngrujic Date: Fri, 22 Nov 2024 10:54:58 +0000 Subject: [PATCH 05/15] #11512: Add license header to a file --- tests/sweep_framework/sweep_utils/sharding_utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/sweep_framework/sweep_utils/sharding_utils.py b/tests/sweep_framework/sweep_utils/sharding_utils.py index 402cf44ca93..22979144c22 100644 --- a/tests/sweep_framework/sweep_utils/sharding_utils.py +++ b/tests/sweep_framework/sweep_utils/sharding_utils.py @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. + +# SPDX-License-Identifier: Apache-2.0 + import ttnn import itertools import random From e48f946e74683fd03b95d9355075e10f3b034941 Mon Sep 17 00:00:00 2001 From: ngrujic Date: Mon, 25 Nov 2024 11:00:28 +0000 Subject: [PATCH 06/15] #11512: Add sweeps for lgamma, logit, mish, and multigammaln sharded --- .github/workflows/ttnn-run-sweeps.yaml | 12 +- .../sweep_utils/sharding_utils.py | 9 +- .../eltwise/unary/{ => lgamma}/lgamma.py | 0 .../eltwise/unary/lgamma/lgamma_sharded.py | 137 +++++++++++++++++ .../sweeps/eltwise/unary/{ => logit}/logit.py | 0 .../eltwise/unary/logit/logit_sharded.py | 139 ++++++++++++++++++ .../sweeps/eltwise/unary/{ => mish}/mish.py | 0 .../sweeps/eltwise/unary/mish/mish_sharded.py | 139 ++++++++++++++++++ .../unary/{ => multigammaln}/multigammaln.py | 0 9 files changed, 428 insertions(+), 8 deletions(-) rename tests/sweep_framework/sweeps/eltwise/unary/{ => lgamma}/lgamma.py (100%) create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/lgamma/lgamma_sharded.py rename tests/sweep_framework/sweeps/eltwise/unary/{ => logit}/logit.py (100%) create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/logit/logit_sharded.py rename tests/sweep_framework/sweeps/eltwise/unary/{ => mish}/mish.py (100%) create mode 100644 tests/sweep_framework/sweeps/eltwise/unary/mish/mish_sharded.py rename tests/sweep_framework/sweeps/eltwise/unary/{ => multigammaln}/multigammaln.py (100%) diff --git a/.github/workflows/ttnn-run-sweeps.yaml b/.github/workflows/ttnn-run-sweeps.yaml index 442348e8e42..156b2859b71 100644 --- a/.github/workflows/ttnn-run-sweeps.yaml +++ b/.github/workflows/ttnn-run-sweeps.yaml @@ -172,10 +172,14 @@ on: - eltwise.binary_complex.add_bw.add_bw - eltwise.binary_complex.sub_bw.sub_bw - eltwise.binary_complex.mul_bw.mul_bw - - eltwise.unary.lgamma - - eltwise.unary.logit - - eltwise.unary.mish - - eltwise.unary.multigammaln + - eltwise.unary.lgamma.lgamma + - eltwise.unary.lgamma.lgamma_sharded + - eltwise.unary.logit.logit + - eltwise.unary.logit.logit_sharded + - eltwise.unary.mish.mish + - eltwise.unary.mish.mish_sharded + - eltwise.unary.multigammaln.multigammaln + - eltwise.unary.multigammaln.multigammaln_sharded - eltwise.unary.isfinite.isfinite - eltwise.unary.isfinite.isfinite_sharded - eltwise.unary.isinf.isinf diff --git a/tests/sweep_framework/sweep_utils/sharding_utils.py b/tests/sweep_framework/sweep_utils/sharding_utils.py index 22979144c22..c17a70118ea 100644 --- a/tests/sweep_framework/sweep_utils/sharding_utils.py +++ b/tests/sweep_framework/sweep_utils/sharding_utils.py @@ -56,14 +56,15 @@ def gen_sharded_spec_unary(num_shapes, y, x, max_tensor_size=4 * 1024 * 1024): elif sharding_strategy == "BLOCK": min_shard_size_y = 32 * y min_shard_size_x = 32 * x - mul_x = random.randint(1, 10) - mul_y = random.randint(1, 64 // mul_x) input_shape = random.choice( - _gen_reshape_args_from_volume(mul_y * min_shard_size_y, step=1, out_dims=rank - 1) + _gen_reshape_args_from_volume( + max_tensor_size // (min_shard_size_x * min_shard_size_y), step=1, out_dims=rank + ) ) input_shape = list(input_shape["reshape_dims"]) - input_shape.append(mul_x * min_shard_size_x) + input_shape[-1] *= min_shard_size_y + input_shape[-2] *= min_shard_size_x elif sharding_strategy == "WIDTH" or sharding_strategy == "HEIGHT": # if shard_width % total_cores != 0: raise RuntimeError("Invalid sharding core_grid") diff --git a/tests/sweep_framework/sweeps/eltwise/unary/lgamma.py b/tests/sweep_framework/sweeps/eltwise/unary/lgamma/lgamma.py similarity index 100% rename from tests/sweep_framework/sweeps/eltwise/unary/lgamma.py rename to tests/sweep_framework/sweeps/eltwise/unary/lgamma/lgamma.py diff --git a/tests/sweep_framework/sweeps/eltwise/unary/lgamma/lgamma_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/lgamma/lgamma_sharded.py new file mode 100644 index 00000000000..9966e3e0220 --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/lgamma/lgamma_sharded.py @@ -0,0 +1,137 @@ +# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. + +# SPDX-License-Identifier: Apache-2.0 + +from typing import Optional, Tuple +from functools import partial + +import json +import torch +import random +import ttnn +import math +from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm, get_device_grid_size +from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_rand_inf + +from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time +from models.utility_functions import torch_random + +# Override the default timeout in seconds for hang detection. +TIMEOUT = 120 +Y, X = get_device_grid_size() + +random.seed(0) + + +# Parameters provided to the test vector generator are defined here. +# They are defined as dict-type suites that contain the arguments to the run function as keys, and lists of possible inputs as values. +# Each suite has a key name (in this case "suite_1" and "suite_2") which will associate the test vectors to this specific suite of inputs. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_spec": gen_sharded_spec_unary(16, Y, X, max_tensor_size=2 * 1024 * 1024), + "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], + }, +} + + +# 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]]: + input_shape, sharding_strategy, _, _, input_layout = test_vector["input_spec"].values() + pre_sharded_height = math.prod(input_shape[:-1]) + pre_sharded_width = input_shape[-1] + + if input_layout == "ROW_MAJOR_LAYOUT": + return True, "Input to eltwise binary must be tilized" + + if input_layout == "ROW_MAJOR_LAYOUT" and test_vector["input_a_dtype"] == ttnn.bfloat8_b: + return True, "bfloat8_b is only supported on tiled layout" + + 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 mesh_device_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_spec, + input_a_dtype, + *, + device, +) -> list: + data_seed = random.randint(0, 20000000) + torch.manual_seed(data_seed) + + input_shape, sharding_strategy, shard_orientation, tensor_hw_as_shard_shape, input_layout = parse_sharding_spec( + input_spec + ) + + # print( + # f"X {X} Y {Y} input_shape {input_shape} {input_a_dtype} {input_layout} {sharding_strategy} {shard_orientation} tensor_hw_as_shard_shape {tensor_hw_as_shard_shape}" + # ) + + if input_layout == ttnn.ROW_MAJOR_LAYOUT: + input_shape = sanitize_shape_rm(input_shape) + + torch_input_tensor_a = gen_func_with_cast_tt( + partial(torch_random, low=-100, high=100, dtype=torch.float32), input_a_dtype + )(input_shape) + torch_output_tensor = torch.lgamma(torch_input_tensor_a) + + sharded_config = ttnn.create_sharded_memory_config( + shape=input_shape, + core_grid=ttnn.CoreGrid(y=Y, x=X), + strategy=sharding_strategy, + orientation=shard_orientation, + use_height_and_width_as_shard_shape=tensor_hw_as_shard_shape, + ) + + input_tensor_a = ttnn.from_torch( + torch_input_tensor_a, + dtype=input_a_dtype, + layout=input_layout, + device=device, + memory_config=sharded_config, + ) + + start_time = start_measuring_time() + output_tensor = ttnn.lgamma(input_tensor_a, memory_config=sharded_config) + e2e_perf = stop_measuring_time(start_time) + output_tensor = ttnn.to_torch(output_tensor) + + pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) + # print(pcc) + return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] + + +# Run sweeps locally +# from tests.sweep_framework.framework.permutations import * + +# start_time = start_measuring_time() +# for suite in parameters.keys(): +# device_id = 0 +# device = ttnn.open_device(device_id=device_id) +# suite_vectors = list(permutations(parameters[suite])) +# print(len(suite_vectors)) +# for vector in suite_vectors: +# invalidate_res = invalidate_vector(vector) +# if invalidate_res[0]: +# print(f"Invalidated: {invalidate_res[1]}") +# continue +# try: +# passed, _ = run(**vector, device=device) +# # if passed[0] != True: +# # print(passed) +# except Exception as e: +# print(e) + +# # break + +# ttnn.close_device(device) + +# e2e_perf = stop_measuring_time(start_time) +# print(f"time {e2e_perf / 1000000000}s") diff --git a/tests/sweep_framework/sweeps/eltwise/unary/logit.py b/tests/sweep_framework/sweeps/eltwise/unary/logit/logit.py similarity index 100% rename from tests/sweep_framework/sweeps/eltwise/unary/logit.py rename to tests/sweep_framework/sweeps/eltwise/unary/logit/logit.py diff --git a/tests/sweep_framework/sweeps/eltwise/unary/logit/logit_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/logit/logit_sharded.py new file mode 100644 index 00000000000..a8eb2e4be74 --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/logit/logit_sharded.py @@ -0,0 +1,139 @@ +# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. + +# SPDX-License-Identifier: Apache-2.0 + +from typing import Optional, Tuple +from functools import partial + +import json +import torch +import random +import ttnn +import math +from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm, get_device_grid_size +from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_rand_inf, gen_func_with_cast_tt + +from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time +from models.utility_functions import torch_random + +# Override the default timeout in seconds for hang detection. +TIMEOUT = 120 +Y, X = get_device_grid_size() + +random.seed(0) + + +# Parameters provided to the test vector generator are defined here. +# They are defined as dict-type suites that contain the arguments to the run function as keys, and lists of possible inputs as values. +# Each suite has a key name (in this case "suite_1" and "suite_2") which will associate the test vectors to this specific suite of inputs. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_spec": gen_sharded_spec_unary(16, Y, X, max_tensor_size=1 * 1024 * 1024), + "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], + "eps": [0, 10e-6, 10e-4, 10e-2, 10e-1], + }, +} + + +# 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]]: + input_shape, sharding_strategy, _, _, input_layout = test_vector["input_spec"].values() + pre_sharded_height = math.prod(input_shape[:-1]) + pre_sharded_width = input_shape[-1] + + if input_layout == "ROW_MAJOR_LAYOUT": + return True, "Input to eltwise binary must be tilized" + + if input_layout == "ROW_MAJOR_LAYOUT" and test_vector["input_a_dtype"] == ttnn.bfloat8_b: + return True, "bfloat8_b is only supported on tiled layout" + + 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 mesh_device_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_spec, + input_a_dtype, + eps, + *, + device, +) -> list: + data_seed = random.randint(0, 20000000) + torch.manual_seed(data_seed) + + input_shape, sharding_strategy, shard_orientation, tensor_hw_as_shard_shape, input_layout = parse_sharding_spec( + input_spec + ) + + print( + f"X {X} Y {Y} input_shape {input_shape} {input_a_dtype} {input_layout} {sharding_strategy} {shard_orientation} tensor_hw_as_shard_shape {tensor_hw_as_shard_shape}" + ) + + if input_layout == ttnn.ROW_MAJOR_LAYOUT: + input_shape = sanitize_shape_rm(input_shape) + + torch_input_tensor_a = gen_func_with_cast_tt( + partial(torch_random, low=-100, high=100, dtype=torch.float32), input_a_dtype + )(input_shape) + torch_output_tensor = torch.logit(torch_input_tensor_a, eps) + + sharded_config = ttnn.create_sharded_memory_config( + shape=input_shape, + core_grid=ttnn.CoreGrid(y=Y, x=X), + strategy=sharding_strategy, + orientation=shard_orientation, + use_height_and_width_as_shard_shape=tensor_hw_as_shard_shape, + ) + + input_tensor_a = ttnn.from_torch( + torch_input_tensor_a, + dtype=input_a_dtype, + layout=input_layout, + device=device, + memory_config=sharded_config, + ) + + start_time = start_measuring_time() + output_tensor = ttnn.logit(input_tensor_a, eps=eps, memory_config=sharded_config) + e2e_perf = stop_measuring_time(start_time) + output_tensor = ttnn.to_torch(output_tensor) + + pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) + print(pcc) + return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] + + +# Run sweeps locally +from tests.sweep_framework.framework.permutations import * + +start_time = start_measuring_time() +for suite in parameters.keys(): + device_id = 0 + device = ttnn.open_device(device_id=device_id) + suite_vectors = list(permutations(parameters[suite])) + print(len(suite_vectors)) + for vector in suite_vectors: + invalidate_res = invalidate_vector(vector) + if invalidate_res[0]: + print(f"Invalidated: {invalidate_res[1]}") + continue + try: + passed, _ = run(**vector, device=device) + # if passed[0] != True: + # print(passed) + except Exception as e: + print(e) + + # break + + ttnn.close_device(device) + +e2e_perf = stop_measuring_time(start_time) +print(f"time {e2e_perf / 1000000000}s") diff --git a/tests/sweep_framework/sweeps/eltwise/unary/mish.py b/tests/sweep_framework/sweeps/eltwise/unary/mish/mish.py similarity index 100% rename from tests/sweep_framework/sweeps/eltwise/unary/mish.py rename to tests/sweep_framework/sweeps/eltwise/unary/mish/mish.py diff --git a/tests/sweep_framework/sweeps/eltwise/unary/mish/mish_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/mish/mish_sharded.py new file mode 100644 index 00000000000..727a982133b --- /dev/null +++ b/tests/sweep_framework/sweeps/eltwise/unary/mish/mish_sharded.py @@ -0,0 +1,139 @@ +# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. + +# SPDX-License-Identifier: Apache-2.0 + +from typing import Optional, Tuple +from functools import partial + +import json +import torch +import random +import ttnn +import math +from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm, get_device_grid_size +from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_rand_inf, gen_func_with_cast_tt + +from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time +from models.utility_functions import torch_random + +# Override the default timeout in seconds for hang detection. +TIMEOUT = 120 +Y, X = get_device_grid_size() + +random.seed(0) + + +# Parameters provided to the test vector generator are defined here. +# They are defined as dict-type suites that contain the arguments to the run function as keys, and lists of possible inputs as values. +# Each suite has a key name (in this case "suite_1" and "suite_2") which will associate the test vectors to this specific suite of inputs. +# Developers can create their own generator functions and pass them to the parameters as inputs. +parameters = { + "nightly": { + "input_spec": gen_sharded_spec_unary(16, Y, X), + "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], + }, +} + + +# 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]]: + input_shape, sharding_strategy, _, _, input_layout = test_vector["input_spec"].values() + pre_sharded_height = math.prod(input_shape[:-1]) + pre_sharded_width = input_shape[-1] + + if input_layout == "ROW_MAJOR_LAYOUT": + return True, "Input to eltwise binary must be tilized" + + if input_layout == "ROW_MAJOR_LAYOUT" and test_vector["input_a_dtype"] == ttnn.bfloat8_b: + return True, "bfloat8_b is only supported on tiled layout" + + 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 mesh_device_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_spec, + input_a_dtype, + *, + device, +) -> list: + data_seed = random.randint(0, 20000000) + torch.manual_seed(data_seed) + + input_shape, sharding_strategy, shard_orientation, tensor_hw_as_shard_shape, input_layout = parse_sharding_spec( + input_spec + ) + + print( + f"X {X} Y {Y} input_shape {input_shape} {input_a_dtype} {input_layout} {sharding_strategy} {shard_orientation} tensor_hw_as_shard_shape {tensor_hw_as_shard_shape}" + ) + + if input_layout == ttnn.ROW_MAJOR_LAYOUT: + input_shape = sanitize_shape_rm(input_shape) + + torch_input_tensor_a = gen_func_with_cast_tt( + partial(torch_random, low=-100, high=100, dtype=torch.float32), input_a_dtype + )(input_shape) + + golden_function = ttnn.get_golden_function(ttnn.mish) + torch_output_tensor = golden_function(torch_input_tensor_a) + + sharded_config = ttnn.create_sharded_memory_config( + shape=input_shape, + core_grid=ttnn.CoreGrid(y=Y, x=X), + strategy=sharding_strategy, + orientation=shard_orientation, + use_height_and_width_as_shard_shape=tensor_hw_as_shard_shape, + ) + + input_tensor_a = ttnn.from_torch( + torch_input_tensor_a, + dtype=input_a_dtype, + layout=input_layout, + device=device, + memory_config=sharded_config, + ) + + start_time = start_measuring_time() + output_tensor = ttnn.mish(input_tensor_a, memory_config=sharded_config) + e2e_perf = stop_measuring_time(start_time) + output_tensor = ttnn.to_torch(output_tensor) + + pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) + print(pcc) + return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] + + +# Run sweeps locally +from tests.sweep_framework.framework.permutations import * + +start_time = start_measuring_time() +for suite in parameters.keys(): + device_id = 0 + device = ttnn.open_device(device_id=device_id) + suite_vectors = list(permutations(parameters[suite])) + print(len(suite_vectors)) + for vector in suite_vectors: + invalidate_res = invalidate_vector(vector) + if invalidate_res[0]: + print(f"Invalidated: {invalidate_res[1]}") + continue + try: + passed, _ = run(**vector, device=device) + # if passed[0] != True: + # print(passed) + except Exception as e: + print(e) + + # break + + ttnn.close_device(device) + +e2e_perf = stop_measuring_time(start_time) +print(f"time {e2e_perf / 1000000000}s") diff --git a/tests/sweep_framework/sweeps/eltwise/unary/multigammaln.py b/tests/sweep_framework/sweeps/eltwise/unary/multigammaln/multigammaln.py similarity index 100% rename from tests/sweep_framework/sweeps/eltwise/unary/multigammaln.py rename to tests/sweep_framework/sweeps/eltwise/unary/multigammaln/multigammaln.py From 587bea845b9987a701fac63689e36cda21543654 Mon Sep 17 00:00:00 2001 From: ngrujic Date: Mon, 25 Nov 2024 15:09:33 +0000 Subject: [PATCH 07/15] #11512: Fix ttnn-run-sweeps.yaml --- .github/workflows/ttnn-run-sweeps.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ttnn-run-sweeps.yaml b/.github/workflows/ttnn-run-sweeps.yaml index 156b2859b71..558362894d3 100644 --- a/.github/workflows/ttnn-run-sweeps.yaml +++ b/.github/workflows/ttnn-run-sweeps.yaml @@ -179,7 +179,6 @@ on: - eltwise.unary.mish.mish - eltwise.unary.mish.mish_sharded - eltwise.unary.multigammaln.multigammaln - - eltwise.unary.multigammaln.multigammaln_sharded - eltwise.unary.isfinite.isfinite - eltwise.unary.isfinite.isfinite_sharded - eltwise.unary.isinf.isinf From 8e343328ea2f441ae671f21865a70125de3f1fb1 Mon Sep 17 00:00:00 2001 From: ngrujic Date: Wed, 27 Nov 2024 10:32:58 +0000 Subject: [PATCH 08/15] #11512: Add unit test for lgamma sharded --- .../sweep_utils/sharding_utils.py | 13 +- .../eltwise/unary/lgamma/lgamma_sharded.py | 9 +- .../test_eltwise_isfinite_sharded_segfault.py | 4 +- .../wormhole/test_eltwise_lgamma_sharded.py | 127 ++++++++++++++++++ 4 files changed, 141 insertions(+), 12 deletions(-) create mode 100644 tests/ttnn/python_api_testing/non_working_unit_tests/wormhole/test_eltwise_lgamma_sharded.py diff --git a/tests/sweep_framework/sweep_utils/sharding_utils.py b/tests/sweep_framework/sweep_utils/sharding_utils.py index c17a70118ea..0d38b4836c0 100644 --- a/tests/sweep_framework/sweep_utils/sharding_utils.py +++ b/tests/sweep_framework/sweep_utils/sharding_utils.py @@ -8,14 +8,16 @@ from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import _gen_reshape_args_from_volume -def gen_sharded_spec_unary(num_shapes, y, x, max_tensor_size=4 * 1024 * 1024): +def gen_sharded_spec_unary( + num_shapes, y, x, max_tensor_size=4 * 1024 * 1024, layouts=["TILE_LAYOUT", "ROW_MAJOR_LAYOUT"] +): # ["BLOCK", "WIDTH", "HEIGHT", "tensor_wh"] sharding_strategy_list = ["BLOCK", "WIDTH", "HEIGHT", "tensor_wh"] shard_orientation_list = ["COL_MAJOR", "ROW_MAJOR"] spec_list = [] for sharding_strategy, shard_orientation, rank, layout in itertools.product( - sharding_strategy_list, shard_orientation_list, [4, 3, 2], ["TILE_LAYOUT", "ROW_MAJOR_LAYOUT"] + sharding_strategy_list, shard_orientation_list, [4, 3, 2], layouts ): if sharding_strategy == "tensor_wh": tensor_hw_as_shard_shape = True @@ -57,11 +59,8 @@ def gen_sharded_spec_unary(num_shapes, y, x, max_tensor_size=4 * 1024 * 1024): min_shard_size_y = 32 * y min_shard_size_x = 32 * x - input_shape = random.choice( - _gen_reshape_args_from_volume( - max_tensor_size // (min_shard_size_x * min_shard_size_y), step=1, out_dims=rank - ) - ) + rest_volume = random.randint(1, max_tensor_size // (min_shard_size_x * min_shard_size_y)) + input_shape = random.choice(_gen_reshape_args_from_volume(rest_volume, step=1, out_dims=rank)) input_shape = list(input_shape["reshape_dims"]) input_shape[-1] *= min_shard_size_y input_shape[-2] *= min_shard_size_x diff --git a/tests/sweep_framework/sweeps/eltwise/unary/lgamma/lgamma_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/lgamma/lgamma_sharded.py index 9966e3e0220..8f893398239 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/lgamma/lgamma_sharded.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/lgamma/lgamma_sharded.py @@ -12,7 +12,7 @@ import math from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm, get_device_grid_size from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec -from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_rand_inf +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time from models.utility_functions import torch_random @@ -30,8 +30,8 @@ # Developers can create their own generator functions and pass them to the parameters as inputs. parameters = { "nightly": { - "input_spec": gen_sharded_spec_unary(16, Y, X, max_tensor_size=2 * 1024 * 1024), - "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], + "input_spec": gen_sharded_spec_unary(16, Y, X, max_tensor_size=2 * 1024 * 1024, layouts=["TILE_LAYOUT"]), + "input_a_dtype": [ttnn.bfloat16], }, } @@ -80,7 +80,8 @@ def run( torch_input_tensor_a = gen_func_with_cast_tt( partial(torch_random, low=-100, high=100, dtype=torch.float32), input_a_dtype )(input_shape) - torch_output_tensor = torch.lgamma(torch_input_tensor_a) + golden_function = ttnn.get_golden_function(ttnn.lgamma) + torch_output_tensor = golden_function(torch_input_tensor_a) sharded_config = ttnn.create_sharded_memory_config( shape=input_shape, diff --git a/tests/ttnn/python_api_testing/non_working_unit_tests/wormhole/test_eltwise_isfinite_sharded_segfault.py b/tests/ttnn/python_api_testing/non_working_unit_tests/wormhole/test_eltwise_isfinite_sharded_segfault.py index b4447fd5baa..8c2a039593b 100644 --- a/tests/ttnn/python_api_testing/non_working_unit_tests/wormhole/test_eltwise_isfinite_sharded_segfault.py +++ b/tests/ttnn/python_api_testing/non_working_unit_tests/wormhole/test_eltwise_isfinite_sharded_segfault.py @@ -46,6 +46,8 @@ def run_tests( use_height_and_width_as_shard_shape=tensor_hw_as_shard_shape, ) + # print(f"sharded_config.shard_spec {sharded_config.shard_spec}") + input_tensor_a = ttnn.from_torch( torch_input_tensor_a, dtype=dtype, @@ -63,7 +65,7 @@ def run_tests( test_sweep_args = [ ( - (1, 1, 25088, 2), + (1, 1, 1024, 32), ttnn.bfloat16, ttnn.ROW_MAJOR_LAYOUT, ttnn.ShardStrategy.BLOCK, diff --git a/tests/ttnn/python_api_testing/non_working_unit_tests/wormhole/test_eltwise_lgamma_sharded.py b/tests/ttnn/python_api_testing/non_working_unit_tests/wormhole/test_eltwise_lgamma_sharded.py new file mode 100644 index 00000000000..46cd91c2ebf --- /dev/null +++ b/tests/ttnn/python_api_testing/non_working_unit_tests/wormhole/test_eltwise_lgamma_sharded.py @@ -0,0 +1,127 @@ +# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. + +# SPDX-License-Identifier: Apache-2.0 + +from loguru import logger +import random +import pytest +import torch +import ttnn +from tests.ttnn.utils_for_testing import assert_with_pcc, check_with_pcc + +Y, X = (8, 8) + + +def run_tests( + input_shape, + dtype, + dlayout, + sharding_strategy, + shard_orientation, + tensor_hw_as_shard_shape, + device, +): + random.seed(0) + data_seed = random.randint(0, 20000000) + torch.manual_seed(data_seed) + + torch_input_tensor_a = torch.Tensor(size=input_shape).uniform_(-100, 100).to(torch.bfloat16) + torch_output_tensor = torch.lgamma(torch_input_tensor_a) + + sharded_config = ttnn.create_sharded_memory_config( + shape=input_shape, + core_grid=ttnn.CoreGrid(y=Y, x=X), + strategy=sharding_strategy, + orientation=shard_orientation, + use_height_and_width_as_shard_shape=tensor_hw_as_shard_shape, + ) + + input_tensor_a = ttnn.from_torch( + torch_input_tensor_a, + dtype=dtype, + layout=dlayout, + device=device, + memory_config=sharded_config, + ) + + output_tensor = ttnn.lgamma(input_tensor_a, memory_config=sharded_config) + output_tensor = ttnn.to_torch(output_tensor) + + [passed, message] = check_with_pcc(torch_output_tensor, output_tensor, 0.999) + assert passed, f"PCC={message}" + + +test_sweep_args = [ + ( + (16, 1, 256, 1024), + ttnn.bfloat16, + ttnn.TILE_LAYOUT, + ttnn.ShardStrategy.BLOCK, + ttnn.ShardOrientation.COL_MAJOR, + False, + ), + ( + (2, 32, 256, 256), + ttnn.bfloat16, + ttnn.TILE_LAYOUT, + ttnn.ShardStrategy.BLOCK, + ttnn.ShardOrientation.COL_MAJOR, + False, + ), + ( + (2, 5, 256, 1280), + ttnn.bfloat16, + ttnn.TILE_LAYOUT, + ttnn.ShardStrategy.BLOCK, + ttnn.ShardOrientation.COL_MAJOR, + False, + ), + ( + (16, 1, 256, 1024), + ttnn.bfloat16, + ttnn.TILE_LAYOUT, + ttnn.ShardStrategy.BLOCK, + ttnn.ShardOrientation.ROW_MAJOR, + False, + ), + ( + (2, 32, 256, 256), + ttnn.bfloat16, + ttnn.TILE_LAYOUT, + ttnn.ShardStrategy.BLOCK, + ttnn.ShardOrientation.ROW_MAJOR, + False, + ), + ( + (2, 5, 256, 1280), + ttnn.bfloat16, + ttnn.TILE_LAYOUT, + ttnn.ShardStrategy.BLOCK, + ttnn.ShardOrientation.ROW_MAJOR, + False, + ), + ( + (7936, 256), + ttnn.bfloat16, + ttnn.TILE_LAYOUT, + ttnn.ShardStrategy.BLOCK, + ttnn.ShardOrientation.ROW_MAJOR, + False, + ), +] + + +@pytest.mark.parametrize( + "input_shape, dtype, dlayout, sharding_strategy, shard_orientation, hw_as_shard_shape", + (test_sweep_args), +) +def test_eltwise_lgamma(input_shape, dtype, dlayout, sharding_strategy, shard_orientation, hw_as_shard_shape, device): + run_tests( + input_shape, + dtype, + dlayout, + sharding_strategy, + shard_orientation, + hw_as_shard_shape, + device, + ) From c5d6e629e2bbee04590cf0816503efc7061438c9 Mon Sep 17 00:00:00 2001 From: ngrujic Date: Wed, 27 Nov 2024 11:00:30 +0000 Subject: [PATCH 09/15] #11512: Add unit test for lgamma sharded --- .../wormhole/test_eltwise_lgamma_sharded.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/ttnn/python_api_testing/non_working_unit_tests/wormhole/test_eltwise_lgamma_sharded.py b/tests/ttnn/python_api_testing/non_working_unit_tests/wormhole/test_eltwise_lgamma_sharded.py index 46cd91c2ebf..cad731fec9c 100644 --- a/tests/ttnn/python_api_testing/non_working_unit_tests/wormhole/test_eltwise_lgamma_sharded.py +++ b/tests/ttnn/python_api_testing/non_working_unit_tests/wormhole/test_eltwise_lgamma_sharded.py @@ -108,6 +108,46 @@ def run_tests( ttnn.ShardOrientation.ROW_MAJOR, False, ), + ( + (5, 1, 32, 10240), + ttnn.bfloat16, + ttnn.TILE_LAYOUT, + ttnn.ShardStrategy.WIDTH, + ttnn.ShardOrientation.COL_MAJOR, + False, + ), + ( + (2, 1, 352, 2048), + ttnn.bfloat16, + ttnn.TILE_LAYOUT, + ttnn.ShardStrategy.WIDTH, + ttnn.ShardOrientation.ROW_MAJOR, + False, + ), + ( + (5, 1, 32, 10240), + ttnn.bfloat16, + ttnn.TILE_LAYOUT, + ttnn.ShardStrategy.HEIGHT, + ttnn.ShardOrientation.COL_MAJOR, + False, + ), + ( + (2, 1, 352, 2048), + ttnn.bfloat16, + ttnn.TILE_LAYOUT, + ttnn.ShardStrategy.HEIGHT, + ttnn.ShardOrientation.ROW_MAJOR, + False, + ), + ( + (5, 1, 160, 32), + ttnn.bfloat16, + ttnn.TILE_LAYOUT, + ttnn.ShardStrategy.HEIGHT, + ttnn.ShardOrientation.COL_MAJOR, + True, + ), ] From 247e8c6ef14c9b905ec0a982d30681e94e0ebb2e Mon Sep 17 00:00:00 2001 From: ngrujic Date: Wed, 27 Nov 2024 12:02:57 +0000 Subject: [PATCH 10/15] #11512: Add sweep test for logit sharded --- .../sweep_utils/sharding_utils.py | 10 +++-- .../eltwise/unary/logit/logit_sharded.py | 43 +++---------------- 2 files changed, 14 insertions(+), 39 deletions(-) diff --git a/tests/sweep_framework/sweep_utils/sharding_utils.py b/tests/sweep_framework/sweep_utils/sharding_utils.py index 0d38b4836c0..9a8ba2d007e 100644 --- a/tests/sweep_framework/sweep_utils/sharding_utils.py +++ b/tests/sweep_framework/sweep_utils/sharding_utils.py @@ -60,10 +60,14 @@ def gen_sharded_spec_unary( min_shard_size_x = 32 * x rest_volume = random.randint(1, max_tensor_size // (min_shard_size_x * min_shard_size_y)) - input_shape = random.choice(_gen_reshape_args_from_volume(rest_volume, step=1, out_dims=rank)) + physical_shape = random.choice(_gen_reshape_args_from_volume(rest_volume, step=1, out_dims=2)) + physical_shape = list(physical_shape["reshape_dims"]) + physical_shape[1] *= min_shard_size_y + physical_shape[0] *= min_shard_size_x + + input_shape = random.choice(_gen_reshape_args_from_volume(physical_shape[0], step=1, out_dims=rank - 1)) input_shape = list(input_shape["reshape_dims"]) - input_shape[-1] *= min_shard_size_y - input_shape[-2] *= min_shard_size_x + input_shape.append(physical_shape[1]) elif sharding_strategy == "WIDTH" or sharding_strategy == "HEIGHT": # if shard_width % total_cores != 0: raise RuntimeError("Invalid sharding core_grid") diff --git a/tests/sweep_framework/sweeps/eltwise/unary/logit/logit_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/logit/logit_sharded.py index a8eb2e4be74..3b2f46a77f6 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/logit/logit_sharded.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/logit/logit_sharded.py @@ -30,9 +30,9 @@ # Developers can create their own generator functions and pass them to the parameters as inputs. parameters = { "nightly": { - "input_spec": gen_sharded_spec_unary(16, Y, X, max_tensor_size=1 * 1024 * 1024), - "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], - "eps": [0, 10e-6, 10e-4, 10e-2, 10e-1], + "input_spec": gen_sharded_spec_unary(16, Y, X, max_tensor_size=1 * 1024 * 1024, layouts=["TILE_LAYOUT"]), + "input_a_dtype": [ttnn.bfloat16], + "eps": [0.2], # 0, 10e-6, 10e-4, 10e-2, }, } @@ -72,9 +72,9 @@ def run( input_spec ) - print( - f"X {X} Y {Y} input_shape {input_shape} {input_a_dtype} {input_layout} {sharding_strategy} {shard_orientation} tensor_hw_as_shard_shape {tensor_hw_as_shard_shape}" - ) + # print( + # f"X {X} Y {Y} input_shape {input_shape} eps {eps} {input_a_dtype} {input_layout} {sharding_strategy} {shard_orientation} tensor_hw_as_shard_shape {tensor_hw_as_shard_shape}" + # ) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) @@ -106,34 +106,5 @@ def run( output_tensor = ttnn.to_torch(output_tensor) pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) - print(pcc) + # print(pcc) return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] - - -# Run sweeps locally -from tests.sweep_framework.framework.permutations import * - -start_time = start_measuring_time() -for suite in parameters.keys(): - device_id = 0 - device = ttnn.open_device(device_id=device_id) - suite_vectors = list(permutations(parameters[suite])) - print(len(suite_vectors)) - for vector in suite_vectors: - invalidate_res = invalidate_vector(vector) - if invalidate_res[0]: - print(f"Invalidated: {invalidate_res[1]}") - continue - try: - passed, _ = run(**vector, device=device) - # if passed[0] != True: - # print(passed) - except Exception as e: - print(e) - - # break - - ttnn.close_device(device) - -e2e_perf = stop_measuring_time(start_time) -print(f"time {e2e_perf / 1000000000}s") From 008878c7a9966a0310c0ad0c74d0fbf24448835c Mon Sep 17 00:00:00 2001 From: ngrujic Date: Wed, 27 Nov 2024 12:29:31 +0000 Subject: [PATCH 11/15] #11512: Add sweep test for mish sharded --- .../sweeps/eltwise/unary/mish/mish_sharded.py | 39 +++---------------- 1 file changed, 5 insertions(+), 34 deletions(-) diff --git a/tests/sweep_framework/sweeps/eltwise/unary/mish/mish_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/mish/mish_sharded.py index 727a982133b..73febf26908 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/mish/mish_sharded.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/mish/mish_sharded.py @@ -30,7 +30,7 @@ # Developers can create their own generator functions and pass them to the parameters as inputs. parameters = { "nightly": { - "input_spec": gen_sharded_spec_unary(16, Y, X), + "input_spec": gen_sharded_spec_unary(12, Y, X, layouts=["TILE_LAYOUT"]), "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], }, } @@ -70,9 +70,9 @@ def run( input_spec ) - print( - f"X {X} Y {Y} input_shape {input_shape} {input_a_dtype} {input_layout} {sharding_strategy} {shard_orientation} tensor_hw_as_shard_shape {tensor_hw_as_shard_shape}" - ) + # print( + # f"X {X} Y {Y} input_shape {input_shape} {input_a_dtype} {input_layout} {sharding_strategy} {shard_orientation} tensor_hw_as_shard_shape {tensor_hw_as_shard_shape}" + # ) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) @@ -106,34 +106,5 @@ def run( output_tensor = ttnn.to_torch(output_tensor) pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) - print(pcc) + # print(pcc) return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] - - -# Run sweeps locally -from tests.sweep_framework.framework.permutations import * - -start_time = start_measuring_time() -for suite in parameters.keys(): - device_id = 0 - device = ttnn.open_device(device_id=device_id) - suite_vectors = list(permutations(parameters[suite])) - print(len(suite_vectors)) - for vector in suite_vectors: - invalidate_res = invalidate_vector(vector) - if invalidate_res[0]: - print(f"Invalidated: {invalidate_res[1]}") - continue - try: - passed, _ = run(**vector, device=device) - # if passed[0] != True: - # print(passed) - except Exception as e: - print(e) - - # break - - ttnn.close_device(device) - -e2e_perf = stop_measuring_time(start_time) -print(f"time {e2e_perf / 1000000000}s") From 73a07938af1157e539293b59e690464594945eaf Mon Sep 17 00:00:00 2001 From: ngrujic Date: Fri, 29 Nov 2024 09:36:02 +0000 Subject: [PATCH 12/15] #11512: Removed commented code from sweep tests --- .../sweep_utils/sharding_utils.py | 10 +++++ tests/sweep_framework/sweep_utils/utils.py | 11 ----- .../unary/isfinite/isfinite_sharded.py | 13 +++--- .../eltwise/unary/isinf/isinf_sharded.py | 13 +++--- .../eltwise/unary/isnan/isnan_sharded.py | 42 +++--------------- .../unary/isneginf/isneginf_sharded.py | 13 +++--- .../unary/isposinf/isposinf_sharded.py | 42 +++--------------- .../eltwise/unary/lgamma/lgamma_sharded.py | 43 +++---------------- .../eltwise/unary/logit/logit_sharded.py | 15 +++---- .../sweeps/eltwise/unary/mish/mish_sharded.py | 15 +++---- 10 files changed, 61 insertions(+), 156 deletions(-) diff --git a/tests/sweep_framework/sweep_utils/sharding_utils.py b/tests/sweep_framework/sweep_utils/sharding_utils.py index 9a8ba2d007e..89bfde977a7 100644 --- a/tests/sweep_framework/sweep_utils/sharding_utils.py +++ b/tests/sweep_framework/sweep_utils/sharding_utils.py @@ -8,6 +8,16 @@ from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import _gen_reshape_args_from_volume +def get_device_grid_size(): + device_name = os.environ.get("ARCH_NAME", os.environ.get("TT_ARCH_NAME", "default")).lower() + if device_name == "grayskull": + y, x = 9, 12 + else: + y, x = 8, 8 + + return y, x + + def gen_sharded_spec_unary( num_shapes, y, x, max_tensor_size=4 * 1024 * 1024, layouts=["TILE_LAYOUT", "ROW_MAJOR_LAYOUT"] ): diff --git a/tests/sweep_framework/sweep_utils/utils.py b/tests/sweep_framework/sweep_utils/utils.py index f1bf618d661..ed16ca6a68d 100644 --- a/tests/sweep_framework/sweep_utils/utils.py +++ b/tests/sweep_framework/sweep_utils/utils.py @@ -19,17 +19,6 @@ from models.utility_functions import torch_random -def get_device_grid_size(): - device_name = os.environ.get("ARCH_NAME", os.environ.get("TT_ARCH_NAME", "default")).lower() - assert device_name in ["wormhole_b0", "grayskull"] - if device_name == "grayskull": - y, x = 9, 12 - else: - y, x = 8, 8 - - return y, x - - def sanitize_shape_rm(input_shape): if input_shape[-1] % 2 != 0: input_shape[-1] = input_shape[-1] + 1 diff --git a/tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite_sharded.py index 121673c0b63..19b2fb1010a 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite_sharded.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite_sharded.py @@ -10,8 +10,12 @@ import random import ttnn import math -from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm, get_device_grid_size -from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec +from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm +from tests.sweep_framework.sweep_utils.sharding_utils import ( + gen_sharded_spec_unary, + parse_sharding_spec, + get_device_grid_size, +) from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_rand_inf from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time @@ -67,10 +71,6 @@ def run( input_spec ) - # print( - # f"X {X} Y {Y} input_shape {input_shape} {input_a_dtype} {input_layout} {sharding_strategy} {shard_orientation} tensor_hw_as_shard_shape {tensor_hw_as_shard_shape}" - # ) - if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) @@ -99,5 +99,4 @@ def run( output_tensor = ttnn.to_torch(output_tensor) pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) - # print(pcc) return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/unary/isinf/isinf_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/isinf/isinf_sharded.py index 94b80869dc4..5f044619fa1 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/isinf/isinf_sharded.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/isinf/isinf_sharded.py @@ -10,8 +10,12 @@ import random import ttnn import math -from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm, get_device_grid_size -from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec +from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm +from tests.sweep_framework.sweep_utils.sharding_utils import ( + gen_sharded_spec_unary, + parse_sharding_spec, + get_device_grid_size, +) from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_rand_inf from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time @@ -67,10 +71,6 @@ def run( input_spec ) - # print( - # f"X {X} Y {Y} input_shape {input_shape} {input_a_dtype} {input_layout} {sharding_strategy} {shard_orientation} tensor_hw_as_shard_shape {tensor_hw_as_shard_shape}" - # ) - if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) @@ -99,5 +99,4 @@ def run( output_tensor = ttnn.to_torch(output_tensor) pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) - # print(pcc) return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/unary/isnan/isnan_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/isnan/isnan_sharded.py index d86bd84c2c3..4dc0c4f9995 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/isnan/isnan_sharded.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/isnan/isnan_sharded.py @@ -10,8 +10,12 @@ import random import ttnn import math -from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm, get_device_grid_size -from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec +from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm +from tests.sweep_framework.sweep_utils.sharding_utils import ( + gen_sharded_spec_unary, + parse_sharding_spec, + get_device_grid_size, +) from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_rand_inf from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time @@ -67,10 +71,6 @@ def run( input_spec ) - # print( - # f"X {X} Y {Y} input_shape {input_shape} {input_a_dtype} {input_layout} {sharding_strategy} {shard_orientation} tensor_hw_as_shard_shape {tensor_hw_as_shard_shape}" - # ) - if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) @@ -99,34 +99,4 @@ def run( output_tensor = ttnn.to_torch(output_tensor) pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) - # print(pcc) return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] - - -# Run sweeps locally -# from tests.sweep_framework.framework.permutations import * - -# start_time = start_measuring_time() -# for suite in parameters.keys(): -# device_id = 0 -# device = ttnn.open_device(device_id=device_id) -# suite_vectors = list(permutations(parameters[suite])) -# print(len(suite_vectors)) -# for vector in suite_vectors: -# invalidate_res = invalidate_vector(vector) -# if invalidate_res[0]: -# print(f"Invalidated: {invalidate_res[1]}") -# continue -# try: -# passed, _ = run(**vector, device=device) -# # if passed[0] != True: -# # print(passed) -# except Exception as e: -# print(e) - -# # break - -# ttnn.close_device(device) - -# e2e_perf = stop_measuring_time(start_time) -# print(f"time {e2e_perf / 1000000000}s") diff --git a/tests/sweep_framework/sweeps/eltwise/unary/isneginf/isneginf_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/isneginf/isneginf_sharded.py index b8bdb32ef66..a515892c8d0 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/isneginf/isneginf_sharded.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/isneginf/isneginf_sharded.py @@ -10,8 +10,12 @@ import random import ttnn import math -from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm, get_device_grid_size -from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec +from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm +from tests.sweep_framework.sweep_utils.sharding_utils import ( + gen_sharded_spec_unary, + parse_sharding_spec, + get_device_grid_size, +) from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_rand_inf from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time @@ -67,10 +71,6 @@ def run( input_spec ) - # print( - # f"X {X} Y {Y} input_shape {input_shape} {input_a_dtype} {input_layout} {sharding_strategy} {shard_orientation} tensor_hw_as_shard_shape {tensor_hw_as_shard_shape}" - # ) - if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) @@ -99,5 +99,4 @@ def run( output_tensor = ttnn.to_torch(output_tensor) pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) - # print(pcc) return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/unary/isposinf/isposinf_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/isposinf/isposinf_sharded.py index 63bf5a9610d..19b2fb1010a 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/isposinf/isposinf_sharded.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/isposinf/isposinf_sharded.py @@ -10,8 +10,12 @@ import random import ttnn import math -from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm, get_device_grid_size -from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec +from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm +from tests.sweep_framework.sweep_utils.sharding_utils import ( + gen_sharded_spec_unary, + parse_sharding_spec, + get_device_grid_size, +) from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_rand_inf from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time @@ -67,10 +71,6 @@ def run( input_spec ) - # print( - # f"X {X} Y {Y} input_shape {input_shape} {input_a_dtype} {input_layout} {sharding_strategy} {shard_orientation} tensor_hw_as_shard_shape {tensor_hw_as_shard_shape}" - # ) - if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) @@ -99,34 +99,4 @@ def run( output_tensor = ttnn.to_torch(output_tensor) pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) - # print(pcc) return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] - - -# Run sweeps locally -# from tests.sweep_framework.framework.permutations import * - -# start_time = start_measuring_time() -# for suite in parameters.keys(): -# device_id = 0 -# device = ttnn.open_device(device_id=device_id) -# suite_vectors = list(permutations(parameters[suite])) -# print(len(suite_vectors)) -# for vector in suite_vectors: -# invalidate_res = invalidate_vector(vector) -# if invalidate_res[0]: -# print(f"Invalidated: {invalidate_res[1]}") -# continue -# try: -# passed, _ = run(**vector, device=device) -# # if passed[0] != True: -# # print(passed) -# except Exception as e: -# print(e) - -# # break - -# ttnn.close_device(device) - -# e2e_perf = stop_measuring_time(start_time) -# print(f"time {e2e_perf / 1000000000}s") diff --git a/tests/sweep_framework/sweeps/eltwise/unary/lgamma/lgamma_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/lgamma/lgamma_sharded.py index 8f893398239..d6fee58bd87 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/lgamma/lgamma_sharded.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/lgamma/lgamma_sharded.py @@ -10,8 +10,12 @@ import random import ttnn import math -from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm, get_device_grid_size -from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec +from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm +from tests.sweep_framework.sweep_utils.sharding_utils import ( + gen_sharded_spec_unary, + parse_sharding_spec, + get_device_grid_size, +) from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time @@ -19,6 +23,7 @@ # Override the default timeout in seconds for hang detection. TIMEOUT = 120 +# device.compute_with_storage_grid_size() Y, X = get_device_grid_size() random.seed(0) @@ -70,10 +75,6 @@ def run( input_spec ) - # print( - # f"X {X} Y {Y} input_shape {input_shape} {input_a_dtype} {input_layout} {sharding_strategy} {shard_orientation} tensor_hw_as_shard_shape {tensor_hw_as_shard_shape}" - # ) - if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) @@ -105,34 +106,4 @@ def run( output_tensor = ttnn.to_torch(output_tensor) pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) - # print(pcc) return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] - - -# Run sweeps locally -# from tests.sweep_framework.framework.permutations import * - -# start_time = start_measuring_time() -# for suite in parameters.keys(): -# device_id = 0 -# device = ttnn.open_device(device_id=device_id) -# suite_vectors = list(permutations(parameters[suite])) -# print(len(suite_vectors)) -# for vector in suite_vectors: -# invalidate_res = invalidate_vector(vector) -# if invalidate_res[0]: -# print(f"Invalidated: {invalidate_res[1]}") -# continue -# try: -# passed, _ = run(**vector, device=device) -# # if passed[0] != True: -# # print(passed) -# except Exception as e: -# print(e) - -# # break - -# ttnn.close_device(device) - -# e2e_perf = stop_measuring_time(start_time) -# print(f"time {e2e_perf / 1000000000}s") diff --git a/tests/sweep_framework/sweeps/eltwise/unary/logit/logit_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/logit/logit_sharded.py index 3b2f46a77f6..6fe27e6408a 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/logit/logit_sharded.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/logit/logit_sharded.py @@ -10,9 +10,13 @@ import random import ttnn import math -from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm, get_device_grid_size -from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec -from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_rand_inf, gen_func_with_cast_tt +from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm +from tests.sweep_framework.sweep_utils.sharding_utils import ( + gen_sharded_spec_unary, + parse_sharding_spec, + get_device_grid_size, +) +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time from models.utility_functions import torch_random @@ -72,10 +76,6 @@ def run( input_spec ) - # print( - # f"X {X} Y {Y} input_shape {input_shape} eps {eps} {input_a_dtype} {input_layout} {sharding_strategy} {shard_orientation} tensor_hw_as_shard_shape {tensor_hw_as_shard_shape}" - # ) - if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) @@ -106,5 +106,4 @@ def run( output_tensor = ttnn.to_torch(output_tensor) pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) - # print(pcc) return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/unary/mish/mish_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/mish/mish_sharded.py index 73febf26908..bb47efd25ef 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/mish/mish_sharded.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/mish/mish_sharded.py @@ -10,9 +10,13 @@ import random import ttnn import math -from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm, get_device_grid_size -from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec -from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_rand_inf, gen_func_with_cast_tt +from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm +from tests.sweep_framework.sweep_utils.sharding_utils import ( + gen_sharded_spec_unary, + parse_sharding_spec, + get_device_grid_size, +) +from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time from models.utility_functions import torch_random @@ -70,10 +74,6 @@ def run( input_spec ) - # print( - # f"X {X} Y {Y} input_shape {input_shape} {input_a_dtype} {input_layout} {sharding_strategy} {shard_orientation} tensor_hw_as_shard_shape {tensor_hw_as_shard_shape}" - # ) - if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) @@ -106,5 +106,4 @@ def run( output_tensor = ttnn.to_torch(output_tensor) pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) - # print(pcc) return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] From e4ecead0728b00222413b6c843fe46c61a7bac16 Mon Sep 17 00:00:00 2001 From: ngrujic Date: Fri, 29 Nov 2024 09:43:59 +0000 Subject: [PATCH 13/15] #11512: Remove commented code from sweep tests --- tests/sweep_framework/sweep_utils/utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/sweep_framework/sweep_utils/utils.py b/tests/sweep_framework/sweep_utils/utils.py index ed16ca6a68d..6f2199055d8 100644 --- a/tests/sweep_framework/sweep_utils/utils.py +++ b/tests/sweep_framework/sweep_utils/utils.py @@ -3,7 +3,6 @@ # SPDX-License-Identifier: Apache-2.0 -import os import random from loguru import logger from itertools import product From 7e733c0c35dd3b078cdf2a401ebef2515d7a65f8 Mon Sep 17 00:00:00 2001 From: ngrujic Date: Fri, 29 Nov 2024 11:33:02 +0000 Subject: [PATCH 14/15] #11512: Make sharded tests use create_sharded_memory_config_ instead of create_sharded_memory_config --- .../sweep_utils/sharding_utils.py | 21 +++++++++++--- .../unary/isfinite/isfinite_sharded.py | 28 +++++++++--------- .../eltwise/unary/isinf/isinf_sharded.py | 28 +++++++++--------- .../eltwise/unary/isnan/isnan_sharded.py | 28 +++++++++--------- .../unary/isneginf/isneginf_sharded.py | 28 +++++++++--------- .../unary/isposinf/isposinf_sharded.py | 28 +++++++++--------- .../eltwise/unary/lgamma/lgamma_sharded.py | 29 +++++++++---------- .../eltwise/unary/logit/logit_sharded.py | 28 +++++++++--------- .../sweeps/eltwise/unary/mish/mish_sharded.py | 28 +++++++++--------- 9 files changed, 129 insertions(+), 117 deletions(-) diff --git a/tests/sweep_framework/sweep_utils/sharding_utils.py b/tests/sweep_framework/sweep_utils/sharding_utils.py index 89bfde977a7..f98022e8396 100644 --- a/tests/sweep_framework/sweep_utils/sharding_utils.py +++ b/tests/sweep_framework/sweep_utils/sharding_utils.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 +import os import ttnn import itertools import random @@ -18,9 +19,10 @@ def get_device_grid_size(): return y, x -def gen_sharded_spec_unary( - num_shapes, y, x, max_tensor_size=4 * 1024 * 1024, layouts=["TILE_LAYOUT", "ROW_MAJOR_LAYOUT"] -): +def gen_sharded_spec_unary(num_shapes, max_tensor_size=4 * 1024 * 1024, layouts=["TILE_LAYOUT", "ROW_MAJOR_LAYOUT"]): + # device.compute_with_storage_grid_size() + y, x = get_device_grid_size() + # ["BLOCK", "WIDTH", "HEIGHT", "tensor_wh"] sharding_strategy_list = ["BLOCK", "WIDTH", "HEIGHT", "tensor_wh"] shard_orientation_list = ["COL_MAJOR", "ROW_MAJOR"] @@ -118,6 +120,8 @@ def gen_sharded_spec_unary( spec_list.append( { "input_shape": input_shape, + "X": x, + "Y": y, "sharding_strategy": sharding_strategy, "shard_orientation": shard_orientation, "tensor_hw_as_shard_shape": tensor_hw_as_shard_shape, @@ -130,6 +134,8 @@ def gen_sharded_spec_unary( def parse_sharding_spec(input_spec): input_shape = input_spec["input_shape"] + X = input_spec["X"] + Y = input_spec["Y"] sharding_strategy = input_spec["sharding_strategy"] shard_orientation = input_spec["shard_orientation"] tensor_hw_as_shard_shape = input_spec["tensor_hw_as_shard_shape"] @@ -152,4 +158,11 @@ def parse_sharding_spec(input_spec): else: input_layout = ttnn.ROW_MAJOR_LAYOUT - return input_shape, sharding_strategy, shard_orientation, tensor_hw_as_shard_shape, input_layout + return ( + input_shape, + ttnn.CoreGrid(y=Y, x=X), + sharding_strategy, + shard_orientation, + tensor_hw_as_shard_shape, + input_layout, + ) diff --git a/tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite_sharded.py index 19b2fb1010a..944a8961a34 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite_sharded.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/isfinite/isfinite_sharded.py @@ -11,11 +11,7 @@ import ttnn import math from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm -from tests.sweep_framework.sweep_utils.sharding_utils import ( - gen_sharded_spec_unary, - parse_sharding_spec, - get_device_grid_size, -) +from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_rand_inf from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time @@ -23,7 +19,6 @@ # Override the default timeout in seconds for hang detection. TIMEOUT = 120 -Y, X = get_device_grid_size() random.seed(0) @@ -34,7 +29,7 @@ # Developers can create their own generator functions and pass them to the parameters as inputs. parameters = { "nightly": { - "input_spec": gen_sharded_spec_unary(16, Y, X), + "input_spec": gen_sharded_spec_unary(16, layouts=["TILE_LAYOUT"]), "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], }, } @@ -44,7 +39,7 @@ # 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]]: - input_shape, sharding_strategy, _, _, input_layout = test_vector["input_spec"].values() + input_shape, X, Y, sharding_strategy, _, _, input_layout = test_vector["input_spec"].values() pre_sharded_height = math.prod(input_shape[:-1]) pre_sharded_width = input_shape[-1] @@ -67,9 +62,14 @@ def run( data_seed = random.randint(0, 20000000) torch.manual_seed(data_seed) - input_shape, sharding_strategy, shard_orientation, tensor_hw_as_shard_shape, input_layout = parse_sharding_spec( - input_spec - ) + ( + input_shape, + core_grid, + sharding_strategy, + shard_orientation, + tensor_hw_as_shard_shape, + input_layout, + ) = parse_sharding_spec(input_spec) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) @@ -77,9 +77,9 @@ def run( torch_input_tensor_a = gen_rand_inf(input_shape, low=-100, high=100) torch_output_tensor = torch.isfinite(torch_input_tensor_a) - sharded_config = ttnn.create_sharded_memory_config( + sharded_config = ttnn.create_sharded_memory_config_( shape=input_shape, - core_grid=ttnn.CoreGrid(y=Y, x=X), + core_grid=core_grid, strategy=sharding_strategy, orientation=shard_orientation, use_height_and_width_as_shard_shape=tensor_hw_as_shard_shape, @@ -99,4 +99,4 @@ def run( output_tensor = ttnn.to_torch(output_tensor) pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) - return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] + return [pcc, e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/unary/isinf/isinf_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/isinf/isinf_sharded.py index 5f044619fa1..03f643861a3 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/isinf/isinf_sharded.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/isinf/isinf_sharded.py @@ -11,11 +11,7 @@ import ttnn import math from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm -from tests.sweep_framework.sweep_utils.sharding_utils import ( - gen_sharded_spec_unary, - parse_sharding_spec, - get_device_grid_size, -) +from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_rand_inf from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time @@ -23,7 +19,6 @@ # Override the default timeout in seconds for hang detection. TIMEOUT = 120 -Y, X = get_device_grid_size() random.seed(0) @@ -34,7 +29,7 @@ # Developers can create their own generator functions and pass them to the parameters as inputs. parameters = { "nightly": { - "input_spec": gen_sharded_spec_unary(16, Y, X), + "input_spec": gen_sharded_spec_unary(16, layouts=["TILE_LAYOUT"]), "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], }, } @@ -44,7 +39,7 @@ # 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]]: - input_shape, sharding_strategy, _, _, input_layout = test_vector["input_spec"].values() + input_shape, X, Y, sharding_strategy, _, _, input_layout = test_vector["input_spec"].values() pre_sharded_height = math.prod(input_shape[:-1]) pre_sharded_width = input_shape[-1] @@ -67,9 +62,14 @@ def run( data_seed = random.randint(0, 20000000) torch.manual_seed(data_seed) - input_shape, sharding_strategy, shard_orientation, tensor_hw_as_shard_shape, input_layout = parse_sharding_spec( - input_spec - ) + ( + input_shape, + core_grid, + sharding_strategy, + shard_orientation, + tensor_hw_as_shard_shape, + input_layout, + ) = parse_sharding_spec(input_spec) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) @@ -77,9 +77,9 @@ def run( torch_input_tensor_a = gen_rand_inf(input_shape, low=-100, high=100) torch_output_tensor = torch.isinf(torch_input_tensor_a) - sharded_config = ttnn.create_sharded_memory_config( + sharded_config = ttnn.create_sharded_memory_config_( shape=input_shape, - core_grid=ttnn.CoreGrid(y=Y, x=X), + core_grid=core_grid, strategy=sharding_strategy, orientation=shard_orientation, use_height_and_width_as_shard_shape=tensor_hw_as_shard_shape, @@ -99,4 +99,4 @@ def run( output_tensor = ttnn.to_torch(output_tensor) pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) - return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] + return [pcc, e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/unary/isnan/isnan_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/isnan/isnan_sharded.py index 4dc0c4f9995..85be026f530 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/isnan/isnan_sharded.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/isnan/isnan_sharded.py @@ -11,11 +11,7 @@ import ttnn import math from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm -from tests.sweep_framework.sweep_utils.sharding_utils import ( - gen_sharded_spec_unary, - parse_sharding_spec, - get_device_grid_size, -) +from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_rand_inf from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time @@ -23,7 +19,6 @@ # Override the default timeout in seconds for hang detection. TIMEOUT = 120 -Y, X = get_device_grid_size() random.seed(0) @@ -34,7 +29,7 @@ # Developers can create their own generator functions and pass them to the parameters as inputs. parameters = { "nightly": { - "input_spec": gen_sharded_spec_unary(16, Y, X), + "input_spec": gen_sharded_spec_unary(16, layouts=["TILE_LAYOUT"]), "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], }, } @@ -44,7 +39,7 @@ # 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]]: - input_shape, sharding_strategy, _, _, input_layout = test_vector["input_spec"].values() + input_shape, X, Y, sharding_strategy, _, _, input_layout = test_vector["input_spec"].values() pre_sharded_height = math.prod(input_shape[:-1]) pre_sharded_width = input_shape[-1] @@ -67,9 +62,14 @@ def run( data_seed = random.randint(0, 20000000) torch.manual_seed(data_seed) - input_shape, sharding_strategy, shard_orientation, tensor_hw_as_shard_shape, input_layout = parse_sharding_spec( - input_spec - ) + ( + input_shape, + core_grid, + sharding_strategy, + shard_orientation, + tensor_hw_as_shard_shape, + input_layout, + ) = parse_sharding_spec(input_spec) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) @@ -77,9 +77,9 @@ def run( torch_input_tensor_a = gen_rand_inf(input_shape, low=-100, high=100) torch_output_tensor = torch.isnan(torch_input_tensor_a) - sharded_config = ttnn.create_sharded_memory_config( + sharded_config = ttnn.create_sharded_memory_config_( shape=input_shape, - core_grid=ttnn.CoreGrid(y=Y, x=X), + core_grid=core_grid, strategy=sharding_strategy, orientation=shard_orientation, use_height_and_width_as_shard_shape=tensor_hw_as_shard_shape, @@ -99,4 +99,4 @@ def run( output_tensor = ttnn.to_torch(output_tensor) pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) - return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] + return [pcc, e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/unary/isneginf/isneginf_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/isneginf/isneginf_sharded.py index a515892c8d0..f10ace7b498 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/isneginf/isneginf_sharded.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/isneginf/isneginf_sharded.py @@ -11,11 +11,7 @@ import ttnn import math from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm -from tests.sweep_framework.sweep_utils.sharding_utils import ( - gen_sharded_spec_unary, - parse_sharding_spec, - get_device_grid_size, -) +from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_rand_inf from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time @@ -23,7 +19,6 @@ # Override the default timeout in seconds for hang detection. TIMEOUT = 120 -Y, X = get_device_grid_size() random.seed(0) @@ -34,7 +29,7 @@ # Developers can create their own generator functions and pass them to the parameters as inputs. parameters = { "nightly": { - "input_spec": gen_sharded_spec_unary(16, Y, X), + "input_spec": gen_sharded_spec_unary(16, layouts=["TILE_LAYOUT"]), "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], }, } @@ -44,7 +39,7 @@ # 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]]: - input_shape, sharding_strategy, _, _, input_layout = test_vector["input_spec"].values() + input_shape, X, Y, sharding_strategy, _, _, input_layout = test_vector["input_spec"].values() pre_sharded_height = math.prod(input_shape[:-1]) pre_sharded_width = input_shape[-1] @@ -67,9 +62,14 @@ def run( data_seed = random.randint(0, 20000000) torch.manual_seed(data_seed) - input_shape, sharding_strategy, shard_orientation, tensor_hw_as_shard_shape, input_layout = parse_sharding_spec( - input_spec - ) + ( + input_shape, + core_grid, + sharding_strategy, + shard_orientation, + tensor_hw_as_shard_shape, + input_layout, + ) = parse_sharding_spec(input_spec) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) @@ -77,9 +77,9 @@ def run( torch_input_tensor_a = gen_rand_inf(input_shape, low=-100, high=100) torch_output_tensor = torch.isneginf(torch_input_tensor_a) - sharded_config = ttnn.create_sharded_memory_config( + sharded_config = ttnn.create_sharded_memory_config_( shape=input_shape, - core_grid=ttnn.CoreGrid(y=Y, x=X), + core_grid=core_grid, strategy=sharding_strategy, orientation=shard_orientation, use_height_and_width_as_shard_shape=tensor_hw_as_shard_shape, @@ -99,4 +99,4 @@ def run( output_tensor = ttnn.to_torch(output_tensor) pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) - return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] + return [pcc, e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/unary/isposinf/isposinf_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/isposinf/isposinf_sharded.py index 19b2fb1010a..944a8961a34 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/isposinf/isposinf_sharded.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/isposinf/isposinf_sharded.py @@ -11,11 +11,7 @@ import ttnn import math from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm -from tests.sweep_framework.sweep_utils.sharding_utils import ( - gen_sharded_spec_unary, - parse_sharding_spec, - get_device_grid_size, -) +from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_rand_inf from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time @@ -23,7 +19,6 @@ # Override the default timeout in seconds for hang detection. TIMEOUT = 120 -Y, X = get_device_grid_size() random.seed(0) @@ -34,7 +29,7 @@ # Developers can create their own generator functions and pass them to the parameters as inputs. parameters = { "nightly": { - "input_spec": gen_sharded_spec_unary(16, Y, X), + "input_spec": gen_sharded_spec_unary(16, layouts=["TILE_LAYOUT"]), "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], }, } @@ -44,7 +39,7 @@ # 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]]: - input_shape, sharding_strategy, _, _, input_layout = test_vector["input_spec"].values() + input_shape, X, Y, sharding_strategy, _, _, input_layout = test_vector["input_spec"].values() pre_sharded_height = math.prod(input_shape[:-1]) pre_sharded_width = input_shape[-1] @@ -67,9 +62,14 @@ def run( data_seed = random.randint(0, 20000000) torch.manual_seed(data_seed) - input_shape, sharding_strategy, shard_orientation, tensor_hw_as_shard_shape, input_layout = parse_sharding_spec( - input_spec - ) + ( + input_shape, + core_grid, + sharding_strategy, + shard_orientation, + tensor_hw_as_shard_shape, + input_layout, + ) = parse_sharding_spec(input_spec) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) @@ -77,9 +77,9 @@ def run( torch_input_tensor_a = gen_rand_inf(input_shape, low=-100, high=100) torch_output_tensor = torch.isfinite(torch_input_tensor_a) - sharded_config = ttnn.create_sharded_memory_config( + sharded_config = ttnn.create_sharded_memory_config_( shape=input_shape, - core_grid=ttnn.CoreGrid(y=Y, x=X), + core_grid=core_grid, strategy=sharding_strategy, orientation=shard_orientation, use_height_and_width_as_shard_shape=tensor_hw_as_shard_shape, @@ -99,4 +99,4 @@ def run( output_tensor = ttnn.to_torch(output_tensor) pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) - return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] + return [pcc, e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/unary/lgamma/lgamma_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/lgamma/lgamma_sharded.py index d6fee58bd87..96c254c6778 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/lgamma/lgamma_sharded.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/lgamma/lgamma_sharded.py @@ -11,11 +11,7 @@ import ttnn import math from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm -from tests.sweep_framework.sweep_utils.sharding_utils import ( - gen_sharded_spec_unary, - parse_sharding_spec, - get_device_grid_size, -) +from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time @@ -23,8 +19,6 @@ # Override the default timeout in seconds for hang detection. TIMEOUT = 120 -# device.compute_with_storage_grid_size() -Y, X = get_device_grid_size() random.seed(0) @@ -35,7 +29,7 @@ # Developers can create their own generator functions and pass them to the parameters as inputs. parameters = { "nightly": { - "input_spec": gen_sharded_spec_unary(16, Y, X, max_tensor_size=2 * 1024 * 1024, layouts=["TILE_LAYOUT"]), + "input_spec": gen_sharded_spec_unary(16, max_tensor_size=2 * 1024 * 1024, layouts=["TILE_LAYOUT"]), "input_a_dtype": [ttnn.bfloat16], }, } @@ -45,7 +39,7 @@ # 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]]: - input_shape, sharding_strategy, _, _, input_layout = test_vector["input_spec"].values() + input_shape, X, Y, sharding_strategy, _, _, input_layout = test_vector["input_spec"].values() pre_sharded_height = math.prod(input_shape[:-1]) pre_sharded_width = input_shape[-1] @@ -71,9 +65,14 @@ def run( data_seed = random.randint(0, 20000000) torch.manual_seed(data_seed) - input_shape, sharding_strategy, shard_orientation, tensor_hw_as_shard_shape, input_layout = parse_sharding_spec( - input_spec - ) + ( + input_shape, + core_grid, + sharding_strategy, + shard_orientation, + tensor_hw_as_shard_shape, + input_layout, + ) = parse_sharding_spec(input_spec) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) @@ -84,9 +83,9 @@ def run( golden_function = ttnn.get_golden_function(ttnn.lgamma) torch_output_tensor = golden_function(torch_input_tensor_a) - sharded_config = ttnn.create_sharded_memory_config( + sharded_config = ttnn.create_sharded_memory_config_( shape=input_shape, - core_grid=ttnn.CoreGrid(y=Y, x=X), + core_grid=core_grid, strategy=sharding_strategy, orientation=shard_orientation, use_height_and_width_as_shard_shape=tensor_hw_as_shard_shape, @@ -106,4 +105,4 @@ def run( output_tensor = ttnn.to_torch(output_tensor) pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) - return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] + return [pcc, e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/unary/logit/logit_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/logit/logit_sharded.py index 6fe27e6408a..697b81ac5a9 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/logit/logit_sharded.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/logit/logit_sharded.py @@ -11,11 +11,7 @@ import ttnn import math from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm -from tests.sweep_framework.sweep_utils.sharding_utils import ( - gen_sharded_spec_unary, - parse_sharding_spec, - get_device_grid_size, -) +from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time @@ -23,7 +19,6 @@ # Override the default timeout in seconds for hang detection. TIMEOUT = 120 -Y, X = get_device_grid_size() random.seed(0) @@ -34,7 +29,7 @@ # Developers can create their own generator functions and pass them to the parameters as inputs. parameters = { "nightly": { - "input_spec": gen_sharded_spec_unary(16, Y, X, max_tensor_size=1 * 1024 * 1024, layouts=["TILE_LAYOUT"]), + "input_spec": gen_sharded_spec_unary(16, max_tensor_size=1 * 1024 * 1024, layouts=["TILE_LAYOUT"]), "input_a_dtype": [ttnn.bfloat16], "eps": [0.2], # 0, 10e-6, 10e-4, 10e-2, }, @@ -45,7 +40,7 @@ # 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]]: - input_shape, sharding_strategy, _, _, input_layout = test_vector["input_spec"].values() + input_shape, X, Y, sharding_strategy, _, _, input_layout = test_vector["input_spec"].values() pre_sharded_height = math.prod(input_shape[:-1]) pre_sharded_width = input_shape[-1] @@ -72,9 +67,14 @@ def run( data_seed = random.randint(0, 20000000) torch.manual_seed(data_seed) - input_shape, sharding_strategy, shard_orientation, tensor_hw_as_shard_shape, input_layout = parse_sharding_spec( - input_spec - ) + ( + input_shape, + core_grid, + sharding_strategy, + shard_orientation, + tensor_hw_as_shard_shape, + input_layout, + ) = parse_sharding_spec(input_spec) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) @@ -84,9 +84,9 @@ def run( )(input_shape) torch_output_tensor = torch.logit(torch_input_tensor_a, eps) - sharded_config = ttnn.create_sharded_memory_config( + sharded_config = ttnn.create_sharded_memory_config_( shape=input_shape, - core_grid=ttnn.CoreGrid(y=Y, x=X), + core_grid=core_grid, strategy=sharding_strategy, orientation=shard_orientation, use_height_and_width_as_shard_shape=tensor_hw_as_shard_shape, @@ -106,4 +106,4 @@ def run( output_tensor = ttnn.to_torch(output_tensor) pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) - return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] + return [pcc, e2e_perf] diff --git a/tests/sweep_framework/sweeps/eltwise/unary/mish/mish_sharded.py b/tests/sweep_framework/sweeps/eltwise/unary/mish/mish_sharded.py index bb47efd25ef..901113ce337 100644 --- a/tests/sweep_framework/sweeps/eltwise/unary/mish/mish_sharded.py +++ b/tests/sweep_framework/sweeps/eltwise/unary/mish/mish_sharded.py @@ -11,11 +11,7 @@ import ttnn import math from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm -from tests.sweep_framework.sweep_utils.sharding_utils import ( - gen_sharded_spec_unary, - parse_sharding_spec, - get_device_grid_size, -) +from tests.sweep_framework.sweep_utils.sharding_utils import gen_sharded_spec_unary, parse_sharding_spec from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import gen_func_with_cast_tt from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time @@ -23,7 +19,6 @@ # Override the default timeout in seconds for hang detection. TIMEOUT = 120 -Y, X = get_device_grid_size() random.seed(0) @@ -34,7 +29,7 @@ # Developers can create their own generator functions and pass them to the parameters as inputs. parameters = { "nightly": { - "input_spec": gen_sharded_spec_unary(12, Y, X, layouts=["TILE_LAYOUT"]), + "input_spec": gen_sharded_spec_unary(12, layouts=["TILE_LAYOUT"]), "input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b], }, } @@ -44,7 +39,7 @@ # 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]]: - input_shape, sharding_strategy, _, _, input_layout = test_vector["input_spec"].values() + input_shape, X, Y, sharding_strategy, _, _, input_layout = test_vector["input_spec"].values() pre_sharded_height = math.prod(input_shape[:-1]) pre_sharded_width = input_shape[-1] @@ -70,9 +65,14 @@ def run( data_seed = random.randint(0, 20000000) torch.manual_seed(data_seed) - input_shape, sharding_strategy, shard_orientation, tensor_hw_as_shard_shape, input_layout = parse_sharding_spec( - input_spec - ) + ( + input_shape, + core_grid, + sharding_strategy, + shard_orientation, + tensor_hw_as_shard_shape, + input_layout, + ) = parse_sharding_spec(input_spec) if input_layout == ttnn.ROW_MAJOR_LAYOUT: input_shape = sanitize_shape_rm(input_shape) @@ -84,9 +84,9 @@ def run( golden_function = ttnn.get_golden_function(ttnn.mish) torch_output_tensor = golden_function(torch_input_tensor_a) - sharded_config = ttnn.create_sharded_memory_config( + sharded_config = ttnn.create_sharded_memory_config_( shape=input_shape, - core_grid=ttnn.CoreGrid(y=Y, x=X), + core_grid=core_grid, strategy=sharding_strategy, orientation=shard_orientation, use_height_and_width_as_shard_shape=tensor_hw_as_shard_shape, @@ -106,4 +106,4 @@ def run( output_tensor = ttnn.to_torch(output_tensor) pcc = check_with_pcc(torch_output_tensor, output_tensor, 0.999) - return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf] + return [pcc, e2e_perf] From 812f11b304ea4ea51c96baa90ef4f72279b4952f Mon Sep 17 00:00:00 2001 From: ngrujic Date: Fri, 29 Nov 2024 11:59:05 +0000 Subject: [PATCH 15/15] #11512: Remove usage of TT_ARCH_NAME env variable --- tests/sweep_framework/sweep_utils/sharding_utils.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/tests/sweep_framework/sweep_utils/sharding_utils.py b/tests/sweep_framework/sweep_utils/sharding_utils.py index f98022e8396..f3941d6b974 100644 --- a/tests/sweep_framework/sweep_utils/sharding_utils.py +++ b/tests/sweep_framework/sweep_utils/sharding_utils.py @@ -9,19 +9,10 @@ from tests.tt_eager.python_api_testing.sweep_tests.generation_funcs import _gen_reshape_args_from_volume -def get_device_grid_size(): - device_name = os.environ.get("ARCH_NAME", os.environ.get("TT_ARCH_NAME", "default")).lower() - if device_name == "grayskull": - y, x = 9, 12 - else: - y, x = 8, 8 - - return y, x - - def gen_sharded_spec_unary(num_shapes, max_tensor_size=4 * 1024 * 1024, layouts=["TILE_LAYOUT", "ROW_MAJOR_LAYOUT"]): # device.compute_with_storage_grid_size() - y, x = get_device_grid_size() + y = 8 + x = 8 # ["BLOCK", "WIDTH", "HEIGHT", "tensor_wh"] sharding_strategy_list = ["BLOCK", "WIDTH", "HEIGHT", "tensor_wh"]