#4490·TensorRT

将 LSTM 模型转换为 TensorRT 后,在 RTX 4090 上的速度要慢于 PyTorch

作者: jds250创建于 2025年6月16日更新于 2026年9月28日
标签Module:Performancetriagedinternal-bug-tracked
  1. Export to ONNX:
python
dummy = torch.randn(32, 60, 293)
torch.onnx.export(
    lstm, dummy, "pyannet_lstm.onnx",
    opset_version=14,
    input_names=["input"],
    output_names=["output", "h_out", "c_out"],
    dynamic_axes={
        "input": {0: "batch", 1: "time"},
        "output": {0: "batch", 1: "time"},
        "h_out": {1: "batch"},
        "c_out": {1: "batch"}
    }
)
  1. Build TensorRT engine:
bash
trtexec \
  --onnx=pyannet_lstm.onnx \
  --minShapes=input:1x60x293 \
  --optShapes=input:32x60x293 \
  --maxShapes=input:32x60x293 \
  --saveEngine=lstm.engine

Performance Benchmark

内容来源: NVIDIA/TensorRT