Error when calling torch.jit.trace

Hi all,
I am trying to import a pytorch model in tvm. I run the following code to get the torchscripted model from tracing.
import tvm
import torch
import torchvision

model_name = "resnet18"
model = getattr(torchvision.models, model_name)(pretrained=True)
model = model.eval()

input_shape = [1, 3, 224, 224]
input_data = torch.randn(input_shape)
scripted_model = torch.jit.trace(model, input_data).eval()

But I get this error:

libc++abi: terminating with uncaught exception of type pybind11::stop_iteration:
Fatal Python error: Aborted

In torch/jit/_trace.py", line 417 in graph_diagnostic_info.
I found out that the error occurs when the torch tries to iterate through a Dict. Any idea on how to solve this?

I build torch with libstdcpp and tvm with libcpp. I suspected that this might be the cause of this.
Since I cannot build tvm with libstdcpp, I tried building torch with libcpp but I still get the same error. When I get dir on the Dict variable which is casusing the error, I see pybind11_module_local_v4_clang_libstdcpp_cxxabi1002. So, it seems that pybind11 is still using libstdcpp. How to build pybind11 submodule with libcpp?

Thank you,
Fateme

@FatemeH Did you try importing torch before importing tvm? That worked for me when I had torch built with libstdcpp and tvm built with libcpp

Thanks for your response. Yes, that’s correct. if I reverse the order of imports it works. But I sometimes I need to call my code through tvm testing module and I get the same failure. So, I need to resolve the issue.