Skip to content

Commit 442c14e

Browse files
committed
Update
[ghstack-poisoned]
2 parents 29122b6 + 0edc858 commit 442c14e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+6242
-3533
lines changed

backends/test/suite/operators/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ def _create_test_for_backend(
133133

134134

135135
class OperatorTest(unittest.TestCase):
136-
def _test_op(self, model, inputs, flow: TestFlow):
136+
def _test_op(
137+
self, model, inputs, flow: TestFlow, generate_random_test_inputs: bool = True
138+
):
137139
context = get_active_test_context()
138140

139141
# This should be set in the wrapped test. See _make_wrapped_test above.
@@ -145,6 +147,7 @@ def _test_op(self, model, inputs, flow: TestFlow):
145147
flow,
146148
context.test_name,
147149
context.params,
150+
generate_random_test_inputs=generate_random_test_inputs,
148151
)
149152

150153
log_test_summary(run_summary)
Lines changed: 65 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,106 @@
1-
# (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
26

3-
# pyre-strict
7+
# pyre-unsafe
48

5-
from typing import Callable
69

710
import torch
11+
from executorch.backends.test.suite.flow import TestFlow
812

9-
from executorch.backends.test.compliance_suite import (
13+
from executorch.backends.test.suite.operators import (
1014
dtype_test,
1115
operator_test,
1216
OperatorTest,
1317
)
1418

19+
1520
class AbsModel(torch.nn.Module):
1621
def __init__(self):
1722
super().__init__()
18-
23+
1924
def forward(self, x):
2025
return torch.abs(x)
2126

27+
2228
@operator_test
2329
class TestAbs(OperatorTest):
2430
@dtype_test
25-
def test_abs_dtype(self, dtype, tester_factory: Callable) -> None:
31+
def test_abs_dtype(self, flow: TestFlow, dtype) -> None:
2632
# Test with different dtypes
2733
model = AbsModel().to(dtype)
28-
self._test_op(model, (torch.rand(10, 10).to(dtype) * 2 - 1,), tester_factory)
29-
30-
def test_abs_basic(self, tester_factory: Callable) -> None:
34+
self._test_op(model, (torch.rand(10, 10).to(dtype) * 2 - 1,), flow)
35+
36+
def test_abs_basic(self, flow: TestFlow) -> None:
3137
# Basic test with default parameters
3238
# Input: tensor with positive and negative values
33-
self._test_op(AbsModel(), (torch.randn(10, 10),), tester_factory)
34-
35-
def test_abs_shapes(self, tester_factory: Callable) -> None:
39+
self._test_op(AbsModel(), (torch.randn(10, 10),), flow)
40+
41+
def test_abs_shapes(self, flow: TestFlow) -> None:
3642
# Test with different tensor shapes
37-
43+
3844
# 1D tensor
39-
self._test_op(AbsModel(), (torch.randn(20),), tester_factory)
40-
45+
self._test_op(AbsModel(), (torch.randn(20),), flow)
46+
4147
# 2D tensor
42-
self._test_op(AbsModel(), (torch.randn(5, 10),), tester_factory)
43-
48+
self._test_op(AbsModel(), (torch.randn(5, 10),), flow)
49+
4450
# 3D tensor
45-
self._test_op(AbsModel(), (torch.randn(3, 4, 5),), tester_factory)
46-
51+
self._test_op(AbsModel(), (torch.randn(3, 4, 5),), flow)
52+
4753
# 4D tensor
48-
self._test_op(AbsModel(), (torch.randn(2, 3, 4, 5),), tester_factory)
49-
54+
self._test_op(AbsModel(), (torch.randn(2, 3, 4, 5),), flow)
55+
5056
# 5D tensor
51-
self._test_op(AbsModel(), (torch.randn(2, 2, 3, 4, 5),), tester_factory)
52-
53-
def test_abs_values(self, tester_factory: Callable) -> None:
57+
self._test_op(AbsModel(), (torch.randn(2, 2, 3, 4, 5),), flow)
58+
59+
def test_abs_values(self, flow: TestFlow) -> None:
5460
# Test with different value ranges
55-
61+
5662
# Small values
57-
self._test_op(AbsModel(), (torch.randn(10, 10) * 0.01,), tester_factory)
58-
63+
self._test_op(AbsModel(), (torch.randn(10, 10) * 0.01,), flow)
64+
5965
# Large values
60-
self._test_op(AbsModel(), (torch.randn(10, 10) * 1000,), tester_factory)
61-
66+
self._test_op(AbsModel(), (torch.randn(10, 10) * 1000,), flow)
67+
6268
# Mixed positive and negative values
63-
self._test_op(AbsModel(), (torch.randn(10, 10) * 10,), tester_factory)
64-
69+
self._test_op(AbsModel(), (torch.randn(10, 10) * 10,), flow)
70+
6571
# All positive values
66-
self._test_op(AbsModel(), (torch.rand(10, 10) * 10,), tester_factory)
67-
72+
self._test_op(AbsModel(), (torch.rand(10, 10) * 10,), flow)
73+
6874
# All negative values
69-
self._test_op(AbsModel(), (torch.rand(10, 10) * -10,), tester_factory)
70-
75+
self._test_op(AbsModel(), (torch.rand(10, 10) * -10,), flow)
76+
7177
# Values close to zero
72-
self._test_op(AbsModel(), (torch.randn(10, 10) * 1e-5,), tester_factory)
73-
74-
def test_abs_edge_cases(self, tester_factory: Callable) -> None:
78+
self._test_op(AbsModel(), (torch.randn(10, 10) * 1e-5,), flow)
79+
80+
def test_abs_edge_cases(self, flow: TestFlow) -> None:
7581
# Test edge cases
76-
82+
7783
# Zero tensor
78-
self._test_op(AbsModel(), (torch.zeros(10, 10),), tester_factory)
79-
84+
self._test_op(
85+
AbsModel(), (torch.zeros(10, 10),), flow, generate_random_test_inputs=False
86+
)
87+
8088
# Tensor with infinity
81-
x = torch.tensor([float('inf'), float('-inf'), 1.0, -1.0])
82-
self._test_op(AbsModel(), (x,), tester_factory)
83-
89+
x = torch.tensor([float("inf"), float("-inf"), 1.0, -1.0])
90+
self._test_op(AbsModel(), (x,), flow, generate_random_test_inputs=False)
91+
8492
# Tensor with NaN
85-
x = torch.tensor([float('nan'), 1.0, -1.0])
86-
self._test_op(AbsModel(), (x,), tester_factory)
87-
88-
def test_abs_scalar(self, tester_factory: Callable) -> None:
93+
x = torch.tensor([float("nan"), 1.0, -1.0])
94+
self._test_op(AbsModel(), (x,), flow, generate_random_test_inputs=False)
95+
96+
def test_abs_scalar(self, flow: TestFlow) -> None:
8997
# Test with scalar input (1-element tensor)
90-
self._test_op(AbsModel(), (torch.tensor([-5.0]),), tester_factory)
91-
self._test_op(AbsModel(), (torch.tensor([5.0]),), tester_factory)
92-
self._test_op(AbsModel(), (torch.tensor([0.0]),), tester_factory)
98+
self._test_op(
99+
AbsModel(), (torch.tensor([-5.0]),), flow, generate_random_test_inputs=False
100+
)
101+
self._test_op(
102+
AbsModel(), (torch.tensor([5.0]),), flow, generate_random_test_inputs=False
103+
)
104+
self._test_op(
105+
AbsModel(), (torch.tensor([0.0]),), flow, generate_random_test_inputs=False
106+
)

0 commit comments

Comments
 (0)