Coremltools: Conversion fails with PyTorch v1.7.0

Created on 27 Oct 2020  路  3Comments  路  Source: apple/coremltools

coremltools unified conversion API fails with traced model from PyTorch v1.7.0. It was fine with PyTorch v1.6.0.

Trace

Traceback (most recent call last):
  File "test_interpolate.py", line 18, in <module>
    mlmodel = ct.convert(
  File ".../coremltools/converters/_converters_entry.py", line 176, in convert
    mlmodel = mil_convert(
  File ".../coremltools/converters/mil/converter.py", line 128, in mil_convert
    proto = mil_convert_to_proto(model, convert_from, convert_to,
  File ".../coremltools/converters/mil/converter.py", line 171, in mil_convert_to_proto
    prog = frontend_converter(model, **kwargs)
  File ".../coremltools/converters/mil/converter.py", line 85, in __call__
    return load(*args, **kwargs)
  File ".../coremltools/converters/mil/frontend/torch/load.py", line 85, in load
    raise e
  File ".../coremltools/converters/mil/frontend/torch/load.py", line 75, in load
    prog = converter.convert()
  File ".../coremltools/converters/mil/frontend/torch/converter.py", line 224, in convert
    convert_nodes(self.context, self.graph)
  File ".../coremltools/converters/mil/frontend/torch/ops.py", line 56, in convert_nodes
    _add_op(context, node)
  File ".../coremltools/converters/mil/frontend/torch/ops.py", line 417, in _convolution
    raise ValueError(
ValueError: unexpected number of inputs for node 11 (_convolution): 13

To Reproduce

  • If a python script can reproduce the error, please paste the code snippet
import torch.nn.functional as F
import torch.nn as nn
import torch
import coremltools as ct

class Model(nn.Module):
    def __init__(self):
        super(Model, self).__init__()
        self.conv = nn.Conv2d(3, 3, 3, 1, 1)

    def forward(self, x):
        return self.conv(x)

input_batch = torch.randn(1,3,10,10)
model = Model()
trace = torch.jit.trace(model, input_batch)

mlmodel = ct.convert(
    trace,
    inputs=[ct.TensorType(name="input", shape=input_batch.shape)],
)

System environment (please complete the following information):

coremltools 4.0
PyTorch v1.7.0

bug pytorch

Most helpful comment

I had the same issue, a bit of digging revealed that the coremltools documentation states:

Currently, the latest supported version of PyTorch is 1.5.1

https://coremltools.readme.io/docs/pytorch-conversion

All 3 comments

I had the same issue. I fix it by downgrading to PyTorch v1.6.0

I had the same issue, a bit of digging revealed that the coremltools documentation states:

Currently, the latest supported version of PyTorch is 1.5.1

https://coremltools.readme.io/docs/pytorch-conversion

I have solved it here https://github.com/apple/coremltools/pull/1020. Also there are couple other fix for 1.7.0.

Was this page helpful?
0 / 5 - 0 ratings