Limitations
Shuffle-op can not be transformed to no-op for perf improvement in some cases. For the NCHW32 format, TensorRT takes the third-to-last dimension as the channel dimension. When a Shuffle-op is added like [N, ‘C’, H, 1] -> [‘N’, C, H], the channel dimension changes to N, then this op can not be transformed to no-op.When running a FP32 model in FP16 or BF16 WeaklyTyped mode on Blackwell GPUs, if the FP32 weights values are used by FP16 kernels, TensorRT will not clip the weights to [fp16_lowest, fp16_max] or [bf16_lowest, bf16_max] to avoid overflow like inf values. If you see inf graph outputs on Blackwell GPUs only, check if any FP32 weights cannot be represented by either FP16 or BF16, and update the weights.There are no optimized FP8 Convolutions for Group Convolutions and Depthwise Convolutions. Therefore, INT8 is still recommended for ConvNets containing these convolution ops.The FP8 Convolutions do not support kernel sizes larger than 32, such as 7x7 convolutions, and FP16 or FP32 fallback kernels will be used with suboptimal performance. Therefore, do not add FP8 Q/DQ ops before Convolutions with large kernel sizes for better performance.On QNX, networks that are segmented into a large number of DLA loadables may fail during inference.The DLA compiler can remove identity transposes but cannot fuse multiple adjacent transpose layers into a single transpose layer (likewise for reshaping). For example, given a TensorRT IShuffleLayer consisting of two non-trivial transposes and an identity reshape in between, the shuffle layer is translated into two consecutive DLA transpose layers unless the user merges the transposes manually in the model definition in advance.nvinfer1::UnaryOperation::kROUND or nvinfer1::UnaryOperation::kSIGN operations of IUnaryLayer are not supported in the implicit batch mode.For networks containing normalization layers, particularly if deploying with mixed precision, target the latest ONNX opset containing the corresponding function ops, such as opset 17 for LayerNormalization or opset 18 GroupNormalization. Numerical accuracy using function ops is superior to the corresponding implementation with primitive ops for normalization layers.When two convolutions with INT8-QDQ and residual add share the same weight, constant weight fusion will not occur. Make a copy of the shared weight for better performance.When building the nonZeroPlugin sample on Windows, you may need to modify the CUDA version specified in the BuildCustomizations paths in the vcxproj file to match the installed version of CUDA.The weights used in INT4 weights-only quantization (WoQ) cannot be refitted.The high-precision weights used in FP4 double quantization are not refittable.Python samples do not support Python 3.13. Only the 3.13 Python bindings are currently supported.Python samples that require PyCUDA do not support CUDA 13.x.Loops with scan outputs (ILoopOutputLayer with LoopOutput property being either LoopOutput::kCONCATENATE or LoopOutput::kREVERSE) must have the number of iterations set, that is, must have an ITripLimitLayer with TripLimit::kCOUNT. This requirement has always been present, but is now explicitly enforced instead of quietly having undefined behavior.
TensorRT 限制條件深度解析(含技術細節與解決方案)
1. 數據格式與算子優化限制
-
Shuffle-op 維度沖突
- 場景:在 NCHW32 格式下,TensorRT 將第三維視為通道維(C)。若執行
[N, C, H, 1] → [N, C, H]
的 Shuffle 操作,通道維會從 C 變為 N,導致無法優化為無操作(no-op)。 - 影響:增加不必要的計算開銷,尤其在動態形狀場景中。
- 解決:手動調整維度順序或使用
reshape
替代shuffle
,確保通道維保持為 C。
- 場景:在 NCHW32 格式下,TensorRT 將第三維視為通道維(C)。若執行
-
大核卷積 FP8 降級
- 場景:FP8 卷積不支持核尺寸 >32(如 7x7 卷積),自動回退到 FP16/FP32,性能下降。
- 影響:大核卷積(如 ResNet 初始層)推理延遲增加。
- 解決:拆分大核為小核(如 7x7→3x3+3x3+1x1),或改用 INT8 量化。
2. 精度與量化限制
-
FP32 權重在 FP16/BF16 模式下的溢出風險
- 場景:Blackwell GPU 上,FP32 權重被 FP16 內核使用時,TensorRT 不會自動裁剪到 FP16/BF16 范圍(如 FP16 最小值為
-65504
)。 - 影響:若權重超出范圍,可能產生
inf
輸出。 - 解決:檢查權重分布,手動裁剪或使用
torch.clamp
預處理;優先使用 FP16/BF16 原生訓練。
- 場景:Blackwell GPU 上,FP32 權重被 FP16 內核使用時,TensorRT 不會自動裁剪到 FP16/BF16 范圍(如 FP16 最小值為
-
INT4/FP4 權重不可重訓練(Refit)
- 場景:INT4 權重量化(WoQ)和 FP4 雙量化后,權重無法通過 Refit API 更新。
- 影響:模型微調或增量訓練受限。
- 解決:采用可重訓練的量化方案(如 QAT),或保留原始權重用于 Refit。
3. 硬件與系統兼容性
-
QNX 系統 DLA 負載失敗
- 場景:分割成大量 DLA 加載單元的網絡在 QNX 上推理失敗。
- 影響:多 DLA 負載場景下穩定性下降。
- 解決:減少 DLA 負載單元數量,或優化網絡分割策略。
-
Windows 構建兼容性
- 場景:構建
nonZeroPlugin
示例時,需匹配 CUDA 版本(如修改vcxproj
文件中的CUDA 12.x
路徑)。 - 影響:編譯失敗或運行時錯誤。
- 解決:確保 CUDA 工具包版本與項目配置一致。
- 場景:構建
4. 算子融合與執行模式
-
DLA 轉置層融合限制
- 場景:DLA 編譯器無法融合多個相鄰轉置層(如
Transpose1 + Identity Reshape + Transpose2
會被拆分為兩個 DLA 轉置層)。 - 影響:增加 DLA 執行單元調用次數,延遲升高。
- 解決:在模型定義中手動合并轉置操作,或使用 TensorRT 的
reshape
算子優化。
- 場景:DLA 編譯器無法融合多個相鄰轉置層(如
-
隱式批處理模式下的算子支持
- 場景:隱式批處理模式下,
kROUND
/kSIGN
一元操作(如IUnaryLayer
)不受支持。 - 影響:模型包含這些算子時無法部署。
- 解決:改用顯式批處理模式,或替換為支持的算子(如
kCEIL
/kFloor
)。
- 場景:隱式批處理模式下,
5. 循環與控制流限制
- 循環迭代次數強制設定
- 場景:帶有掃描輸出(如
kCONCATENATE
/kREVERSE
)的循環必須設置迭代次數(ITripLimitLayer
withTripLimit::kCOUNT
)。 - 影響:未設置時拋出明確錯誤(此前為未定義行為)。
- 解決:在循環層中顯式添加迭代計數層,確保符合規范。
- 場景:帶有掃描輸出(如
6. 歸一化層精度優化
- 混合精度下的歸一化層選擇
- 場景:使用混合精度時,推薦采用最新 ONNX opset 的歸一化函數操作(如 opset 17 的
LayerNormalization
)。 - 影響:函數操作的數值精度優于原始算子組合(如
ReduceMean
+Div
)。 - 解決:升級 ONNX 導出代碼,使用高版本 opset 的歸一化層。
- 場景:使用混合精度時,推薦采用最新 ONNX opset 的歸一化函數操作(如 opset 17 的
總結與建議
- 性能優化路徑:優先使用 TensorRT 官方推薦的算子融合、量化方案和硬件加速特性(如 Tensor Core)。
- 調試策略:結合
trtexec
工具和 TensorRT Profiler 分析性能瓶頸,重點關注未優化的算子或精度降級環節。 - 版本兼容性:關注 CUDA、TensorRT 和驅動版本的匹配關系,避免因版本沖突導致功能缺失或性能下降。
通過理解這些限制條件,開發者可提前規避潛在問題,優化模型部署效率與穩定性。