onnx / onnx-mlir

Representation and Reference Lowering of ONNX Models in MLIR Compiler Infrastructure
Apache License 2.0
743 stars 315 forks source link

Compile Error for compiling bidaf-9 with 'onnx.CategoryMapper' op input rank must be one or two #2153

Open negiyas opened 1 year ago

negiyas commented 1 year ago

We get the following error for compiling bidaf-9 by the latest main branch ( cd7cf7eef3d045c63732731929ba2867a804c6c5 ), because one CategoryMaper has rank-4 input tensor.

Error Message

./build/Debug/bin/onnx-mlir -mcpu=z14 --EmitONNXIR  bidaf-9.onnx
loc("CategoryMapper_5"): error: 'onnx.CategoryMapper' op input rank must be one or two

CategoryMapper op in bidaf-9 causing the error (Rank of input is 4)

    %56 = "onnx.CategoryMapper"(%arg1) {
         cats_int64s = [0, 137, 114, ..., 136], cats_strings = ["", "\E1\B9\83", "<", ..., "\C9\92"],
         default_int64 = 1 : si64, default_string = "_Unused", onnx_node_name = "CategoryMapper_5"} :
         (tensor<?x1x1x16x!onnx.String>) -> tensor<*xi64>                                                                      

In the definition of the ( https://github.com/onnx/onnx/blob/main/docs/Operators-ml.md#ai.onnx.ml.CategoryMapper ), the input tensor's rank should be [N,C] or [C], so that rank should 1 or 2.

CategoryMapper op definition

ai.onnx.ml.CategoryMapper
Converts strings to integers and vice versa.
...
Inputs
X : T1
    Input data
Outputs
Y : T2
    Output data. If strings are input, the output values are integers, and vice versa.

Type Constraints
T1 : tensor(string), tensor(int64)
    The input must be a tensor of strings or integers, either [N,C] or [C].
T2 : tensor(string), tensor(int64)
    The output is a tensor of strings or integers. Its shape will be the same as the input shape.  

How should onnx-mlir support Bidaf-9? Although the rank3+ inputs are illegal, onnx-mlir can handle any rank(shape) of input, because it simply sets shape of the input as shape of the output.

negiyas commented 1 year ago

Created https://github.com/onnx/models/issues/601 as an issue on onnx.model and https://github.com/onnx/onnx/issues/5118 as an issue on onnx.

AlexandreEichenberger commented 1 year ago

Thanks @negiyas I let you decide when to close this one.