Skip to content

RuntimeError: Expected static_cast<int64_t>(scale_factors->size()) == spatial_dimensions to be true, but got false #2696

@zshn25

Description

@zshn25

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.)

Environment

TensorRT Version: 1.3.0
NVIDIA GPU: Tesla V100
NVIDIA Driver Version: 515.86.01
CUDA Version: 11.7
CUDNN Version: 8.5.0.96
Operating System: Ubuntu 18.04 LTS
Python Version (if applicable): 3.8
Tensorflow Version (if applicable):
PyTorch Version (if applicable): 1.13.1
Baremetal or Container (if so, version):

Relevant Files

Steps To Reproduce

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}
)

The error occurs at torch.nn.functional.interpolate(x, scale_factor=2.0, mode="nearest") line in the network definition. JIT Scripting works.


Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions