pytorch / TensorRT

PyTorch/TorchScript/FX compiler for NVIDIA GPUs using TensorRT
https://pytorch.org/TensorRT
BSD 3-Clause "New" or "Revised" License
2.6k stars 351 forks source link

SyntaxError: invalid syntax #1699

Closed pseudotensor closed 1 year ago

pseudotensor commented 1 year ago

due to a bug in torch_tensorrt: https://github.com/pytorch/TensorRT/issues/1465#issuecomment-1347630727

One requires 1.3.0, but kaggle has only support for python3.7. This leads to a syntax error. To reproduce that problem on kaggle, one can locally do:

conda create -n kagpy37 -y
conda activate kagpy37
conda install python=3.7
pip install geffnet timm torch==1.13.1 torchvision==0.14.1 omegaconf torch-tensorrt==1.3.0 nvidia-tensorrt --find-links https://github.com/pytorch/TensorRT/releases/expanded_assets/v1.3.0 --extra-index-url https://download.pytorch.org/whl/cu117

leads to:

Python 3.7.16 (default, Jan 17 2023, 22:20:44) 
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch_tensorrt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jon/miniconda3/envs/kagpy37b/lib/python3.7/site-packages/torch_tensorrt/__init__.py", line 85, in <module>
    from torch_tensorrt._compile import *
  File "/home/jon/miniconda3/envs/kagpy37b/lib/python3.7/site-packages/torch_tensorrt/_compile.py", line 9, in <module>
    import torch_tensorrt.fx
  File "/home/jon/miniconda3/envs/kagpy37b/lib/python3.7/site-packages/torch_tensorrt/fx/__init__.py", line 1, in <module>
    from .converters import *  # noqa: F403 F401
  File "/home/jon/miniconda3/envs/kagpy37b/lib/python3.7/site-packages/torch_tensorrt/fx/converters/__init__.py", line 5, in <module>
    from .activation import *  # noqa: F401 F403
  File "/home/jon/miniconda3/envs/kagpy37b/lib/python3.7/site-packages/torch_tensorrt/fx/converters/activation.py", line 9, in <module>
    from .converter_utils import mark_as_int8_layer
  File "/home/jon/miniconda3/envs/kagpy37b/lib/python3.7/site-packages/torch_tensorrt/fx/converters/converter_utils.py", line 22, in <module>
    from ..utils import torch_dtype_from_trt
  File "/home/jon/miniconda3/envs/kagpy37b/lib/python3.7/site-packages/torch_tensorrt/fx/utils.py", line 9, in <module>
    from torch_tensorrt.fx.passes.lower_basic_pass import (
  File "/home/jon/miniconda3/envs/kagpy37b/lib/python3.7/site-packages/torch_tensorrt/fx/passes/lower_basic_pass.py", line 17, in <module>
    from .pass_utils import log_before_after, validate_inference
  File "<fstring>", line 1
    (RELAX_ACCURACY_FAILURE=)
                           ^
SyntaxError: invalid syntax

That is, even though pip doesn't complain about any compatibility issues, still torch_tensorrt built for python3.7 is incompatible with it.

pseudotensor commented 1 year ago

A work-around is to go back to older torch versions but to fix the batch size:

pip install geffnet timm torch==1.12.1 torchvision==0.13.1 omegaconf torch-tensorrt==1.2.0 nvidia-tensorrt --find-links https://github.com/pytorch/TensorRT/releases/expanded_assets/v1.2.0 --extra-index-url https://download.pytorch.org/whl/cu113
github-actions[bot] commented 1 year ago

This issue has not seen activity for 90 days, Remove stale label or comment or this will be closed in 10 days