-
Notifications
You must be signed in to change notification settings - Fork 370
Closed
Labels
Description
Compiling a Scripted model gives error at torch.nn.functional.interpolate(x, scale_factor=2.0, mode="nearest")
RuntimeError Traceback (most recent call last)
Cell In[14], line 8
2 scripted_model = torch.jit.script(model.to("cuda"), input_image_pytorch.to("cuda"))
4 # trt_encoder = torch_tensorrt.compile(torch.jit.script(encoder).to("cuda"),
5 # inputs= [input_image_pytorch.to("cuda")],
6 # enabled_precisions= { torch.float32} # Run with FP16
7 # )
----> 8 trt_model = torch_tensorrt.compile(scripted_model.to("cuda"),
9 inputs= [input_image_pytorch.to("cuda")], # [torch_tensorrt.Input([1,3,480,768])], # [input_image_pytorch.detach().to("cuda")],
10 enabled_precisions= { torch.float32} # Run with FP16
11 # trt_decoder = torch_tensorrt.compile(torch.jit.script(depth_decoder).to("cuda"),
12 # inputs= [features],
13 # enabled_precisions= { torch.float32} # Run with FP16
14 )
File ~/miniconda3/envs/inference/lib/python3.8/site-packages/torch_tensorrt/_compile.py:125, in compile(module, ir, inputs, enabled_precisions, **kwargs)
120 logging.log(
121 logging.Level.Info,
122 "Module was provided as a torch.nn.Module, trying to script the module with torch.jit.script. In the event of a failure please preconvert your module to TorchScript",
123 )
124 ts_mod = torch.jit.script(module)
--> 125 return torch_tensorrt.ts.compile(
126 ts_mod, inputs=inputs, enabled_precisions=enabled_precisions, **kwargs
127 )
128 elif target_ir == _IRType.fx:
129 if (
130 torch.float16 in enabled_precisions
131 or torch_tensorrt.dtype.half in enabled_precisions
132 ):
File ~/miniconda3/envs/inference/lib/python3.8/site-packages/torch_tensorrt/ts/_compiler.py:136, in compile(module, inputs, input_signature, device, disable_tf32, sparse_weights, enabled_precisions, refit, debug, capability, num_avg_timing_iters, workspace_size, dla_sram_size, dla_local_dram_size, dla_global_dram_size, calibrator, truncate_long_and_double, require_full_compilation, min_block_size, torch_executed_ops, torch_executed_modules)
110 raise ValueError(
111 f"require_full_compilation is enabled however the list of modules and ops to run in torch is not empty. Found: torch_executed_ops: {torch_executed_ops}, torch_executed_modules: {torch_executed_modules}"
112 )
114 spec = {
115 "inputs": inputs,
116 "input_signature": input_signature,
(...)
133 },
134 }
--> 136 compiled_cpp_mod = _C.compile_graph(module._c, _parse_compile_spec(spec))
137 compiled_module = torch.jit._recursive.wrap_cpp_module(compiled_cpp_mod)
138 return compiled_module
RuntimeError: The following operation failed in the TorchScript interpreter.
Traceback of TorchScript (most recent call last):
File "/home/user/miniconda3/envs/inference/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 21, in forward
x = self.quant(x)
x = self.encoder(x)
x = self.decoder(x)
~~~~~~~~~~~~ <--- HERE
x = self.dequant(x[0])
return x
File "/home/user/playground/networks/depth_decoder_for_conversion.py", line 116, in forward
# upsample and horizontal connections
x = torch.nn.functional.interpolate(x, scale_factor=2.0, mode="nearest")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
if self.use_skips and i > 0:
x_concat = input_features[i - 1]
File "/home/user/miniconda3/envs/inference/lib/python3.8/site-packages/torch/nn/functional.py", line 3922, in interpolate
return torch._C._nn.upsample_nearest1d(input, output_size, scale_factors)
if input.dim() == 4 and mode == "nearest":
return torch._C._nn.upsample_nearest2d(input, output_size, scale_factors)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
if input.dim() == 5 and mode == "nearest":
return torch._C._nn.upsample_nearest3d(input, output_size, scale_factors)
RuntimeError: Expected static_cast<int64_t>(scale_factors->size()) == spatial_dimensions to be true, but got false. (Could this error message be improved? If so, please report an enhancement request to PyTorch.)
To Reproduce
Steps to reproduce the behavior:
import torch
import torch_tensorrt
input_image_pytorch = torch.randn((1, 3, 480, 768), requires_grad=False).to("cuda").detach()
scripted_model = torch.jit.script(model.to("cuda"), input_image_pytorch.to("cuda"))
trt_model = torch_tensorrt.compile(scripted_model.to("cuda"),
inputs= [input_image_pytorch.to("cuda")],
enabled_precisions= { torch.float32}
)
Expected behavior
No error.
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: x86
- OS (e.g., Linux): Ubuntu 18.04 LTS
- How you installed PyTorch (
conda
,pip
,libtorch
, source): conda - Build command you used (if compiling from source):
- Are you using local sources or building from archives:
- Python version: 3.8
- CUDA version: 11.7
- GPU models and configuration:
- Any other relevant information:
Additional context
The error occurs at torch.nn.functional.interpolate(x, scale_factor=2.0, mode="nearest")
line in the network definition. JIT Scripting works.