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

オープン
#1,960 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python

調査の方向性

提供された model_1 例の @script デコレーター、FLOAT アノテーション、演算子式から始め、記載されたパッケージバージョンで左オペランドが未サポートであるエラーを再現してください。FLOAT、NumPy の float32 値、Constant、通常の算術演算子がどのように処理されるかを追跡し、サポートされている変換と式の形式を文書化またはテストしてください。

索引モデルが issue の本文から書いたものです。

説明

category: question

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)
主要言語
Python
スター
457
フォーク
149
平均マージ
3日 15時間
マージ済み PR(30日)
24

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/onnxscript のほかの issue

microsoft/onnxscript の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。