TRT-ViT: TensorRT-oriented Vision Transformer

Xin Xia, Jiashi Li, Jie Wu, Xing Wang, Xuefeng Xiao, Min Zheng, Rui WangarXiv 2022

Abstract

We revisit the existing excellent Transformers from the perspective of practical application. Most of them are not even as efficient as the basic ResNets series and deviate from the realistic deployment scenario. It may be due to the current criterion to measure computation efficiency, such as FLOPs or parameters is one-sided, sub-optimal, and hardware-insensitive. Thus, this paper directly treats the TensorRT latency on the specific hardware as an efficiency metric, which provides more comprehensive feedback involving computational capacity, memory cost, and bandwidth. Based on a series of controlled experiments, this work derives four practical guidelines for TensorRT-oriented and deployment-friendly network design, e.g., early CNN and late Transformer at stage-level, early Transformer and late CNN at block-level. Accordingly, a family of TensortRT-oriented Transformers is presented, abbreviated as TRT-ViT. Extensive experiments demonstrate that TRT-ViT significantly outperforms existing ConvNets and vision Transformers with respect to the latency/accuracy trade-off across diverse visual tasks, e.g., image classification, object detection and semantic segmentation.

Introduction: The "FLOPs Trap"

While Vision Transformers (ViTs) have set new records in computer vision, they often struggle in real-world deployment. A major reason for this is the "FLOPs trap." Researchers traditionally use FLOPs (Floating Point Operations) or parameter counts as proxies for efficiency. However, these metrics are hardware-insensitive; they don't account for memory access costs, I/O throughput, or how well an operation parallelizes on a GPU.

Consequently, many "efficient" Transformers are actually slower than basic ResNets when deployed via high-performance engines like NVIDIA’s TensorRT. The authors of TRT-ViT aim to bridge this gap by treating TensorRT latency as the primary design constraint, asking: How can we build a model that performs like a Transformer but runs as fast as a ResNet?

Methods and Design Guidelines

The researchers conducted extensive controlled experiments on NVIDIA T4 GPUs to derive four practical "deployment-friendly" guidelines:

  1. Late-Stage Transformers: Transformers are most efficient at lower resolutions. Placing them in the later stages of a network maximizes the accuracy-to-latency trade-off.
  2. Shallow-then-Deep: A stage pattern that starts shallow and gets deeper in later stages improves capacity without a proportional hit to speed.
  3. Hybrid Blocks: Mixing Transformer and CNN "Bottleneck" components within a single block is more efficient than using pure Transformer blocks.
  4. Global-then-Local: It is more effective to extract global information first (via a Transformer) and then refine it locally (via a CNN) rather than the other way around.

Based on these, they introduced the TRT-ViT Block. This architecture decouples global and local feature extraction, allowing the hardware to handle each specialized operation more efficiently. The block uses a serial scheme: an input passes through a Transformer layer to capture global context, followed by a Bottleneck layer to refine local features.

The TRT-ViT architecture compared to standard ViT, highlighting the hybrid TRT-ViT block design.

Key Results

TRT-ViT consistently dominates the latency/accuracy frontier across image classification (ImageNet-1K), object detection (MS-COCO), and semantic segmentation (ADE20K).

Latency vs. Accuracy/Performance trade-offs for TRT-ViT against various state-of-the-art models on ImageNet, ADE20K, and MS-COCO.
  • ImageNet: At 82.7% top-1 accuracy, TRT-ViT is 2.7× faster than CSWin and 2.0× faster than Twins.
  • Object Detection (COCO): TRT-ViT achieves comparable performance to the Twins model but with a 2.8× increase in inference speed.
  • Semantic Segmentation (ADE20K): It outperforms ResNet by 6.6% mIoU at a similar latency and is 4.4× faster than Twins-SVT-L.
  • ResNet-like Speed: TRT-ViT-A achieves 81.2% accuracy (2.2% higher than ResNet-50) while actually being slightly faster (4.1ms vs 4.6ms).

Conclusion

TRT-ViT demonstrates that by moving away from hardware-insensitive metrics and focusing on actual TensorRT latency, it is possible to design hybrid architectures that offer the best of both worlds: the high accuracy of Transformers and the high efficiency of CNNs. While the current focus is on NVIDIA GPUs, the underlying principles of hardware-aware design provide a valuable framework for future neural architecture research across diverse deployment platforms.

Summary updated

BibTeX
@misc{xia2022trt,
  author = {Xin Xia and Jiashi Li and Jie Wu and Xing Wang and Xuefeng Xiao and Min Zheng and Rui Wang},
  title = {{TRT-ViT: TensorRT-oriented Vision Transformer}},
  year = {2022},
  eprint = {2205.09579},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2205.09579},
}
Figure