Skip to main content

mlx2coreml

mlx2coreml is a MLX -> Core ML translation pipeline.

It captures MLX graphs and converts them to to Core ML models (.mlpackage / .mlmodelc), suitable for on-device deployment through Xcode.

mlx2coreml is still experimental and may not work with all models.

Quick Start

pip install -U mlx2coreml

Examples

Converting MLX LM models to CoreML

python -m mlx2coreml.convert_mlx_lm \
  --model-id mlx-community/Qwen3-0.6B-bf16 \
  --output qwen3_0_6b_coreml \
  --seq-len 128 \
  --deployment-target iOS18 \
  --convert-to mlprogram \
  --compute-precision fp16 \
  --compute-units all

Converting MLX Audio Smart Turn V3 to CoreML

python -m mlx2coreml.convert_mlx_audio \
  --model-id mlx-community/smart-turn-v3 \
  --output smart_turn_v3_coreml \
  --audio-seconds 8 \
  --deployment-target iOS18 \
  --convert-to mlprogram \
  --compute-precision fp16 \
  --compute-units all

Note: This captures the model's input_features graph, which are preprocessed log-mel features; raw waveform preprocessing stays outside the converted Core ML model.

Direct conversion from Python

For arbitrary models, use the conversion API directly:

import numpy as np
import mlx.core as mx

from mlx_lm import load

import mlx2coreml as m2c

# Load an MLX LM model

model_id = "mlx-community/Qwen3-0.6B-bf16"
mlx_model, tokenizer = load(model_id, lazy=False)

# Build sample inputs for conversion

seq_len = 128
prompt = "hello"
input_ids = mx.array(tokenizer.encode(prompt), dtype=mx.int32)[None, ...]
inputs = {"input_ids": input_ids}

# Convert the model to a CoreML .mlprogram

config = m2c.ConversionConfig(
    deployment_target="iOS18",
    convert_to="mlprogram",
    compute_precision="fp16",
    flex_input_lens=[1, seq_len],
    flex_input_names={"input_ids"},
)

coreml_model = m2c.convert_mlx_to_coreml(
    mlx_model,
    inputs,
    config=config,
    capture_function=lambda input_ids: mlx_model(input_ids),
)
model_path = "model.mlpackage"
coreml_model.model.save(model_path)

# Optional: compile the model to a CoreML .mlmodelc

compiled_path = m2c.compile_mlmodel(model_path, "model.mlmodelc")

Note that for some models, you need to prepare the input features if there's additional preprocessing required:

import numpy as np

from mlx_audio.vad import load

import mlx2coreml as m2c

model = load("mlx-community/smart-turn-v3")
features = model.prepare_input_features(np.zeros((16000,), dtype=np.float32), sample_rate=16000)

coreml_model = m2c.convert_mlx_to_coreml(
    model,
    {"input_features": features},
    config=m2c.ConversionConfig(
        deployment_target="iOS18",
        convert_to="mlprogram",
        compute_precision="fp16",
    ),
    capture_function=lambda input_features: model(input_features),
)

model_path = "model.mlpackage"
coreml_model.model.save(model_path)

# Optional: compile the model to a CoreML .mlmodelc

compiled_path = m2c.compile_mlmodel(model_path, "model.mlmodelc")

Docs

Release files for mlx2coreml 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mlx2coreml 0.1.1
File Size Uploaded
mlx2coreml-0.1.1.tar.gz 86.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mlx2coreml 0.1.1
File Interpreter ABI Platform
mlx2coreml-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 152.6 kB

Release files / mlx2coreml-0.1.1.tar.gz

Download URL mlx2coreml-0.1.1.tar.gz
Size 86.3 kB
Tags Source
SHA-256 checksum
How to use checksums
847f0accd1061fddc01d228b6f963169daa27bea11c05d402280a65e4f6f44e1
BLAKE2b-256 checksum
How to use checksums
6d549323222d397f4c60ae19fedd9dc9db600dc58ab507fdb79fd984180d4670
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / mlx2coreml-0.1.1-py3-none-any.whl

Download URL mlx2coreml-0.1.1-py3-none-any.whl
Size 66.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f463aa0f2ce38ee59d1d752f1a507cd593f41c46fb2413092345b8ea31241741
BLAKE2b-256 checksum
How to use checksums
bd408bf23fa6191108ca77e3f0ef29b2d8a24d23e485dfd7a132b74d2f2122b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page