Skip to main content

Experimental MLX to Core ML translation pipeline.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mlx2coreml-0.1.1.tar.gz (86.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mlx2coreml-0.1.1-py3-none-any.whl (66.3 kB view details)

Uploaded Python 3

File details

Details for the file mlx2coreml-0.1.1.tar.gz.

File metadata

  • Download URL: mlx2coreml-0.1.1.tar.gz
  • Upload date:
  • Size: 86.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for mlx2coreml-0.1.1.tar.gz
Algorithm Hash digest
SHA256 847f0accd1061fddc01d228b6f963169daa27bea11c05d402280a65e4f6f44e1
MD5 85f03885e924b13773914df76f00cc29
BLAKE2b-256 6d549323222d397f4c60ae19fedd9dc9db600dc58ab507fdb79fd984180d4670

See more details on using hashes here.

File details

Details for the file mlx2coreml-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mlx2coreml-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 66.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for mlx2coreml-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f463aa0f2ce38ee59d1d752f1a507cd593f41c46fb2413092345b8ea31241741
MD5 c96d8b49df845282d5dc76e63214012e
BLAKE2b-256 bd408bf23fa6191108ca77e3f0ef29b2d8a24d23e485dfd7a132b74d2f2122b0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page