Skip to content

CoreML randn_like fails to lower with internal error #11722

@GregoryComer

Description

@GregoryComer
Member

🐛 Describe the bug

Models with torch.randn_like fail to lower with an internal error in coremltools.

Repro:

import torch

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

class Model(torch.nn.Module):
    def __init__(self):
        super().__init__()
        
    def forward(self, x):
        return torch.randn_like(x)

model = Model()
inputs = (
    torch.zeros(5, 5),
)

print(inputs)

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

ep = torch.export.export(model.eval(), inputs)
print(ep)

print(f"EP: {ep.module()(*inputs)}")

lowered = to_edge_transform_and_lower(
    ep,
    partitioner=[CoreMLPartitioner()],
    compile_config=EdgeCompileConfig(_check_ir_validity=False)
).to_executorch()

print(lowered.exported_program())

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

print(et_outputs)

et_outputs - eager_outputs

Output:

File [~/miniconda3/envs/executorch/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/ops.py:274](http://localhost:8888/lab/tree/~/miniconda3/envs/executorch/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/ops.py#line=273), in _get_inputs.<locals>.check_if_number_of_inputs_expected(num_inputs, expected)
    272 expected = [expected] if isinstance(expected, int) else expected
    273 if num_inputs not in expected:
--> 274     raise ValueError(
    275         f"node {node.name} ({node.kind}) got {num_inputs} input(s), expected {expected}"
    276     )

ValueError: node aten_randn_like_default (randn_like) got 1 input(s), expected [6]

Versions

coremltools version 8.3
executorch commit 67b6009 (Jun 14)

cc @kimishpatel @YifanShenSZ @cymbalrush @metascroy

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend testerThis bug was found by the backend test suite.module: coremlIssues related to Apple's Core ML delegation and code under backends/apple/coreml/

    Type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @GregoryComer

        Issue actions

          CoreML randn_like fails to lower with internal error · Issue #11722 · pytorch/executorch