coremltools.converters.convert gives a RuntimeError during conversion to .mlmodel
🐞Describe the bug
We have followed the instructions in Model Scripting to convert our custom PyTorch model to .mlmodel. Please find our google colab notebook here
Stack Trace
[/usr/local/lib/python3.7/dist-packages/coremltools/converters/mil/frontend/torch/converter.py](https://localhost:8080/#) in _lower_graph_block(graph)
377 attr_name = getattr(node, node.kindOf("name"))("name")
378
--> 379 module = getattr(node_to_module_map[_input], attr_name)
380 node_to_module_map[_output] = module
381
KeyError: images.7 defined in (%images.7 : __torch__.torchvision.models.detection.image_list.ImageList, %targets.31 : Dict(str, Tensor)[]? = prim::TupleUnpack(%427)
)
To Reproduce
Run our google colab notebook to reproduce the issue.
Model conversion fails in the above Google Colab notebook.
System environment (please complete the following information):
PyTorch version: 1.11.0+cu113 Is debug build: False CUDA used to build PyTorch: 11.3 ROCM used to build PyTorch: N/A
OS: Ubuntu 18.04.5 LTS (x86_64) GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 Clang version: 6.0.0-1ubuntu2 (tags/RELEASE_600/final) CMake version: version 3.22.4 Libc version: glibc-2.26
Python version: 3.7.13 (default, Apr 24 2022, 01:04:09) [GCC 7.5.0] (64-bit runtime) Python platform: Linux-5.4.188+-x86_64-with-Ubuntu-18.04-bionic Is CUDA available: True CUDA runtime version: 11.1.105 GPU models and configuration: GPU 0: Tesla T4 Nvidia driver version: 460.32.03 cuDNN version: Probably one of the following: /usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.5 /usr/lib/x86_64-linux-gnu/libcudnn.so.8.0.5 /usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.0.5 /usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.0.5 /usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.0.5 /usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.0.5 /usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.0.5 /usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.0.5 HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True
Versions of relevant libraries: [pip3] numpy==1.21.6 [pip3] torch==1.11.0+cu113 [pip3] torchaudio==0.11.0+cu113 [pip3] torchsummary==1.5.1 [pip3] torchtext==0.12.0 [pip3] torchvision==0.12.0+cu113 [conda] Could not collect
@sheshap - I can't even view your notebook. It is not public. Also sharing a notebook to reproduce the problem is not very helpful. Can you please work to create a minimal code example that reproduces the error?
@TobyRoseman I apologize. I have edited it now. Please access now. The notebook has the code to reproduce the issue.
It looks like you are using a torch script model. Our support for torch script is experimental. Can you try tracing your model, then try converting the traced model?
We have an ongoing issue with torch trace. We were suggested to use the torch script here. Can you please check for the torch script?