pytorch / pytorch/executorch

CoreML InstanceNorm3d fails to load

Open
#11,702 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backend tester module: coreml
Dominant language
Python
Stars
5k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
581

Description

🐛 Describe the bug

Models with InstanceNorm3d on the Core ML backend fail to load at runtime.

Repro:

import torch

from executorch.backends.apple.coreml.partition import CoreMLPartitioner
from executorch.exir import to_edge_transform_and_lower, EdgeCompileConfig
from executorch.extension.pybindings.portable_lib import _load_for_executorch_from_buffer

class Model(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.norm = torch.nn.InstanceNorm3d(3)
        
    def forward(self, x):
        return self.norm(x)

model = Model()
inputs = (
    torch.randn(1, 3, 4, 4, 4),
)

eager_outputs = model(*inputs)
print(f"Eager: {eager_outputs.shape} {eager_outputs}")

ep = torch.export.export(model.eval(), inputs)
lowered = to_edge_transform_and_lower(
    ep,
    partitioner=[CoreMLPartitioner()],
    compile_config=EdgeCompileConfig(_check_ir_validity=False)
).to_executorch()

print(ep)
print(lowered.exported_program())

et_model = _load_for_executorch_from_buffer(lowered.buffer)
et_outputs = et_model([*inputs])[0]

et_outputs - eager_outputs

Output:

[ETCoreMLModelCompiler.mm:55] [Core ML]  Failed to compile model, error = Error Domain=com.apple.mlassetio Code=1 "Failed to parse the model specification. Error: Unable to parse ML Program: in operation aten_instance_norm_default_cast_fp16: parameter x[0] has invalid rank 5, expecte$
[backend_delegate.mm:288] [Core ML] Model init failed Failed to compile model, error = Error Domain=com.apple.mlassetio Code=1 "Failed to parse the model specification. Error: Unable to parse ML Program: in operation aten_instance_norm_default_cast_fp16: parameter x[0] has invali$
[coreml_backend_delegate.mm:193] CoreMLBackend: Failed to init the model.
[method.cpp:113] Init failed for backend CoreMLBackend: 0x23
Versions

coremltools version 8.3
executorch commit https://github.com/pytorch/executorch/commit/67b6009d6b3b67eee775c8ed2fe30eae6e0bb65c (Jun 14)

cc @kimishpatel @YifanShenSZ @cymbalrush @metascroy

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with executorch.backends.apple.coreml.partition.CoreMLPartitioner and run the supplied InstanceNorm3d reproduction using the stated Core ML and ExecuTorch versions. Trace the generated Core ML model around aten_instance_norm_default_cast_fp16 and the reported rank-5 parsing failure. Done means the lowered model loads successfully and its outputs can be compared with eager_outputs.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.