trex is useful for initial model performance debugging, visualization of plan graphs, and for understanding the characteristics of an engine plan. For in-depth performance analysis, Nvidia ® Nsight Systems ™ is the recommended performance analysis tool.
In this project, we use the
trt-engine-explorertool to visualize TensorRT engine files and identify layers that may affect inference accuracy based on the visualized engine.Installation documentation: https://github.com/NVIDIA/TensorRT/tree/release/10.0/tools/experimental/trt-engine-explorer#installation
The typical trex workflow is depicted below:
- Convert an external model to a TensorRT
INetworkDefinition. - Build a TensorRT engine.
- Profile the engine while creating the necessary JSON files.
- Explore the engine by loading the JSON files in a
trexnotebook.
The Python script utils/process_engine.py implements this workflow for ONNX models:
- Use
trtexecto import an ONNX model and create an engine. - Load the engine and create an engine-graph JSON file.
- Use
trtexecto profile the engine's inference execution and store the results in an engine profiling JSON file. - Create an engine graph diagram in SVG format.
For more information see TensorRT Engine Inspector and the Tutorial notebook.
In this project, the code for utilizing trex is located at xtrt/tools/trex.
- Step 1: Build the TensorRT Engine
Modify the code in xtrt/tools/deploy/build/build.cu: To set setProfilingVerbosity in BuilderConfig, you only need to uncomment the following code:
// Config(Debug): NVTX Tracing
config->setProfilingVerbosity(nvinfer1::ProfilingVerbosity::kDETAILED);After modification, continue to use the code in xtrt/scripts/build.sh to rebuild the TensorRT engine files.
- Step 2: Use trtexec to Import the Engine File and Generate a JSON File
trtexec \
--loadEngine=./engine/yolo.plan \
--dumpRefit \
--dumpProfile \
--profilingVerbosity=detailed \
--dumpLayerInfo \
--exportLayerInfo=./engine/layer.json \
--exportProfile=./engine/profile.jsonYou need to modify the parameter following --loadEngine to the path of the actual engine file built in the first step, and --exportLayerInfo and --exportProfile to the paths where the JSON files will be saved.
- Step 3: Run the
xtrt/tools/trex/run_trex.pyScript to Generate an SVG Image, Representing the Visualization of the TensorRT Engine.
