Skip to content
Back to skills

Optimize Models

ASecurity

"Guide coremltools model compression and optimization with Core ML

  • 247 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 8, 2026
toolsrailsdebuggingapi

Works with

  • api

Security analysis

A100/100

Pro scans all 5 files and shows the line behind each finding

Scanned September 8, 2026

npx -y skills add VectorSpaceLab/AREX-Skill --skill optimize-models --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Optimize Models?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Optimize Models
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/vectorspacelab-optimize-models/badge)](https://www.skillsdirectory.com/skills/vectorspacelab-optimize-models)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: optimize-models
description: "Guide coremltools model compression and optimization with Core ML
  package APIs and optional PyTorch optimization APIs."
disable-model-invocation: true
metadata:
  disco-role: operating
license: BSD 3-Clause
---
# optimize-models

Use this sub-skill when the task is to compress or optimize an already-converted Core ML model, or to choose an optional PyTorch-side optimization flow before Core ML export. It covers weight quantization, activation quantization with calibration data, palettization, pruning, decompression, metadata discovery, and joint compression choices.

## Route first

- Need to convert an original TensorFlow, PyTorch, sklearn, XGBoost, LightGBM, LibSVM, MIL, or other source model into Core ML before compression? Route to [convert-models](../convert-models/SKILL.md).
- Need to load, save, inspect metadata/specs, rename features, or run `MLModel.predict()` on an artifact? Route to [model-io-and-prediction](../model-io-and-prediction/SKILL.md).
- Need to debug MIL graph passes, custom ops, typed execution, or pass pipelines? Route to [mil-and-debugging](../mil-and-debugging/SKILL.md).
- Already have a Core ML `mlprogram` and want data-free package compression? Stay here and prefer `coremltools.optimize.coreml`.
- Have a PyTorch model and need calibration-data or fine-tuning/QAT-aware compression before Core ML export? Stay here only if PyTorch and the relevant `coremltools.optimize.torch` APIs import in the user's environment.

## Quick decision rules

1. **No training data, Core ML artifact already exists:** use `coremltools.optimize.coreml` functions directly on an `MLModel` package.
2. **Calibration data needed:** use Core ML activation quantization only when you can supply Core ML input dictionaries and can run calibration; otherwise use the optional Torch layerwise/calibration APIs on a PyTorch source model.
3. **Fine-tuning or QAT required:** use optional `coremltools.optimize.torch` optimizers on the PyTorch model, then convert with [convert-models](../convert-models/SKILL.md).
4. **Need the smallest safe first pass:** inspect weights with `get_weights_metadata`, compress only large weight tensors, and set `op_name_configs` or `op_type_configs` to skip fragile layers.
5. **Need to validate artifact behavior:** inspect compressed/decompressed artifacts with [model-io-and-prediction](../model-io-and-prediction/SKILL.md); prediction remains platform-dependent.

## Reference map

- API names, config fields, and safe snippets: [references/api-reference.md](references/api-reference.md)
- End-to-end workflow decision tree: [references/workflows.md](references/workflows.md)
- Compression-specific failures and fixes: [references/troubleshooting.md](references/troubleshooting.md)
- Local smoke helper: [scripts/optimize_coreml_smoke.py](scripts/optimize_coreml_smoke.py)

## Runtime guardrails

- Do not claim `coremltools.optimize.torch` works until importing the relevant submodule succeeds with PyTorch installed and version-compatible.
- Core ML package compression APIs operate on `mlprogram` `MLModel` objects; if the user has a non-`mlprogram` or original model object, route to conversion first.
- Activation quantization and Torch calibration flows need representative data. If no data exists, recommend weight-only Core ML compression first.
- Use `decompress_weights` and metadata/spec inspection to isolate compression-induced failures before changing the original conversion settings.

Files in this skill

  • SKILL.md3.4 KB
  • references/api-reference.md9 KB
  • references/troubleshooting.md6.8 KB
  • references/workflows.md8.4 KB
  • scripts/optimize_coreml_smoke.py6 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.