Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 18 additions & 47 deletions .github/scripts/verify-executorch-reference-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ set +x
#
# 1. Build //:libtorchtrt first so bazel-bin/libtorchtrt.tar.gz exists.
# 2. Provide an ExecuTorch source checkout with EXECUTORCH_SOURCE_DIR.
# 3. This script exports a small Torch-TensorRT ExecuTorch .pte model,
# unpacks libtorchtrt.tar.gz, configures the packaged CMake runner,
# builds example_executorch_runner, and runs one inference.
# 3. Provide a Torch-TensorRT ExecuTorch .pte model.
# 4. This script unpacks libtorchtrt.tar.gz, configures and builds the
# packaged CMake runner, and runs one inference.
#
# Required:
# First argument: path to an existing .pte model.
# EXECUTORCH_SOURCE_DIR=/path/to/executorch
#
# Optional:
Expand All @@ -28,6 +29,16 @@ set +x
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
cd "${repo_root}"

if [[ $# -ne 1 ]]; then
echo "Usage: $0 PATH_TO_MODEL.pte" >&2
exit 1
fi
model_path="$1"
if [[ ! -f "${model_path}" ]]; then
echo "ExecuTorch model not found: ${model_path}" >&2
exit 1
fi

python_executable="${PYTHON_EXECUTABLE:-}"
if [[ -z "${python_executable}" ]]; then
python_executable="$(command -v python || true)"
Expand Down Expand Up @@ -201,14 +212,13 @@ else
export LD_LIBRARY_PATH="${torch_lib_dir}${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"
fi

# Fail early if the Python environment cannot export a Torch-TensorRT
# ExecuTorch model or run ExecuTorch's CMake codegen.
# Fail early if the Python environment cannot run ExecuTorch's CMake codegen.
if ! "${python_executable}" - <<'PY'
import importlib
import importlib.util

missing = []
for name in ("yaml", "torch", "torch_tensorrt", "executorch.exir"):
for name in ("yaml", "torch", "executorch.exir"):
try:
spec = importlib.util.find_spec(name)
except ModuleNotFoundError:
Expand All @@ -217,56 +227,17 @@ for name in ("yaml", "torch", "torch_tensorrt", "executorch.exir"):
missing.append(name)
if missing:
raise SystemExit(
"Missing Python package(s) required to export the .pte and build the runner: "
"Missing Python package(s) required to build the runner: "
+ ", ".join(missing)
)

for name in ("yaml", "torch", "torch_tensorrt", "executorch.exir"):
for name in ("yaml", "torch", "executorch.exir"):
importlib.import_module(name)
PY
then
exit 1
fi

model_path="${verify_root}/model.pte"
"${python_executable}" - "${model_path}" <<'PY'
import importlib.util
import runpy
import sys
from pathlib import Path

model_path = sys.argv[1]
repo_root = Path.cwd()

# Use the installed package for native extensions and the in-tree ExecuTorch
# route for the serializer/backend under test.
import torch_tensorrt # noqa: F401


def overlay_module(name: str, path: Path) -> None:
spec = importlib.util.spec_from_file_location(name, path)
if spec is None or spec.loader is None:
raise RuntimeError(f"Could not load {name} from {path}")
module = importlib.util.module_from_spec(spec)
sys.modules[name] = module
spec.loader.exec_module(module)


overlay_module(
"torch_tensorrt.executorch.serialization",
repo_root / "py/torch_tensorrt/executorch/serialization.py",
)
overlay_module(
"torch_tensorrt.executorch.backend",
repo_root / "py/torch_tensorrt/executorch/backend.py",
)

export_script = repo_root / "examples/torchtrt_executorch_example/export_static_shape.py"
sys.argv = [str(export_script), "--model_path", model_path]
runpy.run_path(str(export_script), run_name="__main__")
PY
test -f "${model_path}"

if [[ -n "${TensorRT_ROOT:-}" && -d "${TensorRT_ROOT}/lib" ]]; then
export LD_LIBRARY_PATH="${TensorRT_ROOT}/lib${original_ld_library_path:+:${original_ld_library_path}}"
else
Expand Down
19 changes: 16 additions & 3 deletions .github/workflows/_linux-x86_64-core.yml
Comment thread
lanluo-nvidia marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,22 @@ jobs:
use-rtx: ${{ inputs.use-rtx }}
pip-install-torch-extra-args: "--extra-index-url https://pypi.org/simple"

# Standard-TRT only: ExecuTorch static build is not part of the RTX matrix.
executorch-static-build:
# Standard-TRT only: ExecuTorch runtime build is not part of the RTX matrix.
executorch-runtime-build:
needs: [filter-matrix, build]
if: ${{ !inputs.use-rtx }}
uses: ./.github/workflows/executorch-static-linux.yml
uses: ./.github/workflows/executorch-build-linux.yml
with:
repository: "pytorch/tensorrt"
ref: ""
test-infra-repository: pytorch/test-infra
test-infra-ref: main
build-matrix: ${{ needs.filter-matrix.outputs.matrix }}

executorch-runtime-test:
needs: [filter-matrix, executorch-runtime-build]
if: ${{ !inputs.use-rtx && needs.executorch-runtime-build.result == 'success' }}
uses: ./.github/workflows/executorch-test-linux.yml
with:
repository: "pytorch/tensorrt"
ref: ""
Expand Down Expand Up @@ -639,6 +650,8 @@ jobs:
needs:
[
build,
executorch-runtime-build,
executorch-runtime-test,
L0-dynamo-converter-tests,
L0-dynamo-core-tests,
L0-py-core-tests,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ExecuTorch Static Linux Build
name: ExecuTorch Delegate Linux Build

on:
workflow_call:
Expand Down Expand Up @@ -60,14 +60,15 @@ jobs:
needs: select-matrix
uses: ./.github/workflows/linux-test.yml
with:
job-name: executorch-static-build
job-name: executorch-runtime-build
repository: ${{ inputs.repository }}
ref: ${{ inputs.ref }}
test-infra-repository: ${{ inputs.test-infra-repository }}
test-infra-ref: ${{ inputs.test-infra-ref }}
build-matrix: ${{ needs.select-matrix.outputs.matrix }}
pre-script: packaging/pre_build_script.sh
fail-on-empty: false
upload-artifact: torch-tensorrt-executorch-runtime
script: |
set -euo pipefail
BAZELISK_VERSION="1.26.0"
Expand All @@ -90,11 +91,8 @@ jobs:
export PATH="${RUNNER_TEMP}/bin:${PATH}"
bazel --version

# this is to build the libtorchtrt.tar.gz
bazel build //:libtorchtrt --compilation_mode opt --config=linux
executorch_cmake_location="$(bazel query @executorch//: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 "executorch>=1.3.1"
.github/scripts/verify-executorch-reference-runner.sh
python -m pip install pyyaml "executorch==1.3.1"
export TORCH_TENSORRT_EXECUTORCH_RUNTIME_VERSION="$(python -c 'import importlib.metadata; print(importlib.metadata.version("torch-tensorrt"))')"

# Build the no-compile-for-users Python runtime wheel.
python -m pip wheel --no-build-isolation --no-deps --wheel-dir dist py/torch-tensorrt-executorch-runtime
94 changes: 94 additions & 0 deletions .github/workflows/executorch-test-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: ExecuTorch Delegate Linux Test

on:
workflow_call:
inputs:
build-matrix:
description: "Build matrix to utilize"
default: ""
type: string
repository:
description: 'Repository to checkout, defaults to ""'
default: ""
type: string
ref:
description: 'Reference to checkout, defaults to ""'
default: ""
type: string
test-infra-repository:
description: "Test infra repository to use"
default: "pytorch/test-infra"
type: string
test-infra-ref:
description: "Test infra reference to use"
default: ""
type: string

jobs:
select-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.pick.outputs.matrix }}
steps:
- id: pick
env:
FULL_MATRIX: ${{ inputs.build-matrix }}
run: |
set -euo pipefail
python - <<'PY' >> "${GITHUB_OUTPUT}"
import json
import os

matrix = json.loads(os.environ["FULL_MATRIX"])
include = matrix.get("include", [])
if not include:
raise SystemExit("build-matrix include[] is empty")

preferred = None
for entry in include:
if entry.get("python_version") == "3.11":
preferred = entry
break

if preferred is None:
preferred = include[0]

print("matrix=" + json.dumps({"include": [preferred]}))
PY

test:
needs: select-matrix
uses: ./.github/workflows/linux-test.yml
with:
job-name: executorch-runtime-test
repository: ${{ inputs.repository }}
ref: ${{ inputs.ref }}
test-infra-repository: ${{ inputs.test-infra-repository }}
test-infra-ref: ${{ inputs.test-infra-ref }}
build-matrix: ${{ needs.select-matrix.outputs.matrix }}
pre-script: packaging/pre_build_script.sh
additional-artifact: torch-tensorrt-executorch-runtime
script: |
set -euo pipefail
mkdir -p "${RUNNER_TEMP}/bin"
curl -L "https://github.com/bazelbuild/bazelisk/releases/download/v1.26.0/bazelisk-linux-amd64" \
-o "${RUNNER_TEMP}/bin/bazel"
chmod +x "${RUNNER_TEMP}/bin/bazel"
export PATH="${RUNNER_TEMP}/bin:${PATH}"

python -m pip install pyyaml executorch
python -c 'from torch_tensorrt_executorch_runtime import get_runtime; assert get_runtime().backend_registry.is_available("TensorRTBackend")'

source tests/py/utils/ci_helpers.sh
trt_tier_executorch

bazel build //:libtorchtrt --compilation_mode opt --config=linux
executorch_cmake_location="$(bazel query @executorch//:executorch/CMakeLists.txt --output=location)"
export EXECUTORCH_SOURCE_DIR="$(dirname "${executorch_cmake_location%%:*}")"
export EXECUTORCH_ROOT="${EXECUTORCH_SOURCE_DIR}"
python examples/torchtrt_executorch_example/export_static_shape.py \
--model_path="${RUNNER_TEMP}/torchtrt-python.pte"
.github/scripts/verify-executorch-reference-runner.sh \
"${RUNNER_TEMP}/torchtrt-python.pte"
python examples/executorch_reference_runner/load_model.py \
--model_path="${RUNNER_TEMP}/torchtrt-python.pte" --num_runs=1
31 changes: 14 additions & 17 deletions .github/workflows/linux-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ on:
default: false
type: boolean
upload-artifact:
description: 'Name to give artifacts uploaded from ${RUNNER_ARTIFACT_DIR}'
description: 'Name to give wheel artifacts uploaded from the repository dist directory'
default: ''
type: string
additional-artifact:
description: "Optional additional artifact to install alongside the core wheel"
default: ""
type: string
use-rtx:
description: "Whether to use TensorRT-RTX"
default: false
Expand Down Expand Up @@ -146,6 +150,12 @@ jobs:
# with:
# repository: ${{ inputs.repository }}
# script: .github/scripts/install-torch-tensorrt.sh
- name: Download additional artifacts
if: ${{ inputs.additional-artifact != '' }}
uses: actions/download-artifact@v7
with:
name: ${{ inputs.additional-artifact }}
path: /opt/torch-tensorrt-builds/
- name: Pack script
continue-on-error: ${{ inputs.continue-on-error }}
working-directory: ${{ inputs.repository }}
Expand Down Expand Up @@ -174,23 +184,10 @@ jobs:
display-options: fEs
fail-on-empty: ${{ inputs.fail-on-empty }}

- name: Prepare artifacts for upload
- name: Check documentation for upload
working-directory: ${{ inputs.repository }}
id: check-artifacts
env:
UPLOAD_ARTIFACT_NAME: ${{ inputs.upload-artifact }}
run: |
# Only do these steps if we actually want to upload an artifact
if [[ -n "${UPLOAD_ARTIFACT_NAME}" ]]; then
# If the default execution path is followed then we should get a wheel in the dist/ folder
# attempt to just grab whatever is in there and scoop it all up
if find "dist/" -name "*.whl" >/dev/null 2>/dev/null; then
mv -v dist/*.whl "${RUNNER_ARTIFACT_DIR}/"
fi
# Set to fail upload step if there are no files for upload and expected files for upload
echo 'if-no-files-found=error' >> "${GITHUB_OUTPUT}"
fi

upload_docs=0
# Check if there are things in the documentation folder to upload
if find "${RUNNER_DOCS_DIR}" -mindepth 1 -maxdepth 1 | read -r; then
Expand All @@ -205,8 +202,8 @@ jobs:
if: ${{ inputs.upload-artifact != '' }}
with:
name: ${{ inputs.upload-artifact }}
path: ${{ runner.temp }}/artifacts/
if-no-files-found: ${{ steps.check-artifacts.outputs.if-no-files-found }}
path: ${{ inputs.repository }}/dist/
if-no-files-found: error

- name: Upload documentation to S3 (if any)
uses: seemethere/upload-artifact-s3@v5
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,5 @@ CLAUDE.md
/compile_commands.json
/external/
build-executorch/
py/torch-tensorrt-executorch-runtime/build/
py/torch-tensorrt-executorch-runtime/dist/
8 changes: 8 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ config_setting(
},
)

filegroup(
name = "torchtrt_cmake_modules",
srcs = [
"cmake/Modules/FindTensorRT.cmake",
],
visibility = ["//visibility:public"],
)

pkg_tar(
name = "include_core",
package_dir = "include/torch_tensorrt",
Expand Down
9 changes: 5 additions & 4 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ git_override(
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
git_override(
module_name = "hedron_compile_commands",
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
commit = "0e990032f3c5a866e72615cf67e5ce22186dcb97",
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
)

new_local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository")
Expand All @@ -42,12 +42,13 @@ new_git_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:git.bzl"

local_torch = use_repo_rule("//toolchains:local_torch.bzl", "local_torch")

# Pinned to the ExecuTorch release/1.3 branch head.
# Keep this pin synchronized with the ExecuTorch release installed in
# py/torch-tensorrt-executorch-runtime/README.md.
new_git_repository(
name = "executorch",
build_file = "@//third_party/executorch:BUILD",
# latest commit in release/1.3 branch
commit = "6118688a095fd9697224f5cad72ce42db641c9cd",
# executorch==1.3.1
commit = "e2f18eb23c45bd22ca332b0b8b49a81de304b472",
Comment thread
lanluo-nvidia marked this conversation as resolved.
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 cp -a {} executorch/ \\;",
Expand Down
Loading
Loading