engine-building
Build and diagnose TensorRT engines for the repository's Caffe GoogLeNet and MTCNN, TensorFlow UFF SSD, DarkNet YOLO, and ONNX MODNet workflows, including the legacy API boundaries, custom plugin, FP16/INT8 calibration, and Jetson DLA paths.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- engine-building
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Build and diagnose TensorRT engines for the repository's Caffe GoogLeNet and MTCNN, TensorFlow UFF SSD, DarkNet YOLO, and ONNX MODNet workflows, including the legacy API boundaries, custom plugin, FP16/INT8 calibration, and Jetson DLA paths.
- disable-model-invocation
- true
02 资源文件 5
- 参考文档compatibility.md8.0 KB
- 参考文档references/troubleshooting.md10.9 KB
- 参考文档references/workflows.md9.9 KB
- 脚本scripts/check_cuda_arch.py3.9 KB
- 脚本scripts/validate-engine-build-inputs.py10.6 KB
03 SKILL.md 正文
TensorRT engine building
Use this sub-skill when a Researcher needs to prepare inputs, choose a version-compatible path, or build/inspect one of the engines in this repository. It is an operating guide, not a promise that a serialized engine is portable: TensorRT engines and custom CUDA plugins are tied to the TensorRT, CUDA, driver, GPU architecture, and sometimes OS/runtime that built them.
Safety and decision gate
- This skill is intentionally non-mutating by default. Reading files,
--help,scripts/validate-engine-build-inputs.py, andscripts/check_cuda_arch.pydo not build, download, install, create symlinks, patch system packages, or overwrite engines. - Building is an explicit action. Before it, confirm the target TensorRT major version, CUDA/toolkit and driver availability, GPU compute capability, model artifact provenance, output paths, and whether an existing engine may be replaced.
- Do not run
yolo/download_yolo.sh,ssd/install.sh,*/install_pycuda.sh, or the README'swget,apt,pip,ln -s,patch, andsudocommands as an implicit prerequisite. Acquire or install dependencies through the operator's approved, isolated process and record versions. - Prefer a new output filename or a clean, dedicated build directory. Never use a source checkout as a scratch area without an explicit overwrite plan.
- Use
--verbose/-vonly when diagnosing; it can expose useful parser and tactic errors but does not make an unsupported API compatible.
Choose the workflow
| Input/model family | Repository entry point | Outputs and fixed facts |
|---|---|---|
| Caffe GoogLeNet | googlenet/Makefile, googlenet/create_engine.cpp |
deploy.engine; parses deploy.prototxt + deploy.caffemodel, marks prob, max batch 1, deserializes and expects 2 bindings |
| Caffe MTCNN | mtcnn/Makefile, mtcnn/create_engines.cpp |
det1.engine, det2.engine, det3.engine; uses the _relu prototxt/model pairs and max batches PNet 1, RNet 256, ONet 64 |
| TensorFlow frozen graph → UFF SSD | ssd/build_engine.py, ssd/build_engines.sh |
TRT_<model>.bin (temporary <model>.uff); fixed input (3,300,300), Input, NMS; legacy TensorFlow/UFF/GraphSurgeon plus FlattenConcat plugin |
| DarkNet YOLO → ONNX → TensorRT | yolo/yolo_to_onnx.py, yolo/onnx_to_tensorrt.py |
<model>.onnx, then <model>.trt; uses cfg-derived shape/classes/anchors and the YoloLayer_TRT plugin, final output detections |
| YOLO reduced precision / accelerator | yolo/onnx_to_tensorrt.py, build_int8_engines.sh, build_dla_engines.sh |
INT8 uses calib_images/ and calib_<model>.bin; DLA names use --dla_core; both are explicit variants, not defaults |
| ONNX MODNet → TensorRT | modnet/onnx_to_tensorrt.py |
python3 onnx_to_tensorrt.py [options] input.onnx output.engine; fixed batch 1, default profile (1,3,480,640), FP16 + GPU fallback; source explicitly raises for INT8 and DLA |
For detailed command sequences and artifact checks, read references/workflows.md. For version/API and hardware gates, read compatibility.md. For failures, read references/troubleshooting.md.
Common preflight
-
Identify the actual
python3,nvcc, TensorRT Python package, TensorRT headers/libraries, CUDA driver, and GPU. Do not infer them from a path in this checkout.plugins/gpu_cc.pyis a useful native CUDA probe; the bundledscripts/check_cuda_arch.pyis a dependency-free diagnostic and does not build anything. -
Run the safe validator against a read-only source tree or an explicit build-input directory:
python3 scripts/validate-engine-build-inputs.py --repo-root . --allAdd
--model <name>for a model-specific report. It checks presence, regular-file/symlink status, YOLO cfg shape invariants, calibration image count, plugin/source preconditions, and warns on missing optional inputs. -
Confirm paths and expected names before invoking any builder. A successful preflight only proves that inputs are plausible; it does not parse a model, compile a plugin, or validate TensorRT execution.
-
Build the custom plugin before YOLO conversion, then verify that the shared object is loadable in the same runtime that imports
yolo/plugins.py. The plugin must be compiled for every target GPU architecture or a compatible PTX path, and its TensorRT ABI must match the builder/runtime. -
After each build, verify the output exists, is non-empty, can be deserialized by the same TensorRT major/minor family, and has the expected bindings or I/O names. For accuracy-sensitive detection changes, compare FP32/FP16/INT8 outputs or mAP; speed alone is not validation.
Engine-specific operating rules
Caffe: GoogLeNet and MTCNN
- Build from the respective directory so
locateFile()and relative model paths resolve.makecompiles againstcommon/Makefile.config; checkTARGET,CUDA_INSTALL_DIR,CUDNN_INSTALL_DIR, TensorRT include paths, and libraries before compilation. - GoogLeNet parses
deploy.prototxtanddeploy.caffemodel, marksprob, selects FP16 whenplatformHasFastFp16()is true, writesdeploy.engine, then immediately deserializes it and prints two bindings. - MTCNN uses the repository's
det1_relu,det2_relu, anddet3_relufiles; the_reluconversion is deliberate because the README documents the TensorRT 3/4 PReLU workaround. Outputs areprob1plus box/landmark heads: PNetprob1,conv4-2, RNetprob1,conv5-2, ONetprob1,conv6-2,conv6-3. The executable checks 3, 3, and 4 bindings respectively. - These C++ programs contain both legacy and newer branches, but are not
generic modern TensorRT samples. Treat Caffe parser availability and
deprecated
destroy()/implicit-batch APIs as version gates, not as advice to mechanically port every line.
TensorFlow UFF SSD
- Select one of the model keys declared in
ssd/build_engine.py(the build shell script covers four v1/v2 COCO/EgoHands models; the Python map also documents Inception and SSDLite variants). Run fromssd/so all paths andlibflattenconcat.soresolution are predictable. - The script rewrites graph namespaces into
GridAnchor_TRT,NMS_TRT, andFlattenConcat_TRT, replaces unsupportedAddV2andFusedBatchNormV3, removes assertions/identities, and registersInput(1,3,300,300)andMarkOutput_0. It uses FP16 and a 256 MiB legacy workspace setting. - UFF was tested by the repository with TensorFlow 1.12.x/compatible UFF (the
README explicitly says other versions are not guaranteed). This is a legacy
path. Do not substitute a current TensorFlow/UFF stack without an isolated
compatibility test and do not assume an old
.bincan be deserialized by a modern runtime. - Confirm the
libflattenconcat.sosymlink/SONAME matches TensorRT 5 or 6 as applicable. The README records a TensorRT 6 plugin-creator registration warning; distinguish a harmless duplicate registration warning from a real missing creator or parse failure.
DarkNet YOLO → ONNX → TensorRT
- Obtain a cfg and matching DarkNet weights through an approved source. The
conversion script derives classes, anchor masks, input
height/width, and output heads from the cfg; it expects<model>.cfgand<model>.weightsin its working directory and writes<model>.onnx. - Run
python3 yolo/yolo_to_onnx.py --helpto confirm the CLI in the active environment, then use-m <model>only after the matching cfg/weights have been validated. The supported naming convention is an architecture plus a dimension, such asyolov4-416oryolov4-416x256; custom classes require a matching cfg and postprocessing expectations. - Build
plugins/libyolo_layer.sobefore the TensorRT step. The Python module loads it using a path relative to theyolo/working directory, initializes TensorRT's plugin registry, looks upYoloLayer_TRT, replaces each raw YOLO output, and concatenates them asdetections. The plugin accepts linear FLOAT tensors only; it is not an FP16 plugin implementation merely because the rest of the builder sets an FP16 flag. - Run
python3 yolo/onnx_to_tensorrt.py -m <model>for the repository's baseline FP16 path. The script forces batch 1, uses a 1 GiB workspace, creates a fixed optimization profile for the cfg shape, and serializes<model>.trt. TensorRT 7–9 and 10+ use different branches in this checkout; inspect the version-specific warnings incompatibility.mdbefore running. - Do not call the download script as part of a routine build. It downloads several large DarkNet artifacts and creates derivative cfgs/symlinks; use it only as an explicit, reviewed acquisition step.
YOLO FP16, INT8 calibration, and DLA
- FP16 is the default selected builder mode in the legacy YOLO, GoogLeNet, and
MTCNN implementations when supported. Check
platform_has_fast_fp16or the corresponding modern capability before claiming a true FP16 build. - INT8 requires a platform with fast INT8 support and a representative image
set. The repository calibrator reads
.jpgfiles fromcalib_images/, resizes BGR→RGB to the cfg shape, transposes to CHW, scales to[0,1], uses batch 1, and caches atcalib_<model>.bin. The README suggests 500 images and demonstrates 1,000 COCOval2017images; this is guidance, not a proof of sufficient coverage for another deployment distribution. - Check calibration image readability, ordering/reproducibility, class and scene coverage, cache ownership, and whether the cache corresponds to the exact model/input/preprocessing. Delete or quarantine a stale cache only after an explicit decision. INT8 can alter accuracy: the repository reports an unresolved poor mAP result for YOLOv4-608 INT8, so always evaluate.
- DLA is an optional Jetson Xavier/NX-era path. The YOLO builder sets default
device DLA, selects
DLA_core, enables GPU fallback in its TensorRT 7/8 branch, and uses strict types; the TensorRT 3–6 branch rejects DLA. DLA engine creation is not evidence that inference used the requested core. TensorRT 7.1's Python API in the repository could not explicitly select the inference core after deserialization. Verify device placement with the target runtime's supported API and treat unsupported layers/fallback as expected failure modes. The README specifically recordsyolov4-tiny-416DLA build failure in the historical test.
MODNet ONNX → TensorRT
- Use the checked-in
modnet/modnet.onnxor another approved ONNX with the same input contract. The converter requires TensorRT 7+ and sets an explicit batch network, batch 1, a namedInputprofile, FP16, GPU fallback, and a 1 GiB workspace. Defaults are width 640 and height 480; override both together when the model and caller agree. - Invoke
python3 modnet/onnx_to_tensorrt.py --helpfirst, then provideinput_onnx output_engine. The repository implementation deliberately raisesINT8 not implemented yetandDLA_core not implemented yet; do not document those flags as working MODNet features. - TensorRT 7.1 needs the documented private onnx-tensorrt workaround for
dynamic
InstanceNormalization; TensorRT 7.2 fixed the issue according to the README. Treat the uninitializedmodnet/onnx-tensorrt/submodule as third-party build material, not as a bundled dependency. Prefer TensorRT 7.2+ for the direct converter after checking ONNX input dimensions. - Verify the resulting engine with
trt_modnet.py --helpor a controlled headless inference harness. The README's demo expectsmodnet/image.jpg, but display/video tests are separate from engine creation.
Completion and handoff
Record, for each engine: source artifact hashes or provenance, TensorRT/CUDA/ GPU versions, exact command and working directory, plugin and calibration inputs, output path, warnings, deserialization/binding check, and accuracy or runtime result. Mark a path blocked rather than silently falling back when its required backend, legacy parser, custom plugin, calibration data, or DLA hardware is unavailable. A partial static/help-only check is not a successful engine build.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).