Skip to content

Commit

Permalink
#11512: Modify existing sharded sweeps to use new sharding funciton
Browse files Browse the repository at this point in the history
  • Loading branch information
amalbasaTT committed Dec 2, 2024
1 parent 81ef7b8 commit 154f292
Show file tree
Hide file tree
Showing 18 changed files with 852 additions and 491 deletions.
336 changes: 221 additions & 115 deletions tests/sweep_framework/sweep_utils/sharding_utils.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc.

# SPDX-License-Identifier: Apache-2.0

from typing import Optional, Tuple
from functools import partial

import torch
import random
import ttnn
from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm
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

# Override the default timeout in seconds for hang detection.
TIMEOUT = 30

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") 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_shape": gen_shapes([1, 1, 1, 1], [6, 12, 128, 128], [1, 1, 1, 1], 32)
+ gen_shapes([1, 1, 1], [12, 256, 256], [1, 1, 1], 32)
+ gen_shapes([1, 1], [256, 256], [1, 1], 32),
"input_a_dtype": [ttnn.int32],
"input_layout": [ttnn.TILE_LAYOUT, ttnn.ROW_MAJOR_LAYOUT],
"input_a_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG],
"output_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG],
},
}


def mesh_device_fixture():
device = ttnn.open_device(device_id=0)
assert ttnn.device.is_wormhole_b0(device), "This op is available for Wormhole_B0 only"
yield (device, "Wormhole_B0")
ttnn.close_device(device)
del device


# This is the run instructions for the test, defined by the developer.
# The run function must take the above-defined parameters as inputs.
# The runner will call this run function with each test vector, and the returned results from this function will be stored.
# If you defined a device_mesh_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra.
def run(
input_shape,
input_a_dtype,
input_layout,
input_a_memory_config,
output_memory_config,
*,
device,
) -> list:
data_seed = random.randint(0, 20000000)
torch.manual_seed(data_seed)

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=0, high=2147483648, dtype=torch.int64), input_a_dtype
)(input_shape)

scalar = torch.randint(0, 2147483648, (1,), dtype=torch.int32).item()

torch_output_tensor = torch.bitwise_and(torch_input_tensor_a, scalar)

input_tensor_a = ttnn.from_torch(
torch_input_tensor_a,
dtype=input_a_dtype,
layout=input_layout,
device=device,
memory_config=input_a_memory_config,
)

start_time = start_measuring_time()
result = ttnn.bitwise_and(input_tensor_a, value=scalar, memory_config=output_memory_config)
output_tensor = ttnn.to_torch(result)
e2e_perf = stop_measuring_time(start_time)

return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf]
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc.

# SPDX-License-Identifier: Apache-2.0

from typing import Optional, Tuple
from functools import partial

import torch
import random
import ttnn
from tests.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm
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

# Override the default timeout in seconds for hang detection.
TIMEOUT = 30

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") 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_shape": gen_shapes([1, 1, 1, 1], [6, 12, 512, 512], [1, 1, 1, 1], 16)
+ gen_shapes([1, 1, 1], [12, 1024, 1024], [1, 1, 1], 16)
+ gen_shapes([1, 1], [1024, 1024], [1, 1], 16),
"input_a_dtype": [ttnn.int32],
"input_layout": [ttnn.TILE_LAYOUT, ttnn.ROW_MAJOR_LAYOUT],
"input_a_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG],
"output_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG],
},
}


# Invalidate vector is called during the generation phase where each vector will be passed in.
# If invalidated, the vector will still be stored but will be skipped.
# Returns False, None if the vector is valid, and True, str with a reason for invalidation if it is invalid.
def invalidate_vector(test_vector) -> Tuple[bool, Optional[str]]:
if test_vector["input_layout"] == ttnn.ROW_MAJOR_LAYOUT:
return True, "Row Major layout is not supported"
return False, None


def mesh_device_fixture():
device = ttnn.open_device(device_id=0)
assert ttnn.device.is_wormhole_b0(device), "This op is available for Wormhole_B0 only"
yield (device, "Wormhole_B0")
ttnn.close_device(device)
del device


# This is the run instructions for the test, defined by the developer.
# The run function must take the above-defined parameters as inputs.
# The runner will call this run function with each test vector, and the returned results from this function will be stored.
# If you defined a device_mesh_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra.
def run(
input_shape,
input_a_dtype,
input_layout,
input_a_memory_config,
output_memory_config,
*,
device,
) -> list:
data_seed = random.randint(0, 20000000)
torch.manual_seed(data_seed)

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=-2147483647, high=2147483648, dtype=torch.int64), input_a_dtype
)(input_shape)

torch_input_tensor_a = torch.full(size=input_shape, fill_value=-2147483647).to(torch.int32)

torch_output_tensor = torch.bitwise_not(torch_input_tensor_a)

input_tensor_a = ttnn.from_torch(
torch_input_tensor_a,
dtype=input_a_dtype,
layout=input_layout,
device=device,
memory_config=input_a_memory_config,
)

start_time = start_measuring_time()
result = ttnn.bitwise_not(input_tensor_a, memory_config=output_memory_config)
output_tensor = ttnn.to_torch(result)
e2e_perf = stop_measuring_time(start_time)

return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf]
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,28 @@

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.sweep_framework.sweep_utils.utils import gen_shapes, sanitize_shape_rm
from tests.sweep_framework.sweep_utils.sharding_utils import (
gen_unary_sharded_spec,
gen_sharded_spec_unary,
parse_sharding_spec,
invalidate_vector_sharding,
roundup,
divup,
)
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


# Override the default timeout in seconds for hang detection.
TIMEOUT = 120

Y, X = get_device_grid_size()

random.seed(0)


Expand All @@ -36,43 +34,42 @@
# 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 = {
"xfail": {
"input_spec": list(gen_unary_sharded_spec(8, 4, "ROW_MAJOR", "BLOCK", True))
+ list(gen_unary_sharded_spec(8, 4, "COL_MAJOR", "BLOCK", True))
+ list(gen_unary_sharded_spec(8, 4, "ROW_MAJOR", "HEIGHT", True))
+ list(gen_unary_sharded_spec(8, 4, "COL_MAJOR", "HEIGHT", True))
+ list(gen_unary_sharded_spec(8, 4, "ROW_MAJOR", "WIDTH", True))
+ list(gen_unary_sharded_spec(8, 4, "COL_MAJOR", "WIDTH", True))
+ list(gen_unary_sharded_spec(8, 4, "ROW_MAJOR", "TENSOR_HW", True))
+ list(gen_unary_sharded_spec(8, 4, "COL_MAJOR", "TENSOR_HW", True))
+ list(gen_unary_sharded_spec(8, 4, "ROW_MAJOR", "BLOCK", False))
+ list(gen_unary_sharded_spec(8, 4, "COL_MAJOR", "BLOCK", False))
+ list(gen_unary_sharded_spec(8, 4, "ROW_MAJOR", "HEIGHT", False))
+ list(gen_unary_sharded_spec(8, 4, "COL_MAJOR", "HEIGHT", False))
+ list(gen_unary_sharded_spec(8, 4, "ROW_MAJOR", "WIDTH", False))
+ list(gen_unary_sharded_spec(8, 4, "COL_MAJOR", "WIDTH", False))
+ list(gen_unary_sharded_spec(8, 4, "ROW_MAJOR", "TENSOR_HW", False))
+ list(gen_unary_sharded_spec(8, 4, "COL_MAJOR", "TENSOR_HW", False)),
"nightly": {
"input_spec": gen_sharded_spec_unary(16, 4),
"input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b],
"input_layout": [ttnn.TILE_LAYOUT, ttnn.ROW_MAJOR_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]]:
if test_vector["input_layout"] == ttnn.ROW_MAJOR_LAYOUT or test_vector["input_a_dtype"] == ttnn.bfloat8_b:
input_spec = parse_sharding_spec(test_vector["input_spec"])
(
input_shape,
core_grid_size,
shard_orientation,
sharding_strategy,
tensor_hw_as_shard_shape,
shard_height_mul_of_32,
input_layout,
) = input_spec
invlidated, output_str = invalidate_vector_sharding(*input_spec)
if invlidated:
return invlidated, output_str
if input_layout == ttnn.ROW_MAJOR_LAYOUT or test_vector["input_a_dtype"] == ttnn.bfloat8_b:
return True, "Row Major layout and bfloat8_b are not supported"
return False, None


# This is the run instructions forgit a the test, defined by the developer.
# 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:
Expand All @@ -86,6 +83,7 @@ def run(
sharding_strategy,
tensor_hw_as_shard_shape,
shard_height_mul_of_32,
input_layout,
) = parse_sharding_spec(input_spec)
y, x = core_grid_size
device_grid_size = ttnn.CoreGrid(y=y, x=x)
Expand Down
Loading

0 comments on commit 154f292

Please sign in to comment.