CoreML model compiled with Xcode 13 crashes on pre-iOS 15 devices

This is both a heads-up to other developers, and a request for workarounds:

I noticed that the CoreML image segmentation model in my app crashes when compiling the app with Xcode 13 and running it on an iOS 14 device.

Compiling the same app and model with Xcode 12 the compiled CoreML model works just fine when running on the same devices.

The crash seems to be caused by CoreML trying to access the MLShapedArray type, which was only introduced in iOS 15 (see stack trace in screenshot).

So if you have an app using CoreML, make sure you test on iOS 14 devices before submitting a new build using Xcode 13.

For Apple folks, I filed a Feedback on this a little while ago (and of course heard nothing back). The ID is 9584636.

I had hoped this issue would get fixed before the Xcode 13 release, but unfortunately it is still there in the GM build.

Any workarounds (aside from 'keep using Xcode 12') would be appreciated.

Accepted Reply

Thank you for the report. We confirmed it was a problem in the model access code generator. Until we address the issue in an upcoming Xcode, a workaround is:

  1. Open the current model access code by selecting the .mlmodel file and clicking “Model Class” and exporting it to keep.
  2. In “Target Membership”, select “No Generated Classes”.
  3. Add the saved code-gen Swift file in step 1 back to the project.
  4. Remove lazy properties with MLShapedArray . If you need these properties, you can change to a computed property.

Replies

Thank you for the report. We confirmed it was a problem in the model access code generator. Until we address the issue in an upcoming Xcode, a workaround is:

  1. Open the current model access code by selecting the .mlmodel file and clicking “Model Class” and exporting it to keep.
  2. In “Target Membership”, select “No Generated Classes”.
  3. Add the saved code-gen Swift file in step 1 back to the project.
  4. Remove lazy properties with MLShapedArray . If you need these properties, you can change to a computed property.

Perfect, thank you for the quick reply and excellent workaround! Much appreciated!

Same crash with XCode13. But works well on XCode 12, So I had to switch back to 12 for archiving.Please let us know when this will be fixed. I have no clue to fix it from Model side.

Which step of the workaround instructions are you having difficulty with?

This issue has been fixed in Xcode 13.1

Post not yet marked as solved Up vote reply of ppix Down vote reply of ppix

The issue was fixed for iOS 14 devices but it still crashes for iOS 13 devices (13.6.1 (17G80))

Thread 2 name:
Thread 2 Crashed:
0   ???                           	000000000000000000 0 + 0
1   libswiftCore.dylib            	0x000000019b1ae69c swift_getSingletonMetadata + 956 (Metadata.cpp:829)
2   WRIO                          	0x0000000100237940 type metadata accessor for corpus_enOutput + 48 (<compiler-generated>:0)
3   WRIO                          	0x000000010019a694 PredictionCoreMLModelEnglish.prediction(input:) + 140

  • That looks like a separate issue to me. I'd recommend filing a bug report.

Add a Comment