CoreML export β .pte fails with Metadata is invalid or missing
Open
@metascroy is already working on this.
Since Oct 6, 2025.
- Dominant language
- Python
- Stars
- 5k
- Forks
- 1.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 581
Description
π Describe the bug
Iβm trying to export an EfficientViT segmentation model trained on custom data to ExecuTorch .pte with CoreML delegation, following the docs
Problem arises only when using CoreML partitioner not XNNPACK.
-macOS: 15.6 (Apple Silicon, arm64)
-Python: 3.10.18
- torch 2.8.0
- executorch 0.7.0
- coremltools 8.3.0
Script (simplified)
import torch, coremltools as ct
from torch.export import export as torch_export
from executorch.exir import to_edge_transform_and_lower
from executorch.backends.apple.coreml.partition import CoreMLPartitioner
from executorch.backends.apple.coreml.compiler import CoreMLBackend
from executorch.backends.xnnpack.partition.xnnpack_partitioner import XnnpackPartitioner
model = ... # EfficientViT segmentation, checkpoint loaded, eval mode
example_input = torch.randn(1, 3, 640, 640)
with torch.no_grad():
ep = torch_export(model, (example_input,), strict=True)
compile_specs = CoreMLBackend.generate_compile_specs(
minimum_deployment_target=ct.target.iOS17,
compute_precision=ct.precision.FLOAT16,
compute_unit=ct.ComputeUnit.ALL,
model_type=CoreMLBackend.MODEL_TYPE.MODEL
)
edge_mgr = to_edge_transform_and_lower(
ep,
partitioner=[
CoreMLPartitioner(compile_specs=compile_specs),
XnnpackPartitioner(per_op_mode=True),
],
)
pte = edge_mgr.to_executorch()
with open("segmentation_model_ios.pte", "wb") as f:
f.write(pte.buffer)
Output:
WARNING:torchao.kernel.intmm:Warning: Detected no triton, on systems without Triton certain kernels will not work
W0930 12:44:31.462000 69374 .venv/lib/python3.10/site-packages/torch/distributed/elastic/multiprocessing/redirects.py:29] NOTE: Redirects are currently not supported in Windows or MacOs.
/.venv/lib/python3.10/site-packages/executorch/exir/dialects/edge/_ops.py:9: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
import pkg_resources
WARNING:coremltools:Torch version 2.8.0 has not been tested with coremltools. You may run into unexpected errors. Torch 2.5.0 is the most recent version that has been tested.
β
Registrato modello 'efficientvit-seg-b0-cards' nel model zoo.
Missing: []
Unexpected: []
WARNING:root:Torchgen is not able to parse the schema of aten::conv2d(Tensor input, Tensor weight, Tensor? bias=None, SymInt[2] stride=[1, 1], SymInt[2] padding=[0, 0], SymInt[2] dilation=[1, 1], SymInt groups=1) -> Tensor. This is not fatal.
WARNING:root:Op aten.add.Tensor was requested for preservation by partitioner. This request is ignored because it is in a blocklist.
WARNING:root:Torchgen is not able to parse the schema of aten::conv2d(Tensor input, Tensor weight, Tensor? bias=None, SymInt[2] stride=[1, 1], SymInt[2] padding=[0, 0], SymInt[2] dilation=[1, 1], SymInt groups=1) -> Tensor. This is not fatal.
WARNING:root:Op aten._native_batch_norm_legit_no_training.default was requested for preservation by partitioner. This request is ignored because it aliases output.
WARNING:root:Op aten.add.Tensor was requested for preservation by partitioner. This request is ignored because it is in a blocklist.
WARNING:root:Op aten.view.default was requested for preservation by partitioner. This request is ignored because it aliases output.
WARNING:root:Op aten.slice.Tensor was requested for preservation by partitioner. This request is ignored because it aliases output.
WARNING:root:Op aten.permute.default was requested for preservation by partitioner. This request is ignored because it aliases output.
WARNING:root:Op aten.expand.default was requested for preservation by partitioner. This request is ignored because it aliases output.
WARNING:root:Op aten.div.Tensor was requested for preservation by partitioner. This request is ignored because it is in a blocklist.
WARNING:root:Op aten._to_copy.default was requested for preservation by partitioner. This request is ignored because it is in a blocklist.
WARNING:root:Op aten.mul.Tensor was requested for preservation by partitioner. This request is ignored because it is in a blocklist.
WARNING:root:Op aten.sub.Tensor was requested for preservation by partitioner. This request is ignored because it is in a blocklist.
WARNING:root:Op aten.unsqueeze.default was requested for preservation by partitioner. This request is ignored because it aliases output.
WARNING:root:Op aten.squeeze.dims was requested for preservation by partitioner. This request is ignored because it aliases output.
Converting PyTorch Frontend ==> MIL Ops: 0%| | 0/4 [00:00<?, ? ops/s]WARNING:coremltools:Saving value type of int64 into a builtin type of int32, might lose precision!
WARNING:coremltools:Saving value type of int64 into a builtin type of int32, might lose precision!
WARNING:coremltools:Saving value type of int64 into a builtin type of int32, might lose precision!
WARNING:coremltools:Saving value type of int64 into a builtin type of int32, might lose precision!
Converting PyTorch Frontend ==> MIL Ops: 75%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | 3/4 [00:00<00:00, 2036.73 ops/s]
Running MIL frontend_pytorch pipeline: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 5/5 [00:00<00:00, 7679.06 passes/s]
Running MIL default pipeline: 100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 89/89 [00:00<00:00, 7071.82 passes/s]
Running MIL backend_mlprogram pipeline: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 12/12 [00:00<00:00, 29194.69 passes/s]
Converting PyTorch Frontend ==> MIL Ops: 94%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | 17/18 [00:00<00:00, 9870.32 ops/s]
Running MIL frontend_pytorch pipeline: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 5/5 [00:00<00:00, 4882.78 passes/s]
Running MIL default pipeline: 100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 89/89 [00:00<00:00, 1777.23 passes/s]
Running MIL backend_mlprogram pipeline: 100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 12/12 [00:00<00:00, 4067.86 passes/s]
WARNING:coremltools:Core ML does not support scalar input, so dim_order_ops__to_dim_order_copy_default_5 has been wrapped as rank-1 size-1 tensor
WARNING:coremltools:Core ML does not support scalar input, so dim_order_ops__to_dim_order_copy_default_4 has been wrapped as rank-1 size-1 tensor
WARNING:coremltools:Core ML does not support scalar input, so dim_order_ops__to_dim_order_copy_default_11 has been wrapped as rank-1 size-1 tensor
WARNING:coremltools:Core ML does not support scalar input, so dim_order_ops__to_dim_order_copy_default_10 has been wrapped as rank-1 size-1 tensor
Converting PyTorch Frontend ==> MIL Ops: 100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 553/554 [00:00<00:00, 2941.72 ops/s]
Running MIL frontend_pytorch pipeline: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 5/5 [00:00<00:00, 54.42 passes/s]
Running MIL default pipeline: 100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 89/89 [00:02<00:00, 41.62 passes/s]
Running MIL backend_mlprogram pipeline: 100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 12/12 [00:00<00:00, 91.59 passes/s]
Esportato: segmentation_model_ios.pte MB: 2.3654251098632812
Error
When trying to load the .pte:
[Core ML] Metadata is invalid or missing.
[Core ML] Model init failed Metadata is invalid or missing.
CoreMLBackend: Failed to init the model.
Init failed for backend CoreMLBackend: 0x23
RuntimeError: loading method forward failed with error 0x23
Export with XNNPACK-only β .pte loads and runs fine.
Could you help me?
Versions
-macOS: 15.6 (Apple Silicon, arm64)
-Python: 3.10.18
- torch 2.8.0
- executorch 0.7.0
- coremltools 8.3.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up β it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.