coremltools
coremltools copied to clipboard
torch.acosh and torch.asinh did not lower, even though they are registered ops
🐞Describing the bug
torch.acosh and torch.asinh have registrations in torch that do not lower.
To Reproduce
import torch
class Model(torch.nn.Module):
def __init__(self):
super().__init__()
def forward(self, x):
return torch.acosh(x)
model = Model()
inputs = (
torch.randn(1,64),
)
eager_outputs = model(*inputs)
#print(f"Eager: {eager_outputs.shape} {eager_outputs}")
ep = torch.export.export(model.eval(), inputs)
print(ep)
import coremltools as ct
import numpy as np
ep = ep.run_decompositions({})
mlmodel = ct.convert(ep)
coreml_inputs = mlmodel.get_spec().description.input
coreml_outputs = mlmodel.get_spec().description.output
predict_inputs = {str(ct_in.name): pt_in.detach().cpu().numpy().astype(np.int32) for ct_in, pt_in in zip(coreml_inputs, inputs)}
out = mlmodel.predict(predict_inputs)
print("CoremL", out)
This causes the following error:
File "/opt/miniconda3/envs/op-et/lib/python3.10/site-packages/coremltools/converters/mil/converter.py", line 218, in _mil_convert
proto, mil_program = mil_convert_to_proto(
File "/opt/miniconda3/envs/op-et/lib/python3.10/site-packages/coremltools/converters/mil/converter.py", line 294, in mil_convert_to_proto
prog = frontend_converter(model, **kwargs)
File "/opt/miniconda3/envs/op-et/lib/python3.10/site-packages/coremltools/converters/mil/converter.py", line 106, in __call__
return load(*args, **kwargs)
File "/opt/miniconda3/envs/op-et/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/load.py", line 88, in load
return _perform_torch_convert(converter, debug)
File "/opt/miniconda3/envs/op-et/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/load.py", line 151, in _perform_torch_convert
prog = converter.convert()
File "/opt/miniconda3/envs/op-et/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/converter.py", line 1392, in convert
convert_nodes(self.context, self.graph, early_exit=not has_states)
File "/opt/miniconda3/envs/op-et/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/ops.py", line 117, in convert_nodes
raise e # re-raise exception
File "/opt/miniconda3/envs/op-et/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/ops.py", line 112, in convert_nodes
convert_single_node(context, node)
File "/opt/miniconda3/envs/op-et/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/ops.py", line 173, in convert_single_node
add_op(context, node)
File "/opt/miniconda3/envs/op-et/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/ops.py", line 6840, in acosh
context.add(mb.acosh(x=inputs[0], name=node.name))
AttributeError: type object 'Builder' has no attribute 'acosh'. Did you mean: 'acos'?
The issue is the op acosh in coremltools/converters/mil/frontend/torch/ops.py calls a non-existent mb.acosh function.
System environment (please complete the following information):
- coremltools version: 8.3
- OS (e.g. MacOS version or Linux type): macOS15