Skip to content

🐛 [Bug] Can't compile ViT model from torchvision #1682

@adamwawrzynski

Description

@adamwawrzynski

Bug Description

I tried to use TensorRT to optimize the inference of the Vision Transformer model from torchvision but I've got RuntimeError at torch_tensorrt.compile function call.

To Reproduce

Steps to reproduce the behavior:

  1. git clone https://github.com/adamwawrzynski/model_optimization
  2. cd model_optimization
  3. poetry install
  4. download dataset from https://www.kaggle.com/datasets/ifigotin/imagenetmini-1000 and unpack it in the data directory
  5. poetry run python3 benchmark.py --type tensorrt --batch_size 1 --n_runs 5 --model_name vit
$ poetry run python3 benchmark.py --type tensorrt --batch_size 1 --n_runs 5 --model_name vit
Traceback (most recent call last):
  File "/home/user/praca/model_optimization/benchmark.py", line 575, in <module>
    main()
  File "/home/user/praca/model_optimization/benchmark.py", line 537, in main
    benchmark_tensorrt(
  File "/home/user/praca/model_optimization/benchmark.py", line 270, in benchmark_tensorrt
    trt_model = torch_tensorrt.compile(
  File "/home/user/praca/model_optimization/.venv/lib/python3.9/site-packages/torch_tensorrt/_compile.py", line 125, in compile
    return torch_tensorrt.ts.compile(
  File "/home/user/praca/model_optimization/.venv/lib/python3.9/site-packages/torch_tensorrt/ts/_compiler.py", line 136, in compile
    compiled_cpp_mod = _C.compile_graph(module._c, _parse_compile_spec(spec))
RuntimeError: [Error thrown at core/partitioning/shape_analysis.cpp:196] Expected to find type str for value why_not_fast_path.264 but get nothing.

Expected behavior

The model should be converted into TenorRT, inference should be completed without errors and it should take less time than standard inference on GPU.

Environment

Build information about Torch-TensorRT can be found by turning on debug messages

  • Torch-TensorRT Version (e.g. 1.0.0): 1.3.0
  • PyTorch Version (e.g. 1.0): 1.13.1
  • CPU Architecture: AMD® Ryzen 9 5950x 16-core processor × 32
  • OS (e.g., Linux): Ubuntu 22.04.2 LTS
  • How you installed PyTorch (conda, pip, libtorch, source): poetry
  • Build command you used (if compiling from source): -
  • Are you using local sources or building from archives: No
  • Python version: 3.9.16
  • CUDA version: 11.6
  • GPU models and configuration: GeForce RTX 3080 Ti
  • Any other relevant information: You can follow instructions in my repository (https://github.com/adamwawrzynski/model_optimization)

Additional context

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions