@mmerterden/multi-agent-pipeline 20.7.0 → 20.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/LICENSE +0 -10
- package/docs/facts.json +1 -1
- package/manifest.json +266 -267
- package/package.json +2 -2
- package/pipeline/scripts/_notices.mjs +1 -1
- package/pipeline/skills/.skill-manifest.json +68 -68
- package/pipeline/skills/shared/README.md +70 -70
- package/pipeline/skills/shared/external/alarmkit/SKILL.md +373 -381
- package/pipeline/skills/shared/external/alarmkit/evals/evals.json +23 -18
- package/pipeline/skills/shared/external/alarmkit/references/alarmkit-patterns.md +328 -378
- package/pipeline/skills/shared/external/app-clips/SKILL.md +260 -160
- package/pipeline/skills/shared/external/app-clips/evals/evals.json +27 -27
- package/pipeline/skills/shared/external/app-clips/references/data-handoff-notifications-location.md +150 -83
- package/pipeline/skills/shared/external/app-clips/references/routing-and-experiences.md +135 -83
- package/pipeline/skills/shared/external/app-clips/references/size-capabilities-and-promotion.md +143 -85
- package/pipeline/skills/shared/external/app-intents/SKILL.md +302 -304
- package/pipeline/skills/shared/external/app-intents/evals/evals.json +21 -21
- package/pipeline/skills/shared/external/app-intents/references/appintents-advanced.md +594 -894
- package/pipeline/skills/shared/external/app-store-optimization/SKILL.md +339 -277
- package/pipeline/skills/shared/external/app-store-optimization/evals/evals.json +27 -23
- package/pipeline/skills/shared/external/app-store-optimization/references/keyword-research-methodology.md +105 -122
- package/pipeline/skills/shared/external/app-store-optimization/references/product-page-variants.md +143 -166
- package/pipeline/skills/shared/external/app-store-review/SKILL.md +307 -326
- package/pipeline/skills/shared/external/app-store-review/evals/evals.json +21 -21
- package/pipeline/skills/shared/external/app-store-review/references/privacy-manifest.md +105 -67
- package/pipeline/skills/shared/external/app-store-review/references/review-checklists.md +114 -101
- package/pipeline/skills/shared/external/apple-on-device-ai/SKILL.md +333 -360
- package/pipeline/skills/shared/external/apple-on-device-ai/evals/evals.json +24 -27
- package/pipeline/skills/shared/external/apple-on-device-ai/references/coreml-conversion.md +215 -322
- package/pipeline/skills/shared/external/apple-on-device-ai/references/coreml-optimization.md +161 -256
- package/pipeline/skills/shared/external/apple-on-device-ai/references/foundation-models.md +277 -387
- package/pipeline/skills/shared/external/apple-on-device-ai/references/mlx-swift.md +196 -210
- package/pipeline/skills/shared/external/authentication/SKILL.md +265 -381
- package/pipeline/skills/shared/external/authentication/evals/evals.json +25 -25
- package/pipeline/skills/shared/external/authentication/references/keychain-biometric.md +133 -178
- package/pipeline/skills/shared/external/authentication/references/passkeys.md +111 -147
- package/pipeline/skills/shared/external/avkit/SKILL.md +267 -364
- package/pipeline/skills/shared/external/avkit/evals/evals.json +26 -26
- package/pipeline/skills/shared/external/avkit/references/avkit-patterns.md +375 -493
- package/pipeline/skills/shared/external/background-processing/SKILL.md +270 -382
- package/pipeline/skills/shared/external/background-processing/evals/evals.json +22 -22
- package/pipeline/skills/shared/external/background-processing/references/background-task-patterns.md +169 -317
- package/pipeline/skills/shared/external/callkit-voip/SKILL.md +290 -371
- package/pipeline/skills/shared/external/callkit-voip/evals/evals.json +24 -24
- package/pipeline/skills/shared/external/callkit-voip/references/callkit-patterns.md +175 -343
- package/pipeline/skills/shared/external/cloudkit-sync/SKILL.md +292 -381
- package/pipeline/skills/shared/external/cloudkit-sync/evals/evals.json +33 -30
- package/pipeline/skills/shared/external/cloudkit-sync/references/cloudkit-patterns.md +227 -355
- package/pipeline/skills/shared/external/contacts-framework/SKILL.md +197 -346
- package/pipeline/skills/shared/external/contacts-framework/evals/evals.json +19 -21
- package/pipeline/skills/shared/external/contacts-framework/references/contacts-patterns.md +169 -308
- package/pipeline/skills/shared/external/core-bluetooth/SKILL.md +226 -376
- package/pipeline/skills/shared/external/core-bluetooth/evals/evals.json +25 -22
- package/pipeline/skills/shared/external/core-bluetooth/references/ble-patterns.md +257 -337
- package/pipeline/skills/shared/external/core-data/SKILL.md +292 -368
- package/pipeline/skills/shared/external/core-data/evals/evals.json +30 -27
- package/pipeline/skills/shared/external/core-motion/SKILL.md +235 -324
- package/pipeline/skills/shared/external/core-motion/evals/evals.json +31 -27
- package/pipeline/skills/shared/external/core-motion/references/motion-patterns.md +210 -310
- package/pipeline/skills/shared/external/core-nfc/SKILL.md +292 -366
- package/pipeline/skills/shared/external/core-nfc/evals/evals.json +22 -24
- package/pipeline/skills/shared/external/core-nfc/references/nfc-patterns.md +233 -329
- package/pipeline/skills/shared/external/coreml/SKILL.md +323 -367
- package/pipeline/skills/shared/external/coreml/evals/evals.json +24 -21
- package/pipeline/skills/shared/external/coreml/references/coreml-swift-integration.md +562 -565
- package/pipeline/skills/shared/external/cryptokit/SKILL.md +253 -394
- package/pipeline/skills/shared/external/cryptokit/evals/evals.json +20 -18
- package/pipeline/skills/shared/external/cryptokit/references/cryptokit-patterns.md +299 -488
- package/pipeline/skills/shared/external/debugging-instruments/SKILL.md +270 -323
- package/pipeline/skills/shared/external/debugging-instruments/evals/evals.json +27 -30
- package/pipeline/skills/shared/external/debugging-instruments/references/instruments-guide.md +167 -315
- package/pipeline/skills/shared/external/debugging-instruments/references/lldb-patterns.md +140 -193
- package/pipeline/skills/shared/external/device-integrity/SKILL.md +230 -353
- package/pipeline/skills/shared/external/device-integrity/evals/evals.json +25 -21
- package/pipeline/skills/shared/external/device-integrity/references/device-integrity-patterns.md +159 -197
- package/pipeline/skills/shared/external/energykit/SKILL.md +225 -392
- package/pipeline/skills/shared/external/energykit/evals/evals.json +29 -28
- package/pipeline/skills/shared/external/energykit/references/energykit-patterns.md +174 -470
- package/pipeline/skills/shared/external/eventkit-calendar/SKILL.md +261 -383
- package/pipeline/skills/shared/external/eventkit-calendar/evals/evals.json +25 -22
- package/pipeline/skills/shared/external/eventkit-calendar/references/eventkit-patterns.md +165 -268
- package/pipeline/skills/shared/external/healthkit/SKILL.md +252 -303
- package/pipeline/skills/shared/external/healthkit/evals/evals.json +24 -23
- package/pipeline/skills/shared/external/healthkit/references/healthkit-patterns.md +369 -523
- package/pipeline/skills/shared/external/homekit-matter/SKILL.md +233 -348
- package/pipeline/skills/shared/external/homekit-matter/evals/evals.json +27 -22
- package/pipeline/skills/shared/external/homekit-matter/references/matter-commissioning.md +199 -305
- package/pipeline/skills/shared/external/ios-accessibility/SKILL.md +368 -340
- package/pipeline/skills/shared/external/ios-accessibility/evals/evals.json +28 -27
- package/pipeline/skills/shared/external/ios-accessibility/references/a11y-patterns.md +314 -260
- package/pipeline/skills/shared/external/ios-accessibility/references/media-accessibility.md +97 -67
- package/pipeline/skills/shared/external/ios-accessibility/references/nutrition-labels.md +165 -101
- package/pipeline/skills/shared/external/ios-localization/SKILL.md +258 -371
- package/pipeline/skills/shared/external/ios-localization/evals/evals.json +23 -23
- package/pipeline/skills/shared/external/ios-localization/references/formatstyle-locale.md +283 -491
- package/pipeline/skills/shared/external/ios-localization/references/string-catalogs.md +313 -440
- package/pipeline/skills/shared/external/ios-networking/SKILL.md +265 -341
- package/pipeline/skills/shared/external/ios-networking/evals/evals.json +24 -24
- package/pipeline/skills/shared/external/ios-networking/references/background-websocket.md +425 -652
- package/pipeline/skills/shared/external/ios-networking/references/file-storage-patterns.md +143 -285
- package/pipeline/skills/shared/external/ios-networking/references/lightweight-clients.md +93 -53
- package/pipeline/skills/shared/external/ios-networking/references/network-framework.md +231 -456
- package/pipeline/skills/shared/external/ios-networking/references/urlsession-patterns.md +517 -784
- package/pipeline/skills/shared/external/ios-simulator/SKILL.md +265 -393
- package/pipeline/skills/shared/external/ios-simulator/evals/evals.json +21 -21
- package/pipeline/skills/shared/external/ios-simulator/references/simctl-commands.md +177 -270
- package/pipeline/skills/shared/external/live-activities/SKILL.md +318 -360
- package/pipeline/skills/shared/external/live-activities/evals/evals.json +21 -21
- package/pipeline/skills/shared/external/live-activities/references/activitykit-patterns.md +478 -710
- package/pipeline/skills/shared/external/mapkit-location/SKILL.md +295 -267
- package/pipeline/skills/shared/external/mapkit-location/evals/evals.json +28 -24
- package/pipeline/skills/shared/external/mapkit-location/references/mapkit-corelocation-patterns.md +378 -532
- package/pipeline/skills/shared/external/mapkit-location/references/mapkit-patterns.md +397 -499
- package/pipeline/skills/shared/external/metrickit-diagnostics/SKILL.md +165 -348
- package/pipeline/skills/shared/external/metrickit-diagnostics/evals/evals.json +26 -23
- package/pipeline/skills/shared/external/metrickit-diagnostics/references/metrickit-patterns.md +123 -130
- package/pipeline/skills/shared/external/musickit-audio/SKILL.md +189 -315
- package/pipeline/skills/shared/external/musickit-audio/evals/evals.json +22 -21
- package/pipeline/skills/shared/external/musickit-audio/references/musickit-patterns.md +181 -270
- package/pipeline/skills/shared/external/natural-language/SKILL.md +188 -340
- package/pipeline/skills/shared/external/natural-language/evals/evals.json +21 -21
- package/pipeline/skills/shared/external/natural-language/references/translation-patterns.md +171 -225
- package/pipeline/skills/shared/external/passkit-wallet/SKILL.md +258 -392
- package/pipeline/skills/shared/external/passkit-wallet/evals/evals.json +30 -29
- package/pipeline/skills/shared/external/passkit-wallet/references/wallet-passes.md +164 -231
- package/pipeline/skills/shared/external/pdfkit/SKILL.md +312 -344
- package/pipeline/skills/shared/external/pdfkit/evals/evals.json +19 -19
- package/pipeline/skills/shared/external/pdfkit/references/pdfkit-patterns.md +413 -624
- package/pipeline/skills/shared/external/pencilkit-drawing/SKILL.md +242 -358
- package/pipeline/skills/shared/external/pencilkit-drawing/evals/evals.json +25 -21
- package/pipeline/skills/shared/external/pencilkit-drawing/references/pencilkit-patterns.md +161 -226
- package/pipeline/skills/shared/external/permissionkit/SKILL.md +282 -400
- package/pipeline/skills/shared/external/permissionkit/evals/evals.json +27 -30
- package/pipeline/skills/shared/external/permissionkit/references/permissionkit-patterns.md +237 -350
- package/pipeline/skills/shared/external/photos-camera-media/SKILL.md +276 -325
- package/pipeline/skills/shared/external/photos-camera-media/references/av-playback.md +299 -545
- package/pipeline/skills/shared/external/photos-camera-media/references/camera-capture.md +344 -588
- package/pipeline/skills/shared/external/photos-camera-media/references/image-loading-caching.md +316 -660
- package/pipeline/skills/shared/external/photos-camera-media/references/photokit-patterns.md +270 -416
- package/pipeline/skills/shared/external/push-notifications/SKILL.md +312 -340
- package/pipeline/skills/shared/external/push-notifications/evals/evals.json +27 -26
- package/pipeline/skills/shared/external/push-notifications/references/notification-patterns.md +328 -485
- package/pipeline/skills/shared/external/push-notifications/references/rich-notifications.md +327 -560
- package/pipeline/skills/shared/external/realitykit-ar/SKILL.md +218 -410
- package/pipeline/skills/shared/external/realitykit-ar/evals/evals.json +24 -27
- package/pipeline/skills/shared/external/realitykit-ar/references/realitykit-patterns.md +221 -348
- package/pipeline/skills/shared/external/shareplay-activities/SKILL.md +222 -393
- package/pipeline/skills/shared/external/shareplay-activities/evals/evals.json +23 -24
- package/pipeline/skills/shared/external/shareplay-activities/references/shareplay-patterns.md +280 -420
- package/pipeline/skills/shared/external/speech-recognition/SKILL.md +217 -421
- package/pipeline/skills/shared/external/speech-recognition/evals/evals.json +23 -26
- package/pipeline/skills/shared/external/speech-recognition/references/speechanalyzer-patterns.md +133 -125
- package/pipeline/skills/shared/external/storekit/SKILL.md +228 -204
- package/pipeline/skills/shared/external/storekit/evals/evals.json +27 -24
- package/pipeline/skills/shared/external/storekit/references/app-review-guidelines.md +98 -109
- package/pipeline/skills/shared/external/storekit/references/core-patterns.md +298 -242
- package/pipeline/skills/shared/external/storekit/references/storekit-advanced.md +356 -649
- package/pipeline/skills/shared/external/swift-api-design-guidelines/SKILL.md +274 -399
- package/pipeline/skills/shared/external/swift-api-design-guidelines/evals/evals.json +22 -24
- package/pipeline/skills/shared/external/swift-api-design-guidelines/references/argument-labels-and-parameters.md +107 -108
- package/pipeline/skills/shared/external/swift-api-design-guidelines/references/conventions-and-special-rules.md +93 -165
- package/pipeline/skills/shared/external/swift-api-design-guidelines/references/naming-and-clarity.md +99 -137
- package/pipeline/skills/shared/external/swift-api-design-guidelines/references/side-effects-and-mutating-pairs.md +77 -120
- package/pipeline/skills/shared/external/swift-architecture/SKILL.md +334 -350
- package/pipeline/skills/shared/external/swift-architecture/evals/evals.json +22 -22
- package/pipeline/skills/shared/external/swift-charts/SKILL.md +208 -394
- package/pipeline/skills/shared/external/swift-charts/evals/evals.json +27 -30
- package/pipeline/skills/shared/external/swift-charts/references/charts-patterns.md +351 -762
- package/pipeline/skills/shared/external/swift-codable/SKILL.md +339 -343
- package/pipeline/skills/shared/external/swift-codable/evals/evals.json +20 -20
- package/pipeline/skills/shared/external/swift-concurrency/SKILL.md +303 -351
- package/pipeline/skills/shared/external/swift-concurrency/evals/evals.json +27 -24
- package/pipeline/skills/shared/external/swift-concurrency/references/approachable-concurrency.md +65 -80
- package/pipeline/skills/shared/external/swift-concurrency/references/async-algorithms.md +48 -84
- package/pipeline/skills/shared/external/swift-concurrency/references/bridging-interop.md +134 -79
- package/pipeline/skills/shared/external/swift-concurrency/references/concurrency-patterns.md +145 -167
- package/pipeline/skills/shared/external/swift-concurrency/references/diagnostics.md +62 -50
- package/pipeline/skills/shared/external/swift-concurrency/references/swiftui-concurrency.md +92 -121
- package/pipeline/skills/shared/external/swift-concurrency/references/synchronization-primitives.md +177 -241
- package/pipeline/skills/shared/external/swift-formatstyle/SKILL.md +258 -234
- package/pipeline/skills/shared/external/swift-language/SKILL.md +342 -382
- package/pipeline/skills/shared/external/swift-language/evals/evals.json +24 -27
- package/pipeline/skills/shared/external/swift-language/references/swift-attributes-interop.md +79 -56
- package/pipeline/skills/shared/external/swift-language/references/swift-patterns-extended.md +297 -340
- package/pipeline/skills/shared/external/swift-security/SKILL.md +180 -161
- package/pipeline/skills/shared/external/swift-security/evals/evals.json +25 -25
- package/pipeline/skills/shared/external/swift-security/references/biometric-authentication.md +314 -469
- package/pipeline/skills/shared/external/swift-security/references/certificate-trust.md +408 -476
- package/pipeline/skills/shared/external/swift-security/references/common-anti-patterns.md +260 -530
- package/pipeline/skills/shared/external/swift-security/references/compliance-owasp-mapping.md +270 -477
- package/pipeline/skills/shared/external/swift-security/references/credential-storage-patterns.md +573 -571
- package/pipeline/skills/shared/external/swift-security/references/cryptokit-public-key.md +370 -441
- package/pipeline/skills/shared/external/swift-security/references/cryptokit-symmetric.md +332 -433
- package/pipeline/skills/shared/external/swift-security/references/keychain-access-control.md +346 -468
- package/pipeline/skills/shared/external/swift-security/references/keychain-fundamentals.md +352 -472
- package/pipeline/skills/shared/external/swift-security/references/keychain-item-classes.md +431 -432
- package/pipeline/skills/shared/external/swift-security/references/keychain-sharing.md +328 -425
- package/pipeline/skills/shared/external/swift-security/references/migration-legacy-stores.md +341 -579
- package/pipeline/skills/shared/external/swift-security/references/secure-enclave.md +396 -457
- package/pipeline/skills/shared/external/swift-security/references/testing-security-code.md +354 -614
- package/pipeline/skills/shared/external/swift-testing/SKILL.md +188 -175
- package/pipeline/skills/shared/external/swift-testing/evals/evals.json +26 -24
- package/pipeline/skills/shared/external/swift-testing/references/testing-advanced.md +80 -84
- package/pipeline/skills/shared/external/swift-testing/references/testing-patterns.md +317 -433
- package/pipeline/skills/shared/external/swiftdata/SKILL.md +392 -256
- package/pipeline/skills/shared/external/swiftdata/evals/evals.json +24 -24
- package/pipeline/skills/shared/external/swiftdata/references/core-data-coexistence.md +206 -402
- package/pipeline/skills/shared/external/swiftdata/references/indexing.md +59 -52
- package/pipeline/skills/shared/external/swiftdata/references/predicate-pitfalls.md +57 -33
- package/pipeline/skills/shared/external/swiftdata/references/swiftdata-advanced.md +354 -747
- package/pipeline/skills/shared/external/swiftdata/references/swiftdata-queries.md +300 -508
- package/pipeline/skills/shared/external/swiftlint/SKILL.md +175 -226
- package/pipeline/skills/shared/external/swiftlint/references/adoption-and-configuration.md +141 -208
- package/pipeline/skills/shared/external/swiftlint/references/custom-rules-and-analyze.md +100 -109
- package/pipeline/skills/shared/external/swiftlint/references/plugins-run-scripts-and-integrations.md +159 -179
- package/pipeline/skills/shared/external/swiftlint/references/rule-reference.md +383 -18
- package/pipeline/skills/shared/external/swiftlint/references/rules-suppressions-and-baselines.md +143 -229
- package/pipeline/skills/shared/external/swiftui-animation/SKILL.md +283 -366
- package/pipeline/skills/shared/external/swiftui-animation/references/animation-advanced.md +396 -608
- package/pipeline/skills/shared/external/swiftui-animation/references/core-animation-bridge.md +336 -385
- package/pipeline/skills/shared/external/swiftui-gestures/SKILL.md +239 -349
- package/pipeline/skills/shared/external/swiftui-gestures/references/gesture-patterns.md +228 -310
- package/pipeline/skills/shared/external/swiftui-layout-components/SKILL.md +260 -249
- package/pipeline/skills/shared/external/swiftui-layout-components/references/form.md +92 -74
- package/pipeline/skills/shared/external/swiftui-layout-components/references/grids.md +112 -177
- package/pipeline/skills/shared/external/swiftui-layout-components/references/list.md +61 -64
- package/pipeline/skills/shared/external/swiftui-layout-components/references/scrollview.md +94 -134
- package/pipeline/skills/shared/external/swiftui-liquid-glass/SKILL.md +193 -225
- package/pipeline/skills/shared/external/swiftui-liquid-glass/references/liquid-glass.md +173 -327
- package/pipeline/skills/shared/external/swiftui-navigation/SKILL.md +193 -168
- package/pipeline/skills/shared/external/swiftui-navigation/references/deeplinks.md +127 -150
- package/pipeline/skills/shared/external/swiftui-navigation/references/navigationstack.md +132 -133
- package/pipeline/skills/shared/external/swiftui-navigation/references/sheets.md +152 -117
- package/pipeline/skills/shared/external/swiftui-navigation/references/tabview.md +106 -140
- package/pipeline/skills/shared/external/swiftui-patterns/SKILL.md +316 -252
- package/pipeline/skills/shared/external/swiftui-patterns/references/architecture-patterns.md +341 -332
- package/pipeline/skills/shared/external/swiftui-patterns/references/deprecated-migration.md +547 -854
- package/pipeline/skills/shared/external/swiftui-patterns/references/design-polish.md +485 -537
- package/pipeline/skills/shared/external/swiftui-patterns/references/platform-and-sharing.md +417 -499
- package/pipeline/skills/shared/external/swiftui-performance/SKILL.md +213 -376
- package/pipeline/skills/shared/external/swiftui-performance/references/demystify-swiftui-performance-wwdc23.md +86 -175
- package/pipeline/skills/shared/external/swiftui-performance/references/optimizing-swiftui-performance-instruments.md +89 -195
- package/pipeline/skills/shared/external/swiftui-performance/references/understanding-hangs-in-your-app.md +95 -182
- package/pipeline/skills/shared/external/swiftui-performance/references/understanding-improving-swiftui-performance.md +71 -149
- package/pipeline/skills/shared/external/swiftui-performance/references/wwdc-session-sources.md +21 -27
- package/pipeline/skills/shared/external/swiftui-uikit-interop/SKILL.md +303 -295
- package/pipeline/skills/shared/external/swiftui-uikit-interop/references/hosting-migration.md +204 -387
- package/pipeline/skills/shared/external/swiftui-uikit-interop/references/representable-recipes.md +469 -683
- package/pipeline/skills/shared/external/swiftui-webkit/SKILL.md +140 -186
- package/pipeline/skills/shared/external/swiftui-webkit/references/loading-and-observation.md +75 -86
- package/pipeline/skills/shared/external/swiftui-webkit/references/local-content-and-custom-schemes.md +63 -60
- package/pipeline/skills/shared/external/swiftui-webkit/references/migration-and-fallbacks.md +69 -137
- package/pipeline/skills/shared/external/swiftui-webkit/references/navigation-and-javascript.md +95 -67
- package/pipeline/skills/shared/external/tipkit/SKILL.md +220 -335
- package/pipeline/skills/shared/external/tipkit/references/tipkit-patterns.md +356 -494
- package/pipeline/skills/shared/external/vision-framework/SKILL.md +260 -375
- package/pipeline/skills/shared/external/vision-framework/references/vision-requests.md +393 -515
- package/pipeline/skills/shared/external/vision-framework/references/visionkit-scanner.md +363 -539
- package/pipeline/skills/shared/external/weatherkit/SKILL.md +152 -310
- package/pipeline/skills/shared/external/weatherkit/references/weatherkit-patterns.md +288 -407
- package/pipeline/skills/shared/external/widgetkit/SKILL.md +216 -288
- package/pipeline/skills/shared/external/widgetkit/references/widgetkit-advanced.md +414 -719
- package/pipeline/skills/shared/external/NOTICE-swift-ios-skills.md +0 -39
|
@@ -1,431 +1,324 @@
|
|
|
1
|
-
# Core ML
|
|
1
|
+
# Core ML conversion with coremltools
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
This file is about the Python side: exporting from the training framework,
|
|
4
|
+
converting, choosing a deployment target and input shapes, and preparing for
|
|
5
|
+
compression. Swift runtime wiring belongs to the `coreml` skill. In a
|
|
6
|
+
conversion review, describe what the app needs at runtime in prose unless the
|
|
7
|
+
user asked for Swift code.
|
|
8
8
|
|
|
9
9
|
## Contents
|
|
10
10
|
|
|
11
|
-
- [coremltools
|
|
12
|
-
- [
|
|
13
|
-
- [
|
|
14
|
-
- [
|
|
15
|
-
- [
|
|
16
|
-
- [
|
|
17
|
-
- [
|
|
18
|
-
- [
|
|
19
|
-
- [
|
|
20
|
-
- [
|
|
21
|
-
- [
|
|
22
|
-
- [
|
|
23
|
-
- [
|
|
24
|
-
- [
|
|
25
|
-
- [
|
|
26
|
-
- [
|
|
27
|
-
- [
|
|
28
|
-
- [
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
11
|
+
- [Installing coremltools](#installing-coremltools)
|
|
12
|
+
- [Where Core ML sits](#where-core-ml-sits)
|
|
13
|
+
- [ML program versus neural network](#ml-program-versus-neural-network)
|
|
14
|
+
- [ct.convert parameters](#ctconvert-parameters)
|
|
15
|
+
- [From PyTorch](#from-pytorch)
|
|
16
|
+
- [From TensorFlow, scikit-learn and XGBoost](#from-tensorflow-scikit-learn-and-xgboost)
|
|
17
|
+
- [ONNX](#onnx)
|
|
18
|
+
- [Describing inputs and outputs](#describing-inputs-and-outputs)
|
|
19
|
+
- [Flexible shapes](#flexible-shapes)
|
|
20
|
+
- [Deployment targets](#deployment-targets)
|
|
21
|
+
- [Float16 or Float32](#float16-or-float32)
|
|
22
|
+
- [Which processors to allow](#which-processors-to-allow)
|
|
23
|
+
- [Keeping state between predictions](#keeping-state-between-predictions)
|
|
24
|
+
- [Several functions in one package](#several-functions-in-one-package)
|
|
25
|
+
- [Utilities](#utilities)
|
|
26
|
+
- [Controlling graph passes](#controlling-graph-passes)
|
|
27
|
+
- [Unsupported PyTorch ops](#unsupported-pytorch-ops)
|
|
28
|
+
- [Conversion mistakes](#conversion-mistakes)
|
|
29
|
+
|
|
30
|
+
## Installing coremltools
|
|
31
|
+
|
|
32
|
+
Install into a fresh virtual environment and check the published wheels against
|
|
33
|
+
your Python version and the version of the source framework:
|
|
33
34
|
|
|
34
35
|
```bash
|
|
36
|
+
python3 -m venv .venv && source .venv/bin/activate
|
|
35
37
|
pip install coremltools
|
|
36
38
|
```
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
3.13 and adds iOS 26 / macOS 26 deployment targets.
|
|
40
|
+
coremltools 9.0 has wheels up to CPython 3.13 and adds the iOS 26 and macOS 26
|
|
41
|
+
deployment targets.
|
|
41
42
|
|
|
42
|
-
##
|
|
43
|
+
## Where Core ML sits
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|-- Metal Performance Shaders Graph (GPU) / Accelerate (CPU) / Neural Engine (ANE)
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
## Model Formats
|
|
52
|
-
|
|
53
|
-
| Format | Extension | Model Type | When to Use |
|
|
54
|
-
|---|---|---|---|
|
|
55
|
-
| `.mlpackage` | Directory | mlprogram | All new models (iOS 15+) |
|
|
56
|
-
| `.mlmodel` | Single file | neuralnetwork | Legacy only (iOS 11-14) |
|
|
57
|
-
| `.mlmodelc` | Compiled | Either | Pre-compiled for faster loading |
|
|
58
|
-
|
|
59
|
-
Always use mlprogram (.mlpackage) for new work. Neural network format is frozen
|
|
60
|
-
and receives no new features.
|
|
45
|
+
Higher-level frameworks (SoundAnalysis, Natural Language, Vision and
|
|
46
|
+
Foundation Models) are built on Core ML. Core ML in turn runs each operation on
|
|
47
|
+
the CPU through Accelerate, on the GPU through MPS Graph, or on the Neural
|
|
48
|
+
Engine.
|
|
61
49
|
|
|
62
|
-
|
|
50
|
+
## ML program versus neural network
|
|
63
51
|
|
|
64
|
-
| Aspect |
|
|
52
|
+
| Aspect | Neural network (`.mlmodel`) | ML program (`.mlpackage`) |
|
|
65
53
|
|---|---|---|
|
|
66
|
-
|
|
|
67
|
-
|
|
|
68
|
-
|
|
|
69
|
-
|
|
|
70
|
-
|
|
|
71
|
-
|
|
|
54
|
+
| Status | Frozen, no new features | Current format |
|
|
55
|
+
| GPU precision | Float16 only | Float16 or Float32 |
|
|
56
|
+
| Compression APIs | Limited | Quantize, palettize and prune |
|
|
57
|
+
| Where weights live | Inside the protobuf | Separate files, lighter on memory |
|
|
58
|
+
| Training on the device | Yes | No |
|
|
59
|
+
| State and multiple functions | No | Yes, from iOS 18 |
|
|
72
60
|
|
|
73
|
-
##
|
|
61
|
+
## ct.convert parameters
|
|
74
62
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
compute_units=ct.ComputeUnit.ALL,
|
|
87
|
-
skip_model_load=False, # True when converting on Linux
|
|
88
|
-
states=None, # list of StateType for stateful models
|
|
89
|
-
pass_pipeline=None, # PassPipeline for graph optimization
|
|
90
|
-
)
|
|
91
|
-
mlmodel.save("Model.mlpackage")
|
|
92
|
-
```
|
|
63
|
+
| Parameter | Values |
|
|
64
|
+
|---|---|
|
|
65
|
+
| `source` | `"auto"`, `"pytorch"`, `"tensorflow"` |
|
|
66
|
+
| `inputs`, `outputs` | Lists of `ct.TensorType` or `ct.ImageType` |
|
|
67
|
+
| `convert_to` | `"mlprogram"` (default) or `"neuralnetwork"` |
|
|
68
|
+
| `minimum_deployment_target` | any `ct.target` value from iOS15 up to iOS26 |
|
|
69
|
+
| `compute_precision` | `ct.precision.FLOAT16` (default) or `FLOAT32` |
|
|
70
|
+
| `compute_units` | `ct.ComputeUnit.ALL` and the other unit sets |
|
|
71
|
+
| `skip_model_load` | `True` when converting on Linux, where the model cannot be loaded |
|
|
72
|
+
| `states` | List of `ct.StateType` |
|
|
73
|
+
| `pass_pipeline` | A `ct.PassPipeline` |
|
|
93
74
|
|
|
94
|
-
##
|
|
75
|
+
## From PyTorch
|
|
95
76
|
|
|
96
|
-
|
|
77
|
+
Tracing is the recommended route:
|
|
97
78
|
|
|
98
79
|
```python
|
|
99
80
|
import torch
|
|
100
81
|
import coremltools as ct
|
|
101
82
|
|
|
102
|
-
model =
|
|
103
|
-
model.eval()
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
traced_model = torch.jit.trace(model, example_input)
|
|
83
|
+
model = load_keyword_spotter()
|
|
84
|
+
model.eval()
|
|
85
|
+
clip = torch.randn(1, 1, 16000)
|
|
86
|
+
traced = torch.jit.trace(model, clip)
|
|
107
87
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
inputs=[ct.TensorType(shape=example_input.shape, name="input")],
|
|
88
|
+
spotter = ct.convert(
|
|
89
|
+
traced,
|
|
111
90
|
minimum_deployment_target=ct.target.iOS16,
|
|
91
|
+
inputs=[ct.TensorType(name="audio", shape=clip.shape)],
|
|
112
92
|
)
|
|
113
|
-
|
|
93
|
+
spotter.save("KeywordSpotter.mlpackage")
|
|
114
94
|
```
|
|
115
95
|
|
|
116
|
-
|
|
96
|
+
`torch.export` is supported in beta. Dynamic dimensions are declared when you
|
|
97
|
+
export and become `RangeDim` automatically:
|
|
117
98
|
|
|
118
99
|
```python
|
|
119
|
-
import
|
|
120
|
-
import coremltools as ct
|
|
121
|
-
|
|
122
|
-
model.eval()
|
|
123
|
-
example_inputs = (torch.rand(1, 3, 224, 224),)
|
|
100
|
+
from torch.export import Dim, export
|
|
124
101
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
dynamic_shapes={"x": {0: batch_dim}})
|
|
129
|
-
|
|
130
|
-
mlmodel = ct.convert(exported)
|
|
102
|
+
length = Dim(name="length", min=4000, max=48000)
|
|
103
|
+
exported = export(model, (clip,), dynamic_shapes={"x": {2: length}})
|
|
104
|
+
spotter = ct.convert(exported, minimum_deployment_target=ct.target.iOS17)
|
|
131
105
|
```
|
|
132
106
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
RangeDim/EnumeratedShapes.
|
|
136
|
-
|
|
137
|
-
## Converting from TensorFlow
|
|
138
|
-
|
|
139
|
-
```python
|
|
140
|
-
import tensorflow as tf
|
|
141
|
-
import coremltools as ct
|
|
142
|
-
|
|
143
|
-
# Keras model
|
|
144
|
-
tf_model = tf.keras.applications.MobileNetV2()
|
|
145
|
-
mlmodel = ct.convert(tf_model)
|
|
107
|
+
With `export`, shapes are fixed up front; with `trace`, you express flexibility
|
|
108
|
+
inside `ct.convert()` using `RangeDim` or `EnumeratedShapes`.
|
|
146
109
|
|
|
147
|
-
|
|
148
|
-
mlmodel = ct.convert("/path/to/saved_model/")
|
|
110
|
+
## From TensorFlow, scikit-learn and XGBoost
|
|
149
111
|
|
|
150
|
-
|
|
151
|
-
|
|
112
|
+
TensorFlow: `ct.convert` accepts a Keras model object, a SavedModel directory,
|
|
113
|
+
an `.h5` file, or a frozen `.pb` graph (the last needs explicit `inputs`).
|
|
152
114
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
115
|
+
```python
|
|
116
|
+
keras_net = tf.keras.models.load_model("leaf_classifier.keras")
|
|
117
|
+
leaf = ct.convert(keras_net, minimum_deployment_target=ct.target.iOS17)
|
|
156
118
|
```
|
|
157
119
|
|
|
158
|
-
|
|
120
|
+
scikit-learn converts to the older `.mlmodel` format:
|
|
159
121
|
|
|
160
122
|
```python
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
model = LinearRegression()
|
|
165
|
-
model.fit(X_train, y_train)
|
|
166
|
-
|
|
167
|
-
mlmodel = ct.converters.sklearn.convert(
|
|
168
|
-
model, ["feature1", "feature2"], "prediction"
|
|
169
|
-
)
|
|
170
|
-
mlmodel.save("Regressor.mlmodel")
|
|
123
|
+
price = ct.converters.sklearn.convert(forest, ["rooms", "area", "age"], "price")
|
|
124
|
+
price.save("HousePrice.mlmodel")
|
|
171
125
|
```
|
|
172
126
|
|
|
173
|
-
|
|
127
|
+
XGBoost:
|
|
174
128
|
|
|
175
129
|
```python
|
|
176
|
-
|
|
177
|
-
import coremltools as ct
|
|
178
|
-
|
|
179
|
-
model = xgboost.XGBClassifier()
|
|
180
|
-
model.fit(X_train, y_train)
|
|
181
|
-
mlmodel = ct.converters.xgboost.convert(model)
|
|
130
|
+
churn = ct.converters.xgboost.convert(booster)
|
|
182
131
|
```
|
|
183
132
|
|
|
184
|
-
## ONNX
|
|
185
|
-
|
|
186
|
-
ONNX direct conversion is deprecated since coremltools 6. Convert from the
|
|
187
|
-
original framework (PyTorch or TensorFlow) instead. If you only have an ONNX
|
|
188
|
-
file, convert back to PyTorch first using `onnx2torch`.
|
|
133
|
+
## ONNX
|
|
189
134
|
|
|
190
|
-
|
|
135
|
+
coremltools stopped supporting direct ONNX input in version 6, so go back to
|
|
136
|
+
the framework the model was trained in. If ONNX is all you have, convert it back to PyTorch
|
|
137
|
+
with `onnx2torch` and trace that.
|
|
191
138
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
```python
|
|
195
|
-
ct.TensorType(
|
|
196
|
-
name="input", # must match model input name
|
|
197
|
-
shape=(1, 3, 224, 224), # tuple of int, RangeDim, or EnumeratedShapes
|
|
198
|
-
dtype=np.float32, # np.float32, np.float16, np.int32, np.int8 (iOS26+)
|
|
199
|
-
default_value=None, # np.ndarray: makes input optional at runtime
|
|
200
|
-
)
|
|
201
|
-
```
|
|
139
|
+
## Describing inputs and outputs
|
|
202
140
|
|
|
203
|
-
|
|
141
|
+
`ct.TensorType(name=, shape=, dtype=, default_value=)`:
|
|
204
142
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
scale=1/255.0, # per-channel scaling
|
|
210
|
-
bias=[-0.485/0.229, -0.456/0.224, -0.406/0.225], # ImageNet normalization
|
|
211
|
-
color_layout=ct.colorlayout.RGB, # RGB, BGR, GRAYSCALE, GRAYSCALE_FLOAT16
|
|
212
|
-
channel_first=True, # True for PyTorch (NCHW), False for TF (NHWC)
|
|
213
|
-
)
|
|
214
|
-
```
|
|
143
|
+
- `name` must match the model's input name.
|
|
144
|
+
- `shape` takes fixed integers, `RangeDim` or `EnumeratedShapes`.
|
|
145
|
+
- `dtype`: `np.int32`, `np.float16` or `np.float32`, plus `np.int8` from iOS 26.
|
|
146
|
+
- `default_value` (a NumPy array) makes the input optional.
|
|
215
147
|
|
|
216
|
-
|
|
148
|
+
`ct.ImageType(name=, shape=, scale=, bias=, color_layout=, channel_first=)`:
|
|
217
149
|
|
|
218
150
|
```python
|
|
219
|
-
ct.
|
|
220
|
-
|
|
221
|
-
|
|
151
|
+
photo = ct.ImageType(
|
|
152
|
+
name="photo",
|
|
153
|
+
shape=(1, 3, 320, 320),
|
|
154
|
+
scale=1 / 127.5,
|
|
155
|
+
bias=[-1.0, -1.0, -1.0], # maps pixels to the range -1...1
|
|
156
|
+
color_layout=ct.colorlayout.RGB,
|
|
157
|
+
channel_first=True,
|
|
222
158
|
)
|
|
223
159
|
```
|
|
224
160
|
|
|
225
|
-
|
|
161
|
+
- Colour layouts: `GRAYSCALE`, `GRAYSCALE_FLOAT16`, `RGB` or `BGR`.
|
|
162
|
+
- PyTorch models are NCHW, so pass `channel_first=True`; TensorFlow's NHWC
|
|
163
|
+
needs `False`.
|
|
226
164
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
```python
|
|
230
|
-
inputs=[ct.TensorType(shape=(1, 3, 224, 224))]
|
|
231
|
-
```
|
|
165
|
+
`ct.StateType(wrapped_type=ct.TensorType(...), name=)` (iOS 18+) declares
|
|
166
|
+
state, for example a float16 `kv_cache` tensor.
|
|
232
167
|
|
|
233
|
-
|
|
168
|
+
## Flexible shapes
|
|
234
169
|
|
|
235
170
|
```python
|
|
236
|
-
|
|
237
|
-
1, 3,
|
|
238
|
-
ct.RangeDim(lower_bound=128, upper_bound=512, default=224),
|
|
239
|
-
ct.RangeDim(lower_bound=128, upper_bound=512, default=224),
|
|
240
|
-
))]
|
|
241
|
-
```
|
|
171
|
+
fixed = ct.TensorType(name="x", shape=(1, 3, 512, 512))
|
|
242
172
|
|
|
243
|
-
|
|
173
|
+
side = ct.RangeDim(lower_bound=256, upper_bound=1024, default=512)
|
|
174
|
+
ranged = ct.TensorType(name="x", shape=(1, 3, side, side))
|
|
244
175
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
shapes=[(1,3,224,224), (1,3,384,384), (1,3,512,512)],
|
|
248
|
-
default=(1,3,224,224),
|
|
249
|
-
))]
|
|
176
|
+
sizes = [(1, 3, s, s) for s in (256, 512, 1024)]
|
|
177
|
+
listed = ct.TensorType(name="x", shape=ct.EnumeratedShapes(shapes=sizes, default=sizes[1]))
|
|
250
178
|
```
|
|
251
179
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
iOS 18, multiple inputs can use EnumeratedShapes.
|
|
180
|
+
When the real sizes are known, list them with `EnumeratedShapes`: the Neural
|
|
181
|
+
Engine compiles an optimised plan for each listed shape, while with `RangeDim`
|
|
182
|
+
only the default shape gets that treatment. Until iOS 18,
|
|
183
|
+
`EnumeratedShapes` was limited to a single input; newer targets allow it on
|
|
184
|
+
several.
|
|
258
185
|
|
|
259
|
-
## Deployment
|
|
186
|
+
## Deployment targets
|
|
260
187
|
|
|
261
|
-
|
|
|
188
|
+
| iOS target | Matching macOS target | What it unlocks |
|
|
262
189
|
|---|---|---|
|
|
263
|
-
| `ct.target.iOS13` |
|
|
264
|
-
| `ct.target.iOS15` |
|
|
265
|
-
| `ct.target.iOS16` |
|
|
266
|
-
| `ct.target.iOS17` |
|
|
267
|
-
| `ct.target.iOS18` |
|
|
268
|
-
| `ct.target.iOS26` |
|
|
190
|
+
| `ct.target.iOS13` | `ct.target.macOS10_15` | Neural network models only |
|
|
191
|
+
| `ct.target.iOS15` | `ct.target.macOS12` | ML program, FP16, typed tensors |
|
|
192
|
+
| `ct.target.iOS16` | `ct.target.macOS13` | Palettized and sparse weights |
|
|
193
|
+
| `ct.target.iOS17` | `ct.target.macOS14` | W8A8 activation quantization (A17 Pro and later) |
|
|
194
|
+
| `ct.target.iOS18` | `ct.target.macOS15` | Stateful and multifunction models, block-wise quantization |
|
|
195
|
+
| `ct.target.iOS26` | `ct.target.macOS26` | INT8 input and output types, state read and write |
|
|
269
196
|
|
|
270
|
-
|
|
271
|
-
`macOS15`, `macOS26`.
|
|
197
|
+
## Float16 or Float32
|
|
272
198
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|---|---|
|
|
277
|
-
| `ct.precision.FLOAT16` | Default for mlprogram. Smaller, faster. |
|
|
278
|
-
| `ct.precision.FLOAT32` | Higher accuracy. Use when FP16 causes issues. |
|
|
279
|
-
|
|
280
|
-
### Mixed Precision (Selective Per-Op)
|
|
199
|
+
ML programs default to `ct.precision.FLOAT16`, which is smaller and faster. Use
|
|
200
|
+
`FLOAT32` only when half precision measurably hurts accuracy. To keep just the
|
|
201
|
+
sensitive ops in FP32:
|
|
281
202
|
|
|
282
203
|
```python
|
|
283
|
-
def
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
compute_precision=
|
|
290
|
-
|
|
291
|
-
))
|
|
204
|
+
def keep_norms_fp32(op):
|
|
205
|
+
return op.op_type != "layer_norm"
|
|
206
|
+
|
|
207
|
+
policy = ct.transform.FP16ComputePrecision(op_selector=keep_norms_fp32)
|
|
208
|
+
mixed = ct.convert(
|
|
209
|
+
traced,
|
|
210
|
+
compute_precision=policy,
|
|
211
|
+
minimum_deployment_target=ct.target.iOS17,
|
|
212
|
+
inputs=[ct.TensorType(name="tokens", shape=(1, 128))],
|
|
213
|
+
)
|
|
292
214
|
```
|
|
293
215
|
|
|
294
|
-
|
|
216
|
+
The selector returns `False` for an op that should stay in FP32.
|
|
295
217
|
|
|
296
|
-
|
|
297
|
-
|---|---|---|
|
|
298
|
-
| `.all` | CPU + GPU + Neural Engine | Default, recommended |
|
|
299
|
-
| `.cpuOnly` | CPU exclusively | Debugging, FP32 accuracy |
|
|
300
|
-
| `.cpuAndGPU` | CPU and GPU, no ANE | When ANE causes issues |
|
|
301
|
-
| `.cpuAndNeuralEngine` | CPU and ANE, no GPU | Energy efficiency (macOS 13+) |
|
|
218
|
+
## Which processors to allow
|
|
302
219
|
|
|
303
|
-
|
|
220
|
+
| Setting | When |
|
|
221
|
+
|---|---|
|
|
222
|
+
| `.all` | Default and recommended: CPU, GPU and Neural Engine |
|
|
223
|
+
| `.cpuOnly` | Debugging, or checking FP32 reference results |
|
|
224
|
+
| `.cpuAndGPU` | When the Neural Engine produces bad results |
|
|
225
|
+
| `.cpuAndNeuralEngine` | Lowest energy use; macOS 13 or later |
|
|
304
226
|
|
|
305
|
-
|
|
227
|
+
## Keeping state between predictions
|
|
306
228
|
|
|
307
|
-
|
|
229
|
+
From iOS 18 a model can keep values between predictions. The main use is the
|
|
230
|
+
key-value cache of a language model.
|
|
308
231
|
|
|
309
232
|
```python
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
name="accumulator",
|
|
317
|
-
)],
|
|
233
|
+
cache = ct.StateType(
|
|
234
|
+
name="kv_cache",
|
|
235
|
+
wrapped_type=ct.TensorType(dtype=np.float16, shape=(2, 1, 16, 1024, 64)),
|
|
236
|
+
)
|
|
237
|
+
decoder = ct.convert(
|
|
238
|
+
traced_decoder,
|
|
318
239
|
minimum_deployment_target=ct.target.iOS18,
|
|
240
|
+
states=[cache],
|
|
241
|
+
inputs=[ct.TensorType(name="token", dtype=np.int32, shape=(1, 1))],
|
|
319
242
|
)
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
state = mlmodel.make_state()
|
|
323
|
-
result = mlmodel.predict({"x": np.array([2.0])}, state=state)
|
|
243
|
+
state = decoder.make_state()
|
|
244
|
+
step = decoder.predict({"token": np.array([[42]], dtype=np.int32)}, state=state)
|
|
324
245
|
```
|
|
325
246
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
```swift
|
|
329
|
-
let model = try MLModel(contentsOf: modelURL, configuration: config)
|
|
330
|
-
let state = model.makeState()
|
|
331
|
-
let input = try MLDictionaryFeatureProvider(
|
|
332
|
-
dictionary: ["x": MLFeatureValue(double: 2.0)]
|
|
333
|
-
)
|
|
334
|
-
let output = try model.prediction(from: input, using: state)
|
|
335
|
-
```
|
|
247
|
+
On the Swift side the equivalent is `let state = model.makeState()` followed by
|
|
248
|
+
`try model.prediction(from: MLDictionaryFeatureProvider(dictionary: inputs), using: state)`.
|
|
336
249
|
|
|
337
|
-
|
|
338
|
-
|
|
250
|
+
Apple's published measurement for Llama 3.1: 16.26 tokens per second with a
|
|
251
|
+
stateful KV cache against 1.25 without, roughly thirteen times faster.
|
|
339
252
|
|
|
340
|
-
##
|
|
253
|
+
## Several functions in one package
|
|
341
254
|
|
|
342
|
-
|
|
343
|
-
|
|
255
|
+
Also from iOS 18, one `.mlpackage` can hold several functions that share
|
|
256
|
+
deduplicated weights, for example a base model and LoRA variants:
|
|
344
257
|
|
|
345
258
|
```python
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
ct.utils.save_multifunction(desc, "combined.mlpackage")
|
|
259
|
+
bundle = ct.utils.MultiFunctionDescriptor()
|
|
260
|
+
for variant in ("plain", "legal"):
|
|
261
|
+
bundle.add_function(f"Drafting-{variant}.mlpackage",
|
|
262
|
+
target_function_name=variant, src_function_name="main")
|
|
263
|
+
bundle.default_function_name = "plain"
|
|
264
|
+
ct.utils.save_multifunction(bundle, "Drafting.mlpackage")
|
|
353
265
|
```
|
|
354
266
|
|
|
355
|
-
|
|
356
|
-
let config = MLModelConfiguration()
|
|
357
|
-
config.functionName = "style_1"
|
|
358
|
-
let model = try MLModel(contentsOf: modelURL, configuration: config)
|
|
359
|
-
```
|
|
267
|
+
In Swift, pick the function with `MLModelConfiguration.functionName`.
|
|
360
268
|
|
|
361
|
-
##
|
|
269
|
+
## Utilities
|
|
362
270
|
|
|
363
271
|
```python
|
|
364
|
-
|
|
365
|
-
spec
|
|
366
|
-
print(spec.description)
|
|
367
|
-
|
|
368
|
-
# Rename inputs/outputs
|
|
369
|
-
ct.utils.rename_feature(spec, "old_name", "new_name")
|
|
370
|
-
|
|
371
|
-
# Set metadata
|
|
372
|
-
mlmodel.author = "Author"
|
|
373
|
-
mlmodel.short_description = "Description"
|
|
374
|
-
mlmodel.input_description["image"] = "RGB image 224x224"
|
|
375
|
-
|
|
376
|
-
# Split large models for debugging
|
|
377
|
-
ct.models.utils.bisect_model("large.mlpackage", "./output/")
|
|
272
|
+
spec = spotter.get_spec()
|
|
273
|
+
ct.utils.rename_feature(spec, "var_512", "probabilities")
|
|
378
274
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
# Randomize weights (for testing)
|
|
383
|
-
random_model = ct.models.utils.randomize_weights(mlmodel)
|
|
275
|
+
spotter.author = "Audio team"
|
|
276
|
+
spotter.short_description = "Wake-word detector"
|
|
277
|
+
spotter.input_description["audio"] = "One second of 16 kHz mono audio"
|
|
384
278
|
```
|
|
385
279
|
|
|
386
|
-
|
|
280
|
+
- `ct.models.utils.bisect_model` splits a large model into pieces for
|
|
281
|
+
debugging.
|
|
282
|
+
- `make_pipeline` chains models.
|
|
283
|
+
- `randomize_weights` produces a structurally identical model for tests.
|
|
284
|
+
|
|
285
|
+
## Controlling graph passes
|
|
387
286
|
|
|
388
287
|
```python
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
# Predefined pipelines
|
|
395
|
-
ct.PassPipeline.EMPTY # no passes
|
|
396
|
-
ct.PassPipeline.CLEANUP # minimal cleanup
|
|
397
|
-
ct.PassPipeline.DEFAULT_PRUNING # optimized for pruned models
|
|
398
|
-
ct.PassPipeline.DEFAULT_PALETTIZATION # optimized for palettized models
|
|
288
|
+
passes = ct.PassPipeline()
|
|
289
|
+
passes.remove_passes({"common::fuse_conv_batchnorm"}) # keep BN visible while debugging
|
|
290
|
+
debuggable = ct.convert(traced, minimum_deployment_target=ct.target.iOS17,
|
|
291
|
+
pass_pipeline=passes)
|
|
399
292
|
```
|
|
400
293
|
|
|
401
|
-
|
|
294
|
+
Predefined pipelines: `ct.PassPipeline.EMPTY`, `CLEANUP`, `DEFAULT_PRUNING`,
|
|
295
|
+
`DEFAULT_PALETTIZATION`.
|
|
402
296
|
|
|
403
|
-
|
|
297
|
+
## Unsupported PyTorch ops
|
|
298
|
+
|
|
299
|
+
Register a composite for an op the converter does not know, built from MIL
|
|
300
|
+
builder ops:
|
|
404
301
|
|
|
405
302
|
```python
|
|
406
|
-
from coremltools.converters.mil.frontend.torch.torch_op_registry import register_torch_op
|
|
407
303
|
from coremltools.converters.mil.frontend.torch.ops import _get_inputs
|
|
304
|
+
from coremltools.converters.mil import register_torch_op
|
|
408
305
|
from coremltools.converters.mil import Builder as mb
|
|
409
306
|
|
|
410
307
|
@register_torch_op
|
|
411
|
-
def
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
308
|
+
def hardswish(ctx, torch_node):
|
|
309
|
+
(value,) = _get_inputs(ctx, torch_node, expected=1)
|
|
310
|
+
gate = mb.clip(x=mb.add(x=value, y=3.0), alpha=0.0, beta=6.0)
|
|
311
|
+
scaled = mb.mul(y=gate, x=value)
|
|
312
|
+
ctx.add(mb.real_div(x=scaled, y=6.0, name=torch_node.name))
|
|
416
313
|
```
|
|
417
314
|
|
|
418
|
-
##
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
6. **Converting from ONNX directly.** ONNX conversion is deprecated. Convert
|
|
429
|
-
from the original framework.
|
|
430
|
-
7. **Not testing on physical devices.** Simulator does not support Metal GPU
|
|
431
|
-
or Neural Engine.
|
|
315
|
+
## Conversion mistakes
|
|
316
|
+
|
|
317
|
+
- Tracing or exporting without `model.eval()`.
|
|
318
|
+
- `RangeDim` where `EnumeratedShapes` would do.
|
|
319
|
+
- Targeting the neural network format for a new model.
|
|
320
|
+
- Leaving out `minimum_deployment_target`; always set it.
|
|
321
|
+
- Picking Float32 when Float16 is accurate enough.
|
|
322
|
+
- Converting straight from ONNX.
|
|
323
|
+
- Testing only in the Simulator, which has no Metal GPU or Neural Engine path;
|
|
324
|
+
verify on physical devices.
|