Skip to content

Model tracing not working #67834

@axmav

Description

@axmav

🐛 Bug

I am trying to trace SAMPNet and get following error:

Traceback (most recent call last):
  File "trace.py", line 38, in <module>
    traced_cell = torch.jit.trace(torch_model, (x, s))
  File "/home/alex/anaconda3/envs/torch/lib/python3.8/site-packages/torch/jit/_trace.py", line 741, in trace
    return trace_module(
  File "/home/alex/anaconda3/envs/torch/lib/python3.8/site-packages/torch/jit/_trace.py", line 958, in trace_module
    module._c._create_method_from_trace(
RuntimeError: 0INTERNAL ASSERT FAILED at "/opt/conda/conda-bld/pytorch_1634272068694/work/torch/csrc/jit/ir/alias_analysis.cpp":584, please report a bug to PyTorch. We don't have an op for aten::fill_ but it isn't a special case.  Argument types: Tensor, bool, 

To Reproduce

Steps to reproduce the behavior:

  1. Clone SAMPNet
  2. Run code sample listed below
  3. Fix first error TypeError: adaptive_max_pool1d(): argument 'output_size' (position 2) must be tuple of ints, not Tensor by providing output_size directly as constant output_size=784 in samp_module.py line 135
  4. Run code sample again
from samp_net import EMDLoss, SAMPNet
import torch
from config import Config
import torch.nn.functional as F

# Load a pre-trained version of MobileNetV2
cfg = Config()
torch_model = SAMPNet(cfg,pretrained=False)
# Set the model in evaluation mode.
torch_model.eval()

x = torch.randn(2,3,224,224)
s = torch.randn(2,1,224,224)
weight, attribute, score = torch_model(x,s)
if weight is not None:
    print('weight', weight.shape, F.softmax(weight,dim=1))
if attribute is not None:
    print('attribute', attribute.shape, attribute)

print('score', score.shape, score)

traced_cell = torch.jit.trace(torch_model, (x, s))
print(traced_cell)

Expected behavior

As you can see the tensors x and s are actually able to go trough the model. I expected trace function to terminate without the error.

Environment

PyTorch version: 1.10.0
Is debug build: False
CUDA used to build PyTorch: 11.3
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.3 LTS (x86_64)
GCC version: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.31

Python version: 3.8.12 (default, Oct 12 2021, 13:49:34) [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.11.0-38-generic-x86_64-with-glibc2.17
Is CUDA available: True
CUDA runtime version: Could not collect
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3090
Nvidia driver version: 495.29.05
cuDNN version: Probably one of the following:
/usr/local/cuda-11.5/targets/x86_64-linux/lib/libcudnn.so.8.2.4
/usr/local/cuda-11.5/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8.2.4
/usr/local/cuda-11.5/targets/x86_64-linux/lib/libcudnn_adv_train.so.8.2.4
/usr/local/cuda-11.5/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8.2.4
/usr/local/cuda-11.5/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8.2.4
/usr/local/cuda-11.5/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8.2.4
/usr/local/cuda-11.5/targets/x86_64-linux/lib/libcudnn_ops_train.so.8.2.4
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] numpy==1.21.2
[pip3] torch==1.10.0
[pip3] torchaudio==0.10.0
[pip3] torchvision==0.11.1
[conda] blas 1.0 mkl
[conda] cudatoolkit 11.3.1 h2bc3f7f_2
[conda] ffmpeg 4.3 hf484d3e_0 pytorch
[conda] mkl 2021.4.0 h06a4308_640
[conda] mkl-service 2.4.0 py38h7f8727e_0
[conda] mkl_fft 1.3.1 py38hd3c417c_0
[conda] mkl_random 1.2.2 py38h51133e4_0
[conda] numpy 1.21.2 py38h20f2e39_0
[conda] numpy-base 1.21.2 py38h79a1101_0
[conda] pytorch 1.10.0 py3.8_cuda11.3_cudnn8.2.0_0 pytorch
[conda] pytorch-mutex 1.0 cuda pytorch
[conda] torchaudio 0.10.0 py38_cu113 pytorch
[conda] torchvision 0.11.1 py38_cu113 pytorch

Metadata

Metadata

Assignees

No one assigned

    Labels

    oncall: jitAdd this issue/PR to JIT oncall triage queue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions