diff --git a/examples/cadence/operators/TARGETS b/examples/cadence/operators/TARGETS index 732f1ced09..67f2bab681 100644 --- a/examples/cadence/operators/TARGETS +++ b/examples/cadence/operators/TARGETS @@ -1,26 +1,5 @@ -# 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") +load("targets.bzl", "define_common_targets") 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", - ], -) +define_common_targets() diff --git a/examples/cadence/operators/targets.bzl b/examples/cadence/operators/targets.bzl new file mode 100644 index 0000000000..e1fbeb9fdf --- /dev/null +++ b/examples/cadence/operators/targets.bzl @@ -0,0 +1,36 @@ +# 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") + +TESTS_LIST = [ + "add_op", + "quantized_conv1d_op", + "quantized_linear_op", +] + +def define_common_targets(): + for op in TESTS_LIST: + _define_test_target(op) + + +def _define_test_target(test_name): + file_name = "test_{}".format(test_name) + python_unittest( + name = file_name, + srcs = [ + "{}.py".format(file_name), + ], + typing = True, + supports_static_listing = False, + deps = [ + "fbsource//third-party/pypi/parameterized:parameterized", + "fbcode//caffe2:torch", + "fbcode//executorch/backends/cadence/aot:ops_registrations", + "fbcode//executorch/backends/cadence/aot:export_example", + "fbcode//executorch/backends/cadence/aot:compiler", + ], + ) diff --git a/examples/cadence/operators/quantized_conv1d_op.py b/examples/cadence/operators/test_quantized_conv1d_op.py similarity index 93% rename from examples/cadence/operators/quantized_conv1d_op.py rename to examples/cadence/operators/test_quantized_conv1d_op.py index 3247cb690d..e2457077b2 100644 --- a/examples/cadence/operators/quantized_conv1d_op.py +++ b/examples/cadence/operators/test_quantized_conv1d_op.py @@ -8,6 +8,8 @@ import logging +from typing import cast, Sequence + import torch from executorch.backends.cadence.aot.ops_registrations import * # noqa @@ -53,6 +55,6 @@ def forward(self, x: torch.Tensor): model = QuantizedConv() model.eval() - example_inputs = (torch.randn(shape),) + example_inputs = (torch.randn(cast(Sequence[int], shape)),) export_model(model, example_inputs) diff --git a/examples/cadence/operators/quantized_linear_op.py b/examples/cadence/operators/test_quantized_linear_op.py similarity index 100% rename from examples/cadence/operators/quantized_linear_op.py rename to examples/cadence/operators/test_quantized_linear_op.py