Symptom: Model loads on some devices but not others.
Cause: Unsupported operations for target compute unit.
Diagnosis:
Open model in Xcode
Create Performance Report
Check "Unsupported" operations
Hover for hints
Fix:
// Force CPU-only to bypass unsupported GPU/NE operationslet config =MLModelConfiguration()
config.computeUnits = .cpuOnly
let model =tryMLModel(contentsOf: url, configuration: config)
Better fix: Update model precision or operations during conversion:
# Float16 often better supported
mlmodel = ct.convert(traced, compute_precision=ct.precision.FLOAT16)
Pattern 1c - General Load Failures
Symptom: Model fails to load with unclear error.
Checklist:
Check file exists and is readable
Check compiled vs source model (runtime needs .mlmodelc)
Symptom: First prediction after install/update is slow, subsequent are fast.
Cause: Device specialization not cached.
Diagnosis:
Profile with Core ML Instrument
Look at Load event label:
"prepare and cache" = cache miss (slow)
"cached" = cache hit (fast)
Why cache misses:
First launch after install
System update invalidated cache
Low disk space cleared cache
Model file was modified
Mitigation:
// Warm cache in background at app launchTask.detached(priority: .background) {
_=try?awaitMLModel.load(contentsOf: modelURL)
}
Note: Cache is tied to (model path + configuration + device). Different configs = different cache entries.
Pattern 2b - All Predictions Slow
Symptom: Predictions consistently slow, not just first one.
Diagnosis:
Create Xcode Performance Report
Check compute unit distribution
Look for high-cost operations
Common causes:
Cause
Fix
Running on CPU when GPU/NE available
Check computeUnits config
Model too large for Neural Engine
Compress model
Frequent CPU↔GPU↔NE transfers
Adjust segmentation
Dynamic shapes recompiling
Use fixed/enumerated shapes
Profile compute unit usage:
let plan =tryawaitMLComputePlan.load(contentsOf: modelURL)
for op in plan.modelStructure.operations {
let info = plan.computeDeviceInfo(for: op)
print("\(op.name): \(info.preferredDevice)")
}
Pattern 2c - Slow on Specific Device
Symptom: Fast on Mac, slow on iPhone (or vice versa).
Cause: Different hardware characteristics.
Diagnosis:
// Check available computelet devices =MLModel.availableComputeDevices
print(devices) // Different per device
Common issues:
Scenario
Cause
Fix
Fast on M-series Mac, slow on iPhone
Model optimized for GPU
Use palettization (Neural Engine)
Fast on iPhone, slow on Intel Mac
No Neural Engine
Use quantization (GPU)
Slow on older devices
Less compute power
Use more aggressive compression
Recommendation: Profile on target devices, not just development Mac.
Pattern 3a - Memory Grows During Predictions
Symptom: Memory increases with each prediction, doesn't release.
Cause: Input/output buffers accumulating from concurrent predictions.
Diagnosis:
Instruments → Allocations + Core ML template
Look for: Many concurrent prediction intervals
Check: MLMultiArray allocations growing