Native edge AI compiler and deployment toolchain for Coral USB, Apple Silicon, and sloth/unsloth workflows
Project description
edgecompiler
EdgeCompiler – Universal Model Compiler for Apple Silicon & Google Coral USB
EdgeCompiler is a native Apple Silicon compiler toolchain that liberates the
Google Coral USB Accelerator from its x86‑64 Debian shackles. It replaces the
official edgetpu_compiler and runs entirely on a MacBook M1/M2/M3 Pro,
accepting models from PyTorch (.pt), ONNX, TensorFlow, and TensorFlow Lite, then
compiling them into device‑ready *_edgetpu.tflite files without Docker, virtual
machines, or Rosetta emulation.
Why This Exists
Google’s Coral USB is a tiny, low‑power inferencing beast, but its official compiler has three deal‑breakers:
- Locked to Debian Linux + x86‑64 – Mac users must spin up a VM or a separate Linux machine just to compile a model.
- TFLite‑only input – PyTorch, ONNX, and Keras models require clumsy conversions before the Coral compiler can even look at them.
- Zero Apple Silicon support – Even the runtime is tricky to install
natively, and the compiler simply doesn’t exist for
arm64.
EdgeCompiler fixes all of this. It runs natively on Apple Silicon, gives you a single‑command pipeline from any major framework to a compiled Edge TPU model, and even generates Metal‑optimised GPU code when you want to run inference directly on the M1 Pro chip instead.
With EdgeCompiler, you can prototype on your Mac, quantise and compile for the Coral USB, and then offload 100% of the inference compute to the Edge TPU – freeing your CPU/GPU entirely. The entire toolchain is modular, test‑driven, and designed to be easily extended to other accelerators (Hailo‑8, Intel VPU, etc.).
Optional UnsLoth Integration
Because the best Edge TPU models are often tiny, efficient architectures that have been fine‑tuned for a specific task, EdgeCompiler ships with an optional integration for Unsloth. Unsloth is a lightning‑fast fine‑tuning engine that makes training quantised‑aware models 2–5 × faster while using less memory.
With edgecompiler + unsloth, you can:
- Fine‑tune a MobileNet, EfficientNet, or even a small transformer directly on your MacBook with QAT (Quantisation‑Aware Training).
- Export the trained model through EdgeCompiler’s pipeline and deploy it to the Coral USB in one command.
- Iterate on your model without ever leaving the Apple Silicon ecosystem.
The integration is optional – EdgeCompiler works perfectly with pre‑trained models – but it turns your Mac into an end‑to‑end edge‑AI development workstation.
Features
| Category | Details |
|---|---|
| Model Formats | PyTorch .pt / .pth, TFLite .tflite, ONNX .onnx, TF SavedModel, Keras .h5 / .keras |
| Quantisation | Post-Training Quantisation (PTQ), Quantisation-Aware Training (QAT), Dynamic Range |
| Backends | Google Coral USB (Edge TPU), Apple Silicon GPU (Metal / MPS / Neural Engine) |
| Platform | macOS ARM64 (M1/M2/M3/M4) — no Docker, no Rosetta 2, no x86-64 emulation |
| CLI | Single edgecompile command with sensible defaults |
| Python API | Programmatic access via edgecompiler.compile() |
| SLM Pipeline | Integrated sloth_integration package for unsloth fine-tuning to Coral deployment |
| Testing | Full test suite with hardware-specific markers |
Quick Start
Install
# Basic install (TFLite support only)
pip install edgecompiler
# With PyTorch support
pip install "edgecompiler[pytorch]"
# With all frontends
pip install "edgecompiler[all]"
# Development install
pip install -e ".[dev]"
Compile a Model
# PyTorch → Coral USB
edgecompile model.pt --target coral --output model_coral.tflite
# TFLite → Apple Silicon GPU
edgecompile model.tflite --target metal --output model.mlpackage
# ONNX → Coral USB with INT8 PTQ
edgecompile model.onnx --target coral --quantize ptq --output model_coral.tflite
# SavedModel → Metal with calibration data
edgecompile saved_model/ --target metal --quantize ptq --calibration-data calib.npy
Installation
pip (recommended)
pip install edgecompiler
Optional dependencies
Install only the frontends you need:
pip install "edgecompiler[pytorch]" # PyTorch + TorchScript support
pip install "edgecompiler[tensorflow]" # TF SavedModel / Keras support
pip install "edgecompiler[onnx]" # ONNX model support
pip install "edgecompiler[coreml]" # Core ML / Metal backend support
pip install "edgecompiler[coral]" # Coral runtime extras (TensorFlow Lite interpreter path)
pip install "edgecompiler[all]" # Everything
For Coral USB acceleration, also install libedgetpu using
./scripts/install_coral_runtime.sh.
From source
git clone https://github.com/rotsl/edgecompiler.git
cd edgecompiler
make install # pip install -e ".[dev]"
macOS M1 / M2 / M3 specific notes
edgecompiler runs natively on ARM64 — no Docker, no Rosetta 2, and no x86-64
Python environment required. However, there are a few platform-specific considerations:
-
Python: Use an ARM64-native Python build (Homebrew or
python.orginstaller). Verify with:python3 -c "import platform; print(platform.machine())" # Expected: arm64
-
Coral USB runtime: The
libedgetpulibrary does not ship official ARM64 macOS builds. Use our helper script to install a compatible build:./scripts/install_coral_runtime.sh
-
Core ML / Metal:
coremltoolsinstalls natively via pip on ARM64 macOS. No additional setup is needed for the Metal backend. -
TensorFlow: As of TF 2.16+, native ARM64 wheels are available on PyPI for macOS. If you encounter issues, use
tensorflow-macosas a fallback.
Compiling a PyTorch Model for Coral USB
from edgecompiler import compile
result = compile(
"mobilenet_v2.pt",
target="coral",
quantize="ptq",
calibration_data="calibration_images.npy", # N x C x H x W, float32
output="mobilenet_v2_coral.tflite",
)
print(result) # CompileResult(output_path=..., ops_on_target=147, ops_fallback=0)
CLI equivalent:
edgecompile mobilenet_v2.pt \
--target coral \
--quantize ptq \
--calibration-data calibration_images.npy \
--output mobilenet_v2_coral.tflite
What happens under the hood (TFLite path)
- The PyTorch model is traced via
torch.jit.trace(or scripted if trace fails). - The TorchScript graph is converted to our unified IR.
- INT8 post-training quantisation is applied using the provided calibration data.
- The quantised IR is lowered to a TFLite FlatBuffer with Edge TPU custom ops.
- The output
.tflitefile can be run directly with the Coral USB runtime.
Compiling a TFLite Model for Apple Silicon GPU
from edgecompiler import compile
result = compile(
"mobilenet_v2.tflite",
target="metal",
quantize="ptq",
output="mobilenet_v2_ml.mlpackage",
)
print(result) # CompileResult(output_path=..., backend="metal")
CLI equivalent:
edgecompile mobilenet_v2.tflite \
--target metal \
--quantize ptq \
--output mobilenet_v2_ml.mlpackage
What happens under the hood
- The TFLite model is parsed into our unified IR.
- INT8 quantisation is applied (Core ML supports both INT8 and FP16).
- The IR is lowered to a Core ML model via
coremltools. - Compute unit selection (Neural Engine > GPU > CPU) is configured for maximum throughput.
- The output
.mlpackagecan be loaded with Core ML directly or via theedgecompilerruntime.
Running Examples
The examples/ directory contains ready-to-run scripts for common workflows:
# PyTorch model → Coral + Metal compilation pipeline
python examples/pytorch_mobilenet.py
# TFLite model compilation walkthrough
python examples/tflite_mobilenet.py
# ONNX ResNet compilation
python examples/onnx_resnet.py
# Coral USB benchmark (1 000 inferences, latency stats)
python examples/coral_usb_benchmark.py --num-runs 100
See examples documentation for detailed walkthroughs.
Sloth Integration Examples
The repository also includes an integrated Sloth pipeline under sloth-integration/
for unsloth fine-tuning and Coral deployment. This integration is based on
Unsloth:
# Run sloth integration tests
pytest sloth-integration/tests -v
# Run sloth benchmark example
python sloth-integration/examples/benchmark_coral.py \
--model sloth-integration/test_models/synthetic_text_classifier.tflite
See sloth-integration/docs/benchmarks_sloth.md for the latest measured values
and docs/sloth_integration.md for setup and workflow guidance.
Coral USB Quick Start
Run inference on a Google Coral USB Accelerator connected to your MacBook M1 Pro in just a few steps:
# 1. Install edgecompiler with Coral support
pip install edgecompiler
# 2. Install the Edge TPU runtime (see docs/coral_macos_setup.md for details)
./scripts/install_coral_runtime.sh
# 3. Plug in your Coral USB Accelerator
# 4. Compile and run inference in one command
edgecompiler coral-usb model.tflite --image parrot.jpg --labels imagenet_labels.txt
Python API:
from edgecompiler.runtime.coral_usb import CoralUSBRuntime
import numpy as np
with CoralUSBRuntime() as runtime:
devices = runtime.detect_devices()
if devices:
runtime.load_model("model_edgetpu.tflite")
result = runtime.infer(np.zeros((1, 224, 224, 3), dtype=np.uint8))
for cls_id, score in result.top_classes:
print(f" Class {cls_id}: {score:.3f}")
For detailed setup instructions, see docs/coral_macos_setup.md and instructions.md.
Running Tests
# One command: auto-detect Coral and separate simulation/hardware suites
edge-test
# Make target wrapper for auto mode
make test-auto
# Run all unit tests (no hardware required)
make test
# Run with pytest directly
pytest tests/ -v
# Run hardware-specific tests (requires Coral USB or Apple Silicon)
make test-hardware
# Run only Coral tests
pytest tests/ -v -m coral
# Run only Metal tests
pytest tests/ -v -m metal
Useful options:
# Force simulation-only run
edge-test --mode simulation
# Force hardware-only run
edge-test --mode hardware
# Include slow tests
edge-test --include-slow
Hardware test models
Download Coral hardware test assets with:
bash scripts/download_models.sh --output-dir tests/hardware/test_models
The downloader is compatible with macOS default Bash 3.x.
Benchmark report
Current measured results (with and without hardware-focused runs) are tracked in:
benchmarks.md
Architecture Overview
┌──────────────────┐
│ edgecompiler │
│ CLI │
└────────┬─────────┘
│
┌────────▼─────────┐
│ Python API │
│ compile() │
└────────┬─────────┘
│
┌───────────┬──────────────┼──────────────┬────────────┐
│ │ │ │ │
┌─────▼────┐ ┌────▼─────┐ ┌──────▼─────┐ ┌──────▼────┐ ┌─────▼──────┐
│ PyTorch │ │ TFLite │ │ ONNX │ │ TF Saved │ │ Keras │
│ Frontend │ │ Frontend │ │ Frontend │ │ Model │ │ Frontend │
└─────┬────┘ └────┬─────┘ └──────┬─────┘ └──────┬────┘ └─────┬──────┘
│ │ │ │ │
└───────────┴──────────────┼─────────────-┴────────────┘
│
┌───────▼───────-──-┐
│ Unified IR │
│ (Graph + Tensors)│
└────────┬─────────-┘
│
┌────────▼─────────-┐
│ Optimisation │
│ Passes │
│ ├─ Constant fold │
│ ├─ Op fusion │
│ ├─ Dead code elim│
│ └─ Layout xform │
└────────┬─────────-┘
│
┌────────▼─────────┐
│ Quantisation │
│ Pipeline │
│ ├─ PTQ │
│ ├─ QAT │
│ └─ Dynamic range│
└────────┬─────────┘
│
┌───────────────┼───────────────┐
│ │
┌────────▼────────┐ ┌────────▼────────┐
│ Coral Backend │ │ Metal Backend │
│ (Edge TPU) │ │ (Apple Silicon)│
│ │ │ │
│ ├─ TFLite FB │ │ ├─ Core ML │
│ ├─ Custom ops │ │ ├─ MPSGraph │
│ └─ Partitioning│ │ └─ ANE routing │
└────────┬────────┘ └────────┬────────┘
│ │
┌────────▼────────┐ ┌────────▼────────┐
│ .tflite │ │ .mlpackage │
│ (Edge TPU) │ │ (Core ML) │
└─────────────────┘ └─────────────────┘
Sloth Integration (in-repo)
unsloth / HF checkpoints -> sloth_integration adapter/converter
-> edgecompiler compile()
-> SlothCoralRuntime
-> Coral USB inference
sloth_integration is packaged from sloth-integration/src/sloth_integration
and reuses the same frontend -> IR -> backend pipeline, adding text-specific
adapter/converter/runtime layers for SLM deployment workflows.
See architecture documentation for the full design.
Supported Operations
Edge TPU (Coral USB)
| Operation | INT8 | Notes |
|---|---|---|
| Conv2D | ✅ | Depthwise + standard |
| DepthwiseConv2D | ✅ | |
| FullyConnected | ✅ | |
| MaxPool2D | ✅ | |
| AveragePool2D | ✅ | |
| ReLU | ✅ | ReLU, ReLU6, ReLUN1To1 |
| Softmax | ✅ | |
| Sigmoid | ✅ | |
| Tanh | ✅ | |
| Add | ✅ | Element-wise |
| Sub | ✅ | Element-wise |
| Mul | ✅ | Element-wise |
| Concatenation | ✅ | |
| Reshape | ✅ | |
| Transpose | ✅ | |
| Pad | ✅ | |
| ReduceMin / ReduceMax | ✅ | |
| Mean | ✅ | |
| ExpandDims | ✅ | |
| Squeeze | ✅ | |
| Split | ✅ | |
| Slice | ✅ | |
| ResizeBilinear | ✅ | |
| ResizeNearestNeighbor | ✅ | |
| Logistic | ✅ | |
| L2Normalization | ✅ | |
| BatchToSpaceND | ✅ | |
| SpaceToBatchND | ✅ | |
| Gather | ⚠️ | Fallback on some dims |
| StridedSlice | ⚠️ | Limited mask support |
| LSTM | ❌ | Falls back to CPU |
| Einsum | ❌ | Not supported |
| ScatterND | ❌ | Not supported |
Apple Silicon (Metal / Neural Engine)
| Operation | INT8 | FP16 | Notes |
|---|---|---|---|
| Conv2D | ✅ | ✅ | ANE preferred |
| DepthwiseConv2D | ✅ | ✅ | |
| FullyConnected | ✅ | ✅ | |
| MaxPool2D | ✅ | ✅ | |
| AveragePool2D | ✅ | ✅ | |
| ReLU | ✅ | ✅ | |
| Softmax | ✅ | ✅ | |
| Sigmoid | ✅ | ✅ | |
| Tanh | ✅ | ✅ | |
| Add / Sub / Mul | ✅ | ✅ | |
| Concatenation | ✅ | ✅ | |
| Reshape | ✅ | ✅ | |
| Transpose | ✅ | ✅ | |
| BatchNorm | ✅ | ✅ | Fused into conv |
| LayerNorm | ❌ | ✅ | FP16 only on ANE |
| LSTM / GRU | ❌ | ✅ | FP16 on GPU |
| Attention | ❌ | ✅ | FP16, GPU preferred |
| Einsum | ❌ | ✅ | GPU only |
| ScatterND | ❌ | ✅ | GPU only |
Contributing
We welcome contributions! Please follow these guidelines:
Getting Started
- Fork the repository
- Clone your fork:
git clone https://github.com/your-username/edgecompiler.git - Install in development mode:
make install - Create a feature branch:
git checkout -b feature/my-feature
Development Workflow
make lint # Check code style
make format # Auto-format code
make test # Run core test suite
make test-auto # Auto split simulation/hardware where possible
make test-all # Root + sloth integration tests
You can also run the same paths used in CI:
python -m edgecompiler.test_runner --mode simulation --path tests/unit --path tests/integration
pytest -q sloth-integration/tests
Code Areas
- Frontends:
src/edgecompiler/frontend/ - IR and passes:
src/edgecompiler/ir/ - Quantisation:
src/edgecompiler/quantisation/ - Backends:
src/edgecompiler/backend/ - Runtime:
src/edgecompiler/runtime/ - Sloth integration:
sloth-integration/src/sloth_integration/ - Examples:
examples/andsloth-integration/examples/
Adding a New Frontend
- Create
src/edgecompiler/frontend/my_frontend.py - Expose a converter function in
src/edgecompiler/frontend/__init__.py - Convert the model into the unified IR graph and tensor model
- Add targeted unit tests in
tests/unit/
See architecture documentation for details.
Adding a New Backend
- Create
src/edgecompiler/backend/my_backend.py - Expose compile helpers in
src/edgecompiler/backend/__init__.py - Keep unsupported-op behavior explicit (clear fallback/error messages)
- Add tests in
tests/unit/and integration checks intests/integration/as needed
Pull Request Checklist
- Code passes
make lint - Code is formatted with
make format - Unit tests pass with
make test - Integration paths are validated (
make test-allfor cross-package changes) - New features include documentation
- Breaking changes are documented in the PR description
Reporting Issues
Please use GitHub Issues and include:
- macOS version and hardware (e.g., macOS 14.2, M1 Pro)
- Python version (
python3 --version) edgecompilerversion (edgecompile --version)- Full error output with
--verboseflag
License
Licensed under the Apache License 2.0.
Copyright 2026 Rohan R
Note: The sloth-integration in this repo is based on the unsloth repository. We would like to thank the unslothai team.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file edgecompiler-0.1.1.tar.gz.
File metadata
- Download URL: edgecompiler-0.1.1.tar.gz
- Upload date:
- Size: 481.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efc296d29e9910b371304e8d93f990255bb280e16c7f5ea9459334cb92b63fef
|
|
| MD5 |
d1f504a289a84afe7e043154675c7bc7
|
|
| BLAKE2b-256 |
c32906484e2aa27c1c73f09a6d45d35d91e8ce266cf7313b17d7dca0c61e0618
|
Provenance
The following attestation bundles were made for edgecompiler-0.1.1.tar.gz:
Publisher:
pypi-release.yml on rotsl/edgecompiler
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
edgecompiler-0.1.1.tar.gz -
Subject digest:
efc296d29e9910b371304e8d93f990255bb280e16c7f5ea9459334cb92b63fef - Sigstore transparency entry: 1690326684
- Sigstore integration time:
-
Permalink:
rotsl/edgecompiler@2aff479f7e62e246c51bfbd613018cfdd033bd95 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/rotsl
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-release.yml@2aff479f7e62e246c51bfbd613018cfdd033bd95 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file edgecompiler-0.1.1-py3-none-any.whl.
File metadata
- Download URL: edgecompiler-0.1.1-py3-none-any.whl
- Upload date:
- Size: 231.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85849ab80da63a3687654c3f978243a3533932b3b786b3e5c51fe99cad16a555
|
|
| MD5 |
e066ace80dd721cf3e037621901a5f74
|
|
| BLAKE2b-256 |
9291dcb6e438e6427f73a610a2fd0b4d4a52db156e00c84e30d3714fb9933466
|
Provenance
The following attestation bundles were made for edgecompiler-0.1.1-py3-none-any.whl:
Publisher:
pypi-release.yml on rotsl/edgecompiler
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
edgecompiler-0.1.1-py3-none-any.whl -
Subject digest:
85849ab80da63a3687654c3f978243a3533932b3b786b3e5c51fe99cad16a555 - Sigstore transparency entry: 1690326695
- Sigstore integration time:
-
Permalink:
rotsl/edgecompiler@2aff479f7e62e246c51bfbd613018cfdd033bd95 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/rotsl
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-release.yml@2aff479f7e62e246c51bfbd613018cfdd033bd95 -
Trigger Event:
workflow_dispatch
-
Statement type: