Skip to content

Unsupported a / x.shape[0] #2579

@phhusson

Description

@phhusson

🐞Describing the bug

Reproducer:

import torch

class Model(torch.nn.Module):
    def __init__(self):
        super().__init__()
    def forward(self, x):
        return 16 / x.shape[0]

model = Model()
inputs = (
    torch.randn(2, 16, 11),
)

eager_outputs = model(*inputs)

ep = torch.jit.trace(model, inputs)

import coremltools as ct
import numpy as np

mlmodel = ct.convert(ep, inputs = [ct.TensorType(shape=[2,16,11])], convert_to='mlprogram')

Result:
ValueError: Op "5" (op_type: inverse) Input x="4" expects tensor or scalar of dtype from type domain ['fp16', 'fp32'] but got tensor[1,int32], inverse, 5

Expected result: conversion success

Note: This was seen in a RoPE implementation, which can neatly be fixed with a conversion to float

coremltools 8.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUnexpected behaviour that should be corrected (type)triagedReviewed and examined, release as been assigned if applicable (status)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions