Skip to content

Commit

Permalink
#8157: Update doc and move sweep test for leaky_relu
Browse files Browse the repository at this point in the history
  • Loading branch information
mcw-anasuya committed Oct 18, 2024
1 parent e902289 commit c6f9858
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 55 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ttnn-run-sweeps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ on:
- eltwise.unary.prelu.prelu
- eltwise.unary.hardswish.hardswish_pytorch2
- eltwise.unary.hardtanh.hardtanh_pytorch2
- eltwise.unary.leaky_relu.leaky_relu
- eltwise.binary.subtract.subtract
- eltwise.binary.subtract.subtract_tensor_pytorch2
- eltwise.binary.multiply.multiply
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc.

# SPDX-License-Identifier: Apache-2.0

from typing import Optional, Tuple

import torch
import random
import ttnn

from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time

# 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": {
"batch_sizes": [(1,)],
"height": [384, 1024],
"width": [1024, 4096],
"dtype": [ttnn.bfloat16, ttnn.bfloat8_b],
"input_memory_config": [ttnn.DRAM_MEMORY_CONFIG],
"output_memory_config": [ttnn.DRAM_MEMORY_CONFIG],
"layout": [ttnn.TILE_LAYOUT, ttnn.ROW_MAJOR_LAYOUT],
"negative_slope": [-0.5, 0, 0.01, 0.5],
},
}


# 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["layout"] == ttnn.ROW_MAJOR_LAYOUT:
return True, "Row Major layout is not supported"
return False, None


# This is the run instructions for the test, defined by the developer.
# The run function must take the above-defined parameters as inputs.
# The runner will call this run function with each test vector, and the returned results from this function will be stored.
# If you defined a device_mesh_fixture above, the object you yielded will be passed into this function as 'device'. Otherwise, it will be the default ttnn device opened by the infra.
def run(
batch_sizes,
height,
width,
dtype,
input_memory_config,
output_memory_config,
layout,
negative_slope,
*,
device,
) -> list:
input_shape = (*batch_sizes, height, width)

torch_input_tensor = torch.randn(input_shape, dtype=torch.float32)
torch_output_tensor = torch.nn.functional.leaky_relu(torch_input_tensor, negative_slope)

input_tensor = ttnn.from_torch(
torch_input_tensor, dtype=dtype, device=device, memory_config=input_memory_config, layout=layout
)

start_time = start_measuring_time()
result = ttnn.leaky_relu(input_tensor, negative_slope, 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]
55 changes: 0 additions & 55 deletions tests/ttnn/sweep_tests/sweeps/sweeps/leaky_relu.py

This file was deleted.

13 changes: 13 additions & 0 deletions ttnn/cpp/ttnn/operations/eltwise/unary/unary_pybind.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,19 @@ void py_module(py::module& module) {

detail::bind_unary_operation_with_float_parameter(module, ttnn::heaviside, "value", "The value parameter for the Heaviside function", "",
R"doc(Supported dtypes, layouts, and ranks:
+----------------------------+---------------------------------+-------------------+
| Dtypes | Layouts | Ranks |
+----------------------------+---------------------------------+-------------------+
| BFLOAT16, BFLOAT8_B | TILE | 2, 3, 4 |
+----------------------------+---------------------------------+-------------------+
)doc");


detail::bind_unary_operation_with_float_parameter(module, ttnn::leaky_relu, "slope", "The slope parameter for the Leaky ReLU function", "",
R"doc(Supported dtypes, layouts, and ranks:
+----------------------------+---------------------------------+-------------------+
| Dtypes | Layouts | Ranks |
+----------------------------+---------------------------------+-------------------+
Expand Down

0 comments on commit c6f9858

Please sign in to comment.