Run PyTorch models on the Apple Neural Engine via Core AI: compile any nn.Module, LLMs with KV cache, Stable Diffusion
pip install torch-ane==0.1.1 Copy PIP instructions
Pass in a plain nn.Module, or a model from transformers or diffusers. torch-ane rewrites it into a form the ANE runs fast and correctly: fp16, static shapes, and the layout and ops from Apple's ANE guidance. It also works around the ANE's numeric quirks. You get back a module that behaves like the original.
import torch_ane m = torch_ane.compile(model.eval(), example_inputs=(x,)) # any nn.Module -> ANE y = m(x) # torch tensors in, torch tensors out On an M4 MacBook, ANE prefill and convolutions are 2–3× faster than the GPU (MLX/MPS). Decoding is limited by memory bandwidth, and the ANE reads ~57 GB/s.
Requires macOS 27+ on Apple silicon, and Python 3.11+.
pip install torch-ane # core: compile() pip install "torch-ane[llm]" # + CausalLM / ChunkedCausalLM (transformers, gguf) pip install "torch-ane[diffusion]" # + StableDiffusion (diffusers) Core AI's Python packages (coreai-core, coreai-torch, coreai-opt) come from PyPI as dependencies.
import torch_ane torch_ane.available() # is Core AI usable here # Any module. The first call per input shape builds a program (seconds); then it's cached on disk. m = torch_ane.compile(model, example_inputs=(x,), device="ane") # or device="gpu" # A whole LLM on the ANE (up to ~1-3B). The KV cache is Core AI state, so it is never copied. lm = torch_ane.CausalLM.from_pretrained("Qwen/Qwen2.5-0.5B-Instruct", batch=True) ids = lm.generate(prompt_ids, max_new_tokens=64, eos=tok.eos_token_id) outs = lm.generate_batch([ids1, ids2, ids3], max_new_tokens=64) # up to 8 streams per step logits = lm.feed(more_ids) # append to the cache -> last logits # A large model from GGUF, in 4-layer chunks with 4-bit palettes (Devstral 24B etc.) big = torch_ane.ChunkedCausalLM.from_gguf("model.gguf", "config_dir/") # Stable Diffusion: text encoder, UNet and VAE on the ANE sd = torch_ane.StableDiffusion("segmind/tiny-sd") image, timings = sd("a cute robot", steps=20, seed=0) compile(model, example_inputs=None, device="ane", validate=True, compress=None) → CompiledModule. validate checks the first call of each shape against eager. If they disagree, that shape falls back to GPU, then to eager. compress="int8" stores Linear/Conv2d weights in int8 CompiledModule torch module over Core AI programs, one program per input shape (up to 8) CausalLM(hf_model, max_len=2048, compress=None, batch=False, ...) prefill in chunks of 256, decode in windows of 8, a ladder of context sizes 512…max_len in one program ChunkedCausalLM.from_gguf(path, config) 4-bit palettes, plus int8 where the GGUF is more precise (Q6_K). First build takes ~35 min for 24B StableDiffusion(model_id, device="ane", size=512) diffusers pipeline with all three parts on the ANE passes the building blocks: export_for_ane, swap_linear, split_wide, chunk_mlp, palettize_lut, quantize_int8_modules, calibrate_rescale, use_composite_ops, … CACHE_DIR, prune_cache(), clear_system_cache() build cache at ~/.cache/torch_ane (TORCH_ANE_CACHE). It is capped at TORCH_ANE_CACHE_GB (40) and least recently used builds are removed. clear_system_cache() wipes Core AI's own compile cache, which can only be cleared as a whole What it does to your model These passes need no knowledge of the specific model:
UNet/VAE attention uses Apple's layout: BC1S, heads split, einsum with no transposes.
pip install -e ".[llm,diffusion,dev]" pytest License MIT
pytorch apple-silicon neural-engine ane core-ai coreml llm stable-diffusion
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
None of the files in this release were uploaded with provenance metadata.
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.




