Skip to content

Commit 9af9e09

Browse files
author
shoumikhin
committed
[executorch][nvidia][tensorrt][22/n] Add correctness tests
Add comprehensive correctness tests for TensorRT backend including model export and inference validation. Differential Revision: [D93275042](https://our.internmc.facebook.com/intern/diff/D93275042/) [ghstack-poisoned]
1 parent 8e02a40 commit 9af9e09

2 files changed

Lines changed: 56 additions & 7 deletions

File tree

.github/workflows/tensorrt.yml

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ on:
2424
paths:
2525
- backends/nvidia/tensorrt/**
2626
- examples/nvidia/tensorrt/**
27+
- .github/workflows/tensorrt.yml
2728
workflow_dispatch:
2829
schedule:
2930
# Run daily at 3 AM UTC (after CUDA workflow at 2 AM)
@@ -61,7 +62,6 @@ jobs:
6162
echo "::endgroup::"
6263
6364
echo "::group::Build TensorRT Backend"
64-
# Build with TensorRT support
6565
cmake -S . -B cmake-out \
6666
-DCMAKE_BUILD_TYPE=Release \
6767
-DEXECUTORCH_BUILD_TENSORRT=ON \
@@ -87,7 +87,7 @@ jobs:
8787
strategy:
8888
fail-fast: false
8989
matrix:
90-
model: [add, mul, linear]
90+
model: [add, add_mul, conv1d, dl3, edsr, efficient_sam, emformer_join, emformer_transcribe, ic3, ic4, linear, mul, mv2, mv3, resnet18, resnet50, sdpa, softmax, w2l]
9191
with:
9292
timeout: 60
9393
runner: linux.g5.4xlarge.nvidia.gpu
@@ -129,7 +129,7 @@ jobs:
129129
strategy:
130130
fail-fast: false
131131
matrix:
132-
model: [add, mul, linear]
132+
model: [add, add_mul, conv1d, dl3, edsr, efficient_sam, emformer_join, emformer_transcribe, ic3, ic4, linear, mul, mv2, mv3, resnet18, resnet50, sdpa, softmax, w2l]
133133
with:
134134
timeout: 60
135135
runner: linux.g5.4xlarge.nvidia.gpu
@@ -202,16 +202,47 @@ jobs:
202202
echo "::endgroup::"
203203
204204
echo "::group::Run TensorRT Backend Unit Tests"
205-
# Run all test_*.py files in the backend test directory.
206205
# The -o "addopts=" override prevents pytest.ini from injecting
207206
# flags that would run unrelated test suites.
208-
python -m pytest backends/nvidia/tensorrt/test/ -v -o "addopts="
207+
python -m pytest backends/nvidia/tensorrt/test/ \
208+
-v -o "addopts="
209+
echo "::endgroup::"
210+
211+
# ---- Export correctness tests ----
212+
# Exports all supported models and verifies numerical correctness
213+
# against eager PyTorch on GPU via the ExportCorrectnessTest class.
214+
test-export:
215+
name: test-export
216+
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
217+
permissions:
218+
id-token: write
219+
contents: read
220+
with:
221+
timeout: 120
222+
runner: linux.g5.4xlarge.nvidia.gpu
223+
gpu-arch-type: cuda
224+
gpu-arch-version: "12.6"
225+
use-custom-docker-registry: false
226+
submodules: recursive
227+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
228+
script: |
229+
set -eux
230+
231+
echo "::group::Install TensorRT"
232+
pip install tensorrt onnx
233+
echo "::endgroup::"
234+
235+
echo "::group::Install ExecuTorch"
236+
PYTHON_EXECUTABLE=python ./install_executorch.sh
237+
echo "::endgroup::"
238+
239+
echo "::group::Export all models and verify correctness"
240+
python -m pytest examples/nvidia/tensorrt/tests/test_export.py -v -o "addopts="
209241
echo "::endgroup::"
210242
211243
# Summary job to check all tests passed
212244
check-all-tensorrt-tests:
213-
needs: [test-tensorrt-build, test-models-tensorrt-python, test-models-tensorrt-cpp, unittest-tensorrt]
214-
# All four jobs must succeed for the overall check to pass.
245+
needs: [test-tensorrt-build, test-models-tensorrt-python, test-models-tensorrt-cpp, unittest-tensorrt, test-export]
215246
runs-on: ubuntu-latest
216247
if: always()
217248
steps:
@@ -233,4 +264,8 @@ jobs:
233264
echo "ERROR: TensorRT unit tests failed!"
234265
exit 1
235266
fi
267+
if [[ "${{ needs.test-export.result }}" != "success" ]]; then
268+
echo "ERROR: TensorRT export correctness tests failed!"
269+
exit 1
270+
fi
236271
echo "SUCCESS: All TensorRT backend tests passed!"

backends/nvidia/tensorrt/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,20 @@ The TensorRT delegate uses a custom binary blob format:
238238
- cuDNN 8.x
239239
- PyTorch 2.x with CUDA support (for export)
240240

241+
### Correctness Tests
242+
243+
```bash
244+
# Run all correctness tests
245+
python -m pytest examples/nvidia/tensorrt/tests/test_export.py -v
246+
247+
# Run a single model's test
248+
python -m pytest examples/nvidia/tensorrt/tests/test_export.py -v -k test_mv3
249+
```
250+
251+
Each test exports a model with TensorRT, runs inference via ExecuTorch
252+
pybindings, and compares outputs against eager PyTorch (atol=1e-3, rtol=1e-3)
253+
across 3 random seeds.
254+
241255
## Troubleshooting
242256

243257
| Issue | Fix |

0 commit comments

Comments
 (0)