From d685ec6c791d7fe861ad5b61dcd5710637376376 Mon Sep 17 00:00:00 2001 From: Lan Luo Date: Thu, 21 May 2026 11:08:59 -0700 Subject: [PATCH 1/4] [Executorch] clean up build, in dlfw support save only path --- .bazelrc | 1 + .github/scripts/setup-executorch-ci.sh | 148 --------------- .github/workflows/build-test-linux-x86_64.yml | 2 - .github/workflows/executorch-static-linux.yml | 11 +- BUILD.bazel | 23 ++- MODULE.bazel | 18 +- docker/MODULE.bazel.ngc | 10 ++ setup.py | 15 +- third_party/executorch/BUILD | 47 ++++- toolchains/ci_workspaces/MODULE.bazel.tmpl | 15 +- toolchains/local_executorch.bzl | 168 ------------------ 11 files changed, 105 insertions(+), 353 deletions(-) delete mode 100644 .github/scripts/setup-executorch-ci.sh delete mode 100644 toolchains/local_executorch.bzl diff --git a/.bazelrc b/.bazelrc index da112a7ed1..ccee524410 100644 --- a/.bazelrc +++ b/.bazelrc @@ -40,6 +40,7 @@ build:cxx11_abi --define=abi=cxx11_abi build:jetpack --//toolchains/dep_collection:compute_libs=jetpack build:rtx --//toolchains/dep_collection:compute_libs=rtx +build:dlfw --//:package_executorch=false build:ci_testing --define=torchtrt_src=prebuilt --cxxopt="-DDISABLE_TEST_IN_CI" --action_env "NVIDIA_TF32_OVERRIDE=0" build:use_precompiled_torchtrt --define=torchtrt_src=prebuilt diff --git a/.github/scripts/setup-executorch-ci.sh b/.github/scripts/setup-executorch-ci.sh deleted file mode 100644 index cfe8165a58..0000000000 --- a/.github/scripts/setup-executorch-ci.sh +++ /dev/null @@ -1,148 +0,0 @@ -#!/usr/bin/env bash - -# Prepare an ExecuTorch source checkout for CI builds that need Bazel @executorch. -# -# This script is intended to be sourced from CI steps so the exported -# EXECUTORCH_ROOT / EXECUTORCH_SOURCE_DIR values are available to commands in -# the same shell. It also writes the variables to GitHub and build env files -# when those files are available. - -_torchtrt_executorch_normalize_ref() { - case "$1" in - ""|"latest"|"latest-main"|"latest_main"|"latest main") - printf '%s\n' "main" - ;; - *) - printf '%s\n' "$1" - ;; - esac -} - -_torchtrt_executorch_python() { - if command -v python3 >/dev/null 2>&1; then - command -v python3 - elif command -v python >/dev/null 2>&1; then - command -v python - else - return 1 - fi -} - -_torchtrt_executorch_ensure_cmake() { - if command -v cmake >/dev/null 2>&1; then - return 0 - fi - - local python_executable - python_executable="$(_torchtrt_executorch_python)" || { - echo "cmake is not installed and no Python interpreter is available to install it" >&2 - return 1 - } - - "${python_executable}" -m pip install --progress-bar=off cmake ninja || return 1 - export PATH="$("${python_executable}" -m site --user-base)/bin:${PATH}" - - if ! command -v cmake >/dev/null 2>&1; then - echo "cmake is still unavailable after pip install" >&2 - return 1 - fi -} - -_torchtrt_executorch_find_core_archive() { - local executorch_root="$1" - local candidate - for candidate in \ - "${executorch_root}/cmake-out/libexecutorch_core.a" \ - "${executorch_root}/cmake-out/lib/libexecutorch_core.a" \ - "${executorch_root}/cmake-out/executorch/libexecutorch_core.a" \ - "${executorch_root}/lib/libexecutorch_core.a" \ - "${executorch_root}/lib64/libexecutorch_core.a" \ - "${executorch_root}/libexecutorch_core.a"; do - if [[ -f "${candidate}" ]]; then - printf '%s\n' "${candidate}" - return 0 - fi - done - - find "${executorch_root}/cmake-out" -name libexecutorch_core.a -type f -print -quit 2>/dev/null || true -} - -_torchtrt_executorch_export_env() { - local executorch_root="$1" - export EXECUTORCH_ROOT="${executorch_root}" - export EXECUTORCH_SOURCE_DIR="${executorch_root}" - - if [[ -n "${GITHUB_ENV:-}" ]]; then - { - echo "EXECUTORCH_ROOT=${EXECUTORCH_ROOT}" - echo "EXECUTORCH_SOURCE_DIR=${EXECUTORCH_SOURCE_DIR}" - } >> "${GITHUB_ENV}" - fi - - if [[ -n "${BUILD_ENV_FILE:-}" ]]; then - { - echo "export EXECUTORCH_ROOT=\"${EXECUTORCH_ROOT}\"" - echo "export EXECUTORCH_SOURCE_DIR=\"${EXECUTORCH_SOURCE_DIR}\"" - } >> "${BUILD_ENV_FILE}" - fi -} - -_torchtrt_setup_executorch_ci() { - local executorch_ref - local executorch_root - local executorch_parent - local core_archive - local max_jobs - - executorch_ref="$(_torchtrt_executorch_normalize_ref "${EXECUTORCH_REF:-main}")" - executorch_root="${EXECUTORCH_ROOT:-${EXECUTORCH_SOURCE_DIR:-}}" - - if [[ -z "${executorch_root}" ]]; then - executorch_parent="${RUNNER_TEMP:-/tmp}" - executorch_root="${executorch_parent%/}/executorch" - fi - - if [[ ! -f "${executorch_root}/CMakeLists.txt" ]]; then - if [[ -e "${executorch_root}" ]]; then - echo "EXECUTORCH_ROOT exists but is not an ExecuTorch source checkout: ${executorch_root}" >&2 - return 1 - fi - - mkdir -p "$(dirname "${executorch_root}")" || return 1 - git clone --depth 1 --branch "${executorch_ref}" --recurse-submodules --shallow-submodules \ - https://github.com/pytorch/executorch.git "${executorch_root}" || return 1 - fi - - core_archive="$(_torchtrt_executorch_find_core_archive "${executorch_root}")" - if [[ -z "${core_archive}" ]]; then - _torchtrt_executorch_ensure_cmake || return 1 - - cmake -S "${executorch_root}" -B "${executorch_root}/cmake-out" \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ - -DBUILD_TESTING=OFF \ - -DEXECUTORCH_BUILD_PYBIND=OFF \ - -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \ - -DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON \ - -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \ - -DEXECUTORCH_BUILD_EXTENSION_NAMED_DATA_MAP=ON || return 1 - - max_jobs="${MAX_JOBS:-$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 2)}" - cmake --build "${executorch_root}/cmake-out" --target executorch_core -j "${max_jobs}" || return 1 - - core_archive="$(_torchtrt_executorch_find_core_archive "${executorch_root}")" - if [[ -z "${core_archive}" ]]; then - echo "ExecuTorch build completed but libexecutorch_core.a was not found under ${executorch_root}" >&2 - return 1 - fi - fi - - if [[ "${core_archive}" != "${executorch_root}/libexecutorch_core.a" ]]; then - ln -sf "${core_archive}" "${executorch_root}/libexecutorch_core.a" || return 1 - fi - - _torchtrt_executorch_export_env "${executorch_root}" - echo "Using EXECUTORCH_ROOT=${EXECUTORCH_ROOT}" -} - -_torchtrt_setup_executorch_ci "$@" diff --git a/.github/workflows/build-test-linux-x86_64.yml b/.github/workflows/build-test-linux-x86_64.yml index ec2ed9a367..7c067709a6 100644 --- a/.github/workflows/build-test-linux-x86_64.yml +++ b/.github/workflows/build-test-linux-x86_64.yml @@ -88,8 +88,6 @@ jobs: test-infra-repository: pytorch/test-infra test-infra-ref: main build-matrix: ${{ needs.filter-matrix.outputs.matrix }} - # it can pin to a specific version of executorch(can be a tag or a branch etc.) - executorch-ref: "main" L0-dynamo-converter-tests: diff --git a/.github/workflows/executorch-static-linux.yml b/.github/workflows/executorch-static-linux.yml index 62521071e1..687e2c3ce8 100644 --- a/.github/workflows/executorch-static-linux.yml +++ b/.github/workflows/executorch-static-linux.yml @@ -15,10 +15,6 @@ on: description: 'Reference to checkout, defaults to ""' default: "" type: string - executorch-ref: - description: "ExecuTorch branch or tag to checkout; defaults to latest main" - default: "main" - type: string test-infra-repository: description: "Test infra repository to use" default: "pytorch/test-infra" @@ -73,10 +69,6 @@ jobs: fail-on-empty: false script: | set -euo pipefail - export EXECUTORCH_ROOT="${RUNNER_TEMP}/executorch" - export EXECUTORCH_REF="${{ inputs.executorch-ref }}" - source .github/scripts/setup-executorch-ci.sh || exit 1 - BAZELISK_VERSION="1.26.0" case "$(uname -m)" in aarch64|arm64) @@ -99,6 +91,9 @@ jobs: # this is to build the libtorchtrt.tar.gz bazel build //:libtorchtrt --compilation_mode opt --config=linux + executorch_cmake_location="$(bazel query @executorch//:CMakeLists.txt --output=location)" + export EXECUTORCH_SOURCE_DIR="$(dirname "${executorch_cmake_location%%:*}")" + export EXECUTORCH_ROOT="${EXECUTORCH_SOURCE_DIR}" # this is to verify the end user's workflow python -m pip install pyyaml .github/scripts/verify-executorch-reference-runner.sh diff --git a/BUILD.bazel b/BUILD.bazel index 12cd9db3b9..5cc60aa674 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,6 +1,12 @@ +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") load("@rules_pkg//:pkg.bzl", "pkg_tar", "pkg_zip") load("@rules_pkg//pkg:mappings.bzl", "pkg_files") +bool_flag( + name = "package_executorch", + build_setting_default = True, +) + config_setting( name = "windows", constraint_values = [ @@ -39,6 +45,13 @@ config_setting( }, ) +config_setting( + name = "no_package_executorch", + flag_values = { + ":package_executorch": "false", + }, +) + pkg_tar( name = "include_core", package_dir = "include/torch_tensorrt", @@ -199,10 +212,11 @@ pkg_tar( pkg_tar( name = "bin", srcs = ["//cpp/bin/torchtrtc"] + select({ - ":rtx_win": [], - ":windows": [], ":jetpack": [], + ":no_package_executorch": [], + ":rtx_win": [], ":rtx_x86_64": [], + ":windows": [], "//conditions:default": [ "//examples/executorch_reference_runner:example_executorch_runner", ], @@ -241,10 +255,11 @@ pkg_tar( ":include_core", ":lib", ] + select({ - ":rtx_win": [], - ":windows": [], ":jetpack": [], + ":no_package_executorch": [], + ":rtx_win": [], ":rtx_x86_64": [], + ":windows": [], "//conditions:default": [ ":executorch_source_package", ":include_executorch", diff --git a/MODULE.bazel b/MODULE.bazel index ea1c0946bf..efe50c01b4 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -25,16 +25,18 @@ git_override( new_local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository") -local_torch = use_repo_rule("//toolchains:local_torch.bzl", "local_torch") +new_git_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository") -local_executorch = use_repo_rule("//toolchains:local_executorch.bzl", "local_executorch") +local_torch = use_repo_rule("//toolchains:local_torch.bzl", "local_torch") -# Detect ExecuTorch from the active Python environment (VIRTUAL_ENV / CONDA_PREFIX / PATH). -# Supports both pip-installed wheel layout and source-tree layout. -# Optional overrides: -# EXECUTORCH_ROOT=/path/to/executorch -# EXECUTORCH_SOURCE_DIR=/path/to/executorch -local_executorch(name = "executorch") +# Pinned to the ExecuTorch release/1.3 branch head. +new_git_repository( + name = "executorch", + build_file = "@//third_party/executorch:BUILD", + commit = "6118688a095fd9697224f5cad72ce42db641c9cd", + recursive_init_submodules = True, + remote = "https://github.com/pytorch/executorch.git", +) torch_nccl_detect = use_repo_rule("//toolchains/torch_nccl:defs.bzl", "torch_nccl_detect") diff --git a/docker/MODULE.bazel.ngc b/docker/MODULE.bazel.ngc index 729233c467..9ee8f25ca4 100644 --- a/docker/MODULE.bazel.ngc +++ b/docker/MODULE.bazel.ngc @@ -26,6 +26,7 @@ git_override( local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository") new_local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository") +new_git_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository") torch_nccl_detect = use_repo_rule("//toolchains/torch_nccl:defs.bzl", "torch_nccl_detect") @@ -62,6 +63,15 @@ new_local_repository( build_file = "third_party/libtorch/BUILD" ) +# Pinned to the ExecuTorch release/1.3 branch head. +new_git_repository( + name = "executorch", + build_file = "@//third_party/executorch:BUILD", + commit = "6118688a095fd9697224f5cad72ce42db641c9cd", + recursive_init_submodules = True, + remote = "https://github.com/pytorch/executorch.git", +) + # This is a workaround (WAR), not a functional Bazel repository. # It directly references a system-installed PyTorch package, which breaks hermeticity diff --git a/setup.py b/setup.py index 736e659d8b..874fb91196 100644 --- a/setup.py +++ b/setup.py @@ -246,6 +246,10 @@ def build_libtorchtrt_cxx11_abi( cmd.append("--config=rtx") print("TensorRT RTX build") + if IS_DLFW_CI: + cmd.append("--config=dlfw") + print("DLFW build") + if IS_JETPACK: cmd.append("--config=jetpack") print("Jetpack build") @@ -602,6 +606,9 @@ def run(self): ) package_data = {} +executorch_header_package_data = ( + [] if IS_DLFW_CI else ["include/torch_tensorrt/executorch/*.h"] +) if not (PY_ONLY or NO_TS): tensorrt_x86_64_external_dir = ( @@ -768,7 +775,7 @@ def run(self): { "torch_tensorrt": [ "include/torch_tensorrt/*.h", - "include/torch_tensorrt/executorch/*.h", + *executorch_header_package_data, "include/torch_tensorrt/core/*.h", "include/torch_tensorrt/core/conversion/*.h", "include/torch_tensorrt/core/conversion/conversionctx/*.h", @@ -798,7 +805,7 @@ def run(self): { "torch_tensorrt": [ "include/torch_tensorrt/*.h", - "include/torch_tensorrt/executorch/*.h", + *executorch_header_package_data, "include/torch_tensorrt/core/*.h", "include/torch_tensorrt/core/runtime/*.h", "lib/*", @@ -835,7 +842,9 @@ def get_x86_64_requirements(base_requirements): requirements = base_requirements + ["numpy"] if IS_DLFW_CI: - return requirements + return requirements + [ + "executorch>=1.2.0", + ] else: requirements = requirements + [ "torch>=2.13.0.dev,<2.14.0", diff --git a/third_party/executorch/BUILD b/third_party/executorch/BUILD index 16a363e6f4..8a2160a1fb 100644 --- a/third_party/executorch/BUILD +++ b/third_party/executorch/BUILD @@ -3,11 +3,46 @@ load("@rules_cc//cc:defs.bzl", "cc_import", "cc_library") package(default_visibility = ["//visibility:public"]) exports_files([ - "libexecutorch_core.a", + "CMakeLists.txt", ]) -# Headers are normalized to source layout (runtime/, extension/) by local_executorch.bzl -# regardless of whether the installation is a pip wheel or a source tree. +# The ExecuTorch external repository is source-layout only. Keep this BUILD +# overlay small and build only the static core archive needed by the reference +# runner path. +genrule( + name = "executorch_core_archive", + srcs = ["CMakeLists.txt"], + outs = ["libexecutorch_core.a"], + cmd = """ +set -e +command -v cmake >/dev/null 2>&1 || { + echo "cmake is required to build @executorch//:libexecutorch_core.a" >&2 + exit 1 +} +src_dir="$$(dirname "$(location CMakeLists.txt)")" +build_dir="$(@D)/executorch_cmake" +rm -rf "$$build_dir" +cmake -S "$$src_dir" -B "$$build_dir" \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ + -DBUILD_TESTING=OFF \ + -DEXECUTORCH_BUILD_PYBIND=OFF \ + -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \ + -DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON \ + -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \ + -DEXECUTORCH_BUILD_EXTENSION_NAMED_DATA_MAP=ON +max_jobs="$${MAX_JOBS:-$$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 2)}" +cmake --build "$$build_dir" --target executorch_core -j "$$max_jobs" +core_archive="$$(find "$$build_dir" -name libexecutorch_core.a -type f -print -quit)" +if [ -z "$$core_archive" ]; then + echo "ExecuTorch build completed but libexecutorch_core.a was not found" >&2 + exit 1 +fi +cp "$$core_archive" "$@" +""", + local = True, +) + cc_library( name = "executorch_headers", hdrs = glob( @@ -18,13 +53,13 @@ cc_library( ], allow_empty = True, ), + defines = [ + "C10_USING_CUSTOM_GENERATED_MACROS", + ], include_prefix = "executorch", includes = [ "runtime/core/portable_type/c10", ], - defines = [ - "C10_USING_CUSTOM_GENERATED_MACROS", - ], ) # ExecuTorch runtime carrier — provides register_backend and related symbols. diff --git a/toolchains/ci_workspaces/MODULE.bazel.tmpl b/toolchains/ci_workspaces/MODULE.bazel.tmpl index c76530778d..ff7ca70029 100644 --- a/toolchains/ci_workspaces/MODULE.bazel.tmpl +++ b/toolchains/ci_workspaces/MODULE.bazel.tmpl @@ -37,7 +37,7 @@ local_repository( new_local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository") -local_executorch = use_repo_rule("//toolchains:local_executorch.bzl", "local_executorch") +new_git_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository") # CUDA should be installed on the system locally @@ -156,11 +156,14 @@ new_local_repository( build_file = "third_party/libtorch/BUILD" ) -# Detect ExecuTorch from the active Python environment (VIRTUAL_ENV / CONDA_PREFIX / PATH). -# Optional overrides: -# EXECUTORCH_ROOT=/path/to/executorch -# EXECUTORCH_SOURCE_DIR=/path/to/executorch -local_executorch(name = "executorch") +# Pinned to the ExecuTorch release/1.3 branch head. +new_git_repository( + name = "executorch", + build_file = "@//third_party/executorch:BUILD", + commit = "6118688a095fd9697224f5cad72ce42db641c9cd", + recursive_init_submodules = True, + remote = "https://github.com/pytorch/executorch.git", +) #new_local_repository( # name = "tensorrt", diff --git a/toolchains/local_executorch.bzl b/toolchains/local_executorch.bzl deleted file mode 100644 index bdb6a6044c..0000000000 --- a/toolchains/local_executorch.bzl +++ /dev/null @@ -1,168 +0,0 @@ -"""Repository rule that locates ExecuTorch from a local source tree or Python installation. - -Discovery order: - 1. EXECUTORCH_ROOT env var — absolute path to the ExecuTorch source/package directory - 2. EXECUTORCH_SOURCE_DIR — CMake-facing alias for the ExecuTorch source directory - 3. Adjacent source checkout — ../executorch or ../../executorch from the workspace root - 4. VIRTUAL_ENV env var — virtualenv / uv venv ($VIRTUAL_ENV/bin/python3) - 5. CONDA_PREFIX env var — conda environment ($CONDA_PREFIX/bin/python3) - 6. .venv/bin/python3 relative to the workspace root (uv / virtualenv default) - 7. venv/bin/python3 relative to the workspace root - 8. python3 / python on PATH -""" - -def _has_required_headers(et_dir): - return et_dir.get_child("runtime/backend/interface.h").exists or et_dir.get_child( - "include/executorch/runtime/backend/interface.h", - ).exists - -def _find_source_checkout(ctx): - """Return a nearby ExecuTorch source checkout with backend headers, or None.""" - ws = ctx.workspace_root - candidates = [ - ws.get_child("executorch"), - ws.dirname.get_child("executorch"), - ws.dirname.dirname.get_child("executorch"), - ] - for candidate in candidates: - if _has_required_headers(candidate): - return candidate - return None - -def _find_python(ctx): - """Return a path to a Python interpreter that has executorch importable, or None.""" - candidates = [] - - virtual_env = ctx.os.environ.get("VIRTUAL_ENV", "") - if virtual_env: - candidates.append(ctx.path(virtual_env + "/bin/python3")) - candidates.append(ctx.path(virtual_env + "/bin/python")) - - conda_prefix = ctx.os.environ.get("CONDA_PREFIX", "") - if conda_prefix: - candidates.append(ctx.path(conda_prefix + "/bin/python3")) - candidates.append(ctx.path(conda_prefix + "/bin/python")) - - ws = ctx.workspace_root - for rel in [".venv/bin/python3", ".venv/bin/python", "venv/bin/python3", "venv/bin/python"]: - candidates.append(ws.get_child(rel)) - - for name in ["python3", "python"]: - p = ctx.which(name) - if p: - candidates.append(p) - - for candidate in candidates: - if candidate.exists: - result = ctx.execute([candidate, "-c", "import executorch"]) - if result.return_code == 0: - return candidate - return None - -def _local_executorch_impl(ctx): - # 1. Env-var override (takes priority over auto-detection). - # setup.py sets this when building via pip's isolated build environment. - et_dir_str = ctx.os.environ.get("EXECUTORCH_ROOT", "").strip() - if not et_dir_str: - et_dir_str = ctx.os.environ.get("EXECUTORCH_SOURCE_DIR", "").strip() - - if not et_dir_str: - source_checkout = _find_source_checkout(ctx) - if source_checkout: - et_dir_str = str(source_checkout) - - if not et_dir_str: - python = _find_python(ctx) - if not python: - fail( - "Cannot locate a Python interpreter that has executorch installed. " + - "Either keep an ExecuTorch source checkout next to this repository, " + - "activate the project venv, or set EXECUTORCH_ROOT/EXECUTORCH_SOURCE_DIR " + - "to the ExecuTorch source/package directory.", - ) - result = ctx.execute( - [python, "-c", "import executorch, os; print(os.path.realpath(next(iter(executorch.__path__))))"], - ) - if result.return_code != 0: - fail("Failed to get executorch path from Python: " + result.stderr) - et_dir_str = result.stdout.strip() - - if not et_dir_str: - fail( - "EXECUTORCH_ROOT/EXECUTORCH_SOURCE_DIR is empty. Set one of them " + - "or ensure executorch is installed in the active Python.", - ) - - et_dir = ctx.path(et_dir_str) - - # Validate that the installation has headers. - has_wheel_layout = et_dir.get_child("include/executorch").exists - has_source_layout = et_dir.get_child("runtime").exists - if not has_wheel_layout and not has_source_layout: - fail( - "executorch at '" + et_dir_str + "' is missing headers. " + - "Expected include/executorch/ (wheel) or runtime/ (source). " + - "Install a full executorch package or set EXECUTORCH_ROOT/EXECUTORCH_SOURCE_DIR correctly.", - ) - if not _has_required_headers(et_dir): - fail( - "executorch at '" + et_dir_str + "' is missing runtime/backend/interface.h, " + - "which is required by the TensorRT ExecuTorch backend. The active Python " + - "package may be an incomplete namespace/wheel layout. Set " + - "EXECUTORCH_ROOT=/path/to/executorch or " + - "EXECUTORCH_SOURCE_DIR=/path/to/executorch, or place an ExecuTorch " + - "source checkout at ../executorch or ../../executorch.", - ) - - # Normalize to source layout so the static BUILD file always works. - # Wheel layout: include/executorch/runtime/*.h → symlink as runtime/ - # Source layout: runtime/*.h → symlink as runtime/ - if has_wheel_layout: - for sub in ["runtime", "extension"]: - child = et_dir.get_child("include/executorch/" + sub) - if child.exists: - ctx.symlink(child, sub) - else: - for sub in ["runtime", "extension"]: - child = et_dir.get_child(sub) - if child.exists: - ctx.symlink(child, sub) - - # Symlink libqnn_executorch_backend.so (ExecuTorch runtime carrier). - qnn_so_candidates = [ - "backends/qualcomm/libqnn_executorch_backend.so", - "cmake-out/backends/qualcomm/libqnn_executorch_backend.so", - "libqnn_executorch_backend.so", - "lib/libqnn_executorch_backend.so", - "lib64/libqnn_executorch_backend.so", - ] - for rel in qnn_so_candidates: - candidate = et_dir.get_child(rel) - if candidate.exists: - ctx.symlink(candidate, "libqnn_executorch_backend.so") - break - - # Symlink libexecutorch_core.a (full C++ runtime for trt_executor_runner). - core_candidates = [ - "cmake-out/libexecutorch_core.a", - "lib/libexecutorch_core.a", - "lib64/libexecutorch_core.a", - "libexecutorch_core.a", - ] - for rel in core_candidates: - candidate = et_dir.get_child(rel) - if candidate.exists: - ctx.symlink(candidate, "libexecutorch_core.a") - break - - ctx.file("BUILD", ctx.read(Label("@//third_party/executorch:BUILD"))) - -local_executorch = repository_rule( - implementation = _local_executorch_impl, - environ = [ - "EXECUTORCH_ROOT", - "EXECUTORCH_SOURCE_DIR", - "VIRTUAL_ENV", - "CONDA_PREFIX", - ], -) From 2d7c5a867874dec4c9571d30da990e3d1849546b Mon Sep 17 00:00:00 2001 From: Lan Luo Date: Thu, 21 May 2026 11:33:22 -0700 Subject: [PATCH 2/4] test --- MODULE.bazel | 1 + docker/MODULE.bazel.ngc | 1 + setup.py | 6 ++++-- third_party/executorch/BUILD | 11 ++++++++--- toolchains/ci_workspaces/MODULE.bazel.tmpl | 1 + 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index efe50c01b4..e437d55524 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -33,6 +33,7 @@ local_torch = use_repo_rule("//toolchains:local_torch.bzl", "local_torch") new_git_repository( name = "executorch", build_file = "@//third_party/executorch:BUILD", + # latest commit in release/1.3 branch commit = "6118688a095fd9697224f5cad72ce42db641c9cd", recursive_init_submodules = True, remote = "https://github.com/pytorch/executorch.git", diff --git a/docker/MODULE.bazel.ngc b/docker/MODULE.bazel.ngc index 9ee8f25ca4..bb0e4492e3 100644 --- a/docker/MODULE.bazel.ngc +++ b/docker/MODULE.bazel.ngc @@ -67,6 +67,7 @@ new_local_repository( new_git_repository( name = "executorch", build_file = "@//third_party/executorch:BUILD", + # latest commit in release/1.3 branch commit = "6118688a095fd9697224f5cad72ce42db641c9cd", recursive_init_submodules = True, remote = "https://github.com/pytorch/executorch.git", diff --git a/setup.py b/setup.py index 874fb91196..b491019689 100644 --- a/setup.py +++ b/setup.py @@ -99,6 +99,8 @@ def load_dep_info(): CI_BUILD = False USE_TRT_RTX = False +EXECUTORCH_REQUIREMENT = "executorch>=1.2.0" + if "--use-rtx" in sys.argv: USE_TRT_RTX = True @@ -843,7 +845,7 @@ def get_x86_64_requirements(base_requirements): if IS_DLFW_CI: return requirements + [ - "executorch>=1.2.0", + EXECUTORCH_REQUIREMENT, ] else: requirements = requirements + [ @@ -855,7 +857,7 @@ def get_x86_64_requirements(base_requirements): ] else: requirements = requirements + [ - "executorch>=1.2.0", + EXECUTORCH_REQUIREMENT, "tensorrt>=10.16.1,<10.17.0", ] cuda_version = torch.version.cuda diff --git a/third_party/executorch/BUILD b/third_party/executorch/BUILD index 8a2160a1fb..6715a19deb 100644 --- a/third_party/executorch/BUILD +++ b/third_party/executorch/BUILD @@ -19,10 +19,15 @@ command -v cmake >/dev/null 2>&1 || { echo "cmake is required to build @executorch//:libexecutorch_core.a" >&2 exit 1 } -src_dir="$$(dirname "$(location CMakeLists.txt)")" +src_dir="$$(cd "$$(dirname "$(location CMakeLists.txt)")" && pwd)" +source_parent="$(@D)/executorch_source" +cmake_src_dir="$$source_parent/executorch" build_dir="$(@D)/executorch_cmake" -rm -rf "$$build_dir" -cmake -S "$$src_dir" -B "$$build_dir" \ +rm -rf "$$build_dir" "$$source_parent" +mkdir -p "$$cmake_src_dir" +cp -a "$$src_dir/." "$$cmake_src_dir/" +find "$$cmake_src_dir" -name .git -prune -exec rm -rf {} + +cmake -S "$$cmake_src_dir" -B "$$build_dir" \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ -DBUILD_TESTING=OFF \ diff --git a/toolchains/ci_workspaces/MODULE.bazel.tmpl b/toolchains/ci_workspaces/MODULE.bazel.tmpl index ff7ca70029..32bf7bc45d 100644 --- a/toolchains/ci_workspaces/MODULE.bazel.tmpl +++ b/toolchains/ci_workspaces/MODULE.bazel.tmpl @@ -160,6 +160,7 @@ new_local_repository( new_git_repository( name = "executorch", build_file = "@//third_party/executorch:BUILD", + # latest commit in release/1.3 branch commit = "6118688a095fd9697224f5cad72ce42db641c9cd", recursive_init_submodules = True, remote = "https://github.com/pytorch/executorch.git", From 1af2644cc9573357525eab9cdb96c7659366bc37 Mon Sep 17 00:00:00 2001 From: Lan Luo Date: Thu, 21 May 2026 12:16:19 -0700 Subject: [PATCH 3/4] test --- packaging/pre_build_script.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/packaging/pre_build_script.sh b/packaging/pre_build_script.sh index 4198be7b2f..755ecc6cff 100755 --- a/packaging/pre_build_script.sh +++ b/packaging/pre_build_script.sh @@ -41,7 +41,6 @@ curl -L https://github.com/bazelbuild/bazelisk/releases/download/v1.26.0/bazelis && mv bazelisk-linux-${BAZEL_PLATFORM} /usr/bin/bazel \ && chmod +x /usr/bin/bazel -source .github/scripts/setup-executorch-ci.sh || exit 1 pip uninstall -y torch torchvision From 153d34245682274034c72324f2304bfdd81e9dcc Mon Sep 17 00:00:00 2001 From: Lan Luo Date: Thu, 21 May 2026 14:58:20 -0700 Subject: [PATCH 4/4] test --- BUILD.bazel | 4 +- MODULE.bazel | 9 +++ docker/MODULE.bazel.ngc | 9 +++ third_party/executorch/BUILD | 72 +++++++++------------- toolchains/ci_workspaces/MODULE.bazel.tmpl | 9 +++ 5 files changed, 57 insertions(+), 46 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 5cc60aa674..60826f6dc2 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -125,9 +125,9 @@ pkg_tar( genrule( name = "executorch_core_archive", - srcs = ["@executorch//:libexecutorch_core.a"], + srcs = ["@executorch//:executorch_core"], outs = ["libexecutorch_core.a"], - cmd = "cp $(location @executorch//:libexecutorch_core.a) $@", + cmd = "cp $(location @executorch//:executorch_core) $@", ) genrule( diff --git a/MODULE.bazel b/MODULE.bazel index e437d55524..3bd6e8aa2b 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -9,6 +9,7 @@ bazel_dep(name = "platforms", version = "0.0.11") bazel_dep(name = "rules_cc", version = "0.1.1") bazel_dep(name = "rules_python", version = "1.3.0") bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "rules_foreign_cc", version = "0.15.1") python = use_extension("@rules_python//python/extensions:python.bzl", "python") python.toolchain( @@ -36,6 +37,14 @@ new_git_repository( # latest commit in release/1.3 branch commit = "6118688a095fd9697224f5cad72ce42db641c9cd", recursive_init_submodules = True, + patch_cmds = [ + "find . -mindepth 2 \\( -name BUILD -o -name BUILD.bazel \\) -delete", + "mkdir executorch && find . -mindepth 1 -maxdepth 1 ! -name executorch ! -name BUILD ! -name BUILD.bazel ! -name REPO.bazel -exec ln -s ../{} executorch/ \\;", + ], + patch_cmds_win = [ + "Get-ChildItem -Recurse -Include BUILD,BUILD.bazel | Where-Object { $_.DirectoryName -ne (Get-Location).Path } | Remove-Item -Force", + "New-Item -ItemType Directory executorch | Out-Null; Get-ChildItem -Force | Where-Object { $_.Name -notin @('executorch','BUILD','BUILD.bazel','REPO.bazel') } | Copy-Item -Destination executorch -Recurse -Force", + ], remote = "https://github.com/pytorch/executorch.git", ) diff --git a/docker/MODULE.bazel.ngc b/docker/MODULE.bazel.ngc index bb0e4492e3..2a2d68bf18 100644 --- a/docker/MODULE.bazel.ngc +++ b/docker/MODULE.bazel.ngc @@ -9,6 +9,7 @@ bazel_dep(name = "platforms", version = "0.0.10") bazel_dep(name = "rules_cc", version = "0.0.9") bazel_dep(name = "rules_python", version = "0.34.0") bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "rules_foreign_cc", version = "0.15.1") python = use_extension("@rules_python//python/extensions:python.bzl", "python") python.toolchain( @@ -70,6 +71,14 @@ new_git_repository( # latest commit in release/1.3 branch commit = "6118688a095fd9697224f5cad72ce42db641c9cd", recursive_init_submodules = True, + patch_cmds = [ + "find . -mindepth 2 \\( -name BUILD -o -name BUILD.bazel \\) -delete", + "mkdir executorch && find . -mindepth 1 -maxdepth 1 ! -name executorch ! -name BUILD ! -name BUILD.bazel ! -name REPO.bazel -exec ln -s ../{} executorch/ \\;", + ], + patch_cmds_win = [ + "Get-ChildItem -Recurse -Include BUILD,BUILD.bazel | Where-Object { $_.DirectoryName -ne (Get-Location).Path } | Remove-Item -Force", + "New-Item -ItemType Directory executorch | Out-Null; Get-ChildItem -Force | Where-Object { $_.Name -notin @('executorch','BUILD','BUILD.bazel','REPO.bazel') } | Copy-Item -Destination executorch -Recurse -Force", + ], remote = "https://github.com/pytorch/executorch.git", ) diff --git a/third_party/executorch/BUILD b/third_party/executorch/BUILD index 6715a19deb..2d1953aedc 100644 --- a/third_party/executorch/BUILD +++ b/third_party/executorch/BUILD @@ -1,4 +1,5 @@ load("@rules_cc//cc:defs.bzl", "cc_import", "cc_library") +load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") package(default_visibility = ["//visibility:public"]) @@ -9,43 +10,33 @@ exports_files([ # The ExecuTorch external repository is source-layout only. Keep this BUILD # overlay small and build only the static core archive needed by the reference # runner path. -genrule( - name = "executorch_core_archive", - srcs = ["CMakeLists.txt"], - outs = ["libexecutorch_core.a"], - cmd = """ -set -e -command -v cmake >/dev/null 2>&1 || { - echo "cmake is required to build @executorch//:libexecutorch_core.a" >&2 - exit 1 -} -src_dir="$$(cd "$$(dirname "$(location CMakeLists.txt)")" && pwd)" -source_parent="$(@D)/executorch_source" -cmake_src_dir="$$source_parent/executorch" -build_dir="$(@D)/executorch_cmake" -rm -rf "$$build_dir" "$$source_parent" -mkdir -p "$$cmake_src_dir" -cp -a "$$src_dir/." "$$cmake_src_dir/" -find "$$cmake_src_dir" -name .git -prune -exec rm -rf {} + -cmake -S "$$cmake_src_dir" -B "$$build_dir" \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ - -DBUILD_TESTING=OFF \ - -DEXECUTORCH_BUILD_PYBIND=OFF \ - -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \ - -DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON \ - -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \ - -DEXECUTORCH_BUILD_EXTENSION_NAMED_DATA_MAP=ON -max_jobs="$${MAX_JOBS:-$$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 2)}" -cmake --build "$$build_dir" --target executorch_core -j "$$max_jobs" -core_archive="$$(find "$$build_dir" -name libexecutorch_core.a -type f -print -quit)" -if [ -z "$$core_archive" ]; then - echo "ExecuTorch build completed but libexecutorch_core.a was not found" >&2 - exit 1 -fi -cp "$$core_archive" "$@" -""", - local = True, +filegroup( + name = "executorch_sources", + srcs = glob( + ["**"], + exclude = [".git/**"], + ), +) + +cmake( + name = "executorch_core", + cache_entries = { + "BUILD_TESTING": "OFF", + "CMAKE_ARCHIVE_OUTPUT_DIRECTORY": "$$INSTALLDIR/lib", + "CMAKE_BUILD_TYPE": "Release", + "CMAKE_POSITION_INDEPENDENT_CODE": "ON", + "EXECUTORCH_BUILD_EXTENSION_DATA_LOADER": "ON", + "EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR": "ON", + "EXECUTORCH_BUILD_EXTENSION_MODULE": "ON", + "EXECUTORCH_BUILD_EXTENSION_NAMED_DATA_MAP": "ON", + "EXECUTORCH_BUILD_PYBIND": "OFF", + }, + install = False, + lib_source = ":executorch_sources", + out_include_dir = "", + out_static_libs = ["libexecutorch_core.a"], + working_directory = "executorch", + targets = ["executorch_core"], ) cc_library( @@ -74,13 +65,6 @@ cc_import( shared_library = "libqnn_executorch_backend.so", ) -# Full ExecuTorch C++ runtime (Program, Method, MethodMeta, runtime_init, …). -# Linked into C++ binaries that use the ExecuTorch C++ API (e.g. trt_executor_runner). -cc_import( - name = "executorch_core", - static_library = "libexecutorch_core.a", -) - # FileDataLoader compiled from source (present in source-tree installs). cc_library( name = "executorch_file_data_loader", diff --git a/toolchains/ci_workspaces/MODULE.bazel.tmpl b/toolchains/ci_workspaces/MODULE.bazel.tmpl index 32bf7bc45d..b41098ce1e 100644 --- a/toolchains/ci_workspaces/MODULE.bazel.tmpl +++ b/toolchains/ci_workspaces/MODULE.bazel.tmpl @@ -9,6 +9,7 @@ bazel_dep(name = "platforms", version = "0.0.11") bazel_dep(name = "rules_cc", version = "0.1.1") bazel_dep(name = "rules_python", version = "1.3.0") bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "rules_foreign_cc", version = "0.15.1") python = use_extension("@rules_python//python/extensions:python.bzl", "python") python.toolchain( @@ -163,6 +164,14 @@ new_git_repository( # latest commit in release/1.3 branch commit = "6118688a095fd9697224f5cad72ce42db641c9cd", recursive_init_submodules = True, + patch_cmds = [ + "find . -mindepth 2 \\( -name BUILD -o -name BUILD.bazel \\) -delete", + "mkdir executorch && find . -mindepth 1 -maxdepth 1 ! -name executorch ! -name BUILD ! -name BUILD.bazel ! -name REPO.bazel -exec ln -s ../{} executorch/ \\;", + ], + patch_cmds_win = [ + "Get-ChildItem -Recurse -Include BUILD,BUILD.bazel | Where-Object { $_.DirectoryName -ne (Get-Location).Path } | Remove-Item -Force", + "New-Item -ItemType Directory executorch | Out-Null; Get-ChildItem -Force | Where-Object { $_.Name -notin @('executorch','BUILD','BUILD.bazel','REPO.bazel') } | Copy-Item -Destination executorch -Recurse -Force", + ], remote = "https://github.com/pytorch/executorch.git", )