apple / apple/coremltools

coremltools.converters.convert gives a RuntimeError during conversion to .mlmodel

Open
#1,496 4 comments 0 reactions 0 assignees View on GitHub
bug PyTorch (not traced)
Dominant language
Python
Stars
5.4k
Forks
850
Avg merge
4d 5h
Merged PRs (30d)
10

Description

## 🐞Describe the bug
We have followed the instructions in [Model Scripting](https://coremltools.readme.io/docs/model-scripting) to convert our custom PyTorch model to .mlmodel. Please find our google colab notebook [here](https://colab.research.google.com/drive/1Ha_-zvu0diDdlPnYr8RiEYdD80KBkO9k?usp=sharing)

## 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](https://colab.research.google.com/drive/1Ha_-zvu0diDdlPnYr8RiEYdD80KBkO9k?usp=sharing) 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

Contributor guide

Open the contributing guide

Research direction

Start by running the linked Google Colab notebook with the reported PyTorch 1.11.0 and torchvision 0.12.0 environment. Then inspect coremltools/converters/mil/frontend/torch/converter.py around _lower_graph_block, where the KeyError for images.7 occurs. Done means the notebook converts the custom model to an .mlmodel without this RuntimeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
devtools, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.