Convert StableHLO models into Apple Core ML format
Project description
Convert StableHLO models into Apple Core ML format
This repo is currently experimental!
Only a subset of the StableHLO operations have been implemented, and some of them may have restrictions.
Due to the current dot_general op implementation, it is only possible to target iOS >= 18.
Look in the tests
directory, to see what has currently been tested.
The package is published to PyPi as stablehlo-coreml-experimental
.
Converting a model
To convert a StableHLO module, do the following:
import coremltools as ct
from stablehlo_coreml.converter import convert
mil_program = convert(hlo_module, minimum_deployment_target=ct.target.iOS18)
cml_model = ct.convert(mil_program, source="milinternal", minimum_deployment_target=ct.target.iOS18)
For a Jax project, the hlo_module
can be obtained the following way:
import jax
from jax._src.lib.mlir import ir
from jax._src.interpreters import mlir as jax_mlir
from jax.export import export
import jax.numpy as jnp
def jax_function(a, b):
return jnp.einsum("ij,jk -> ik", a, b)
context = jax_mlir.make_ir_context()
input_shapes = (jnp.zeros((2, 4)), jnp.zeros((4, 3)))
jax_exported = export(jax.jit(jax_function))(*input_shapes)
hlo_module = ir.Module.parse(jax_exported.mlir_module(), context=context)
For the Jax example to work, you will additionally need to install absl-py
and flatbuffers
as dependencies.
For additional examples see the tests
directory.
Notes
coremltools
supports up to python 3.11. Do not run hatch with a newer version. Can be controlled using fxexport HATCH_PYTHON=python3.11
- Run tests using
hatch run test:pytest tests
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
File details
Details for the file stablehlo_coreml_experimental-0.0.1.tar.gz
.
File metadata
- Download URL: stablehlo_coreml_experimental-0.0.1.tar.gz
- Upload date:
- Size: 19.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 670dfa04340316850a5175bedc281bd567948a4e14aa7d5def0c8157a7b8b302 |
|
MD5 | 22bca519c31c94431a2d06bbad07875d |
|
BLAKE2b-256 | 629cb26da9129d5646c80f76b3f3700421ceb207e2e1da52c6e0b377bfd13f61 |
File details
Details for the file stablehlo_coreml_experimental-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: stablehlo_coreml_experimental-0.0.1-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d21cb8c175d98c2a556e74b073acc041d2966ded5abdfa4528fbaa0f663390c |
|
MD5 | 72bb0aa87d493f9b187ba5173825f807 |
|
BLAKE2b-256 | a658c702ca335fd33f63a8ed2cb6ea21814cf3b7d1be1a293cb66b4db367fd31 |