From 23225f4cb9b18294a16e9d80c6ac5cfc1594ac0a Mon Sep 17 00:00:00 2001 From: Chen Lai Date: Tue, 17 Dec 2024 17:57:04 -0800 Subject: [PATCH] Add buck file for static llama (#7276) Summary: As title, moves the buck file related changes in D66107964 to here. Reviewed By: kirklandsign Differential Revision: D67057242 --- examples/qualcomm/TARGETS | 14 +++++- examples/qualcomm/oss_scripts/llama2/TARGETS | 43 +++++++++++++++++++ examples/qualcomm/oss_scripts/llama2/llama.py | 3 ++ .../oss_scripts/llama2/model/static_llama.py | 3 ++ .../qualcomm/oss_scripts/llama3_2/TARGETS | 34 ++++++++++++--- .../qualcomm/oss_scripts/llama3_2/llama.py | 3 ++ examples/qualcomm/utils.py | 3 ++ 7 files changed, 96 insertions(+), 7 deletions(-) create mode 100644 examples/qualcomm/oss_scripts/llama2/TARGETS diff --git a/examples/qualcomm/TARGETS b/examples/qualcomm/TARGETS index d6232977478..8a625bdad21 100644 --- a/examples/qualcomm/TARGETS +++ b/examples/qualcomm/TARGETS @@ -1,11 +1,12 @@ # 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") +load("@fbcode_macros//build_defs:python_library.bzl", "python_library") +load("@fbcode_macros//build_defs:python_binary.bzl", "python_binary") oncall("executorch") -runtime.python_binary( +python_binary( name = "export_example", srcs = ["scripts/export_example.py"], main_function = ".scripts.export_example.main", @@ -20,3 +21,12 @@ runtime.python_binary( "//executorch/extension/export_util:export_util", ], ) + +python_library( + name = "utils", + srcs = ["utils.py"], + deps = [ + "//executorch/backends/qualcomm/partition:partition", + "//executorch/backends/qualcomm/quantizer:quantizer", + ], +) diff --git a/examples/qualcomm/oss_scripts/llama2/TARGETS b/examples/qualcomm/oss_scripts/llama2/TARGETS new file mode 100644 index 00000000000..b0f5ea7f640 --- /dev/null +++ b/examples/qualcomm/oss_scripts/llama2/TARGETS @@ -0,0 +1,43 @@ +load("@fbcode_macros//build_defs:python_library.bzl", "python_library") +load("@fbsource//xplat/executorch/backends/qualcomm/qnn_version.bzl", "get_qnn_library_verision") +load("@fbcode_macros//build_defs:python_binary.bzl", "python_binary") +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") + +oncall("executorch") + + +python_library( + name = "static_llama", + srcs = [ + "model/static_llama.py", + ], + deps = [ + "//caffe2:torch", + ], +) + +python_binary( + name = "llama", + srcs = ["llama.py"], + main_function = "executorch.examples.qualcomm.oss_scripts.llama2.llama.main", + deps = [ + ":static_llama", + "//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/examples/qualcomm:utils", + "//executorch/extension/export_util:export_util", + "//executorch/extension/llm/export:export_lib", + ], +) + +runtime.command_alias( + name = "llama_qnn", + env = { + "LD_LIBRARY_PATH": "$(location fbsource//third-party/qualcomm/qnn/qnn-{0}:qnn_offline_compile_libs)".format(get_qnn_library_verision()), + }, + exe = ":llama", +) diff --git a/examples/qualcomm/oss_scripts/llama2/llama.py b/examples/qualcomm/oss_scripts/llama2/llama.py index ebabfc5ca64..323874a3fa8 100755 --- a/examples/qualcomm/oss_scripts/llama2/llama.py +++ b/examples/qualcomm/oss_scripts/llama2/llama.py @@ -4,6 +4,9 @@ # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. +# TODO: reenable pyre after fixing the issues +# pyre-ignore-all-errors + import codecs import getpass import json diff --git a/examples/qualcomm/oss_scripts/llama2/model/static_llama.py b/examples/qualcomm/oss_scripts/llama2/model/static_llama.py index a0d3397ad9d..6894537b82f 100755 --- a/examples/qualcomm/oss_scripts/llama2/model/static_llama.py +++ b/examples/qualcomm/oss_scripts/llama2/model/static_llama.py @@ -4,6 +4,9 @@ # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. +# TODO: reenable pyre after fixing the issues +# pyre-ignore-all-errors + from typing import List, Optional, Tuple import torch diff --git a/examples/qualcomm/oss_scripts/llama3_2/TARGETS b/examples/qualcomm/oss_scripts/llama3_2/TARGETS index 1e8cc179228..e35f7153bdd 100644 --- a/examples/qualcomm/oss_scripts/llama3_2/TARGETS +++ b/examples/qualcomm/oss_scripts/llama3_2/TARGETS @@ -1,8 +1,32 @@ -# Any targets that should be shared between fbcode and xplat must be defined in -# targets.bzl. This file can contain xplat-only targets. - -load(":targets.bzl", "define_common_targets") +load("@fbcode_macros//build_defs:python_library.bzl", "python_library") +load("@fbsource//xplat/executorch/backends/qualcomm/qnn_version.bzl", "get_qnn_library_verision") +load("@fbcode_macros//build_defs:python_binary.bzl", "python_binary") +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") oncall("executorch") -define_common_targets() +python_binary( + name = "llama", + srcs = ["llama.py"], + main_function = "executorch.examples.qualcomm.oss_scripts.llama3_2.llama.main", + deps = [ + "//executorch/examples/qualcomm/oss_scripts/llama2:static_llama", + "//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/examples/qualcomm:utils", + "//executorch/extension/export_util:export_util", + "//executorch/extension/llm/export:export_lib", + ], +) + +runtime.command_alias( + name = "llama_qnn", + env = { + "LD_LIBRARY_PATH": "$(location fbsource//third-party/qualcomm/qnn/qnn-{0}:qnn_offline_compile_libs)".format(get_qnn_library_verision()), + }, + exe = ":llama", +) diff --git a/examples/qualcomm/oss_scripts/llama3_2/llama.py b/examples/qualcomm/oss_scripts/llama3_2/llama.py index 50b43e86fb3..bb6c65aea21 100755 --- a/examples/qualcomm/oss_scripts/llama3_2/llama.py +++ b/examples/qualcomm/oss_scripts/llama3_2/llama.py @@ -4,6 +4,9 @@ # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. +# TODO: reenable pyre after fixing the issues +# pyre-ignore-all-errors + import getpass import json import logging diff --git a/examples/qualcomm/utils.py b/examples/qualcomm/utils.py index 38d7c9a64e7..bebe99c1d77 100755 --- a/examples/qualcomm/utils.py +++ b/examples/qualcomm/utils.py @@ -4,6 +4,9 @@ # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. +# TODO: reenable pyre after fixing the issues +# pyre-ignore-all-errors + import argparse import os import subprocess