coremltools
coremltools copied to clipboard
RuntimeError: PyTorch convert function for op 'new_empty' not implemented.
🐞Describing the bug
Hey there,
While converting a PyTorch model, we're getting the error written in title. We don't use torch.new_empty
anywhere in the forward
method of model but traced_model.graph
shows the usage of new_empty
op of PyTorch.
To Reproduce
x = torch.rand(1, 3, 512, 512)
traced_model = torch.jit.trace(model, x)
inputs = [ct.ImageType(name='image', shape=x.shape)]
mlmodel = ct.convert(traced_model, inputs=inputs)
Throws the following error:
RuntimeError: PyTorch convert function for op 'new_empty' not implemented.
How can we fix it???
System environment (please complete the following information):
- coremltools version: 6.0b1
- OS (e.g. MacOS version or Linux type): macOS 15.5
- Any other relevant version information (e.g. PyTorch or TensorFlow version): PyTorch 1.12
Additional context
N/A
That means some part of the pytorch code is getting lowered into the new_empty
op after tracing.
Can you please check by printing traced_model.forward.graph
which part of the code corresponds to the new_empty
op?
Currently we handle the empty
op by just aliasing it to the zeros
op. To solve this issue, we could probably just alias new_empty
to new_zeros
. We already support new_zeros
.
@RahulBhalley - you could try changing this line to:
@register_torch_op(torch_alias=["new_empty"])
Let us know if that works for you.
Thanks for quick replies @aseemw and @TobyRoseman. And yes @TobyRoseman, your solution works for new_empty
op. But I've encountered issue with non-implementation of torch.normal_
op. Will fix it next. Thanks.
@RahulBhalley - Thanks for letting us know that works. Let's leave this issue open until we have this fix in main
.
Thanks for replies @aseemw and @TobyRoseman. Your solution works for new_empty
op and torch.normal_
op. But I've encountered issue with non-implementation of profiler::_record_function_enter_new
. Can we re-open this issue? Thanks.
Exception has occurred: RuntimeError
PyTorch convert function for op 'profiler::_record_function_enter_new' not implemented.
File "/Users/boshang/Developer/pytorchMobile/convert2CoreML.py", line 143, in <module>
mlmodel = ct.convert(
RuntimeError: PyTorch convert function for op 'profiler::_record_function_enter_new' not implemented.
@cnpcshangbo - profiler::_record_function_enter_new
is a separate op. So please create a new GitHub issue for supporting that op. In your issue please include steps to reproduce the problem.