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 type for - ("FLOAT") [operator] #1960

Open
tuanle0910 opened this issue Nov 20, 2024 · 4 comments
Open

Unsupported left operand type for - ("FLOAT") [operator] #1960

tuanle0910 opened this issue Nov 20, 2024 · 4 comments
Labels
question Further information is requested

Comments

@tuanle0910
Copy link

tuanle0910 commented Nov 20, 2024

Hi everyone, I am trying to use onnxscript to convert a function into a script via the @script decorator. I have two questions:

  1. Is there any ways to do subtraction between an input with the FLOAT type and the input with np.float32? If not, how do I convert from one to the other (I have looked up ALL the possible documentations from onnx but it's not much helpful). Right now I keep getting the error error: Unsupported left operand type for - ("FLOAT") [operator] with note: Right operand is of type "BFLOAT16 | BOOL | COMPLEX128 | COMPLEX64 | DOUBLE | <11 more items>"
  2. Can I still use the normal operator (e.g. +, -, :, *) to do addition/subtraction/division/multiplication within the function that is supposed to be rewritten into .onnx model? The reason I ask is because it looks like onnxscript needs data to be of TensorType?

Package versions. onnxscript = 0.1.0.dev2024112, onnx=1.17.0, onnxconverter-common=1.13.0, onnxruntime=1.20.0, skl2onnx=1.17.0

Example.

         import numpy as np
         import onnx
         import pandas as pd
         from onnxscript import FLOAT
         from onnxscript import opset15 as op
        from onnxscript import script      
        z1 = 5.0
        z2 = 3.0
        t1 = z1.astype('np.float32')
        t2 = z2.astype('np.float32')
        cum_mins = [1,2,3,4]
        @script()
        def model_1(x: FLOAT, y: FLOAT) -> Tuple[Any, Any]:
            # Define constants
            coeff1 = op.Constant(value_float=t1)
            coeff2 = op.Constant(value_float=t2)

            mean_x = op.Constant(value_float=x)
            mean_y = op.Constant(value_float=y)

            exp_arg = coeff1 * (x - mean_x) + coeff2 * (y - mean_y)    
            exp = op.Constant(value_float=0.75) * op.Exp(exp_arg)

            h = op.Constant(value_floats=cum_mins)

            return (exp, h)
@tuanle0910
Copy link
Author

tuanle0910 commented Nov 21, 2024

@justinchuby I'm sorry, but can someone please help me with my question above? I kept encountering these errors while running make lints with mypy ---> Not sure if this is due to the incompatibility between onnxscript and mypy? Without running lints check, the code works perfectly.

For example, make lints complained the following error: Argument 1 to "Where" of "Opset16" has incompatible type "bool"; expected "BOOL" [arg-type], but I tried it in the Python Console within Pycharm and it worked perfectly well --- so I don't understand why it complains this, and how to circumvent it. Can you please help check on your end the compatibility between mypy and onnxscript?

x = 2.0
op.Where(x==1.0, 0.0, 3.0)

@justinchuby justinchuby added the question Further information is requested label Nov 21, 2024
@titaiwangms
Copy link
Contributor

  1. Use op.Cast to cast the value to your intended datatype first
  2. Yes

@tuanle0910
Copy link
Author

@titaiwangms Thank you very much for your help, Mr. Wang. I tried op.Cast but I still got the error message of Left Operand Type is not supported for '*' --- Is there an internal issue between the data type used by onnxscript and the one by mypy?

@justinchuby
Copy link
Collaborator

The current typing system we have in onnxscript doesn't work well with mypy. I suggest disabling mypy for files that uses onnxscript for now. That's something on our roadmap but may take time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants