pytorch / TensorRT

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

🐛 [Bug] Encountered bug when using Torch-TensorRT's example tutorial #3256

Closed deo-abhijit closed 1 month ago

deo-abhijit commented 1 month ago

I was trying out this tutorial but got error while running.

https://pytorch.org/TensorRT/tutorials/_rendered_examples/dynamo/dynamo_compile_transformers_example.html#

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[5], [line 1](vscode-notebook-cell:?execution_count=5&line=1)
----> [1](vscode-notebook-cell:?execution_count=5&line=1) optimized_model = torch_tensorrt.dynamo.compile(
      [2](vscode-notebook-cell:?execution_count=5&line=2)     model,
      [3](vscode-notebook-cell:?execution_count=5&line=3)     inputs,
      [4](vscode-notebook-cell:?execution_count=5&line=4)     enabled_precisions=enabled_precisions,
      [5](vscode-notebook-cell:?execution_count=5&line=5)     debug=debug,
      [6](vscode-notebook-cell:?execution_count=5&line=6)     workspace_size=workspace_size,
      [7](vscode-notebook-cell:?execution_count=5&line=7)     min_block_size=min_block_size,
      [8](vscode-notebook-cell:?execution_count=5&line=8)     torch_executed_ops=torch_executed_ops,
      [9](vscode-notebook-cell:?execution_count=5&line=9) )

File ~/miniconda3/envs/tensorrt/lib/python3.10/site-packages/torch_tensorrt/dynamo/_compiler.py:181, in compile(exported_program, inputs, device, disable_tf32, assume_dynamic_shape_support, sparse_weights, enabled_precisions, engine_capability, refit, debug, num_avg_timing_iters, workspace_size, dla_sram_size, dla_local_dram_size, dla_global_dram_size, truncate_double, require_full_compilation, min_block_size, torch_executed_ops, torch_executed_modules, pass_through_build_failures, max_aux_streams, version_compatible, optimization_level, use_python_runtime, use_fast_partitioner, enable_experimental_decompositions, dryrun, hardware_compatible, timing_cache_path, **kwargs)
    [178](https://file+.vscode-resource.vscode-cdn.net/home/mzcar/ResNetTensorRT/~/miniconda3/envs/tensorrt/lib/python3.10/site-packages/torch_tensorrt/dynamo/_compiler.py:178) enabled_precisions = {dtype._from(p) for p in enabled_precisions}
    [180](https://file+.vscode-resource.vscode-cdn.net/home/mzcar/ResNetTensorRT/~/miniconda3/envs/tensorrt/lib/python3.10/site-packages/torch_tensorrt/dynamo/_compiler.py:180) if not isinstance(exported_program, ExportedProgram):
--> [181](https://file+.vscode-resource.vscode-cdn.net/home/mzcar/ResNetTensorRT/~/miniconda3/envs/tensorrt/lib/python3.10/site-packages/torch_tensorrt/dynamo/_compiler.py:181)     raise AssertionError(
    [182](https://file+.vscode-resource.vscode-cdn.net/home/mzcar/ResNetTensorRT/~/miniconda3/envs/tensorrt/lib/python3.10/site-packages/torch_tensorrt/dynamo/_compiler.py:182)         f"Input graph should be an ExportedProgram but got type {type(exported_program)}"
    [183](https://file+.vscode-resource.vscode-cdn.net/home/mzcar/ResNetTensorRT/~/miniconda3/envs/tensorrt/lib/python3.10/site-packages/torch_tensorrt/dynamo/_compiler.py:183)     )
    [184](https://file+.vscode-resource.vscode-cdn.net/home/mzcar/ResNetTensorRT/~/miniconda3/envs/tensorrt/lib/python3.10/site-packages/torch_tensorrt/dynamo/_compiler.py:184) exported_program = pre_export_lowering(exported_program, torch_inputs)
    [185](https://file+.vscode-resource.vscode-cdn.net/home/mzcar/ResNetTensorRT/~/miniconda3/envs/tensorrt/lib/python3.10/site-packages/torch_tensorrt/dynamo/_compiler.py:185) exported_program = exported_program.run_decompositions(
    [186](https://file+.vscode-resource.vscode-cdn.net/home/mzcar/ResNetTensorRT/~/miniconda3/envs/tensorrt/lib/python3.10/site-packages/torch_tensorrt/dynamo/_compiler.py:186)     get_decompositions(enable_experimental_decompositions)
    [187](https://file+.vscode-resource.vscode-cdn.net/home/mzcar/ResNetTensorRT/~/miniconda3/envs/tensorrt/lib/python3.10/site-packages/torch_tensorrt/dynamo/_compiler.py:187) )

AssertionError: Input graph should be an ExportedProgram but got type <class 'transformers.models.bert.modeling_bert.BertModel'>

Maybe api got changed and the tutorial needs an update.

deo-abhijit commented 1 month ago

my bad! This is older version of pytorch and torch-tensorrt