add torch-tensorrt-executorch-delegate wheel build - #4398
Conversation
|
@lanluo-nvidia the new package should be in //py See: https://packaging.python.org/en/latest/guides/packaging-namespace-packages/ |
shoumikhin
left a comment
There was a problem hiding this comment.
Nice work on this. The core idea is right. You build _portable_lib from source and pull TensorRTBackend into the same module that holds the backend registry, so the two always share one copy of the ExecuTorch core. That is the correct way to fix the undefined symbol crash people hit today. I checked the linking part and it holds up: one registry, no duplicate core, and the whole-archive flag is actually needed.
|
One more note, on a file this PR does not change so I cannot leave it inline. In |
There was a problem hiding this comment.
There are some changes that do not conform to Python style guidelines:
--- /home/runner/work/TensorRT/TensorRT/py/torch-tensorrt-executorch-delegate/setup.py 2026-07-17 19:30:44.124103+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch-tensorrt-executorch-delegate/setup.py 2026-07-17 19:31:08.985550+00:00
@@ -14,10 +14,11 @@
from setuptools import Extension, find_packages, setup
from setuptools.command.build_ext import build_ext
HERE = pathlib.Path(__file__).resolve().parent
REPO_ROOT = HERE.parents[1]
+
def torchtrt_version() -> str:
if value := os.getenv("TORCH_TENSORRT_EXECUTORCH_DELEGATE_VERSION"):
return value
version_py = REPO_ROOT / "py/torch_tensorrt/_version.py"There was a problem hiding this comment.
There are some changes that do not conform to C++ style guidelines:
diff --git a/home/runner/work/TensorRT/TensorRT/cpp/src/torch_tensorrt/executorch/TensorRTBackend.cpp b/tmp/changes.txt
index 648fb88..e335748 100644
--- a/home/runner/work/TensorRT/TensorRT/cpp/src/torch_tensorrt/executorch/TensorRTBackend.cpp
+++ b/tmp/changes.txt
@@ -56,8 +56,7 @@ extern const Error kRegistrationResult;
Error check_registration() {
if (kRegistrationResult != Error::Ok) {
- ET_LOG(
- Error, "TensorRTBackend registration failed: %s", ::executorch::runtime::to_string(kRegistrationResult));
+ ET_LOG(Error, "TensorRTBackend registration failed: %s", ::executorch::runtime::to_string(kRegistrationResult));
}
return kRegistrationResult;
}
ERROR: Some files do not conform to style guidelinesThere was a problem hiding this comment.
There are some changes that do not conform to C++ style guidelines:
diff --git a/home/runner/work/TensorRT/TensorRT/cpp/src/torch_tensorrt/executorch/TensorRTBackend.cpp b/tmp/changes.txt
index 648fb88..e335748 100644
--- a/home/runner/work/TensorRT/TensorRT/cpp/src/torch_tensorrt/executorch/TensorRTBackend.cpp
+++ b/tmp/changes.txt
@@ -56,8 +56,7 @@ extern const Error kRegistrationResult;
Error check_registration() {
if (kRegistrationResult != Error::Ok) {
- ET_LOG(
- Error, "TensorRTBackend registration failed: %s", ::executorch::runtime::to_string(kRegistrationResult));
+ ET_LOG(Error, "TensorRTBackend registration failed: %s", ::executorch::runtime::to_string(kRegistrationResult));
}
return kRegistrationResult;
}
ERROR: Some files do not conform to style guidelinesThere was a problem hiding this comment.
There are some changes that do not conform to Python style guidelines:
--- /home/runner/work/TensorRT/TensorRT/setup.py 2026-07-27 20:11:18.445428+00:00
+++ /home/runner/work/TensorRT/TensorRT/setup.py 2026-07-27 20:11:43.549449+00:00
@@ -183,12 +183,11 @@
else:
__version__ = f"{get_base_version()}.dev0+{get_git_revision_short_hash()}"
EXECUTORCH_REQUIREMENT = "executorch>=1.3.1"
EXECUTORCH_DELEGATE_REQUIREMENT = (
- f"torch-tensorrt-executorch-delegate=={__version__}; "
- "platform_system == 'Linux'"
+ f"torch-tensorrt-executorch-delegate=={__version__}; " "platform_system == 'Linux'"
)
EXTRAS_REQUIRE = {
"executorch": [EXECUTORCH_REQUIREMENT, EXECUTORCH_DELEGATE_REQUIREMENT],
"all": [EXECUTORCH_REQUIREMENT, EXECUTORCH_DELEGATE_REQUIREMENT],
}There was a problem hiding this comment.
There are some changes that do not conform to C++ style guidelines:
diff --git a/home/runner/work/TensorRT/TensorRT/cpp/src/torch_tensorrt/executorch/TensorRTBackend.cpp b/tmp/changes.txt
index 648fb88..e335748 100644
--- a/home/runner/work/TensorRT/TensorRT/cpp/src/torch_tensorrt/executorch/TensorRTBackend.cpp
+++ b/tmp/changes.txt
@@ -56,8 +56,7 @@ extern const Error kRegistrationResult;
Error check_registration() {
if (kRegistrationResult != Error::Ok) {
- ET_LOG(
- Error, "TensorRTBackend registration failed: %s", ::executorch::runtime::to_string(kRegistrationResult));
+ ET_LOG(Error, "TensorRTBackend registration failed: %s", ::executorch::runtime::to_string(kRegistrationResult));
}
return kRegistrationResult;
}
ERROR: Some files do not conform to style guidelines|
Net: let's land this as the TensorRT-only Python runtime and treat the coalesced TRT+CUDA case as a separate follow-up that we'll drive, so it doesn't block you here. Quick context on the two ExecuTorch-side features in play, since both postdate this PR:
Both are out of scope for a TensorRT-only runner, so to land:
Everything else I raised (external |
|
Clarifying point 2: coalesced or external-.ptd models already fail with a hard ExecuTorch error (like "Backend CudaBackend is not registered"), just deferred to the first forward() and worded cryptically, so no silent-wrong-answer risk, so skip any .pte pre-scanner. |
Description
Adds a separately packaged
torch-tensorrt-executorch-delegatewheel that bundles the ExecuTorch Python portable runtime withTensorRTBackendregistered. This allows an exported.ptemodel to be loaded and executed withtorch_tensorrt.load(..., format="executorch")without requiring an ExecuTorch source checkout or a native build on the deployment system.The main
torch-tensorrtpackage continues to own compilation and export. ExecuTorch runtime loading and its native libraries are isolated in the optional delegate package.Changes
ExecuTorch delegate package and build
torch-tensorrt-executorch-delegatePython package._portable_lib.soanddata_loader.soin the wheel.pip wheelinvocation to rebuild and recopy the native libraries, preventing stale.sofiles from being packaged.Package and API separation
torch-tensorrtpackage.Program,.pteloading, runtime activation, and native module handling into the delegate package.format="executorch"support totorch_tensorrt.load.executorchandallextras.Runtime activation
_portable_lib.PyDataLoader.TensorRTBackendis present in the runtime backend registry.ExecuTorch version and dependencies
e2f18eb23c45bd22ca332b0b8b49a81de304b472, matchingexecutorch==1.3.1.torch,executorch, andtorch-tensorrtfor the delegate wheel.CI, examples, and documentation
.ptemodel with both the C++ reference runner and the Python delegate runtime.load_model.pyto accept--model_pathand--num_runs.Tests
Validation
model.ptethroughtorch_tensorrt.load(..., format="executorch")and verified the TensorRT delegate result against the expectedx + 1output.Type of change