Skip to main content

Convert MLX models to CoreAI

Project description

mlx2coreai

Experimental MLX to CoreAI conversion.

mlx2coreai captures MLX graphs, lowers supported ops to CoreAI MLIR, and writes .aimodel assets or coreai-models-style LLM bundles.

Install

pip install mlx2coreai

Convert an mlx-lm Model

For autoregressive language models, use the stateful converter. It writes a bundle containing metadata.json, tokenizer/, and a nested .aimodel.

mlx2coreai convert-mlx-lm-stateful mlx-community/Qwen3-0.6B-bf16 \
  --output qwen \
  --max-context-length 256

The exported model has one main entrypoint with input_ids, position_ids, and mutable keyCache / valueCache state.

Benchmark Sampling

python scripts/benchmark_aimodel_sampling.py qwen \
  --contexts 16,32,64,128,256 \
  --steps 16 \
  --decode

The benchmark accepts either the bundle directory (qwen) or the nested asset path (qwen/qwen.aimodel). It uses the embedded tokenizer when present.

Convert a Generic MLX Function

import mlx.core as mx
import numpy as np

from mlx2coreai import ConversionConfig, convert_mlx_to_coreai


def model(x, w):
    return mx.tanh(mx.matmul(x, w))


converted = convert_mlx_to_coreai(
    model,
    {
        "x": np.ones((2, 3), dtype=np.float32),
        "w": np.ones((3, 4), dtype=np.float32),
    },
    config=ConversionConfig(optimize=True),
    output_path="model.aimodel",
)

print(converted.asset_path)

Run an Asset

When the local CoreAI runtime is available:

import asyncio
import numpy as np

from mlx2coreai import run_aimodel


async def main():
    result = await run_aimodel(
        "model.aimodel",
        {"x": np.ones((2, 3), dtype=np.float32)},
    )
    print(result.outputs)


asyncio.run(main())

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

mlx2coreai-0.1.1.tar.gz (74.8 kB view details)

Uploaded Source

Built Distribution

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

mlx2coreai-0.1.1-py3-none-any.whl (73.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mlx2coreai-0.1.1.tar.gz
Algorithm Hash digest
SHA256 05027e6c8bd03b4d02d9b6c40f8a1a845c7b81f526ad06cc916aa492797c7437
MD5 3ffb22ef9e05e7c98df5e8c7d16bcaa4
BLAKE2b-256 3c543fd055912447dcdc429cc807bbe6cf07ae1a114cef1f9062d3b3b0c8e5d1

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for mlx2coreai-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c6aba409198fb4a24c714296b38ff41d8f664c43b00f92cdeb5b3359f0c20765
MD5 c75ea5184d8d745e7d6ed86383e27e89
BLAKE2b-256 6b72c242d556a041f219e7fda0a36f9cc42d0f66a2789f54612256b3165d784b

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