-
Notifications
You must be signed in to change notification settings - Fork 407
add torch-tensorrt-executorch-delegate wheel build #4398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lanluo-nvidia
wants to merge
6
commits into
main
Choose a base branch
from
lluo/executorch_wheel_build
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f215c0c
add torch-tensorrt-executorch-delegate wheel
lanluo-nvidia f1339a0
fix the test error
lanluo-nvidia e3a8f27
test
lanluo-nvidia 5ccbfcd
Merge branch 'main' into lluo/executorch_wheel_build
lanluo-nvidia 14c9c71
resolve review comments
lanluo-nvidia e6a6f7a
resolve review commits
lanluo-nvidia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ filegroup( | |
| srcs = [ | ||
| "CMakeLists.txt", | ||
| "README.md", | ||
| "load_model.py", | ||
| "main.cpp", | ||
| ], | ||
| ) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| """Load and optionally run a Torch-TensorRT ExecuTorch ``.pte`` model. | ||
|
|
||
| The default input matches ``export_static_shape.py``: one CUDA float tensor | ||
| with shape ``(2, 3, 4, 4)`` filled with ones. | ||
| """ | ||
|
|
||
| import argparse | ||
| from pathlib import Path | ||
|
|
||
| import torch | ||
| from torch_tensorrt.executorch.runtime import load | ||
|
|
||
|
|
||
| def parse_args() -> argparse.Namespace: | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("--model_path", type=Path, default=Path("model.pte")) | ||
| parser.add_argument("--method", default="forward") | ||
| parser.add_argument("--num_runs", type=int, default=1) | ||
| parser.add_argument( | ||
| "--load_only", | ||
| action="store_true", | ||
| help="Parse the program and print its methods without loading/executing one", | ||
| ) | ||
| return parser.parse_args() | ||
|
|
||
|
|
||
| def main() -> None: | ||
| args = parse_args() | ||
| if not args.model_path.is_file(): | ||
| raise FileNotFoundError(f"ExecuTorch model not found: {args.model_path}") | ||
| if args.num_runs < 1: | ||
| raise ValueError("--num_runs must be at least 1") | ||
|
|
||
| program = load(args.model_path) | ||
| print(f"Loaded {args.model_path}") | ||
| print(f"Program methods: {sorted(program.method_names)}") | ||
|
|
||
| if args.load_only: | ||
| return | ||
| if args.method not in program.method_names: | ||
| raise ValueError( | ||
| f"Method {args.method!r} is not in the program; " | ||
| f"available methods: {sorted(program.method_names)}" | ||
| ) | ||
| inputs = (torch.ones((2, 3, 4, 4), dtype=torch.float32),) | ||
| for run in range(args.num_runs): | ||
| outputs = program.run(inputs, args.method) | ||
| print(f"Run {run + 1} outputs:") | ||
| for index, output in enumerate(outputs): | ||
| if isinstance(output, torch.Tensor): | ||
| print( | ||
| f" output[{index}]: shape={tuple(output.shape)}, " | ||
| f"dtype={output.dtype}, device={output.device}, " | ||
| f"sample={output.flatten()[:8]}" | ||
| ) | ||
| else: | ||
| print(f" output[{index}]: {output!r}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # Torch-TensorRT ExecuTorch Delegate Wheel | ||
|
|
||
| This directory builds `torch-tensorrt-executorch-delegate`. The Linux wheel | ||
| contains an ExecuTorch `_portable_lib` Python runtime with `TensorRTBackend` | ||
| force-linked into the same native module that owns the backend registry. | ||
|
|
||
| The wheel must use the same Python, PyTorch, ExecuTorch, CUDA, TensorRT, and | ||
| C++ ABI as its matching Torch-TensorRT wheel. | ||
|
|
||
| ## Build | ||
|
|
||
| > [!IMPORTANT] | ||
| > Build this wheel with `--no-build-isolation`. Its native extension must use | ||
| > the exact PyTorch installation that the matching Torch-TensorRT artifacts | ||
| > were built against. An isolated build may download a newer, ABI-incompatible | ||
| > PyTorch version. | ||
|
|
||
| ```bash | ||
| executorch_cmake_location="$(bazel query \ | ||
| @executorch//:executorch/CMakeLists.txt --output=location)" | ||
| export EXECUTORCH_SOURCE_DIR="$(dirname "${executorch_cmake_location%%:*}")" | ||
| export TensorRT_ROOT=/path/to/TensorRT | ||
|
|
||
| python -m pip install executorch==1.3.1 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: the README says |
||
| python -m pip wheel --no-build-isolation --no-deps \ | ||
| --wheel-dir dist py/torch-tensorrt-executorch-delegate | ||
| ``` | ||
|
|
||
| The static ExecuTorch and delegate archives are intermediate build inputs; | ||
| users receive the final native Python module and do not compile anything. | ||
|
|
||
| ## Use | ||
|
|
||
| ```bash | ||
| pip install "torch-tensorrt[executorch]" | ||
| ``` | ||
|
|
||
| ```python | ||
| import torch | ||
| from torch_tensorrt.executorch.runtime import load | ||
|
|
||
| program = load("model.pte") | ||
| outputs = program.forward(torch.ones((2, 3, 4, 4))) | ||
| ``` | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.