forked from pytorch/executorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit test for op_add (pytorch#7087)
add op_add shapes to generate as binaries (pytorch#7087) Summary: generates the add model pte’s for cadence to execute on. will use graph builder in later diffs Test Plan: Imported from GitHub, without a `Test Plan:` line. {F1968254537} Reviewed By: hsharma35 Differential Revision: D66510372 Pulled By: zonglinpeng
- Loading branch information
1 parent
dedf77b
commit 5785fc3
Showing
6 changed files
with
173 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
load("@fbcode_macros//build_defs:python_unittest.bzl", "python_unittest") | ||
|
||
oncall("odai_jarvis") | ||
|
||
|
||
python_unittest( | ||
name = "test_add_op", | ||
srcs = [ | ||
"test_add_op.py", | ||
], | ||
typing = True, | ||
supports_static_listing = False, | ||
deps = [ | ||
"fbsource//third-party/pypi/parameterized:parameterized", | ||
"//caffe2:torch", | ||
"//executorch/backends/cadence/aot:ops_registrations", | ||
"//executorch/backends/cadence/aot:export_example", | ||
"//executorch/backends/cadence/aot:compiler", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary. | ||
|
||
import unittest | ||
from typing import Tuple | ||
|
||
from parameterized import parameterized | ||
|
||
from executorch.backends.cadence.aot.ops_registrations import * # noqa | ||
|
||
import torch | ||
import torch.nn as nn | ||
from executorch.backends.cadence.aot.export_example import export_model | ||
|
||
|
||
class ATenOpTestCases(unittest.TestCase): | ||
@parameterized.expand( | ||
[ | ||
[(7, 5, 6), (7, 5, 6)], | ||
[(7, 5, 6), (1)], | ||
[(1), (7, 5, 6)], | ||
[(1), (7, 5, 6), 2.23], | ||
[(1), (7, 5, 6), -1.0], | ||
[(1), (7, 5, 6), -2.23], | ||
[(7, 5, 6), (7, 5, 6), 1.23], | ||
[(6, 7), (6, 7)], | ||
[(6, 7), (6, 7), 2], | ||
# Broadcast tests (should be optimized on G3) | ||
[(1, 32, 64), (1, 1, 64)], | ||
[(1, 32, 64), (64)], | ||
[(1, 1, 32), (32)], | ||
[(16, 1, 16), (1, 1, 16)], | ||
[(16, 1, 16), (16)], | ||
[(1, 4, 8, 8), (1, 1, 8, 8)], | ||
[(1, 4, 8, 8), (8, 8)], | ||
# Broadcast tests (should go to portable ops) | ||
[(1, 10, 1, 8), (4, 1, 4, 1)], | ||
[(1, 1, 16), (1, 8, 1), 2.5], | ||
# # aten.upsample_nearest2d tests | ||
[(5, 6, 6, 8), (5, 6, 6, 8)], | ||
[(1, 1, 12, 16), (1, 1, 12, 16)], | ||
] | ||
) | ||
def test_aten_add_out( | ||
self, Xshape: Tuple[int], Yshape: Tuple[int], alpha: float = 1 | ||
) -> None: | ||
class AddTensor(nn.Module): | ||
def __init__(self, alpha: float): | ||
super().__init__() | ||
self.alpha = alpha | ||
|
||
def forward(self, x: torch.Tensor, y: torch.Tensor): | ||
return torch.add(x, y, alpha=self.alpha) | ||
|
||
model = AddTensor(alpha) | ||
|
||
X = torch.randn(Xshape) | ||
Y = torch.randn(Yshape) | ||
|
||
model.eval() | ||
export_model( | ||
model, (X, Y), file_name=self._testMethodName, run_and_compare=False | ||
) | ||
|
||
@parameterized.expand( | ||
[ | ||
[(7, 5, 6), (7, 5, 6)], | ||
[(7, 5, 6), (1)], | ||
[(1), (7, 5, 6)], | ||
[(1), (7, 5, 6), 2.23], | ||
[(1), (7, 5, 6), -1.0], | ||
[(1), (7, 5, 6), -2.23], | ||
[(7, 5, 6), (7, 5, 6), 1.23], | ||
[(6, 7), (6, 7)], | ||
[(6, 7), (6, 7), 2], | ||
# Broadcast tests (should be optimized on G3) | ||
[(1, 32, 64), (1, 1, 64)], | ||
[(1, 32, 64), (64)], | ||
[(1, 1, 32), (32)], | ||
[(16, 1, 16), (1, 1, 16)], | ||
[(16, 1, 16), (16)], | ||
[(1, 4, 8, 8), (1, 1, 8, 8)], | ||
[(1, 4, 8, 8), (8, 8)], | ||
# Broadcast tests (should go to portable ops) | ||
[(1, 10, 1, 8), (4, 1, 4, 1)], | ||
[(1, 1, 16), (1, 8, 1), 2.5], | ||
# # aten.upsample_nearest2d tests | ||
[(5, 6, 6, 8), (5, 6, 6, 8)], | ||
[(1, 1, 12, 16), (1, 1, 12, 16)], | ||
] | ||
) | ||
def test_aten_add_scalar_out( | ||
self, Xshape: Tuple[int], Yshape: Tuple[int], alpha: float = 1 | ||
) -> None: | ||
# Tensor-Scalar addition | ||
class AddScalar(nn.Module): | ||
def __init__(self, alpha: float): | ||
super().__init__() | ||
self.alpha = alpha | ||
|
||
def forward(self, x: torch.Tensor, y: float): | ||
return torch.add(x, y, alpha=self.alpha) | ||
|
||
model = AddScalar(alpha) | ||
|
||
X = torch.randn(Xshape) | ||
Y = 2.34 | ||
|
||
model.eval() | ||
export_model( | ||
model, (X, Y), file_name=self._testMethodName, run_and_compare=False | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |