Core AI is Apple's new Python-based suite for converting, optimizing, and deploying PyTorch models on Apple Silicon. It covers the full lifecycle from torch.export through compression via coreai-opt to on-device inference, with a companion Core AI Debugger app for runtime inspection.
• Convert any PyTorch model to an optimized .aimodel asset with a handful of Python calls — no manual Metal or ANE tuning required
• Config-driven quantization presets (w4, int8, FP8) shrink large models like SAM3 from 3 GB to ~430 MB while keeping the same export pipeline
• Core AI Debugger lets you visualize graph structure, inspect intermediate tensors per-operation, and validate against a PyTorch reference run — all without code changes
Shows the Core AI Python conversion pipeline: exporting a PyTorch model, applying a 4-bit weight compression preset with coreai-opt, and loading the resulting .aimodel for on-device inference — then loading it in a SwiftUI app via CoreML.
import SwiftUI
import CoreML
import CoreImage
// MARK: - CoreML model wrapper for a Core AI–authored .aimodel asset
// The .aimodel is produced offline by the coreai-torch Python pipeline:
// exported = torch.export.export(model, example_inputs)
// core_ai_program = TorchConverter().convert(exported, ...)
// compressed = Quantizer(config=presets.w4).finalize(core_ai_program)
// asset = compressed.specialize() // writes MyModel.aimodel
// Then add MyModel.mlpackage to your Xcode project.
struct CoreAIInferenceView: View {
@State private var resultLabel: String = "Tap Run to infer"
@State private var isRunning = false
var body: some View {
VStack(spacing: 24) {
Text("Core AI On-Device Inference")
.font(.headline)
Text(resultLabel)
.multilineTextAlignment(.center)
.padding()
Button(isRunning ? "Running…" : "Run Model") {
Task { await runInference() }
}
.buttonStyle(.borderedProminent)
.disabled(isRunning)
}
.padding()
}
@MainActor
private func runInference() async {
isRunning = true
defer { isRunning = false }
do {
// Load the Core AI–authored model compiled from the .mlpackage
let config = MLModelConfiguration()
config.computeUnits = .all // ANE + GPU + CPU
// MLModel(contentsOf:configuration:) loads any .mlmodelc
// produced from a coreai-torch conversion output.
guard let modelURL = Bundle.main.url(
forResource: "SAM3_w4",
withExtension: "mlmodelc"
) else {
resultLabel = "Model file not found in bundle."
return
}
let model = try await MLModel.load(
contentsOf: modelURL,
configuration: config
)
// Build a feature provider with the inputs the model expects.
// Input names come from the TorchConverter call:
// TorchConverter().convert(exported, input_names:["pixel_values",
// "input_ids", "attention_mask"])
let pixelValues = try MLMultiArray(shape: [1, 3, 1024, 1024],
dataType: .float16)
let inputIDs = try MLMultiArray(shape: [1, 77],
dataType: .int32)
let attentionMask = try MLMultiArray(shape: [1, 77],
dataType: .int32)
// Fill with dummy data for demonstration
for i in 0 ..< pixelValues.count { pixelValues[i] = 0.5 }
for i in 0 ..< inputIDs.count { inputIDs[i] = 0 }
for i in 0 ..< attentionMask.count { attentionMask[i] = 1 }
let provider = try MLDictionaryFeatureProvider(dictionary: [
"pixel_values": MLFeatureValue(multiArray: pixelValues),
"input_ids": MLFeatureValue(multiArray: inputIDs),
"attention_mask": MLFeatureValue(multiArray: attentionMask)
])
let startTime = Date()
let output = try await model.prediction(from: provider)
let elapsed = Date().timeIntervalSince(startTime)
// The w4-compressed SAM3 outputs a segmentation mask tensor.
if let maskArray = output.featureValue(for: "pred_masks")?.multiArrayValue {
resultLabel = "✅ Inference OK in \(String(format: "%.2f", elapsed))s\n" +
"Mask shape: \(maskArray.shape)\n" +
"Model: SAM3 w4 (≈430 MB, down from 3 GB)"
} else {
resultLabel = "⚠️ Output tensor 'pred_masks' not found."
}
} catch {
resultLabel = "❌ Error: \(error.localizedDescription)"
}
}
}
#Preview {
CoreAIInferenceView()
}Foundation Models is a new Apple framework introduced in iOS 27 that gives developers on-device access to the same Apple Intelligence language model powering system features, enabling text generation, structured output, and tool-calling entirely on-device without a network connection.
Visual Intelligence brings iOS 17's Visual Look Up capabilities to a new developer-facing API surface in iOS 27, letting apps pipe live camera frames or static images through on-device scene understanding to extract subjects, text, barcodes, and rich semantic labels without any cloud round-trip.
iOS 27 opens the Foundation Models framework to third-party LLM providers via a new public LanguageModel protocol, allowing anyone to integrate server-based or local models (e.g. Claude, Gemini, CoreAI, MLX) using the same API as Apple's on-device system model.
In-depth guide
iOS 27 On-Device AI & Apple Intelligence →• coreai-torch and coreai-opt are Python packages installed via pip — they are part of the authoring/conversion toolchain, not a Swift runtime API
• The save_intermediates API used in the Debugger workflow is new in iOS 27 and not available in earlier CoreML Tools versions
• w4 presets apply aggressive per-layer quantization uniformly — layer-sensitive models may need per-layer overrides to maintain accuracy
• EAGER execution mode is for weight-only compression; use GRAPH mode when quantizing activations
On-device specialization and inference require Apple Silicon (A-series or M-series); Core AI Debugger is a macOS standalone application
iOS 27 opens the Foundation Models framework to third-party LLM providers via a new public LanguageModel protocol, enabling anyone to integrate custom, server-based, or open-source models using the same Swift API as Apple's on-device system model.