Open robertsulej opened 1 year ago
The PyTorch traced model appears valid. traced_model(x,y)
returns predictions without error.
mlmodel.predict({'x': x.numpy(), 'y': y.numpy()})
produces Segmentation fault: 11
error. So this is not a Xcode issue. This is either an issue in the Core ML Framework or coremltools is producing an invalid model.
In order to run the code on macOS, I had to remove the three to('cuda')
calls.
Thanks for checking! I am using to('cuda')
to play with 16-bit precision, but even leaving all precision related options to default I see the crash in my swift project.
Please. let me know if I can provide you with any additional tests or if there is a way to go around this problem.
Looks like this does work correctly if you convert to 'mlprogram'
rather than 'neuralnetwork'
. I know you can't use MIL because it doesn't support custom layers.
One possible workaround would be to use a pipeline model that contains a MIL model and a neuralNetwork model.
Yes, I already started working on such approach... it is going to be hard in my case, the custom features are repeating deep in the complex model structure.
Please, consider supporting custom layers in the mlprogram
format.
I struggle with deploying a big model into a swift application. I need it in the neuralnetwork format since a crucial part has to be a custom layer performing calculations on gpu. Problem occurs in the standard code though and I managed to narrow it down to ~simple code. It does not calculate anything usefull, but shows the problem.
Pytorch model is:
Conversion to mlmodel is also standard:
Then I add the model to a swift project in Xcode and load/run it with the code:
The
prediction()
function throwsEXC_BAD_ACCESS
with not much usefull information. Exception comes from the auto-generatedlet outFeatures = try model.prediction(...)
line.When I reduce the model further, I can get some hopefully usefull info.
The model:
Conversion code and swift code are the same. The exception on
model.prediction()
reads:I am using:
I could probably avoid problems if custom layers were supported with
mlprogram
format... are there any plans for rhis?Thanks for help! Robert