Section 3/161 menit

3. Teori: Cara Kerja Core ML

3. Teori: Cara Kerja Core ML

Pipeline Eksekusi

Ketika kamu memanggil model.prediction(input:), Core ML menjalankan pipeline ini:

swift
1. Input Validation
   └─ Verifikasi shape, dtype, range sesuai model spec

2. Preprocessing (opsional, tergantung model)
   └─ Normalisasi, resize, color space conversion

3. Compute Plan Selection
   └─ Pilih hardware: Neural Engine > GPU > CPU
   └─ Fallback otomatis jika hardware tidak support

4. Model Execution
   └─ Layer-by-layer forward pass
   └─ Di-tile untuk cache locality

5. Postprocessing (opsional)
   └─ Softmax, NMS untuk detection, dll

6. Output Formatting
   └─ Convert ke Swift types yang di-generate

Format File Model

Format Ekstensi Keterangan
Core ML Package .mlpackage Format baru (iOS 15+), folder-based, metadata lengkap
Core ML Bundle .mlmodelc Compiled form, yang di-bundle ke app
Core ML Model .mlmodel Source form, dikompilasi Xcode saat build

Saat build, Xcode mengkompilasi .mlmodel.mlmodelc dan meng-generate Swift wrapper class.

Neural Engine (ANE)

Apple Neural Engine adalah dedicated co-processor untuk operasi matrix multiply yang dominan di neural network. Keunggulan ANE:

  • Throughput: 15–35 TOPS (Tera Operations Per Second) di chip A-series terbaru
  • Efisiensi daya: 10–20x lebih efisien dari GPU untuk workload ML
  • Batasan: Hanya mendukung subset operasi (tidak semua layer type), precision terbatas (Float16/Int8)

Core ML secara otomatis mem-partition model: layer yang didukung ANE dijalankan di ANE, sisanya di CPU/GPU.