ConvTranspose with output_shape has completely different output for CPU only vs ALL #2281
Closed
Description
🐞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 M1ProductName: macOS
ProductVersion: 14.5
BuildVersion: 23F79