ckorhonen/claude-skills/coreml-optimizer
Claude Code and agent skill by ckorhonen/claude-skills
- community
Checking that the SKILL.md file is still in the repository.
Optimize CoreML models for iOS and macOS deployment. Covers quantization, palettization, pruning, Neural Engine targeting, compute unit selection, and performance profiling. Use when converting ML models to CoreML, optimizing model size/latency, debugging Neural Engine issues, or benchmarking on-device inference.
Install
npx vskill@latest install ckorhonen/claude-skills/coreml-optimizerSKILL.md
CoreML Optimizer
Expert guidance for optimizing machine learning models for Apple's CoreML framework on iOS and macOS devices.
When to Use This Skill
Use this skill when:
- Converting PyTorch/TensorFlow models to CoreML format
- Optimizing CoreML model size and inference latency
- Targeting the Neural Engine for maximum performance
- Debugging slow model inference or compute unit issues
- Applying quantization, palettization, or pruning
- Profiling model performance with Instruments
- Troubleshooting accuracy degradation after compression
Speed Optimization Checklist
The critical path to fast CoreML inference:
1. Verify Compute Unit Configuration
Many "slow" models are accidentally CPU-bound. Configure via MLModelConfiguration.computeUnits:
| Option | Description | |
|---|---|---|
.all | Uses all available compute units including Neural Engine (default, recommended) | |
.cpuAndNeuralEngine | CPU + Neural Engine, excludes GPU | |
.cpuAndGPU | CPU + GPU, excludes Neural Engine | |
.cpuOnly | Forces CPU-only execution (for debugging/consistency) |
In Swift:
Benchmark each configuration - if .all isn't faster than .cpuAndGPU, your model may not be hitting the Neural Engine.
2. Apply Weight Compression with coremltools
CoreML execution commonly uses float16 where possible. Use coremltools.optimize for further compression:
3. Consider 4-bit Quantization
Recent coremltools releases support 4-bit quantization for even more aggressive compression:
4. Profile the FULL Pipeline
Pre/post-processing (image resize, tokenization, NMS, etc.) is often the real bottleneck. Profile the entire pipeline, not just prediction().
Hardware Recommendations (iOS 18 / macOS 15)
| Technique | Best Hardware | Use Case | |
|---|---|---|---|
| Weight palettization (1-8 bit) | Neural Engine | Runtime memory + latency gains | |
| W8A8 quantization | Neural Engine (A17 Pro, M4) | Compute-bound models | |
| INT4 per-block quantization | GPU (Mac) | Large models on Mac | |
| Pruning (sparse weights) | Neural Engine, CPU | Memory-bound models |
Core Compression Techniques
Quantization
Reduces precision from float16/32 to int8/int4:
Expected results:
- INT8: ~75% size reduction, 2-3x speedup
- INT4: ~87.5% size reduction, 3-4x speedup
Palettization
Clusters weights into a small lookup table:
When to use: Models sensitive to quantization often tolerate palettization better.
Pruning
Zeros out unimportant weights:
Note: Training-aware pruning yields better results than post-training pruning.
Combined Compression
For maximum compression, combine techniques:
Neural Engine Optimization
Querying Neural Engine Capabilities (iOS 17+)
Checking Neural Engine Usage
Operations That Block Neural Engine
These operations fall back to CPU/GPU:
- Dynamic tensor shapes (use fixed shapes)
- TopK, Scatter, GatherND
- Custom layers without ANE implementation
- Very large spatial dimensions (>4096)
- Odd channel counts (prefer multiples of 8/16)
Optimal Tensor Shapes
Model Introspection
Inspect model structure before optimization:
Model Conversion Best Practices
Always Use ML Program Format
Embed Preprocessing
Handle Flexible Shapes
Performance Profiling
Python Benchmarking
Swift Benchmarking
Xcode Instruments
- Product > Profile (Cmd+I)
- Select "Core ML" template
- Record trace during inference
- Analyze:
- Layer-by-layer execution time
- Compute unit usage (ANE/GPU/CPU icons)
- Memory allocation patterns
Advanced Optimization APIs (iOS 17.4+)
MLOptimizationHints
Configure optimization behavior for different usage patterns:
ReshapeFrequency options:
.frequent- Minimizes latency when shapes change often. Individual predictions may be slower, but shape transitions are fast..infrequent- Re-optimizes for new shapes when they change. Initial delay but faster subsequent predictions for that shape.
MLComputePlan (Pre-Execution Analysis)
Analyze compute unit allocation and cost before running inference:
This helps identify which operations run on which compute units without executing inference.
MLState (Stateful Models - iOS 18+)
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationWarning, 90 of 100Marginal. 1 run. Evaluated 8 months ago.
Source
- SKILL.md in the repositoryCheckingskills/coreml-optimizer/SKILL.md
Popularity
- Repository stars
- 3
- 7-day trend score
- 7
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 21 Apr 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/ckorhonen/claude-skills/coreml-optimizer)