You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Traceback (most recent call last):
File "/dev/opensource/detectron2/export_test.py", line 20, in <module>
result = ct.convert(model_traced, inputs=[ct.TensorType(name="x", shape=x.shape)])
File "/dev/opensource/coremltools/coremltools/converters/_converters_entry.py", line 444, in convert
mlmodel = mil_convert(
File "/dev/opensource/coremltools/coremltools/converters/mil/converter.py", line 187, in mil_convert
return _mil_convert(model, convert_from, convert_to, ConverterRegistry, MLModel, compute_units, **kwargs)
File "/dev/opensource/coremltools/coremltools/converters/mil/converter.py", line 211, in _mil_convert
proto, mil_program = mil_convert_to_proto(
File "/dev/opensource/coremltools/coremltools/converters/mil/converter.py", line 281, in mil_convert_to_proto
prog = frontend_converter(model, **kwargs)
File "/dev/opensource/coremltools/coremltools/converters/mil/converter.py", line 109, in __call__
return load(*args, **kwargs)
File "/dev/opensource/coremltools/coremltools/converters/mil/frontend/torch/load.py", line 57, in load
return _perform_torch_convert(converter, debug)
File "/dev/opensource/coremltools/coremltools/converters/mil/frontend/torch/load.py", line 96, in _perform_torch_convert
prog = converter.convert()
File "/dev/opensource/coremltools/coremltools/converters/mil/frontend/torch/converter.py", line 281, in convert
convert_nodes(self.context, self.graph)
File "/dev/opensource/coremltools/coremltools/converters/mil/frontend/torch/ops.py", line 89, in convert_nodes
add_op(context, node)
File "/dev/opensource/coremltools/coremltools/converters/mil/frontend/torch/ops.py", line 1871, in stack
res = mb.stack(values=values, axis=axis, name=node.name)
File "/dev/opensource/coremltools/coremltools/converters/mil/mil/ops/registry.py", line 176, in add_op
return cls._add_op(op_cls_to_add, **kwargs)
File "/dev/opensource/coremltools/coremltools/converters/mil/mil/builder.py", line 182, in _add_op
new_op.type_value_inference()
File "/dev/opensource/coremltools/coremltools/converters/mil/mil/operation.py", line 253, in type_value_inference
output_types = self.type_inference()
File "/dev/opensource/coremltools/coremltools/converters/mil/mil/ops/defs/iOS15/tensor_operation.py", line 1262, in type_inference
raise ValueError(msg)
ValueError: Tensors in 'values' of the stack op (14) should share the same data type. Got [<class 'coremltools.converters.mil.mil.types.type_double.make_float.<locals>.double'>, <class 'coremltools.converters.mil.mil.types.type_int.make_int.<locals>.int'>].
To Reproduce
import torch
import torch.nn as nn
import coremltools as ct
class Broken(nn.Module):
def __init__(self) -> None:
super().__init__()
def forward(self, x):
y = torch.zeros((1, 3, 512, 512), dtype=torch.int32)
return torch.stack((x, y))
if __name__ == '__main__':
model = Broken()
x = torch.zeros((1, 3, 512, 512), dtype=torch.float32)
res = model(x)
print(res.dtype, res.shape)
model_traced = torch.jit.trace(model, (x, ))
result = ct.convert(model_traced, inputs=[ct.TensorType(name="x", shape=x.shape)])
System environment (please complete the following information):
Rand into this trying to convert detectron2 models with this pull request. The same issue happens if you replace stack with cat btw I assume they are implemented with each other.
The text was updated successfully, but these errors were encountered:
🐞Describing the bug
Exporting a PyTorch model with a https://pytorch.org/docs/stable/generated/torch.stack.html operation with float32 and int32 doesn't work correctly, with native PyTorch the 2 different types are cast to float32.
Stack Trace
To Reproduce
System environment (please complete the following information):
Additional context
Rand into this trying to convert detectron2 models with this pull request. The same issue happens if you replace stack with cat btw I assume they are implemented with each other.
The text was updated successfully, but these errors were encountered: