coreml-optimizer

Optimize CoreML models for iOS and macOS deployment using quantization, palettization, and pruning.

1|Updated May 6, 2026
One-click install
npx skills add https://github.com/surfingalien/FinSurfing --skill coreml-optimizer-surfingalien
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: coreml-optimizer
Source: https://github.com/surfingalien/FinSurfing/tree/main/.claude/skills/coreml-optimizer
Command: npx skills add https://github.com/surfingalien/FinSurfing --skill coreml-optimizer-surfingalien

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires coremltools, and includes references (resource) components.

What problem does it solve? Converting and deploying machine learning models on Apple devices often results in slow inference, oversized models, or models that never reach the Neural Engine. This Skill provides systematic guidance to compress CoreML models, target the right compute units, and profile on-device performance. ## Core Features & Use Cases - Weight Compression: Apply 8-bit and 4-bit quantization, k-means palettization, and magnitude pruning via coremltools, with combined compression pipelines. - Neural Engine Targeting: Configure MLModelConfiguration compute units, detect ANE usage, and fix operations that fall back to CPU/GPU. - Performance Profiling: Benchmark latency in Python and Swift, profile full pre/post-processing pipelines, and analyze layer execution with Xcode Instruments. - Use Case: You converted a PyTorch vision model to CoreML but inference takes 200ms on an iPhone. Use this Skill to verify compute unit configuration, apply per-channel INT8 quantization, and re-benchmark to reach under 50ms. ## Quick Start Ask the assistant to quantize your CoreML model to 8-bit precision and explain how to verify it runs on the Neural Engine.

Frequently Asked Questions about coreml-optimizer

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I quantize a CoreML model to 8-bit?

Use coremltools.optimize with OpLinearQuantizerConfig set to linear_symmetric mode, int8 dtype, and per_channel granularity, then call linear_quantize_weights on your MLModel. This typically reduces size by 75% with 2-3x speedup and minimal accuracy loss.

How do I check if my CoreML model uses the Neural Engine?

Benchmark the model with computeUnits set to .all versus .cpuAndGPU; if .all is significantly faster, the Neural Engine is active. You can also pause the app in the debugger and look for the H11ANEServicesThread, or use the Core ML Instruments template.

Why is my CoreML model inference slow on iPhone?

Slow inference usually comes from CPU-bound execution, unsupported operations falling back from the Neural Engine, or unoptimized pre/post-processing. Verify compute unit configuration, use ML Program format with fixed tensor shapes, and profile the full pipeline rather than just prediction.

What is the difference between quantization and palettization in coremltools?

Quantization maps weights to lower-precision integers like int8 or int4, while palettization clusters weights into a small lookup table using k-means. Palettization often preserves accuracy better for models sensitive to quantization, and both are well-optimized for the Neural Engine.

Which operations prevent CoreML from using the Neural Engine?

Dynamic tensor shapes, TopK, Scatter, GatherND, custom layers without ANE kernels, very large spatial dimensions over 4096, and odd channel counts fall back to CPU or GPU. Use fixed shapes, batch size of 1, and channel counts that are multiples of 8 or 16.

How do I fix accuracy loss after CoreML quantization?

Use per-channel granularity, supply calibration data of around 128 representative samples, or switch to palettization. You can also apply mixed precision by keeping sensitive layers like the first convolution and final classifier in float16.