solo-model-shrink

Solid

Take a trained neural model to devices — ONNX export, int8 quantization, Core ML conversion, on-device benchmarking, download-on-demand delivery. Use when user says "сожми модель", "quantize the model", "convert to Core ML / ONNX", "model is too big for the app", "run the model on iPhone/Android/web", or an ML feature needs to ship inside a mobile/web app. Do NOT use for training or fine-tuning models, or for LLM API integration (that's app plumbing, not model porting).

AI & Automation 18 stars 2 forks Updated today MIT

Install

View on GitHub

Quality Score: 84/100

Stars 20%
43
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
80
License 10%
100
Description 5%
100

Skill Content

# model-shrink — ship a trained model to phones and browsers A PyTorch checkpoint becomes: an eval, an ONNX int8 file (web/Android), a Core ML package (Apple), an on-device number, and a download-on-demand delivery. Every step below was paid for once; the order is the method. ## Workflow 1. **Eval before anything.** Ground truth + one scalar metric (F-measure, accuracy — whatever the task has) + a script that runs any model variant against it. Every later decision — quantize? fp16? distill? — is this script's output, never a guess. Keep 5–10 held-out samples as a smoke set. 2. **Export ONNX at a fixed shape** (`torch.onnx.export`, one export per batch size — see Gotchas). Verify against the original: max abs diff and the eval score. `onnxruntime` CPU is the portable baseline: web (`onnxruntime-web` WASM), Android (ORT mobile), desktop. 3. **Quantize weights to int8** (`onnxruntime.quantization` / `ct.optimize.coreml.linear_quantize_weights`). Weights-only int8 is usually free — measured twice on a 20M-param transformer: F 0.872→0.871 (ONNX) and 0.864→0.863 (Core ML), 4x smaller. Re-run the eval anyway; "usually" is not "always". 4. **Apple: convert to native Core ML** (`coremltools`), never the ORT Core ML execution provider (see Don't). Conversion of transformer-ish models fails on Python-int shape math; the fixes that work: - Replace einops layers/`rearrange` with explicit `permute`/`reshape`. - Bake shapes as constants: capture ...

Details

Author
fortunto2
Repository
fortunto2/solo-factory
Created
7 months ago
Last Updated
today
Language
Shell
License
MIT

Bundled in these plugins

Similar Skills

Semantically similar based on skill content — not just same category

AI & Automation Listed

shipping-a-model-in-an-ios-app

Put a local language model inside a native iOS or macOS app written in Swift. Covers MLX on Apple silicon, Core ML conversion, llama.cpp via a Swift wrapper, choosing between them, app binary size and memory limits, background and memory-pressure behaviour, and whether to bundle the model or download it on first run. Also covers when Apple Foundation Models is the better answer than shipping your own. Use when the project is native Swift for iOS, iPadOS or macOS and someone wants on-device or offline AI or local inference. Not for React Native or Expo projects, not for Android native Kotlin projects, not for Flutter, and not for models running on a server.

2 Updated 4 weeks ago
ErtasAI
AI & Automation Listed

shipping-a-model-in-a-react-native-app

Put a local language model inside a React Native or Expo app and get it generating on device. Covers react-native-executorch for .pte models and llama.rn for GGUF models, choosing between them, native build configuration and model loading, streaming answers into the UI as tokens arrive, and whether to bundle the model in the binary or download it on first run. Use when the project is React Native or Expo and someone wants on-device or offline AI, local inference, or a model running without an API. Not for iOS native Swift projects, not for Android native Kotlin projects, not for Flutter, and not for models running on a server.

2 Updated 4 weeks ago
ErtasAI
AI & Automation Listed

shipping-a-model-in-an-android-app

Put a local language model inside a native Android app written in Kotlin or Java. Covers MediaPipe LLM Inference and LiteRT-LM for .task and .litertlm models, llama.cpp through the NDK for GGUF, ML Kit GenAI and Gemini Nano where a built-in model is enough, GPU and NNAPI delegation, Play asset packs, and whether to bundle the model or download it on first run. Use when the project is a native Android app and someone wants on-device or offline AI or local inference. Not for React Native or Expo projects, not for iOS native Swift projects, not for Flutter, and not for models running on a server.

2 Updated 4 weeks ago
ErtasAI