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

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 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")

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.0.tar.gz (79.9 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.0-py3-none-any.whl (58.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mlx2coreml-0.1.0.tar.gz
  • Upload date:
  • Size: 79.9 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.0.tar.gz
Algorithm Hash digest
SHA256 2d79b5f5d19eea4ba33464290cb0b559a03573809eaadcd043a8d70a4775f545
MD5 cbbc9d054f3add601ab257e7b4870268
BLAKE2b-256 40d1497e5d4e69da0981c77daaa5ba7bad6284379b687c86161b2b1c90fc3263

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mlx2coreml-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 58.1 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aeff7b2b088cdbe2105341f0f7e95eec84209a9aed727d613935b4e1e1daf5bc
MD5 7d2193f8c7cbc42fe1a617436411341a
BLAKE2b-256 b1da3305402f31ea97e106d48c55f0096218538d5a4bdde6d10dc12bfbc72136

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