Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConvTranspose with output_shape has completely different output for CPU only vs ALL #2281

Closed
skottmckay opened this issue Jul 19, 2024 · 1 comment
Labels
bug Unexpected behaviour that should be corrected (type)

Comments

@skottmckay
Copy link

🐞Describing the bug

  • Make sure to only create an issue here for bugs in the coremltools Python package. If this is a bug with the Core ML Framework or Xcode, please submit your bug here: https://developer.apple.com/bug-reporting/
  • Provide a clear and consise description of the bug.
    Output from ConvTranspose when output_shape is specified is significantly different depending on which devices are enabled.

To Reproduce

  • Please add a minimal code example that can reproduce the error when running it.
import numpy as np
import coremltools as ct
from coremltools.converters.mil import Builder as mb

target = ct.target.iOS15

x_shape = (1, 3, 4, 4)
w_shape = (3, 3, 3, 3)

@mb.program(input_specs=[mb.TensorSpec(shape=x_shape)],
            opset_version=target,
            )
def prog(x):
    weight = mb.const(name="weight", val=np.ones(w_shape, dtype=np.float32))
    output_shape = mb.const(name="output_shape", val=np.array([1, 3, 4, 4]))
    strides = mb.const(name="strides", val=np.ones((2), dtype=np.int32))
    dilations = mb.const(name="dilations", val=np.ones((2), dtype=np.int32))
    z = mb.conv_transpose(x=x, weight=weight, strides=strides, dilations=dilations, output_shape=output_shape)
    return z

m = ct.convert(prog, minimum_deployment_target=target, compute_precision=ct.precision.FLOAT32)

m.save("ConvTranspose.mlpackage")

m_cpu = ct.models.MLModel('ConvTranspose.mlpackage', compute_units=ct.ComputeUnit.CPU_ONLY)
m_all = ct.models.MLModel('ConvTranspose.mlpackage', compute_units=ct.ComputeUnit.ALL)

x = np.ones(x_shape, dtype=np.float32)
print(m_cpu.predict({'x': x}))
print(m_all.predict({'x': x}))

Output appears to indicate the CPU only version is offset by a row.

The non-CPU output is what I expected (based on translating an ONNX ConvTranspose to the CoreML version, but I would have expected that the CPU-only version is the reference and should be considered to be correct.

{'conv_transpose_0': array([[[[ 3.,  6.,  9.,  9.],
         [ 6., 12., 18., 18.],
         [ 9., 18., 27., 27.],
         [ 9., 18., 27., 27.]],

        [[ 3.,  6.,  9.,  9.],
         [ 6., 12., 18., 18.],
         [ 9., 18., 27., 27.],
         [ 9., 18., 27., 27.]],

        [[ 3.,  6.,  9.,  9.],
         [ 6., 12., 18., 18.],
         [ 9., 18., 27., 27.],
         [ 9., 18., 27., 27.]]]], dtype=float32)}
{'conv_transpose_0': array([[[[12., 18., 18., 12.],
         [18., 27., 27., 18.],
         [18., 27., 27., 18.],
         [12., 18., 18., 12.]],

        [[12., 18., 18., 12.],
         [18., 27., 27., 18.],
         [18., 27., 27., 18.],
         [12., 18., 18., 12.]],

        [[12., 18., 18., 12.],
         [18., 27., 27., 18.],
         [18., 27., 27., 18.],
         [12., 18., 18., 12.]]]], dtype=float32)}

System environment (please complete the following information):

  • coremltools version: 7.1

  • OS (e.g. MacOS version or Linux type): macOS
    Model Name: Mac mini
    Model Identifier: Macmini9,1
    Model Number: MGNT3LL/A
    Chip: Apple M1

    ProductName: macOS
    ProductVersion: 14.5
    BuildVersion: 23F79

@skottmckay skottmckay added the bug Unexpected behaviour that should be corrected (type) label Jul 19, 2024
@TobyRoseman
Copy link
Collaborator

I cannot reproduce this issue. It works fine for me on macOS 14.3.

This is going to be an issue with the Core ML Frame work, not the coremltools Python package. Please file a bug report using The Feedback Assitant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected behaviour that should be corrected (type)
Projects
None yet
Development

No branches or pull requests

2 participants