onnx / sklearn-onnx

Convert scikit-learn models and pipelines to ONNX
Apache License 2.0
551 stars 101 forks source link

Concat Op does not properly check types, resulting in redundant Cast Ops #929

Open nolangroves opened 1 year ago

nolangroves commented 1 year ago

https://github.com/onnx/sklearn-onnx/blob/7bfcd523b00c0043437387d17e23438fd5713eee/skl2onnx/operator_converters/concat_op.py#L12-L22

The Concat operation does not properly compare typings (line 15), resulting in an excess of redundant Cast operations. It will return False when the input and output tensors are the same type but of different sizes (which is most of the use cases of the Concat operation)

For example, Int64TensorType(shape=[None, 1]) == Int64TensorType(shape=[None, 10]) returns False, resulting in an extra cast operation on each of the 10 Int64 inputs.

xadupre commented 1 year ago

Thanks for finding it.