apple / coremltools

Core ML tools contain supporting tools for Core ML model conversion, editing, and validation.
https://coremltools.readme.io
BSD 3-Clause "New" or "Revised" License
4.38k stars 631 forks source link

when converting scripted model to coremltools, Unknown type bool encountered in graph lowering. This type is not supported in ONNX export. #1085

Open matthewchung74 opened 3 years ago

matthewchung74 commented 3 years ago

🐛 Bug

getting this error Unknown type bool encountered in graph lowering. This type is not supported in ONNX export.

To Reproduce

Steps to reproduce the behavior:

  1. run this colab https://colab.research.google.com/drive/13tF8p9x4FCPG0KEC_PBEEMianWKo8mfG?usp=sharing

which basically grabs a visual transformer from time, and tries to convert to torchscript to coreml

Expected behavior

should not get the error

Environment

colab

TobyRoseman commented 3 years ago

I can reproduce this issue using the code from the colab notebook.

Here is simplified code to reproduce:

import coremltools
import timm
import torch

model = timm.create_model('vit_base_patch16_224', pretrained=True)
scripted_model = torch.jit.script(model)
mlmodel = coremltools.converters.convert(
  scripted_model,
  inputs=[coremltools.TensorType(shape=(1, 3, 224, 224))],
)

This error is actually being generated by PyTorch. It looks like this happens when we try to make the graph self contained. You can reproduce this issue without coremltools using the scripted_model from the previous code:

torch._C._jit_pass_lower_graph(scripted_model.forward.graph, scripted_model._c)
matthewchung74 commented 3 years ago

thank you. does it make sense to create a bug in the pytorch repo and reference this one?

TobyRoseman commented 3 years ago

thank you. does it make sense to create a bug in the pytorch repo and reference this one?

I think that would make sense. Yes, when you create the issue please reference this one. Also please share that issue here.

matthewchung74 commented 3 years ago

reference https://github.com/pytorch/pytorch/issues/52889

PareshKamble commented 3 years ago

Hi @yhatpub Did you find a solution for this error yet?

matthewchung74 commented 3 years ago

unfortunately, i never found a solution.

On Wed, Oct 13, 2021 at 3:31 AM Paresh Kamble @.***> wrote:

Hi @yhatpub https://github.com/yhatpub Did you find a solution for this error yet?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/apple/coremltools/issues/1085#issuecomment-942159376, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM3RRARWOTFHKP5DLQLHM3UGVNYRANCNFSM4XLNMNPA .

-- Regards, Matt

PareshKamble commented 2 years ago

Hi @yhatpub We are facing issue while converting the scripted model (our model has control statements). We get the error RuntimeError: Unknown type bool encountered in graph lowering. This type is not supported in ONNX export. Traced model gets converted without any error but its size inflates 12x due to a loop involved in forward function of our seq-to-seq pytorch model available here. Code can be found in the notebook here. Any suggestuion would be highly appreciated!

matthewchung74 commented 2 years ago

@PareshKamble I've never converted a seq to seq model to coreml or to torchscript, so I'm afraid I have suggestions.