From 6eb0b072a0846ee61bbb83a2542c6c9aacfab0a3 Mon Sep 17 00:00:00 2001 From: Abhishek Chandra Date: Thu, 26 Sep 2024 07:55:02 -0700 Subject: [PATCH] Add buck targets for QNN AOT export (#5476) Summary: Pull Request resolved: https://github.com/pytorch/executorch/pull/5476 Added the necessary buck targets needed to compile qnn export. Next steps: Get llama model export to succeed without any errors. bypass-github-export-checks Reviewed By: derekxu, cccclai Differential Revision: D61808158 --- backends/qualcomm/aot/python/TARGETS | 5 + backends/qualcomm/aot/python/targets.bzl | 100 ++++++++++ backends/qualcomm/builders/TARGETS | 5 + backends/qualcomm/builders/targets.bzl | 25 +++ backends/qualcomm/partition/TARGETS | 5 + backends/qualcomm/partition/targets.bzl | 24 +++ backends/qualcomm/passes/TARGETS | 5 + backends/qualcomm/passes/targets.bzl | 22 +++ backends/qualcomm/quantizer/TARGETS | 5 + backends/qualcomm/quantizer/targets.bzl | 20 ++ backends/qualcomm/runtime/targets.bzl | 69 ++++--- backends/qualcomm/serialization/TARGETS | 8 + backends/qualcomm/serialization/targets.bzl | 31 +++ backends/qualcomm/targets.bzl | 13 ++ backends/qualcomm/utils/TARGETS | 8 + backends/qualcomm/utils/targets.bzl | 22 +++ backends/transforms/TARGETS | 196 +------------------ backends/transforms/targets.bzl | 201 ++++++++++++++++++++ examples/models/llama2/TARGETS | 1 + examples/qualcomm/TARGETS | 22 +++ examples/qualcomm/scripts/export_example.py | 8 +- extension/llm/custom_ops/model_sharding.py | 1 + extension/llm/custom_ops/targets.bzl | 14 ++ extension/llm/export/TARGETS | 2 + 24 files changed, 586 insertions(+), 226 deletions(-) create mode 100644 backends/qualcomm/aot/python/TARGETS create mode 100644 backends/qualcomm/aot/python/targets.bzl create mode 100644 backends/qualcomm/builders/TARGETS create mode 100644 backends/qualcomm/builders/targets.bzl create mode 100644 backends/qualcomm/partition/TARGETS create mode 100644 backends/qualcomm/partition/targets.bzl create mode 100644 backends/qualcomm/passes/TARGETS create mode 100644 backends/qualcomm/passes/targets.bzl create mode 100644 backends/qualcomm/quantizer/TARGETS create mode 100644 backends/qualcomm/quantizer/targets.bzl create mode 100644 backends/qualcomm/serialization/TARGETS create mode 100644 backends/qualcomm/serialization/targets.bzl create mode 100644 backends/qualcomm/utils/TARGETS create mode 100644 backends/qualcomm/utils/targets.bzl create mode 100644 backends/transforms/targets.bzl create mode 100644 examples/qualcomm/TARGETS diff --git a/backends/qualcomm/aot/python/TARGETS b/backends/qualcomm/aot/python/TARGETS new file mode 100644 index 00000000000..0a42614a385 --- /dev/null +++ b/backends/qualcomm/aot/python/TARGETS @@ -0,0 +1,5 @@ +load(":targets.bzl", "define_common_targets") + +oncall("executorch") + +define_common_targets() diff --git a/backends/qualcomm/aot/python/targets.bzl b/backends/qualcomm/aot/python/targets.bzl new file mode 100644 index 00000000000..b16acfc4905 --- /dev/null +++ b/backends/qualcomm/aot/python/targets.bzl @@ -0,0 +1,100 @@ +load( + "@fbsource//tools/build_defs:default_platform_defs.bzl", + "ANDROID", +) +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") + +PYTHON_MODULE_NAME = "PyQnnManagerAdaptor" + +def define_common_targets(): + """Defines targets that should be shared between fbcode and xplat. + The directory containing this targets.bzl file should also contain both + TARGETS and BUCK files that call this function. + """ + + runtime.cxx_python_extension( + name = "PyQnnManagerAdaptor", + srcs = [ + "PyQnnManagerAdaptor.cpp", + ], + headers = [ + "PyQnnManagerAdaptor.h", + ], + base_module = "executorch.backends.qualcomm.python", + preprocessor_flags = [ + "-DEXECUTORCH_PYTHON_MODULE_NAME={}".format(PYTHON_MODULE_NAME), + ], + deps = [ + "//executorch/runtime/core:core", + "//executorch/backends/qualcomm/aot/python:python_lib", + "//executorch/backends/qualcomm/aot/wrappers:wrappers", + "//executorch/backends/qualcomm/runtime:logging", + "//executorch/backends/qualcomm:schema", + "//executorch/backends/qualcomm/aot/ir:qcir_utils", + "//executorch/backends/qualcomm/runtime:runtime", + "fbsource//third-party/qualcomm/qnn:api", + ], + external_deps = [ + "pybind11", + "libtorch_python", + ], + use_static_deps = True, + visibility = [ + "//executorch/backends/qualcomm/...", + ], + ) + + + runtime.cxx_python_extension( + name = "PyQnnWrapperAdaptor", + srcs = [ + "PyQnnWrapperAdaptor.cpp", + ], + headers = [ + "PyQnnWrapperAdaptor.h", + ], + base_module = "executorch.backends.qualcomm.python", + preprocessor_flags = [ + "-DEXECUTORCH_PYTHON_MODULE_NAME={}".format(PYTHON_MODULE_NAME), + ], + deps = [ + "//executorch/runtime/core:core", + "//executorch/backends/qualcomm/aot/python:python_lib", + "//executorch/backends/qualcomm/aot/wrappers:wrappers", + "//executorch/backends/qualcomm/runtime:logging", + "//executorch/backends/qualcomm:schema", + "//executorch/backends/qualcomm/aot/ir:qcir_utils", + "//executorch/backends/qualcomm/runtime:runtime", + "fbsource//third-party/qualcomm/qnn:api", + ], + external_deps = [ + "pybind11", + "libtorch_python", + ], + use_static_deps = True, + visibility = [ + "//executorch/backends/qualcomm/...", + ], + ) + + runtime.cxx_library( + name = "python_lib", + srcs = glob([ + "*.cpp", + ]), + exported_headers = glob([ + "*.h", + ]), + visibility = ["@EXECUTORCH_CLIENTS"], + deps = [ + "//executorch/backends/qualcomm/aot/wrappers:wrappers", + "//executorch/backends/qualcomm/runtime:logging", + "//executorch/backends/qualcomm:schema", + "//executorch/backends/qualcomm/aot/ir:qcir_utils", + "//executorch/backends/qualcomm/runtime:runtime", + "fbsource//third-party/qualcomm/qnn:api", + ], + external_deps = [ + "pybind11", + ], + ) diff --git a/backends/qualcomm/builders/TARGETS b/backends/qualcomm/builders/TARGETS new file mode 100644 index 00000000000..0a42614a385 --- /dev/null +++ b/backends/qualcomm/builders/TARGETS @@ -0,0 +1,5 @@ +load(":targets.bzl", "define_common_targets") + +oncall("executorch") + +define_common_targets() diff --git a/backends/qualcomm/builders/targets.bzl b/backends/qualcomm/builders/targets.bzl new file mode 100644 index 00000000000..39159e56cd8 --- /dev/null +++ b/backends/qualcomm/builders/targets.bzl @@ -0,0 +1,25 @@ +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") + +def define_common_targets(): + """Defines targets that should be shared between fbcode and xplat. + The directory containing this targets.bzl file should also contain both + TARGETS and BUCK files that call this function. + """ + + runtime.python_library( + name = "builders", + srcs = glob([ + "*.py", + ]), + visibility = [ + "@EXECUTORCH_CLIENTS", + ], + deps = [ + "//executorch/exir/backend:backend_details", + "//executorch/exir/backend:compile_spec_schema", + "//executorch/backends/qualcomm/aot/python:PyQnnWrapperAdaptor", + "//executorch/backends/qualcomm/aot/python:PyQnnManagerAdaptor", + "//executorch/backends/qualcomm/utils:utils", + "//executorch/exir:lib", + ], + ) diff --git a/backends/qualcomm/partition/TARGETS b/backends/qualcomm/partition/TARGETS new file mode 100644 index 00000000000..0a42614a385 --- /dev/null +++ b/backends/qualcomm/partition/TARGETS @@ -0,0 +1,5 @@ +load(":targets.bzl", "define_common_targets") + +oncall("executorch") + +define_common_targets() diff --git a/backends/qualcomm/partition/targets.bzl b/backends/qualcomm/partition/targets.bzl new file mode 100644 index 00000000000..72248a6cebb --- /dev/null +++ b/backends/qualcomm/partition/targets.bzl @@ -0,0 +1,24 @@ +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") + +def define_common_targets(): + """Defines targets that should be shared between fbcode and xplat. + The directory containing this targets.bzl file should also contain both + TARGETS and BUCK files that call this function. + """ + + runtime.python_library( + name = "partition", + srcs = glob([ + "*.py", + ]), + visibility = [ + "@EXECUTORCH_CLIENTS", + ], + deps = [ + "//executorch/exir/backend:backend_details", + "//executorch/exir/backend:compile_spec_schema", + "//executorch/backends/qualcomm/builders:builders", + "//executorch/backends/qualcomm:preprocess", + "//executorch/exir/backend/canonical_partitioners:canonical_partitioner_lib", + ], + ) diff --git a/backends/qualcomm/passes/TARGETS b/backends/qualcomm/passes/TARGETS new file mode 100644 index 00000000000..0a42614a385 --- /dev/null +++ b/backends/qualcomm/passes/TARGETS @@ -0,0 +1,5 @@ +load(":targets.bzl", "define_common_targets") + +oncall("executorch") + +define_common_targets() diff --git a/backends/qualcomm/passes/targets.bzl b/backends/qualcomm/passes/targets.bzl new file mode 100644 index 00000000000..d5bf8cf01ee --- /dev/null +++ b/backends/qualcomm/passes/targets.bzl @@ -0,0 +1,22 @@ +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") + +def define_common_targets(): + """Defines targets that should be shared between fbcode and xplat. + The directory containing this targets.bzl file should also contain both + TARGETS and BUCK files that call this function. + """ + + runtime.python_library( + name = "passes", + srcs = glob([ + "*.py", + ]), + visibility = [ + "@EXECUTORCH_CLIENTS", + ], + deps = [ + "//executorch/exir/backend:backend_details", + "//executorch/exir/backend:compile_spec_schema", + "//executorch/backends/transforms:addmm_mm_to_linear", + ], + ) diff --git a/backends/qualcomm/quantizer/TARGETS b/backends/qualcomm/quantizer/TARGETS new file mode 100644 index 00000000000..0a42614a385 --- /dev/null +++ b/backends/qualcomm/quantizer/TARGETS @@ -0,0 +1,5 @@ +load(":targets.bzl", "define_common_targets") + +oncall("executorch") + +define_common_targets() diff --git a/backends/qualcomm/quantizer/targets.bzl b/backends/qualcomm/quantizer/targets.bzl new file mode 100644 index 00000000000..a6689012b25 --- /dev/null +++ b/backends/qualcomm/quantizer/targets.bzl @@ -0,0 +1,20 @@ +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") + +def define_common_targets(): + """Defines targets that should be shared between fbcode and xplat. + + The directory containing this targets.bzl file should also contain both + TARGETS and BUCK files that call this function. + """ + runtime.python_library( + name = "quantizer", + srcs = glob([ + "*.py", + ]), + visibility = [ + "@EXECUTORCH_CLIENTS", + ], + deps = [ + "//executorch/backends/transforms:decompose_sdpa", + ], + ) diff --git a/backends/qualcomm/runtime/targets.bzl b/backends/qualcomm/runtime/targets.bzl index 61650fab268..4bd981dc7ad 100644 --- a/backends/qualcomm/runtime/targets.bzl +++ b/backends/qualcomm/runtime/targets.bzl @@ -25,44 +25,51 @@ def define_common_targets(): deps = [ "fbsource//third-party/qualcomm/qnn:api", "//executorch/runtime/backend:interface", - "//executorch/runtime/core:core", ], exported_deps = [ "//executorch/backends/qualcomm:schema", + "//executorch/runtime/core:core", ], ) runtime.cxx_library( - name = "runtime", - srcs = glob( - [ - "*.cpp", - "backends/*.cpp", - "backends/htpbackend/*.cpp", - "backends/htpbackend/aarch64/*.cpp", + name = "runtime", + srcs = glob( + [ + "*.cpp", + "backends/*.cpp", + "backends/htpbackend/*.cpp", + "backends/htpbackend/aarch64/*.cpp", + ], + exclude = ["Logging.cpp"], + ), + exported_headers = glob( + [ + "*.h", + "backends/*.h", + "backends/htpbackend/*.h", + ], + exclude = ["Logging.h"], + ), + define_static_target = True, + link_whole = True, # needed for executorch/examples/models/llama2:main to register QnnBackend + platforms = [ANDROID], + visibility = ["@EXECUTORCH_CLIENTS"], + resources = { + "qnn_lib": "fbsource//third-party/qualcomm/qnn/qnn-2.25:qnn_offline_compile_libs", + }, + deps = [ + "fbsource//third-party/qualcomm/qnn:api", + ":logging", + "//executorch/backends/qualcomm:schema", + "//executorch/backends/qualcomm/aot/ir:qcir_utils", + "//executorch/backends/qualcomm/aot/wrappers:wrappers", + "//executorch/runtime/backend:interface", + "//executorch/runtime/core:core", + "//executorch/extension/tensor:tensor", ], - exclude = ["Logging.cpp"], - ), - exported_headers = glob( - [ - "*.h", - "backends/*.h", - "backends/htpbackend/*.h", + exported_deps = [ + "//executorch/runtime/core/exec_aten/util:scalar_type_util", + "//executorch/runtime/core:event_tracer", ], - exclude = ["Logging.h"], - ), - define_static_target = True, - link_whole = True, # needed for executorch/examples/models/llama2:main to register QnnBackend - platforms = [ANDROID], - visibility = ["@EXECUTORCH_CLIENTS"], - deps = [ - "fbsource//third-party/qualcomm/qnn:api", - ":logging", - "//executorch/backends/qualcomm:schema", - "//executorch/backends/qualcomm/aot/ir:qcir_utils", - "//executorch/backends/qualcomm/aot/wrappers:wrappers", - "//executorch/runtime/backend:interface", - "//executorch/runtime/core:core", - "//executorch/extension/tensor:tensor", - ], ) diff --git a/backends/qualcomm/serialization/TARGETS b/backends/qualcomm/serialization/TARGETS new file mode 100644 index 00000000000..2341af9282f --- /dev/null +++ b/backends/qualcomm/serialization/TARGETS @@ -0,0 +1,8 @@ +# Any targets that should be shared between fbcode and xplat must be defined in +# targets.bzl. This file can contain fbcode-only targets. + +load(":targets.bzl", "define_common_targets") + +oncall("executorch") + +define_common_targets() diff --git a/backends/qualcomm/serialization/targets.bzl b/backends/qualcomm/serialization/targets.bzl new file mode 100644 index 00000000000..c3c571109e7 --- /dev/null +++ b/backends/qualcomm/serialization/targets.bzl @@ -0,0 +1,31 @@ +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") +load("@fbcode_macros//build_defs:export_files.bzl", "export_file") + +def define_common_targets(): + """Defines targets that should be shared between fbcode and xplat. + The directory containing this targets.bzl file should also contain both + TARGETS and BUCK files that call this function. + """ + + export_file( + name = "qnn_schema", + src = "schema.fbs", + visibility = ["//executorch/backends/qualcomm/serialization/..."], + ) + + runtime.python_library( + name = "serialization", + srcs = glob([ + "*.py", + ]), + resources = { + ":qnn_schema": "schema.fbs", + }, + visibility = [ + "@EXECUTORCH_CLIENTS", + ], + deps = [ + "//executorch/exir/backend:backend_details", + "//executorch/exir/backend:compile_spec_schema", + ], + ) diff --git a/backends/qualcomm/targets.bzl b/backends/qualcomm/targets.bzl index 55fe390f6b0..680e74681e7 100644 --- a/backends/qualcomm/targets.bzl +++ b/backends/qualcomm/targets.bzl @@ -2,6 +2,7 @@ load( "@fbsource//tools/build_defs:default_platform_defs.bzl", "ANDROID", ) +load("@fbcode_macros//build_defs:python_library.bzl", "python_library") load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") @@ -93,3 +94,15 @@ def define_common_targets(): ":schema", ], ) + + runtime.python_library( + name = "preprocess", + srcs = ["qnn_preprocess.py"], + deps = [ + "//executorch/backends/qualcomm/passes:passes", + ], + visibility = [ + "//executorch/backends/qualcomm/...", + "@EXECUTORCH_CLIENTS", + ], + ) diff --git a/backends/qualcomm/utils/TARGETS b/backends/qualcomm/utils/TARGETS new file mode 100644 index 00000000000..2341af9282f --- /dev/null +++ b/backends/qualcomm/utils/TARGETS @@ -0,0 +1,8 @@ +# Any targets that should be shared between fbcode and xplat must be defined in +# targets.bzl. This file can contain fbcode-only targets. + +load(":targets.bzl", "define_common_targets") + +oncall("executorch") + +define_common_targets() diff --git a/backends/qualcomm/utils/targets.bzl b/backends/qualcomm/utils/targets.bzl new file mode 100644 index 00000000000..c76ef7f1906 --- /dev/null +++ b/backends/qualcomm/utils/targets.bzl @@ -0,0 +1,22 @@ +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") + +def define_common_targets(): + """Defines targets that should be shared between fbcode and xplat. + The directory containing this targets.bzl file should also contain both + TARGETS and BUCK files that call this function. + """ + + runtime.python_library( + name = "utils", + srcs = glob([ + "*.py", + ]), + visibility = [ + "@EXECUTORCH_CLIENTS", + ], + deps = [ + "//executorch/exir/backend:backend_details", + "//executorch/exir/backend:compile_spec_schema", + "//executorch/backends/qualcomm/serialization:serialization", + ], + ) diff --git a/backends/transforms/TARGETS b/backends/transforms/TARGETS index df50e45f099..0a42614a385 100644 --- a/backends/transforms/TARGETS +++ b/backends/transforms/TARGETS @@ -1,197 +1,5 @@ -load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") +load(":targets.bzl", "define_common_targets") oncall("executorch") -runtime.python_library( - name = "lib", - srcs = [ - "__init__.py", - ], - visibility = [ - "//executorch/backends/...", - ], - deps = [ - ":addmm_mm_to_linear", - ], -) - -runtime.python_library( - name = "addmm_mm_to_linear", - srcs = ["addmm_mm_to_linear.py"], - visibility = [ - "//executorch/backends/...", - ], - deps = [ - "//caffe2:torch", - "//executorch/exir:pass_base", - "//executorch/exir:sym_util", - "//executorch/exir/dialects:lib", - ], -) - -runtime.python_library( - name = "decompose_sdpa", - srcs = ["decompose_sdpa.py"], - visibility = [ - "//executorch/backends/...", - "@EXECUTORCH_CLIENTS", - ], - deps = [ - "//caffe2:torch", - "//executorch/exir:pass_base", - ], -) - -runtime.python_library( - name = "fuse_batch_norm_with_conv", - srcs = ["fuse_batch_norm_with_conv.py"], - visibility = [ - "//executorch/backends/...", - ], - deps = [ - ":utils", - "//caffe2:torch", - "//executorch/exir:pass_base", - "//executorch/exir:sym_util", - "//executorch/exir/dialects:lib", - ], -) - -runtime.python_library( - name = "fuse_conv_with_clamp", - srcs = ["fuse_conv_with_clamp.py"], - visibility = [ - "//executorch/backends/...", - ], - deps = [ - ":utils", - "//caffe2:torch", - "//executorch/backends/vulkan/passes:custom_ops_defs", - "//executorch/exir:pass_base", - "//executorch/exir:sym_util", - "//executorch/exir/dialects:lib", - ], -) - -runtime.python_library( - name = "fuse_dequant_linear", - srcs = ["fuse_dequant_linear.py"], - visibility = [ - "//executorch/backends/...", - ], - deps = [ - ":utils", - "//caffe2:torch", - "//executorch/exir:pass_base", - "//executorch/exir:sym_util", - "//executorch/exir/dialects:lib", - ], -) - -runtime.python_library( - name = "view_copy_to_squeeze_unsqueeze", - srcs = ["view_copy_to_squeeze_unsqueeze.py"], - visibility = [ - "//executorch/backends/...", - ], - deps = [ - ":utils", - "//caffe2:torch", - "//executorch/exir:pass_base", - "//executorch/exir/dialects:lib", - ], -) - -runtime.python_library( - name = "fuse_view_copy", - srcs = ["fuse_view_copy.py"], - visibility = [ - "//executorch/backends/...", - ], - deps = [ - "//caffe2:torch", - "//executorch/exir:pass_base", - "//executorch/exir/dialects:lib", - ], -) - -runtime.python_library( - name = "remove_clone_ops", - srcs = ["remove_clone_ops.py"], - visibility = [ - "//executorch/backends/...", - ], - deps = [ - "//caffe2:torch", - "//executorch/exir:pass_base", - "//executorch/exir/dialects:lib", - ], -) - -runtime.python_library( - name = "mean_to_sum_div", - srcs = ["mean_to_sum_div.py"], - visibility = [ - "//executorch/backends/...", - ], - deps = [ - "//caffe2:torch", - "//executorch/exir:pass_base", - "//executorch/exir:sym_util", - "//executorch/exir/dialects:lib", - ], -) - -runtime.python_library( - name = "utils", - srcs = ["utils.py"], - deps = [ - "//caffe2:torch", - "//executorch/exir:lib", - "//executorch/exir:pass_manager", - "//executorch/exir/backend/canonical_partitioners:canonical_partitioner_lib", - "//executorch/exir/dialects:lib", - "//pytorch/ao:torchao", # @manual - ], -) - -runtime.python_library( - name = "duplicate_dynamic_quant_chain", - srcs = ["duplicate_dynamic_quant_chain.py"], - visibility = [ - "//executorch/backends/...", - "//executorch/examples/...", - "//executorch/extension/llm/...", - "@EXECUTORCH_CLIENTS", - ], - deps = [ - "//caffe2:torch", - ], -) - -runtime.python_library( - name = "convert_dtype_pass", - srcs = [ - "convert_dtype_pass.py", - ], - visibility = [ - "//executorch/backends/...", - ], - deps = [ - "//caffe2:torch", - "//executorch/exir:pass_base", - ], -) - -runtime.python_test( - name = "test_duplicate_dynamic_quant_chain", - srcs = [ - "test/test_duplicate_dynamic_quant_chain.py", - ], - deps = [ - "fbsource//third-party/pypi/expecttest:expecttest", # @manual - ":duplicate_dynamic_quant_chain", - "//caffe2:torch", - "//executorch/exir:lib", - ], -) +define_common_targets() diff --git a/backends/transforms/targets.bzl b/backends/transforms/targets.bzl new file mode 100644 index 00000000000..458a2d71bb5 --- /dev/null +++ b/backends/transforms/targets.bzl @@ -0,0 +1,201 @@ +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") + +def define_common_targets(): + """Defines targets that should be shared between fbcode and xplat. + The directory containing this targets.bzl file should also contain both + TARGETS and BUCK files that call this function. + """ + + runtime.python_library( + name = "lib", + srcs = [ + "__init__.py", + ], + visibility = [ + "//executorch/backends/...", + ], + deps = [ + ":addmm_mm_to_linear", + ], + ) + + runtime.python_library( + name = "addmm_mm_to_linear", + srcs = ["addmm_mm_to_linear.py"], + visibility = [ + "//executorch/backends/...", + ], + deps = [ + "//caffe2:torch", + "//executorch/exir:pass_base", + "//executorch/exir:sym_util", + "//executorch/exir/dialects:lib", + ], + ) + + runtime.python_library( + name = "decompose_sdpa", + srcs = ["decompose_sdpa.py"], + visibility = [ + "//executorch/backends/...", + "@EXECUTORCH_CLIENTS", + ], + deps = [ + "//caffe2:torch", + "//executorch/exir:pass_base", + ], + ) + + runtime.python_library( + name = "fuse_batch_norm_with_conv", + srcs = ["fuse_batch_norm_with_conv.py"], + visibility = [ + "//executorch/backends/...", + ], + deps = [ + ":utils", + "//caffe2:torch", + "//executorch/exir:pass_base", + "//executorch/exir:sym_util", + "//executorch/exir/dialects:lib", + ], + ) + + runtime.python_library( + name = "fuse_conv_with_clamp", + srcs = ["fuse_conv_with_clamp.py"], + visibility = [ + "//executorch/backends/...", + ], + deps = [ + ":utils", + "//caffe2:torch", + "//executorch/backends/vulkan/passes:custom_ops_defs", + "//executorch/exir:pass_base", + "//executorch/exir:sym_util", + "//executorch/exir/dialects:lib", + ], + ) + + runtime.python_library( + name = "fuse_dequant_linear", + srcs = ["fuse_dequant_linear.py"], + visibility = [ + "//executorch/backends/...", + ], + deps = [ + ":utils", + "//caffe2:torch", + "//executorch/exir:pass_base", + "//executorch/exir:sym_util", + "//executorch/exir/dialects:lib", + ], + ) + + runtime.python_library( + name = "view_copy_to_squeeze_unsqueeze", + srcs = ["view_copy_to_squeeze_unsqueeze.py"], + visibility = [ + "//executorch/backends/...", + ], + deps = [ + ":utils", + "//caffe2:torch", + "//executorch/exir:pass_base", + "//executorch/exir/dialects:lib", + ], + ) + + runtime.python_library( + name = "fuse_view_copy", + srcs = ["fuse_view_copy.py"], + visibility = [ + "//executorch/backends/...", + ], + deps = [ + "//caffe2:torch", + "//executorch/exir:pass_base", + "//executorch/exir/dialects:lib", + ], + ) + + runtime.python_library( + name = "remove_clone_ops", + srcs = ["remove_clone_ops.py"], + visibility = [ + "//executorch/backends/...", + ], + deps = [ + "//caffe2:torch", + "//executorch/exir:pass_base", + "//executorch/exir/dialects:lib", + ], + ) + + runtime.python_library( + name = "mean_to_sum_div", + srcs = ["mean_to_sum_div.py"], + visibility = [ + "//executorch/backends/...", + ], + deps = [ + "//caffe2:torch", + "//executorch/exir:pass_base", + "//executorch/exir:sym_util", + "//executorch/exir/dialects:lib", + ], + ) + + runtime.python_library( + name = "utils", + srcs = ["utils.py"], + deps = [ + "//caffe2:torch", + "//executorch/exir:lib", + "//executorch/exir:pass_manager", + "//executorch/exir/backend/canonical_partitioners:canonical_partitioner_lib", + "//executorch/exir/dialects:lib", + "//pytorch/ao:torchao", # @manual + ], + ) + + runtime.python_library( + name = "duplicate_dynamic_quant_chain", + srcs = ["duplicate_dynamic_quant_chain.py"], + visibility = [ + "//executorch/backends/...", + "//executorch/examples/...", + "//executorch/extension/llm/...", + "@EXECUTORCH_CLIENTS", + ], + deps = [ + "//caffe2:torch", + ], + ) + + runtime.python_library( + name = "convert_dtype_pass", + srcs = [ + "convert_dtype_pass.py", + ], + visibility = [ + "//executorch/backends/...", + ], + deps = [ + "//caffe2:torch", + "//executorch/exir:pass_base", + ], + ) + + runtime.python_test( + name = "test_duplicate_dynamic_quant_chain", + srcs = [ + "test/test_duplicate_dynamic_quant_chain.py", + ], + deps = [ + "fbsource//third-party/pypi/expecttest:expecttest", # @manual + ":duplicate_dynamic_quant_chain", + "//caffe2:torch", + "//executorch/exir:lib", + ], + ) diff --git a/examples/models/llama2/TARGETS b/examples/models/llama2/TARGETS index 7ed858a33c5..eeeb8e5a04c 100644 --- a/examples/models/llama2/TARGETS +++ b/examples/models/llama2/TARGETS @@ -54,6 +54,7 @@ runtime.python_binary( main_function = "executorch.examples.models.llama2.export_llama.main", # visibility = ["//executorch/examples/..."], preload_deps = [ + "//executorch/extension/llm/custom_ops:model_sharding_py", "//executorch/extension/llm/custom_ops:custom_ops_aot_lib", "//executorch/kernels/quantized:aot_lib", ], diff --git a/examples/qualcomm/TARGETS b/examples/qualcomm/TARGETS new file mode 100644 index 00000000000..d6232977478 --- /dev/null +++ b/examples/qualcomm/TARGETS @@ -0,0 +1,22 @@ +# Any targets that should be shared between fbcode and xplat must be defined in +# targets.bzl. This file can contain fbcode-only targets. + +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") + +oncall("executorch") + +runtime.python_binary( + name = "export_example", + srcs = ["scripts/export_example.py"], + main_function = ".scripts.export_example.main", + visibility = ["//executorch/examples/..."], + deps = [ + "//caffe2:torch", + "//executorch/extension/pybindings:aten_lib", + "//executorch/backends/qualcomm/partition:partition", + "//executorch/backends/qualcomm/quantizer:quantizer", + "//executorch/devtools:lib", + "//executorch/examples/models:models", + "//executorch/extension/export_util:export_util", + ], +) diff --git a/examples/qualcomm/scripts/export_example.py b/examples/qualcomm/scripts/export_example.py index 08f18d6ac6a..9e073b998d7 100644 --- a/examples/qualcomm/scripts/export_example.py +++ b/examples/qualcomm/scripts/export_example.py @@ -1,3 +1,4 @@ +# pyre-ignore-all-errors import argparse import copy @@ -24,7 +25,8 @@ from torch.ao.quantization.quantize_pt2e import convert_pt2e, prepare_pt2e -if __name__ == "__main__": + +def main() -> None: parser = argparse.ArgumentParser() parser.add_argument( "-m", @@ -104,3 +106,7 @@ generate_etrecord(etrecord_path, edge_copy, executorch_program) save_pte_program(executorch_program, args.model_name, args.output_folder) + + +if __name__ == "__main__": + main() # pragma: no cover diff --git a/extension/llm/custom_ops/model_sharding.py b/extension/llm/custom_ops/model_sharding.py index 75d6fd25740..244c036c9b7 100644 --- a/extension/llm/custom_ops/model_sharding.py +++ b/extension/llm/custom_ops/model_sharding.py @@ -3,6 +3,7 @@ # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. +# pyre-ignore-all-errors import re from typing import List diff --git a/extension/llm/custom_ops/targets.bzl b/extension/llm/custom_ops/targets.bzl index 488f214e2bf..43fed39a5d5 100644 --- a/extension/llm/custom_ops/targets.bzl +++ b/extension/llm/custom_ops/targets.bzl @@ -123,6 +123,20 @@ def define_common_targets(): ], ) + runtime.python_library( + name = "model_sharding_py", + srcs = [ + "model_sharding.py", + ], + visibility = [ + "//executorch/...", + "@EXECUTORCH_CLIENTS", + ], + deps = [ + "//caffe2:torch", + ], + ) + runtime.cxx_library( name = "op_tile_crop", srcs = ["op_tile_crop.cpp"], diff --git a/extension/llm/export/TARGETS b/extension/llm/export/TARGETS index be9bc183dbe..e4ade20228b 100644 --- a/extension/llm/export/TARGETS +++ b/extension/llm/export/TARGETS @@ -27,6 +27,8 @@ runtime.python_library( "//executorch/backends/apple/coreml:backend", "//executorch/backends/apple/coreml:partitioner", "//executorch/backends/apple/mps:partitioner", + "//executorch/backends/qualcomm/partition:partition", + "//executorch/backends/qualcomm/quantizer:quantizer", "//executorch/backends/transforms:duplicate_dynamic_quant_chain", "//executorch/backends/vulkan/partitioner:vulkan_partitioner", "//executorch/backends/xnnpack/partition:xnnpack_partitioner",