-
Notifications
You must be signed in to change notification settings - Fork 544
[OMNIML-5563] Add PETR ONNX PTQ and accuracy evaluation example #2180
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| FROM nvcr.io/nvidia/pytorch:26.07-py3 | ||
|
|
||
| ENV LD_LIBRARY_PATH=/usr/local/cuda/compat/lib:/usr/local/nvidia/lib:/usr/local/nvidia/lib64 | ||
|
|
||
| RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ | ||
| libgl1 \ | ||
| libglib2.0-0 && \ | ||
| rm -rf /var/lib/apt/lists/* | ||
|
|
||
| ENV UV_PYTHON_INSTALL_DIR=/opt/python | ||
|
|
||
| RUN python -m pip install --no-cache-dir uv && \ | ||
| uv python install 3.8 && \ | ||
| uv venv --seed --python 3.8 /opt/petr | ||
|
Comment on lines
+15
to
+17
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. 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- candidate files ---'
git ls-files examples/onnx_ptq/petr/Dockerfile examples/onnx_ptq/petr/requirements.txt examples/onnx_ptq/petr/README.md
printf '%s\n' '--- Dockerfile ---'
cat -n examples/onnx_ptq/petr/Dockerfile
printf '%s\n' '--- requirements ---'
cat -n examples/onnx_ptq/petr/requirements.txt
printf '%s\n' '--- README ---'
cat -n examples/onnx_ptq/petr/README.md
printf '%s\n' '--- related PETR references ---'
rg -n -S 'DL4AGX|megvii-research/PETR|mmdetection3d|uv python install|uv venv|requirements\.txt|petr' \
examples/onnx_ptq/petr .github 2>/dev/null | head -250Repository: NVIDIA/Model-Optimizer Length of output: 18773 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- all PETR requirement files ---'
git ls-files 'examples/onnx_ptq/petr/requirements*.txt' | while read -r file; do
printf '\n### %s\n' "$file"
cat -n "$file"
done
printf '%s\n' '--- source-reference comments and repository metadata ---'
rg -n -S 'Adapted from|Source|Copyright|DL4AGX|PETR|mmdetection3d|nvcr\.io|FROM ' \
examples/onnx_ptq/petr --glob '!README.md'
printf '%s\n' '--- reproducibility-pattern verifier ---'
python3 - <<'PY'
from pathlib import Path
import re
root = Path("examples/onnx_ptq/petr")
dockerfile = (root / "Dockerfile").read_text()
print("Docker base image:", re.search(r"^FROM\s+(\S+)", dockerfile, re.M).group(1))
print("uv install is version-pinned:",
bool(re.search(r"pip install(?:[^\\\n]*\\\n)?[^\\\n]*\buv(?:==|===|~=)", dockerfile)))
print("uv Python selector:", re.search(r"uv python install\s+(\S+)", dockerfile).group(1))
for path in sorted(root.glob("requirements*.txt")):
print(f"\n{path}:")
for lineno, line in enumerate(path.read_text().splitlines(), 1):
line = line.strip()
if not line or line.startswith(("#", "-", "--")):
continue
print(f" {lineno}: {'pinned' if re.search(r'(?<![<>~!])==[^=]', line) else 'unconstrained/ranged'}: {line}")
readme = (root / "README.md").read_text().splitlines()
for lineno, line in enumerate(readme, 1):
if "git clone" in line:
print(f"README:{lineno}: {line.strip()}")
PYRepository: NVIDIA/Model-Optimizer Length of output: 5019 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- remote source refs ---'
for repo in \
https://github.com/NVIDIA/DL4AGX.git \
https://github.com/megvii-research/PETR.git \
https://github.com/open-mmlab/mmdetection3d.git
do
printf '\n### %s\n' "$repo"
git ls-remote --symref "$repo" HEAD 'refs/tags/v0.17.1' \
| grep -E '^(ref:|[0-9a-f]+\s+HEAD$|[0-9a-f]+\s+refs/tags/v0\.17\.1(\^\{\})?$)' || true
done
printf '%s\n' '--- requirement determinism summary ---'
python3 - <<'PY'
from pathlib import Path
import re
root = Path("examples/onnx_ptq/petr")
for path in sorted(root.glob("requirements*.txt")):
entries = []
for line in path.read_text().splitlines():
line = line.strip()
if not line or line.startswith(("#", "-")):
continue
entries.append(line)
unpinned = [x for x in entries if not re.search(r"(?<![<>~!])==[^=]", x)]
print(f"{path}: {len(entries)} entries, {len(unpinned)} without exact == pins")
if unpinned:
print(" " + "\n ".join(unpinned))
PYRepository: NVIDIA/Model-Optimizer Length of output: 1070 Pin the PETR build inputs to immutable artifacts.
📍 Affects 3 files
🤖 Prompt for AI Agents |
||
|
|
||
| COPY examples/onnx_ptq/petr/requirements*.txt /tmp/petr-requirements/ | ||
| RUN env -u PIP_CONSTRAINT /opt/petr/bin/python -m pip install --no-cache-dir \ | ||
| -r /tmp/petr-requirements/requirements-torch.txt && \ | ||
| env -u PIP_CONSTRAINT /opt/petr/bin/python -m pip install --no-cache-dir \ | ||
| -r /tmp/petr-requirements/requirements.txt && \ | ||
| env -u PIP_CONSTRAINT /opt/petr/bin/python -m pip install --no-cache-dir \ | ||
| --no-build-isolation \ | ||
| -r /tmp/petr-requirements/requirements-mmdet3d.txt && \ | ||
| mkdir -p /opt/petr/lib/python3.8/site-packages/tensorrt && \ | ||
| cp /opt/petr/lib/python3.8/site-packages/tensorrt_bindings/__init__.py \ | ||
| /opt/petr/lib/python3.8/site-packages/tensorrt/__init__.py && \ | ||
| cp /opt/petr/lib/python3.8/site-packages/tensorrt_bindings/tensorrt.so \ | ||
| /opt/petr/lib/python3.8/site-packages/tensorrt/tensorrt.so | ||
|
|
||
| COPY . /opt/Model-Optimizer | ||
| RUN cd /opt/Model-Optimizer && \ | ||
| env -u PIP_CONSTRAINT python -m pip install --no-cache-dir \ | ||
| -e ".[onnx]" \ | ||
| "onnxruntime-gpu[cuda,cudnn]~=1.24.2" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,231 @@ | ||
| # PETR ONNX PTQ and nuScenes evaluation | ||
|
|
||
| This example quantizes the PETRv1 and PETRv2 image backbones and detection heads to INT8 or FP8 with Model Optimizer. It follows the [NVIDIA DL4AGX PETR TensorRT workflow](https://github.com/NVIDIA/DL4AGX/tree/master/AV-Solutions/petr-trt) and evaluates TensorRT engines on the nuScenes validation set. | ||
|
|
||
| PETR uses a legacy PyTorch/MMCV environment that is incompatible with current Model Optimizer dependencies. The provided image uses `nvcr.io/nvidia/pytorch:26.07-py3` with TensorRT 11.1 and isolates PETR in a Python 3.8 virtual environment. | ||
|
|
||
| ## 1. Prepare PETR and nuScenes | ||
|
|
||
| Clone the reference repositories and apply the DL4AGX compatibility patch: | ||
|
|
||
| ```bash | ||
| git clone https://github.com/NVIDIA/DL4AGX.git | ||
| git clone https://github.com/megvii-research/PETR.git | ||
| cd PETR | ||
| git apply ../DL4AGX/AV-Solutions/petr-trt/patch.diff | ||
| git clone https://github.com/open-mmlab/mmdetection3d.git -b v0.17.1 | ||
| mkdir -p ckpts data | ||
| ln -s /path/to/nuscenes data/nuscenes | ||
| cd .. | ||
| ``` | ||
|
|
||
| Download the `PETR-vov-p4-800x320_epoch24.pth` and `PETRv2-vov-p4-800x320_epoch24.pth` checkpoints linked from the DL4AGX README, rename them as shown below, and prepare this layout: | ||
|
|
||
| ```text | ||
| PETR/ | ||
| ├── ckpts/ | ||
| │ ├── PETR-vov-p4-800x320_e24.pth | ||
| │ └── PETRv2-vov-p4-800x320_e24.pth | ||
| ├── data/nuscenes/ | ||
| │ ├── samples/ | ||
| │ ├── sweeps/ | ||
| │ ├── v1.0-trainval/ | ||
| │ └── nuscenes_infos_val.pkl | ||
| └── mmdetection3d/ | ||
| ``` | ||
|
|
||
| PETRv2 also needs metadata for the previous camera sweeps: | ||
|
|
||
| ```bash | ||
| /opt/petr/bin/python \ | ||
|
Collaborator
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.
Ordering problem: this step invokes Also, the directory layout above lists |
||
| /opt/Model-Optimizer/examples/onnx_ptq/petr/prepare_sweep_metadata.py \ | ||
| /workspace/PETR/data/nuscenes \ | ||
| --split val | ||
| ``` | ||
|
|
||
| This creates `mmdet3d_nuscenes_30f_infos_val.pkl`. | ||
|
|
||
| Build and start the example image from the Model Optimizer checkout: | ||
|
|
||
| ```bash | ||
| docker build \ | ||
| -f examples/onnx_ptq/petr/Dockerfile \ | ||
| -t petr-modelopt \ | ||
| . | ||
|
|
||
| docker run --rm -it --network=host --gpus=all --shm-size=64G \ | ||
| -v /path/to/Model-Optimizer:/opt/Model-Optimizer \ | ||
| -v /path/to/PETR:/workspace/PETR \ | ||
| -v /path/to/DL4AGX:/workspace/DL4AGX \ | ||
| petr-modelopt | ||
| ``` | ||
|
|
||
| Use the isolated Python 3.8 environment for PETR export, calibration preparation, and evaluation. Keep its site-packages first so the installed MMDetection3D 1.0.0rc6 package takes precedence over the v0.17.1 source tree used by the configs: | ||
|
|
||
| ```bash | ||
| export PYTHONPATH=/opt/petr/lib/python3.8/site-packages:/workspace/PETR:/workspace/DL4AGX/AV-Solutions/petr-trt/export_eval | ||
| ``` | ||
|
|
||
| ## 2. Export PETRv1 and PETRv2 to ONNX | ||
|
|
||
| Follow the DL4AGX exporter setup: | ||
|
|
||
| ```bash | ||
| cd /workspace/DL4AGX/AV-Solutions/petr-trt/export_eval | ||
| ln -s /workspace/PETR/data data | ||
| mkdir -p onnx_files engines | ||
|
|
||
| /opt/petr/bin/python v1/v1_export_to_onnx.py \ | ||
| /workspace/PETR/projects/configs/petr/petr_vovnet_gridmask_p4_800x320.py \ | ||
| /workspace/PETR/ckpts/PETR-vov-p4-800x320_e24.pth \ | ||
| --eval bbox | ||
|
|
||
| /opt/petr/bin/python v2/v2_export_to_onnx.py \ | ||
| /workspace/PETR/projects/configs/petrv2/petrv2_vovnet_gridmask_p4_800x320.py \ | ||
| /workspace/PETR/ckpts/PETRv2-vov-p4-800x320_e24.pth \ | ||
| --eval bbox | ||
| ``` | ||
|
|
||
| The exporters create a backbone graph and a head graph. Simplify both graphs: | ||
|
|
||
| ```bash | ||
| for version in v1 v2; do | ||
| model="PETR${version}" | ||
| python -m onnxsim \ | ||
| "onnx_files/${model}.extract_feat.onnx" \ | ||
| "onnx_files/sim_${model}.extract_feat.onnx" | ||
| python -m onnxsim \ | ||
| "onnx_files/${model}.pts_bbox_head.forward.onnx" \ | ||
| "onnx_files/sim_${model}.pts_bbox_head.forward.onnx" | ||
|
Comment on lines
+92
to
+99
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. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- candidate files ---'
git ls-files | rg '(^|/)(README\.md|Dockerfile|requirements\.txt)$|petr'
printf '%s\n' '--- README context ---'
sed -n '70,165p' examples/onnx_ptq/petr/README.md
printf '%s\n' '--- Dockerfile candidates and context ---'
fd -i '^dockerfile$' . | while IFS= read -r f; do
printf '\n### %s\n' "$f"
rg -n -C 5 'petr|requirements|onnxsim|PATH|autocast|model optimizer|mo' "$f" || true
done
printf '%s\n' '--- requirements context ---'
fd -i '^requirements\.txt$' . | while IFS= read -r f; do
printf '\n### %s\n' "$f"
rg -n -C 3 'onnxsim|onnx|openvino|mo|model' "$f" || true
done
printf '%s\n' '--- all relevant command references ---'
rg -n -C 4 'onnxsim|AutoCast|autocast|/opt/petr/bin/python|python -m' examples/onnx_ptq/petr .github docker* 2>/dev/null || trueRepository: NVIDIA/Model-Optimizer Length of output: 30539 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- complete PETR Dockerfile ---'
cat -n examples/onnx_ptq/petr/Dockerfile
printf '%s\n' '--- README setup and AutoCast sections ---'
sed -n '1,70p' examples/onnx_ptq/petr/README.md
sed -n '136,165p' examples/onnx_ptq/petr/README.md
printf '%s\n' '--- modelopt ONNX dependency and AutoCast declarations ---'
rg -n -C 5 'onnx|autocast|convert_to_mixed_precision|modelopt\.onnx' pyproject.toml setup.cfg setup.py modelopt examples/onnx_ptq/petr 2>/dev/null || true
printf '%s\n' '--- read-only command/environment verifier ---'
python3 - <<'PY'
from pathlib import Path
import re
docker = Path("examples/onnx_ptq/petr/Dockerfile").read_text()
readme = Path("examples/onnx_ptq/petr/README.md").read_text()
requirements = Path("examples/onnx_ptq/petr/requirements.txt").read_text()
docker_path_lines = [
line for line in docker.splitlines()
if re.search(r'(^|\s)(ENV|ARG).*PATH|PATH\s*=', line)
]
python_invocations = [
(i, line.strip())
for i, line in enumerate(readme.splitlines(), 1)
if re.search(r'(^|\s)(python|/opt/petr/bin/python)\b', line)
]
print("Dockerfile PATH declarations:", docker_path_lines or "<none>")
print("requirements.txt declares onnxsim:", bool(re.search(r"(?m)^onnxsim\s*$", requirements)))
print("Dockerfile installs PETR requirements with /opt/petr/bin/python:",
"/opt/petr/bin/python -m pip install" in docker and
"-r /tmp/petr-requirements/requirements.txt" in docker)
print("Dockerfile installs Model Optimizer in base-environment python:",
'env -u PIP_CONSTRAINT python -m pip install' in docker)
print("README Python invocations:")
for item in python_invocations:
print(" ", item)
PYRepository: NVIDIA/Model-Optimizer Length of output: 50379 🏁 Script executed: #!/bin/bash
set -eu
log=/tmp/coderabbit-shell-logs/shell-output-yUgE4z
printf '%s\n' '--- Dockerfile and README excerpts from prior result ---'
rg -n -A 4 -B 2 '^ *([0-9]+:)?(FROM|ENV|RUN|COPY)|/opt/petr/bin/python|python /opt/Model-Optimizer/examples/onnx_ptq/petr/convert_to_fp16.py|python -m onnxsim|Docker|container|PATH' "$log" | head -n 240
printf '%s\n' '--- verifier output from prior result ---'
rg -n -A 30 -B 3 'Dockerfile PATH declarations|requirements.txt declares|README Python invocations' "$log"
printf '%s\n' '--- focused dependency declarations ---'
rg -n -A 8 -B 4 'onnxsim|optional-dependencies|onnx.*=' pyproject.toml setup.cfg setup.py 2>/dev/null | head -n 180
printf '%s\n' '--- conversion script imports ---'
cat -n examples/onnx_ptq/petr/convert_to_fp16.py | sed -n '1,80p'Repository: NVIDIA/Model-Optimizer Length of output: 17961 Use the correct Python environment for each command. Use 🤖 Prompt for AI Agents |
||
| done | ||
| ``` | ||
|
|
||
| ## 3. Prepare calibration batches | ||
|
|
||
| Build temporary FP32 engines for collecting the backbone and head inputs: | ||
|
|
||
| ```bash | ||
| for version in v1 v2; do | ||
| model="PETR${version}" | ||
| trtexec \ | ||
| --onnx="onnx_files/sim_${model}.extract_feat.onnx" \ | ||
| --saveEngine="engines/${model}.backbone.calibration.engine" \ | ||
| --skipInference | ||
| trtexec \ | ||
| --onnx="onnx_files/sim_${model}.pts_bbox_head.forward.onnx" \ | ||
| --saveEngine="engines/${model}.head.calibration.engine" \ | ||
| --skipInference | ||
| done | ||
| ``` | ||
|
|
||
| Collect 512 representative backbone and head input batches. The default interval samples across the 6,019-frame validation set: | ||
|
|
||
| ```bash | ||
| /opt/petr/bin/python /opt/Model-Optimizer/examples/onnx_ptq/petr/prepare_calibration.py \ | ||
| v1 \ | ||
| /workspace/PETR/projects/configs/petr/petr_vovnet_gridmask_p4_800x320.py \ | ||
| /workspace/PETR/ckpts/PETR-vov-p4-800x320_e24.pth \ | ||
| onnx_files/sim_PETRv1.extract_feat.onnx \ | ||
| onnx_files/sim_PETRv1.pts_bbox_head.forward.onnx \ | ||
| engines/PETRv1.backbone.calibration.engine \ | ||
| engines/PETRv1.head.calibration.engine \ | ||
| calibration/PETRv1 | ||
| ``` | ||
|
|
||
| Repeat with `v2`, the PETRv2 config, checkpoint, graphs, engines, and `calibration/PETRv2` output directory. | ||
|
|
||
| TensorRT 11 uses strongly typed networks and no longer accepts `--fp16`. | ||
| Create calibrated mixed-FP16 graphs with Model Optimizer AutoCast, preserving | ||
| FP32 model inputs and outputs, then build the reference engines. The example | ||
| below uses one representative batch for AutoCast node classification: | ||
|
|
||
| ```bash | ||
| for version in v1 v2; do | ||
| model="PETR${version}" | ||
| python /opt/Model-Optimizer/examples/onnx_ptq/petr/convert_to_fp16.py \ | ||
| "onnx_files/sim_${model}.extract_feat.onnx" \ | ||
| "onnx_files/sim_${model}.extract_feat.fp16.onnx" \ | ||
| "calibration/${model}/backbone/batch_0000.npz" | ||
| python /opt/Model-Optimizer/examples/onnx_ptq/petr/convert_to_fp16.py \ | ||
| "onnx_files/sim_${model}.pts_bbox_head.forward.onnx" \ | ||
| "onnx_files/sim_${model}.pts_bbox_head.forward.fp16.onnx" \ | ||
| "calibration/${model}/head/batch_0000.npz" | ||
| trtexec \ | ||
| --onnx="onnx_files/sim_${model}.extract_feat.fp16.onnx" \ | ||
| --saveEngine="engines/${model}.backbone.fp16.engine" \ | ||
| --skipInference | ||
| trtexec \ | ||
| --onnx="onnx_files/sim_${model}.pts_bbox_head.forward.fp16.onnx" \ | ||
| --saveEngine="engines/${model}.head.fp16.engine" \ | ||
| --skipInference | ||
| done | ||
| ``` | ||
|
|
||
| ## 4. Quantize the ONNX models | ||
|
|
||
| Use the base Python environment for Model Optimizer. This command quantizes the backbone and keeps the head in FP16: | ||
|
|
||
| ```bash | ||
| python /opt/Model-Optimizer/examples/onnx_ptq/petr/quantize.py \ | ||
| --backbone-onnx onnx_files/sim_PETRv1.extract_feat.onnx \ | ||
| --head-onnx onnx_files/sim_PETRv1.pts_bbox_head.forward.onnx \ | ||
| --calibration-dir calibration/PETRv1 \ | ||
| --precision int8 | ||
| ``` | ||
|
|
||
| Use `--precision fp8` for FP8. Add `--quantize-head` to quantize both the backbone and head. Repeat the commands for PETRv2. FP8 deployment requires an FP8-capable GPU. | ||
|
|
||
| The backbone quantizer preserves the accuracy-sensitive final VoVNet stage and FPN output layers in FP16, matching the exclusions used by the FAR3D example. | ||
|
|
||
| ## 5. Build and evaluate TensorRT engines | ||
|
|
||
| Build the quantized backbone as a strongly typed engine: | ||
|
|
||
| ```bash | ||
| precision=int8 | ||
| model=PETRv1 | ||
| trtexec \ | ||
| --onnx="onnx_files/sim_${model}.extract_feat.${precision}.onnx" \ | ||
| --saveEngine="engines/${model}.backbone.${precision}.engine" \ | ||
| --stronglyTyped \ | ||
| --skipInference | ||
| ``` | ||
|
|
||
| If `--quantize-head` was used, build the generated head graph with the same `trtexec` options. Otherwise, use the FP16 head engine from step 3. | ||
|
|
||
| Evaluate any backbone/head pairing. For example, INT8 backbone with FP16 head: | ||
|
|
||
| ```bash | ||
| /opt/petr/bin/python /opt/Model-Optimizer/examples/onnx_ptq/petr/evaluate.py \ | ||
| v1 \ | ||
| /workspace/PETR/projects/configs/petr/petr_vovnet_gridmask_p4_800x320.py \ | ||
| /workspace/PETR/ckpts/PETR-vov-p4-800x320_e24.pth \ | ||
| engines/PETRv1.backbone.int8.engine \ | ||
| engines/PETRv1.head.fp16.engine | ||
| ``` | ||
|
|
||
| Use `--max-samples N` for an inference smoke test. Dataset metrics are skipped when only part of the validation set is processed. | ||
|
|
||
| Measure each engine with host/device transfers disabled and add the backbone and head median GPU compute times: | ||
|
|
||
| ```bash | ||
| trtexec --loadEngine=engines/PETRv1.backbone.int8.engine \ | ||
| --noDataTransfers --useCudaGraph --warmUp=1000 --duration=10 | ||
| trtexec --loadEngine=engines/PETRv1.head.fp16.engine \ | ||
| --noDataTransfers --useCudaGraph --warmUp=1000 --duration=10 | ||
| ``` | ||
|
|
||
| ## Results on the nuScenes validation set | ||
|
|
||
| Results below use TensorRT 11.1.0.106 on an NVIDIA RTX 6000 Ada Generation GPU. Accuracy is measured over all 6,019 validation samples after calibration with 512 batches. GPU compute time is the sum of the backbone and head median times reported by `trtexec`; it excludes data transfers and PETRv2's reusable previous-frame feature extraction. | ||
|
|
||
| | Model | Backbone precision | Head precision | Framework | GPU compute time (ms) | Accuracy (mAP) | | ||
| | --- | --- | --- | --- | ---: | ---: | | ||
| | PETRv1-vov-p4-800x320 | FP16 | FP16 | TensorRT 11.1 | 14.507 | 0.3781 | | ||
| | PETRv1-vov-p4-800x320 | INT8 | FP16 | TensorRT 11.1 | 9.992 | 0.3711 | | ||
| | PETRv1-vov-p4-800x320 | FP8 | FP16 | TensorRT 11.1 | 11.455 | 0.3757 | | ||
| | PETRv2-vov-p4-800x320 | FP16 | FP16 | TensorRT 11.1 | 19.349 | 0.4105 | | ||
| | PETRv2-vov-p4-800x320 | INT8 | FP16 | TensorRT 11.1 | 14.468 | 0.4017 | | ||
| | PETRv2-vov-p4-800x320 | FP8 | FP16 | TensorRT 11.1 | 16.242 | 0.4092 | | ||
|
|
||
| TensorRT engines are specific to the TensorRT version and GPU architecture used to build them. These x86 results are not directly comparable with the DRIVE Orin measurements in the DL4AGX reference. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import argparse | ||
|
|
||
| from modelopt.onnx import utils as onnx_utils | ||
| from modelopt.onnx.autocast import convert_to_mixed_precision | ||
|
|
||
|
|
||
| def parse_args(): | ||
| parser = argparse.ArgumentParser(description="Convert a PETR ONNX model to FP16") | ||
| parser.add_argument("input") | ||
| parser.add_argument("output") | ||
| parser.add_argument("calibration_data") | ||
| return parser.parse_args() | ||
|
|
||
|
|
||
| def main(): | ||
|
Collaborator
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.
This script is a thin re-implementation of the AutoCast CLI that ModelOpt already ships ( |
||
| args = parse_args() | ||
| model = convert_to_mixed_precision( | ||
| onnx_path=args.input, | ||
| low_precision_type="fp16", | ||
| calibration_data=args.calibration_data, | ||
| keep_io_types=True, | ||
| providers=["cuda:0", "cpu"], | ||
| ) | ||
| onnx_utils.save_onnx(model, args.output) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Run the container as a non-root user.
The Dockerfile never sets
USER, so the runtime shell and example commands run as root. The README mounts host directories into the container. A compromised dependency or example script can then write those bind mounts with container-root privileges. Create a dedicated user after the installation steps, grant access only to the required paths, and setUSERbefore runtime.Trivy reports DS-0002 for this image.
🤖 Prompt for AI Agents
Source: Linters/SAST tools