@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,493 +1,466 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: apple-on-device-ai
|
|
3
|
-
description: "
|
|
3
|
+
description: "On-device AI on Apple hardware: Foundation Models (SystemLanguageModel, LanguageModelSession, @Generable and @Guide structured output, tool calling), coremltools conversion, quantization, palettization, pruning, Neural Engine and MLTensor, MLX Swift transformer inference on unified memory, llama.cpp GGUF models. Use when building tool-calling AI features, designing guided generation schemas, converting a model or running inference on device. Not for Swift-side Core ML integration (coreml), OCR, sentiment, NER or classifier training."
|
|
4
4
|
metadata:
|
|
5
|
-
source:
|
|
5
|
+
source: multi-agent-pipeline
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
# On-
|
|
8
|
+
# On-device AI on Apple platforms
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
Four stacks run models locally on Apple hardware. Pick by the job, the OS floor
|
|
11
|
+
and the model you need, then follow the stack's rules for availability, memory
|
|
12
|
+
and testing.
|
|
12
13
|
|
|
13
14
|
## Contents
|
|
14
15
|
|
|
15
|
-
- [
|
|
16
|
-
- [
|
|
17
|
-
- [Core ML
|
|
18
|
-
- [MLX Swift
|
|
19
|
-
- [
|
|
20
|
-
- [Performance
|
|
21
|
-
- [
|
|
22
|
-
- [
|
|
23
|
-
- [
|
|
16
|
+
- [Choosing a stack](#choosing-a-stack)
|
|
17
|
+
- [Foundation Models](#foundation-models)
|
|
18
|
+
- [Core ML](#core-ml)
|
|
19
|
+
- [MLX Swift](#mlx-swift)
|
|
20
|
+
- [Running several backends](#running-several-backends)
|
|
21
|
+
- [Performance habits](#performance-habits)
|
|
22
|
+
- [Mistakes to catch](#mistakes-to-catch)
|
|
23
|
+
- [Before approving](#before-approving)
|
|
24
|
+
- [Reference files](#reference-files)
|
|
24
25
|
|
|
25
|
-
##
|
|
26
|
+
## Choosing a stack
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
**Foundation Models** gives apps the system language model. It runs on iOS 26+
|
|
29
|
+
and macOS 26+ where Apple Intelligence is enabled, and covers summaries, text
|
|
30
|
+
generation, typed output, pulling entities out of text, and brief back-and-forth
|
|
31
|
+
chat. The app ships no API key, runs no server and makes no network call, yet it
|
|
32
|
+
still has to cope with model assets that are not downloaded yet.
|
|
28
33
|
|
|
29
|
-
|
|
34
|
+
- Fits: typed output with `@Generable`; summarizing, classifying and tagging;
|
|
35
|
+
generation that calls app code through the `Tool` protocol; features where
|
|
36
|
+
data must stay on the device.
|
|
37
|
+
- Does not fit: complex math, writing code, answers that must be factually
|
|
38
|
+
right, or apps that still support releases before iOS 26.
|
|
30
39
|
|
|
31
|
-
**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
handle system model asset readiness.
|
|
40
|
+
**Core ML** runs models you trained yourself (vision, text, audio) on every
|
|
41
|
+
Apple platform, after coremltools converts them from scikit-learn, TensorFlow
|
|
42
|
+
or PyTorch.
|
|
35
43
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
- Apps that need guaranteed on-device privacy
|
|
44
|
+
- Fits: image classification, detection and segmentation; custom text or
|
|
45
|
+
sentiment classifiers; audio through SoundAnalysis; tuning for the Neural
|
|
46
|
+
Engine; models that need compressing by quantization, pruning or
|
|
47
|
+
palettization.
|
|
41
48
|
|
|
42
|
-
**
|
|
43
|
-
|
|
49
|
+
**MLX Swift** runs particular open-weight models (Gemma, Qwen, Mistral, Llama)
|
|
50
|
+
and reaches the best sustained speed on Apple Silicon. It is also a good
|
|
51
|
+
research and prototyping tool.
|
|
44
52
|
|
|
45
|
-
|
|
53
|
+
- Fits: highest token rate on Apple Silicon; models from the `mlx-community`
|
|
54
|
+
organisation on Hugging Face; research that needs automatic differentiation;
|
|
55
|
+
fine-tuning on a Mac.
|
|
46
56
|
|
|
47
|
-
**
|
|
48
|
-
|
|
49
|
-
with coremltools.
|
|
57
|
+
**llama.cpp** runs GGUF models on nearly any platform and suits production apps
|
|
58
|
+
that need wide device coverage.
|
|
50
59
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
- Custom NLP classifiers, sentiment analysis models
|
|
54
|
-
- Audio/speech models via SoundAnalysis integration
|
|
55
|
-
- Any scenario needing Neural Engine optimization
|
|
56
|
-
- Models requiring quantization, palettization, or pruning
|
|
60
|
+
- Fits: quantized GGUF files (Q4_K_M, Q5_K_M, Q8_0); one engine across iOS,
|
|
61
|
+
Android and desktop; the broadest open model ecosystem.
|
|
57
62
|
|
|
58
|
-
|
|
63
|
+
Quick routing:
|
|
59
64
|
|
|
60
|
-
|
|
61
|
-
on Apple Silicon with maximum throughput. Research and prototyping.
|
|
62
|
-
|
|
63
|
-
**Best for:**
|
|
64
|
-
- Highest sustained token generation on Apple Silicon
|
|
65
|
-
- Running Hugging Face models from `mlx-community`
|
|
66
|
-
- Research requiring automatic differentiation
|
|
67
|
-
- Fine-tuning workflows on Mac
|
|
68
|
-
|
|
69
|
-
### llama.cpp
|
|
70
|
-
|
|
71
|
-
**When to use:** Cross-platform LLM inference using GGUF model format. Production
|
|
72
|
-
deployments needing broad device support.
|
|
73
|
-
|
|
74
|
-
**Best for:**
|
|
75
|
-
- GGUF quantized models (Q4_K_M, Q5_K_M, Q8_0)
|
|
76
|
-
- Cross-platform apps (iOS + Android + desktop)
|
|
77
|
-
- Maximum compatibility with open-source model ecosystem
|
|
78
|
-
|
|
79
|
-
### Quick Reference
|
|
80
|
-
|
|
81
|
-
| Scenario | Framework |
|
|
65
|
+
| Need | Go to |
|
|
82
66
|
|---|---|
|
|
83
|
-
|
|
|
84
|
-
|
|
|
85
|
-
| Image classification
|
|
86
|
-
|
|
|
87
|
-
|
|
|
88
|
-
|
|
|
89
|
-
|
|
|
90
|
-
|
|
|
91
|
-
| Sentiment
|
|
92
|
-
|
|
|
67
|
+
| Generate text where Apple Intelligence is on (iOS 26+) | Foundation Models |
|
|
68
|
+
| Typed LLM output | Foundation Models, `@Generable` |
|
|
69
|
+
| Image classification or object detection | Core ML |
|
|
70
|
+
| Bring a PyTorch or TensorFlow model | Core ML, converted with coremltools |
|
|
71
|
+
| Top speed on Apple Silicon | MLX Swift |
|
|
72
|
+
| A named open-weight LLM | MLX Swift or llama.cpp |
|
|
73
|
+
| One LLM engine on every platform | llama.cpp |
|
|
74
|
+
| Read text in images (OCR) | Vision |
|
|
75
|
+
| Sentiment, named entities, tokenization | Natural Language |
|
|
76
|
+
| Train a custom classifier on device | Create ML |
|
|
93
77
|
|
|
94
|
-
##
|
|
78
|
+
## Foundation Models
|
|
95
79
|
|
|
96
|
-
|
|
97
|
-
supporting Apple Intelligence (iOS 26+, macOS 26+).
|
|
80
|
+
Facts that shape every design:
|
|
98
81
|
|
|
99
|
-
-
|
|
100
|
-
-
|
|
101
|
-
|
|
102
|
-
|
|
82
|
+
- Prompt and reply draw on one token budget. `contextSize` gives its size.
|
|
83
|
+
- Choose the locale before generating: try `Locale.current`, then the user's
|
|
84
|
+
other preferred languages, with `supportsLocale(_:)`. Do not match against
|
|
85
|
+
`supportedLanguages` yourself.
|
|
86
|
+
- Guardrails are always on and cannot be disabled.
|
|
103
87
|
|
|
104
|
-
###
|
|
88
|
+
### Check availability first
|
|
105
89
|
|
|
106
|
-
|
|
90
|
+
Every entry point checks availability and falls back without crashing.
|
|
107
91
|
|
|
108
92
|
```swift
|
|
93
|
+
import Foundation
|
|
109
94
|
import FoundationModels
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
95
|
+
import os
|
|
96
|
+
|
|
97
|
+
private let aiLog = Logger(subsystem: "StudyApp", category: "AI")
|
|
98
|
+
|
|
99
|
+
enum SummaryState { case ready, openSettings, downloading, unsupported }
|
|
100
|
+
|
|
101
|
+
func summaryState() -> SummaryState {
|
|
102
|
+
let model = SystemLanguageModel.default
|
|
103
|
+
switch model.availability {
|
|
104
|
+
case .available:
|
|
105
|
+
return model.supportsLocale(Locale.current) ? .ready : .unsupported
|
|
106
|
+
case .unavailable(.appleIntelligenceNotEnabled):
|
|
107
|
+
return .openSettings // point the user to Settings
|
|
108
|
+
case .unavailable(.modelNotReady):
|
|
109
|
+
return .downloading // assets still arriving; show progress
|
|
110
|
+
case .unavailable(.deviceNotEligible):
|
|
111
|
+
return .unsupported // hardware cannot run it; use a fallback
|
|
112
|
+
case .unavailable(let other):
|
|
113
|
+
aiLog.notice("Model unavailable: \(String(describing: other))")
|
|
114
|
+
return .unsupported
|
|
116
115
|
}
|
|
117
|
-
// Proceed with model usage
|
|
118
|
-
case .unavailable(.appleIntelligenceNotEnabled):
|
|
119
|
-
// Guide user to enable Apple Intelligence in Settings
|
|
120
|
-
case .unavailable(.modelNotReady):
|
|
121
|
-
// System model assets are not ready; show loading state
|
|
122
|
-
case .unavailable(.deviceNotEligible):
|
|
123
|
-
// Device cannot run Apple Intelligence; use fallback
|
|
124
|
-
case .unavailable(let reason):
|
|
125
|
-
// Unknown or future unavailable reason; use fallback and log reason
|
|
126
116
|
}
|
|
127
117
|
```
|
|
128
118
|
|
|
129
|
-
###
|
|
119
|
+
### Sessions
|
|
130
120
|
|
|
131
121
|
```swift
|
|
132
|
-
|
|
133
|
-
let session = LanguageModelSession()
|
|
122
|
+
let plain = LanguageModelSession()
|
|
134
123
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
"You are a helpful cooking assistant."
|
|
124
|
+
let tutor = LanguageModelSession {
|
|
125
|
+
"You write short study notes for high-school biology."
|
|
138
126
|
}
|
|
139
127
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
tools: [weatherTool, recipeTool]
|
|
143
|
-
) {
|
|
144
|
-
"You are a helpful assistant with access to tools."
|
|
128
|
+
let withTools = LanguageModelSession(tools: [GlossaryTool()]) {
|
|
129
|
+
"Explain terms using the glossary when a term is unfamiliar."
|
|
145
130
|
}
|
|
131
|
+
|
|
132
|
+
let resumed = LanguageModelSession(model: .default, tools: [], transcript: savedTranscript)
|
|
146
133
|
```
|
|
147
134
|
|
|
148
|
-
|
|
149
|
-
-
|
|
150
|
-
|
|
151
|
-
-
|
|
152
|
-
|
|
135
|
+
- A session remembers the conversation; each turn sees the ones before it.
|
|
136
|
+
- A session serves a single request at once. `isResponding` is true while one
|
|
137
|
+
is in flight.
|
|
138
|
+
- Prewarm with `session.prewarm()` ahead of the user's first question so the
|
|
139
|
+
first reply arrives sooner.
|
|
140
|
+
- Restore a conversation by passing a saved `Transcript`.
|
|
153
141
|
|
|
154
|
-
### Structured
|
|
142
|
+
### Structured output
|
|
155
143
|
|
|
156
|
-
|
|
144
|
+
`@Generable` builds the output schema at compile time, and the response comes
|
|
145
|
+
back as your type.
|
|
157
146
|
|
|
158
147
|
```swift
|
|
159
148
|
@Generable
|
|
160
|
-
struct
|
|
161
|
-
@Guide(description: "The
|
|
162
|
-
var
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
@Guide(description: "Prep time in minutes", .range(1...120))
|
|
168
|
-
var prepTime: Int
|
|
149
|
+
struct StudyCard {
|
|
150
|
+
@Guide(description: "The term being studied, two to four words")
|
|
151
|
+
var term: String
|
|
152
|
+
@Guide(description: "Plain-language definitions", .count(2))
|
|
153
|
+
var definitions: [String]
|
|
154
|
+
@Guide(.range(1...5))
|
|
155
|
+
var difficulty: Int
|
|
169
156
|
}
|
|
170
157
|
|
|
171
|
-
let
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
)
|
|
175
|
-
print(response.content.name)
|
|
158
|
+
let reply = try await tutor.respond(to: "Make a card for osmosis",
|
|
159
|
+
generating: StudyCard.self)
|
|
160
|
+
let card = reply.content
|
|
176
161
|
```
|
|
177
162
|
|
|
178
|
-
|
|
163
|
+
`@Guide` options:
|
|
179
164
|
|
|
180
|
-
|
|
|
165
|
+
| Guide | Effect |
|
|
181
166
|
|---|---|
|
|
182
|
-
| `description:` | Natural
|
|
183
|
-
| `.anyOf([
|
|
184
|
-
| `.count(n)` |
|
|
185
|
-
| `.range(
|
|
186
|
-
| `.minimum(n)` / `.maximum(n)` |
|
|
187
|
-
| `.minimumCount(n)` / `.maximumCount(n)` |
|
|
188
|
-
| `.constant(value)` |
|
|
189
|
-
| `.pattern(regex)` | String
|
|
190
|
-
| `.element(guide)` |
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
167
|
+
| `description:` | Natural-language hint for the field |
|
|
168
|
+
| `.anyOf([...])` | String must be one of the listed values |
|
|
169
|
+
| `.count(n)` | Array has exactly `n` elements |
|
|
170
|
+
| `.range(a...b)` | Number within a closed range |
|
|
171
|
+
| `.minimum(n)` / `.maximum(n)` | Lower or upper limit on a number |
|
|
172
|
+
| `.minimumCount(n)` / `.maximumCount(n)` | Limits on how many elements an array has |
|
|
173
|
+
| `.constant(value)` | Field is always exactly this |
|
|
174
|
+
| `.pattern(regex)` | String matches a pattern |
|
|
175
|
+
| `.element(guide)` | Applies a guide to every array element |
|
|
176
|
+
|
|
177
|
+
Fields are generated in declaration order. Put the fields that others depend on
|
|
178
|
+
first.
|
|
179
|
+
|
|
180
|
+
Streaming gives partial values as they form; each property of
|
|
181
|
+
`StudyCard.PartiallyGenerated` is optional:
|
|
196
182
|
|
|
197
183
|
```swift
|
|
198
|
-
let
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
for try await snapshot in stream {
|
|
203
|
-
// snapshot.content is Recipe.PartiallyGenerated (all properties optional)
|
|
204
|
-
if let name = snapshot.content.name { updateNameLabel(name) }
|
|
184
|
+
let cardStream = tutor.streamResponse(to: "Card for diffusion", generating: StudyCard.self)
|
|
185
|
+
for try await partial in cardStream {
|
|
186
|
+
draft.term = partial.content.term ?? draft.term
|
|
187
|
+
draft.definitions = partial.content.definitions ?? draft.definitions
|
|
205
188
|
}
|
|
206
189
|
```
|
|
207
190
|
|
|
208
|
-
###
|
|
191
|
+
### Tools
|
|
209
192
|
|
|
210
193
|
```swift
|
|
211
|
-
struct
|
|
212
|
-
let name = "
|
|
213
|
-
let description = "
|
|
194
|
+
struct GlossaryTool: Tool {
|
|
195
|
+
let name = "lookUpTerm"
|
|
196
|
+
let description = "Returns the course glossary entry for a biology term."
|
|
214
197
|
|
|
215
198
|
@Generable
|
|
216
199
|
struct Arguments {
|
|
217
|
-
@Guide(description: "
|
|
218
|
-
var
|
|
200
|
+
@Guide(description: "Singular form of the term to look up")
|
|
201
|
+
var term: String
|
|
202
|
+
@Guide(.range(1...3))
|
|
203
|
+
var gradeLevel: Int
|
|
219
204
|
}
|
|
220
205
|
|
|
221
206
|
func call(arguments: Arguments) async throws -> String {
|
|
222
|
-
|
|
223
|
-
|
|
207
|
+
await Glossary.shared.entry(for: arguments.term, level: arguments.gradeLevel)
|
|
208
|
+
?? "No entry found."
|
|
224
209
|
}
|
|
225
210
|
}
|
|
226
211
|
```
|
|
227
212
|
|
|
228
|
-
Register
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
213
|
+
- Register tools when creating the session, and only the ones the task needs.
|
|
214
|
+
- `Tool` is `Sendable`; captured state must be safe to share.
|
|
215
|
+
- Tool names, descriptions and argument schemas, like `@Generable` schemas,
|
|
216
|
+
use up part of the context budget.
|
|
217
|
+
- Whether a tool runs is the model's decision. Data the answer always needs
|
|
218
|
+
should be fetched beforehand and put in the prompt; keep tools for lookups
|
|
219
|
+
that depend on the conversation.
|
|
232
220
|
|
|
233
|
-
###
|
|
221
|
+
### Errors
|
|
234
222
|
|
|
235
223
|
```swift
|
|
236
224
|
do {
|
|
237
|
-
let
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
case .
|
|
243
|
-
|
|
244
|
-
case .
|
|
245
|
-
|
|
246
|
-
case .
|
|
247
|
-
|
|
248
|
-
case .
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
// Model assets not available on device
|
|
252
|
-
case .refusal(let refusal, _):
|
|
253
|
-
// Model refused; stream refusal.explanation for details
|
|
254
|
-
case .rateLimited(let context):
|
|
255
|
-
// Too many requests; back off and retry
|
|
256
|
-
case .decodingFailure(let context):
|
|
257
|
-
// Response could not be decoded into the expected type
|
|
258
|
-
default: break
|
|
225
|
+
let answer = try await tutor.respond(to: question)
|
|
226
|
+
show(answer.content)
|
|
227
|
+
} catch let failure as LanguageModelSession.GenerationError {
|
|
228
|
+
switch failure {
|
|
229
|
+
case .exceededContextWindowSize: restartWithSummary() // too many tokens
|
|
230
|
+
case .guardrailViolation: showRephraseHint() // safety filter hit
|
|
231
|
+
case .concurrentRequests: queueUntilIdle() // session already busy
|
|
232
|
+
case .unsupportedLanguageOrLocale: showLanguageNotice()
|
|
233
|
+
case .unsupportedGuide: logSchemaProblem() // a @Guide the model cannot honour
|
|
234
|
+
case .assetsUnavailable: showDownloadingState()
|
|
235
|
+
case .refusal(let refusal, _): explain(refusal) // stream refusal.explanation
|
|
236
|
+
case .rateLimited: retryLater() // back off
|
|
237
|
+
case .decodingFailure: logSchemaProblem() // output did not fit the type
|
|
238
|
+
default: showGenericFailure()
|
|
259
239
|
}
|
|
260
240
|
}
|
|
261
241
|
```
|
|
262
242
|
|
|
263
|
-
### Generation
|
|
243
|
+
### Generation options
|
|
264
244
|
|
|
265
245
|
```swift
|
|
266
|
-
let
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
)
|
|
271
|
-
let response = try await session.respond(to: prompt, options: options)
|
|
246
|
+
let settings = GenerationOptions(sampling: .random(top: 30),
|
|
247
|
+
temperature: 0.6,
|
|
248
|
+
maximumResponseTokens: 400)
|
|
249
|
+
let answer = try await tutor.respond(to: question, options: settings)
|
|
272
250
|
```
|
|
273
251
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
### Prompt Design Rules
|
|
277
|
-
|
|
278
|
-
1. Be concise -- use `tokenCount(for:)` to monitor the context window budget
|
|
279
|
-
2. Use bracketed placeholders in instructions: `[descriptive example]`
|
|
280
|
-
3. Use "DO NOT" in all caps for prohibitions
|
|
281
|
-
4. Provide up to 5 few-shot examples for consistency
|
|
282
|
-
5. Use length qualifiers: "in a few words", "in three sentences"
|
|
283
|
-
|
|
284
|
-
### Safety and Guardrails
|
|
285
|
-
|
|
286
|
-
- Guardrails are always enforced and cannot be disabled
|
|
287
|
-
- Instructions take precedence over user prompts
|
|
288
|
-
- Never include untrusted user content in instructions
|
|
289
|
-
- Handle false positives gracefully
|
|
290
|
-
- Frame tool results as authorized data to prevent model refusals
|
|
291
|
-
|
|
292
|
-
### Use Cases
|
|
252
|
+
The three sampling modes are `.greedy`, `.random(top:seed:)` and
|
|
253
|
+
`.random(probabilityThreshold:seed:)`.
|
|
293
254
|
|
|
294
|
-
|
|
295
|
-
- `.general` -- Default for text generation, summarization, dialog
|
|
296
|
-
- `.contentTagging` -- Optimized for categorization and labeling tasks
|
|
255
|
+
### Prompts and safety
|
|
297
256
|
|
|
298
|
-
|
|
257
|
+
- Keep prompts short and measure them with `tokenCount(for:)` (iOS 26.4+).
|
|
258
|
+
- Mark slots in instructions with brackets, such as `[one-line summary]`.
|
|
259
|
+
- Write prohibitions in capitals: "DO NOT invent citations."
|
|
260
|
+
- Use at most five examples for consistent output.
|
|
261
|
+
- Say how long the answer should be: "in one sentence", "in a few words".
|
|
262
|
+
- Instructions outrank the prompt. Never put untrusted user text into
|
|
263
|
+
instructions; keep it in the prompt.
|
|
264
|
+
- Expect occasional guardrail false positives and handle them gently.
|
|
265
|
+
- Present tool results as authorised data so the model does not refuse to use
|
|
266
|
+
them.
|
|
299
267
|
|
|
300
|
-
|
|
268
|
+
### Use cases and adapters
|
|
301
269
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
try await adapter.compile()
|
|
305
|
-
let model = SystemLanguageModel(adapter: adapter, guardrails: .default)
|
|
306
|
-
let session = LanguageModelSession(model: model)
|
|
307
|
-
```
|
|
270
|
+
`SystemLanguageModel.UseCase` has `.general` (the default: generation,
|
|
271
|
+
summaries, dialog) and `.contentTagging` (labelling and categorising).
|
|
308
272
|
|
|
309
|
-
|
|
310
|
-
|
|
273
|
+
A fine-tuned adapter needs an entitlement. Load it with
|
|
274
|
+
`SystemLanguageModel.Adapter(name:)`, compile it with
|
|
275
|
+
`try await adapter.compile()`, wrap it as
|
|
276
|
+
`SystemLanguageModel(adapter: adapter, guardrails: .default)`, and pass that
|
|
277
|
+
model to `LanguageModelSession(model:)`.
|
|
311
278
|
|
|
312
|
-
|
|
279
|
+
Full API detail: [the Foundation Models reference](references/foundation-models.md).
|
|
313
280
|
|
|
314
|
-
|
|
315
|
-
optimal compute unit (CPU, GPU, or Neural Engine).
|
|
281
|
+
## Core ML
|
|
316
282
|
|
|
317
|
-
|
|
283
|
+
Core ML dispatches work to the CPU, GPU or Neural Engine by itself.
|
|
318
284
|
|
|
319
|
-
| Format |
|
|
320
|
-
|
|
321
|
-
| `.mlpackage`
|
|
322
|
-
| `.mlmodel`
|
|
323
|
-
| `.mlmodelc` | Compiled
|
|
324
|
-
|
|
325
|
-
Always use mlprogram (`.mlpackage`) for new work.
|
|
285
|
+
| Format | Use |
|
|
286
|
+
|---|---|
|
|
287
|
+
| `.mlpackage` (ML program) | Every new model; iOS 15+ |
|
|
288
|
+
| `.mlmodel` (neural network) | Older format, the only choice for iOS 11 to 14; do not use for new work |
|
|
289
|
+
| `.mlmodelc` | Compiled form that loads faster |
|
|
326
290
|
|
|
327
|
-
|
|
291
|
+
New conversions always target the ML program format:
|
|
328
292
|
|
|
329
293
|
```python
|
|
294
|
+
import torch
|
|
330
295
|
import coremltools as ct
|
|
331
296
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
297
|
+
net = build_segmenter()
|
|
298
|
+
net.eval() # never trace in training mode
|
|
299
|
+
sample = torch.rand(1, 3, 256, 256)
|
|
300
|
+
traced = torch.jit.trace(net, sample)
|
|
301
|
+
|
|
302
|
+
segmenter = ct.convert(
|
|
336
303
|
traced,
|
|
337
|
-
|
|
304
|
+
convert_to="mlprogram",
|
|
338
305
|
minimum_deployment_target=ct.target.iOS18,
|
|
339
|
-
|
|
306
|
+
inputs=[ct.TensorType(name="frame", shape=sample.shape)],
|
|
340
307
|
)
|
|
341
|
-
|
|
308
|
+
segmenter.save("Segmenter.mlpackage")
|
|
342
309
|
```
|
|
343
310
|
|
|
344
|
-
|
|
311
|
+
Compression at a glance:
|
|
345
312
|
|
|
346
|
-
| Technique | Size
|
|
313
|
+
| Technique | Size cut | Accuracy risk | Best on |
|
|
347
314
|
|---|---|---|---|
|
|
348
|
-
|
|
|
349
|
-
|
|
|
350
|
-
|
|
|
351
|
-
| W8A8 (weights
|
|
352
|
-
|
|
|
353
|
-
|
|
354
|
-
### Boundary with `coreml`
|
|
355
|
-
|
|
356
|
-
This skill owns Python-side conversion, compression, profiling, and framework
|
|
357
|
-
selection. Use the sibling `coreml` skill for Swift app integration, prediction
|
|
358
|
-
APIs, runtime configuration, Vision request wiring, and detailed model loading.
|
|
315
|
+
| 4-bit palettization | about 8x | low to medium | Neural Engine |
|
|
316
|
+
| INT8, per channel | about 4x | low | CPU and GPU |
|
|
317
|
+
| INT4, per block | about 8x | medium | GPU |
|
|
318
|
+
| W8A8 (weights and activations) | about 4x | low | Neural Engine on A17 Pro and M4 or later |
|
|
319
|
+
| 75% pruning | about 4x | medium | CPU, Neural Engine |
|
|
359
320
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
321
|
+
Boundary: this skill decides which framework to use and owns the Python side
|
|
322
|
+
(conversion, compression, profiling). The `coreml` skill owns the Swift side:
|
|
323
|
+
loading models in the app, runtime settings, calling predictions, and hooking
|
|
324
|
+
models into Vision requests.
|
|
363
325
|
|
|
364
|
-
|
|
326
|
+
Conversion: [the conversion guide](references/coreml-conversion.md).
|
|
327
|
+
Compression and profiling: [the optimization guide](references/coreml-optimization.md).
|
|
365
328
|
|
|
366
|
-
|
|
367
|
-
Apple Silicon via unified memory architecture.
|
|
329
|
+
## MLX Swift
|
|
368
330
|
|
|
369
|
-
|
|
331
|
+
MLX Swift gets the highest sustained throughput on Apple Silicon because CPU
|
|
332
|
+
and GPU share unified memory.
|
|
370
333
|
|
|
371
334
|
```swift
|
|
372
|
-
import MLX
|
|
373
|
-
import MLXLLM
|
|
374
335
|
import MLXLMCommon
|
|
336
|
+
import MLXLLM
|
|
375
337
|
import MLXLMHFAPI
|
|
338
|
+
import MLX
|
|
376
339
|
|
|
377
|
-
let
|
|
340
|
+
let factory = LLMModelFactory.shared
|
|
341
|
+
let modelContainer = try await factory.loadContainer(
|
|
378
342
|
from: HubClient.default,
|
|
379
343
|
using: TokenizersLoader(),
|
|
380
|
-
configuration:
|
|
344
|
+
configuration: ModelConfiguration(id: "mlx-community/Qwen3-1.7B-4bit")
|
|
381
345
|
)
|
|
382
|
-
let
|
|
383
|
-
|
|
346
|
+
let chat = ChatSession(modelContainer)
|
|
347
|
+
let text = try await chat.respond(to: "List three uses of chlorophyll.")
|
|
384
348
|
```
|
|
385
349
|
|
|
386
|
-
|
|
350
|
+
Starting points by device:
|
|
387
351
|
|
|
388
|
-
| Device
|
|
389
|
-
|
|
390
|
-
| iPhone 12
|
|
391
|
-
| iPhone 15 Pro
|
|
392
|
-
| Mac 8 GB |
|
|
393
|
-
| Mac 16 GB
|
|
352
|
+
| Device and RAM | Resident memory | Suggested model |
|
|
353
|
+
|---|---|---|
|
|
354
|
+
| iPhone 12 to 14, 4 to 6 GB | about 0.3 GB | SmolLM2-135M, or Qwen 2.5 at 0.5B |
|
|
355
|
+
| iPhone 15 Pro or newer, 8 GB | about 3.5 GB | Gemma 3n E4B at 4 bits |
|
|
356
|
+
| Mac, 8 GB | about 3 GB | Llama 3.2 3B at 4 bits |
|
|
357
|
+
| Mac, 16 GB or more | about 6 GB | Mistral 7B at 4 bits |
|
|
394
358
|
|
|
395
|
-
|
|
359
|
+
Memory rules:
|
|
396
360
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
361
|
+
- On iOS stay under 60% of total RAM.
|
|
362
|
+
- Cap the MLX cache: `Memory.cacheLimit = 512 * 1024 * 1024`.
|
|
363
|
+
- Release llama.cpp and MLX models on backgrounding or a memory warning, and
|
|
364
|
+
after heavy MLX generation also call `Memory.clearCache()`.
|
|
365
|
+
- Larger models need the Increased Memory Limit entitlement.
|
|
366
|
+
- Test MLX and llama.cpp code on real Apple Silicon hardware. The Simulator
|
|
367
|
+
does not run Metal inference and shows neither real memory limits nor real
|
|
368
|
+
speed.
|
|
404
369
|
|
|
405
|
-
|
|
406
|
-
> patterns and llama.cpp integration.
|
|
370
|
+
MLX lifecycle, llama.cpp and GGUF: [the MLX and llama.cpp guide](references/mlx-swift.md).
|
|
407
371
|
|
|
408
|
-
##
|
|
372
|
+
## Running several backends
|
|
409
373
|
|
|
410
|
-
|
|
374
|
+
Try the system model first, then a local open model, and fail clearly when
|
|
375
|
+
neither is there:
|
|
411
376
|
|
|
412
377
|
```swift
|
|
413
|
-
func
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
} else {
|
|
419
|
-
throw AIError.noBackendAvailable
|
|
420
|
-
}
|
|
378
|
+
func pickBackend() async throws -> Backend {
|
|
379
|
+
let systemModel = SystemLanguageModel.default
|
|
380
|
+
if systemModel.isAvailable { return .foundationModels }
|
|
381
|
+
if await mlxModelCanLoad() { return .mlx }
|
|
382
|
+
throw AIError.noBackendAvailable
|
|
421
383
|
}
|
|
422
384
|
```
|
|
423
385
|
|
|
424
|
-
|
|
386
|
+
Send every model call through one actor so requests never compete for the same
|
|
387
|
+
hardware. Actors are reentrant: a method that awaits lets the next caller in,
|
|
388
|
+
so an actor that only forwards the call does not serialise anything. Chain the
|
|
389
|
+
work instead:
|
|
425
390
|
|
|
426
391
|
```swift
|
|
427
|
-
actor
|
|
428
|
-
|
|
429
|
-
|
|
392
|
+
actor InferenceGate {
|
|
393
|
+
private var last: Task<Void, Never>?
|
|
394
|
+
|
|
395
|
+
func exclusive<Value: Sendable>(
|
|
396
|
+
_ work: @escaping @Sendable () async throws -> Value
|
|
397
|
+
) async throws -> Value {
|
|
398
|
+
let previous = last
|
|
399
|
+
let current = Task { () async throws -> Value in
|
|
400
|
+
await previous?.value
|
|
401
|
+
return try await work()
|
|
402
|
+
}
|
|
403
|
+
last = Task { _ = try? await current.value }
|
|
404
|
+
return try await current.value
|
|
430
405
|
}
|
|
431
406
|
}
|
|
432
407
|
```
|
|
433
408
|
|
|
434
|
-
For custom Core ML
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
- [ ]
|
|
476
|
-
|
|
477
|
-
- [ ]
|
|
478
|
-
- [ ]
|
|
479
|
-
- [ ]
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
- [ ]
|
|
484
|
-
|
|
485
|
-
- [ ]
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
- [
|
|
491
|
-
|
|
492
|
-
- [Core ML Optimization](references/coreml-optimization.md) -- Quantization, palettization, pruning, performance tuning
|
|
493
|
-
- [MLX Swift & llama.cpp](references/mlx-swift.md) -- MLX Swift patterns, llama.cpp integration, memory management
|
|
409
|
+
- For a custom Core ML model, this skill stops at conversion and
|
|
410
|
+
optimisation. Swift integration, loading, Vision hookup and running
|
|
411
|
+
predictions are for `coreml`.
|
|
412
|
+
- Private material such as journals or health notes stays on the device unless
|
|
413
|
+
the product has deliberately chosen a non-local fallback.
|
|
414
|
+
|
|
415
|
+
## Performance habits
|
|
416
|
+
|
|
417
|
+
1. Benchmark without the debugger: in the scheme's Run action (Cmd-Opt-R),
|
|
418
|
+
clear "Debug executable".
|
|
419
|
+
2. Prewarm Foundation Models sessions before the user needs them.
|
|
420
|
+
3. Ship Core ML models precompiled to `.mlmodelc`.
|
|
421
|
+
4. For the Neural Engine, prefer `EnumeratedShapes` to `RangeDim`.
|
|
422
|
+
5. Palettize to 4 bits for the lowest Neural Engine memory and latency.
|
|
423
|
+
6. Runtime code for Vision, Natural Language and Core ML in Swift belongs to
|
|
424
|
+
the skills for those frameworks.
|
|
425
|
+
|
|
426
|
+
## Mistakes to catch
|
|
427
|
+
|
|
428
|
+
| Mistake | Consequence | Fix |
|
|
429
|
+
|---|---|---|
|
|
430
|
+
| No availability check | Unsupported devices fail instead of degrading | Switch on `availability` first |
|
|
431
|
+
| No fallback UI | Users on older systems or with Apple Intelligence off get a blank feature | Always offer a degraded path |
|
|
432
|
+
| Overflowing the context | Input plus output exceed the window | Measure with `tokenCount(for:)` (iOS 26.4+), summarise |
|
|
433
|
+
| Two requests on one session | `concurrentRequests` error | Check `isResponding` or serialise |
|
|
434
|
+
| User text in instructions | Weakens the instruction boundary and guardrails | Keep user text in the prompt |
|
|
435
|
+
| Tracing without `model.eval()` | Dropout and batch-norm training behaviour baked in | Call `eval()` before trace or export |
|
|
436
|
+
| Converting to neural network format | Deprecated, missing features | Use ML program |
|
|
437
|
+
| MLX using over 60% RAM on iOS | App killed for memory | Pick a smaller model, cap caches |
|
|
438
|
+
| Trusting Simulator numbers for MLX | Misleading; it only proves UI and control flow | Measure on hardware |
|
|
439
|
+
| Releasing an MLX model but not its cache | Memory stays high | Call `Memory.clearCache()` as part of unloading |
|
|
440
|
+
|
|
441
|
+
## Before approving
|
|
442
|
+
|
|
443
|
+
- [ ] The framework matches the use case and the deployment target.
|
|
444
|
+
- [ ] Foundation Models: every call is preceded by an availability check, and
|
|
445
|
+
a degraded path exists.
|
|
446
|
+
- [ ] Foundation Models: sessions prewarmed, `@Generable` fields in dependency
|
|
447
|
+
order, token use compared with `contextSize`.
|
|
448
|
+
- [ ] Core ML: ML program `.mlpackage` (iOS 15+); the conversion, its
|
|
449
|
+
deployment target and any compression were verified.
|
|
450
|
+
- [ ] MLX: the model fits in the device's memory, the cache has a limit, and
|
|
451
|
+
caches are cleared when models are released.
|
|
452
|
+
- [ ] One coordinating actor mediates every model call.
|
|
453
|
+
- [ ] Model types and tools are `Sendable` or isolated to `@MainActor`.
|
|
454
|
+
- [ ] Tested on physical devices, not only the Simulator.
|
|
455
|
+
|
|
456
|
+
## Reference files
|
|
457
|
+
|
|
458
|
+
- [Foundation Models reference](references/foundation-models.md): the full API,
|
|
459
|
+
long conversations, feedback.
|
|
460
|
+
- [Conversion guide](references/coreml-conversion.md): coremltools from each
|
|
461
|
+
source framework, input types, shapes, deployment targets, stateful and
|
|
462
|
+
multifunction models.
|
|
463
|
+
- [Optimization guide](references/coreml-optimization.md): quantizing,
|
|
464
|
+
palettizing, pruning, QAT, Swift loading basics, profiling.
|
|
465
|
+
- [MLX and llama.cpp guide](references/mlx-swift.md): MLX Swift lifecycle,
|
|
466
|
+
llama.cpp, GGUF levels, routing between backends, built-in frameworks.
|