From 0d3d362a30c43be20fbc29562c1c13048df91691 Mon Sep 17 00:00:00 2001 From: Zonglin Peng Date: Wed, 5 Feb 2025 13:14:14 -0800 Subject: [PATCH] enable facto generation on G3 operators (#8202) Summary: - Move facto utiles to backends/cadence/utils - Add pytorch/facto as a submodule because it's fairly small. - Install facto as editable module by python in bash Pull Request resolved: https://github.com/pytorch/executorch/pull/8202 Test Plan: python3 -m examples.cadence.operators.test_g3_ops Reviewed By: hsharma35 Differential Revision: D69156210 Pulled By: zonglinpeng --- .gitmodules | 3 +++ backends/cadence/install_requirements.sh | 7 ++++++- backends/cadence/utils/FACTO | 1 + backends/cadence/utils/TARGETS | 5 +++++ .../cadence/utils}/facto_util.py | 0 backends/cadence/utils/targets.bzl | 20 +++++++++++++++++++ examples/cadence/operators/targets.bzl | 15 +------------- examples/cadence/operators/test_g3_ops.py | 2 +- 8 files changed, 37 insertions(+), 16 deletions(-) create mode 160000 backends/cadence/utils/FACTO create mode 100644 backends/cadence/utils/TARGETS rename {examples/cadence/operators => backends/cadence/utils}/facto_util.py (100%) create mode 100644 backends/cadence/utils/targets.bzl diff --git a/.gitmodules b/.gitmodules index f3407ec95fb..1468cca6363 100644 --- a/.gitmodules +++ b/.gitmodules @@ -64,3 +64,6 @@ [submodule "third-party/ao"] path = third-party/ao url = https://github.com/pytorch/ao.git +[submodule "backends/cadence/utils/FACTO"] + path = backends/cadence/utils/FACTO + url = https://github.com/pytorch-labs/FACTO.git diff --git a/backends/cadence/install_requirements.sh b/backends/cadence/install_requirements.sh index 76cff4b30f3..a80529a2c97 100755 --- a/backends/cadence/install_requirements.sh +++ b/backends/cadence/install_requirements.sh @@ -12,10 +12,11 @@ EXECUTORCH_ROOT_PATH=$(realpath "$SCRIPT_DIR_PATH/../../") CADENCE_DIR_PATH="$EXECUTORCH_ROOT_PATH/backends/cadence" HIFI_DIR_PATH="$CADENCE_DIR_PATH/hifi/third-party/nnlib/nnlib-hifi4" FUSION_DIR_PATH="$CADENCE_DIR_PATH/fusion_g3/third-party/nnlib/nnlib-FusionG3" +FACTO_DIR_PATH="$CADENCE_DIR_PATH/utils/FACTO" cd "$EXECUTORCH_ROOT_PATH" -## HiFi +## HiFi rm -rf "$HIFI_DIR_PATH" mkdir -p "$HIFI_DIR_PATH" @@ -47,3 +48,7 @@ if [ $STATUS -ne 0 ]; then fi git checkout 11230f47b587b074ba0881deb28beb85db566ac2 + + +## FACTO +pip install -e $FACTO_DIR_PATH diff --git a/backends/cadence/utils/FACTO b/backends/cadence/utils/FACTO new file mode 160000 index 00000000000..1db37fc79d0 --- /dev/null +++ b/backends/cadence/utils/FACTO @@ -0,0 +1 @@ +Subproject commit 1db37fc79d0d59638cbb794fa49d878aafc24461 diff --git a/backends/cadence/utils/TARGETS b/backends/cadence/utils/TARGETS new file mode 100644 index 00000000000..67f2bab681a --- /dev/null +++ b/backends/cadence/utils/TARGETS @@ -0,0 +1,5 @@ +load("targets.bzl", "define_common_targets") + +oncall("odai_jarvis") + +define_common_targets() diff --git a/examples/cadence/operators/facto_util.py b/backends/cadence/utils/facto_util.py similarity index 100% rename from examples/cadence/operators/facto_util.py rename to backends/cadence/utils/facto_util.py diff --git a/backends/cadence/utils/targets.bzl b/backends/cadence/utils/targets.bzl new file mode 100644 index 00000000000..5a8d18ec8a2 --- /dev/null +++ b/backends/cadence/utils/targets.bzl @@ -0,0 +1,20 @@ +# 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_library.bzl", "python_library") + + +def define_common_targets(): + python_library( + name = "facto_util", + srcs = [ + "facto_util.py", + ], + typing = True, + deps = [ + "fbcode//caffe2:torch", + "fbcode//pytorch/facto:facto", + ], + ) diff --git a/examples/cadence/operators/targets.bzl b/examples/cadence/operators/targets.bzl index dd6294f85a6..68d90e8238f 100644 --- a/examples/cadence/operators/targets.bzl +++ b/examples/cadence/operators/targets.bzl @@ -18,19 +18,6 @@ def define_common_targets(): for op in TESTS_LIST: _define_test_target(op) - python_library( - name = "facto_util", - srcs = [ - "facto_util.py", - ], - typing = True, - deps = [ - "fbcode//caffe2:torch", - "fbcode//pytorch/facto:facto", - ], - ) - - def _define_test_target(test_name): file_name = "test_{}".format(test_name) python_unittest( @@ -46,6 +33,6 @@ def _define_test_target(test_name): "fbcode//executorch/backends/cadence/aot:ops_registrations", "fbcode//executorch/backends/cadence/aot:export_example", "fbcode//executorch/backends/cadence/aot:compiler", - "fbcode//executorch/examples/cadence/operators:facto_util", + "fbcode//executorch/backends/cadence/utils:facto_util", ], ) diff --git a/examples/cadence/operators/test_g3_ops.py b/examples/cadence/operators/test_g3_ops.py index 58433cc739e..d557c5a3e81 100644 --- a/examples/cadence/operators/test_g3_ops.py +++ b/examples/cadence/operators/test_g3_ops.py @@ -1,7 +1,7 @@ import unittest from typing import Any, cast, List, OrderedDict, Tuple -from executorch.examples.cadence.operators import facto_util +from executorch.backends.cadence.utils import facto_util from parameterized import parameterized