Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsupported left operand for type * in onnxscript and opset15 #18200

Closed
tuanle0910 opened this issue Nov 27, 2024 · 5 comments
Closed

Unsupported left operand for type * in onnxscript and opset15 #18200

tuanle0910 opened this issue Nov 27, 2024 · 5 comments
Labels
bug mypy got something wrong

Comments

@tuanle0910
Copy link

tuanle0910 commented Nov 27, 2024

Bug Report

I tried to convert a Python function to onnx Model using onnxscript (the @script() decorator). However, I keep getting weird error types from running python run mypy [Python-file-name], including operator, no-any-return and no-untyped call. When I run the code without mypy, it worked perfectly (the result was accurate).

(A clear and concise description of what the bug is.)

To Reproduce

import numpy as np
import onnx
import onnxruntime
import pandas as pd
from onnxscript import FLOAT
from onnxscript import opset20 as op

x = np.array([1,2,3,4,5,6,7,8,9,10,11,12,13])
y = np.array(x[len(x) - 3: len(x)], dtype=np.float32)
z = np.array(x[len(x)-8: len(x)-3], dtype=np.float32)

x_coef = np.array([1.1, 1.5, 1.7, 1.9, 1.2, 3.1, 4.5, 5.2, 8.5, 9.0, 11.0]
y_coef = np.array([8.5, 9.0, 11.0])
z_coef = np.array([5,7,9,9,10,11])

t1 = len(x)
t2 = len(y)
t3 = len(z)

const_term = 2.37698
h1 = 1.5689
h2 = 1.799
@script()
def conv(a1: FLOAT, a2: FLOAT, a3: FLOAT, a4: FLOAT, a5: FLOAT) -> FLOAT:
    const = op.Constant(value_float=const_term)
    # Define constants
    coeff1 = op.Constant(value_float=h1)
    coeff2 = op.Constant(value_float=h2)
    s = coeff1 * a1  + coeff2 * a2 - const

    for inx in range(t1):
        if a4 == x[inx]:
            s = s + x_coef[inx]
    for inx2 in range(t2):
        if a5 == y[inx2]:
            s = s + y_coef[inx2]
    for inx3 in range(t3):
        if a6 == z[inx3]:
            s = s + z_coef[inx3]
    
    return op.Exp(s)

Expected Behavior

Actual Behavior

error: Unsupported left operand type for * ("BFLOAT16") [operator]
error: Unsupported left operand type for * ("BOOL") [operator]
error: Unsupported left operand type for * ("COMPLEX128") [operator]
error: Unsupported left operand type for * ("COMPLEX64") [operator]
error: Unsupported left operand type for * ("DOUBLE") [operator]
error: Unsupported left operand type for * ("FLOAT") [operator]
error: Unsupported left operand type for * ("FLOAT16") [operator]
error: Unsupported left operand type for * ("FLOAT8E4M3FN") [operator]
error: Unsupported left operand type for * ("FLOAT8E4M3FNUZ") [operator]
error: Unsupported left operand type for * ("FLOAT8E5M2") [operator]
error: Unsupported left operand type for * ("FLOAT8E5M2FNUZ") [operator]
error: Unsupported left operand type for * ("INT16") [operator]
error: Unsupported left operand type for * ("INT32") [operator]
error: Unsupported left operand type for * ("INT64") [operator]
error: Unsupported left operand type for * ("INT8") [operator]
error: Unsupported left operand type for * ("STRING") [operator]
error: Unsupported left operand type for * ("UINT16") [operator]
error: Unsupported left operand type for * ("UINT32") [operator]
error: Unsupported left operand type for * ("UINT64") [operator]
error: Unsupported left operand type for * ("UINT8") [operator]
note: Left operand is of type "BFLOAT16 | BOOL | COMPLEX128 | COMPLEX64 | DOUBLE | <15 more items>"
error: Unsupported left operand type for * ("BFLOAT16") [operator]
error: Unsupported left operand type for * ("BOOL") [operator]
error: Unsupported left operand type for * ("COMPLEX128") [operator]
error: Unsupported left operand type for * ("COMPLEX64") [operator]
error: Unsupported left operand type for * ("DOUBLE") [operator]
error: Unsupported left operand type for * ("FLOAT") [operator]
error: Unsupported left operand type for * ("FLOAT16") [operator]
error: Unsupported left operand type for * ("FLOAT8E4M3FN") [operator]
error: Unsupported left operand type for * ("FLOAT8E4M3FNUZ") [operator]
error: Unsupported left operand type for * ("FLOAT8E5M2") [operator]
error: Unsupported left operand type for * ("FLOAT8E5M2FNUZ") [operator]
error: Unsupported left operand type for * ("INT16") [operator]
error: Unsupported left operand type for * ("INT32") [operator]
error: Unsupported left operand type for * ("INT64") [operator]
error: Unsupported left operand type for * ("INT8") [operator]
error: Unsupported left operand type for * ("STRING") [operator]
error: Unsupported left operand type for * ("UINT16") [operator]
error: Unsupported left operand type for * ("UINT32") [operator]
error: Unsupported left operand type for * ("UINT64") [operator]
error: Unsupported left operand type for * ("UINT8") [operator]
note: Left operand is of type "BFLOAT16 | BOOL | COMPLEX128 | COMPLEX64 | DOUBLE | <15 more items>"
error: Returning Any from function declared to return "FLOAT" [no-any-return] --- Puzzled by this!!
error: Call to untyped function "to_model_proto" in typed context [no-untyped-call]

Your Environment

  • Mypy version used: 1.13.0
  • Mypy command-line flags: [operator], [no-any-return], [no-untyped-call]
  • Mypy configuration options from mypy.ini (and other config files):

[mypy]
python_version=3.11
platform=linux
show_column_numbers=True
follow_imports=normal
ignore_missing_imports=True
disallow_untyped_calls=True
warn_return_any=True
strict_optional=True
warn_no_return=True
warn_redundant_casts=True
warn_unused_ignores=True
disallow_any_generics=True
disallow_untyped_defs=True
check_untyped_defs=True
cache_dir=/dev/null
[mypy-aiohttp.*]
follow_imports=skip
[mypy-_version]
follow_imports=skip

  • Python version used: Python 3.11

  • onnxscript version: 0.1.0.dev20241120

  • onnx version: 1.16.0

  • onnxruntime version: 1.16.3

Tasks

Preview Give feedback
No tasks being tracked yet.
@tuanle0910 tuanle0910 added the bug mypy got something wrong label Nov 27, 2024
@tuanle0910
Copy link
Author

@JukkaL @msullivan @ilevkivskyi Hi everyone, could either of you please help take a look at this issue? I will really appreciate your inputs.

@JelleZijlstra
Copy link
Member

This is likely an issue with the third-party onnx library you are using; it may not expose any typing information, or its typing information may be incorrect.

@tuanle0910
Copy link
Author

@JelleZijlstra Thank you for your quick response. Does mypy support onnx though? From my reading of the attached .pdf file (page 26-27), looks like it did. And can you clarify further on this: "it may not expose any typing information, or its typing information may be incorrect"? My understanding was that the onnx package made by Microsoft only allows certain data types and they are all...weird (e.g. it favors BOOL but not bool).
onnx.pdf

@JelleZijlstra
Copy link
Member

I know nothing about onnx and I don't have time to familiarize myself with it. But mypy doesn't "support" individual third-party packages; these packages should expose typing information using the standards set by the Python type system, and mypy will read that information.

@gvanrossum
Copy link
Member

Moved to onnx/onnx#6563

@gvanrossum gvanrossum closed this as not planned Won't fix, can't repro, duplicate, stale Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants