-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Shape inference fails on Concat when first tensor is initialized empty #6276
Comments
I think onnx/onnx/defs/data_propagators.h Lines 40 to 44 in f22a2ad
This is also used by Gather and it is broken: import numpy as np
import torch
import onnx # build from commit f22a2ad78c9b8f3bd2bb402bfce2b0079570ecb6
from onnx import TensorProto
from onnx.helper import (
make_model, make_node, make_tensor, make_graph,
make_tensor_value_info)
print(np.take(np.array([], np.float32), np.array([], np.int64), axis=0))
# []
print(torch.gather(torch.tensor([]), 0, torch.LongTensor([])))
# tensor([])
model = make_model(
make_graph(
[make_node("Gather", ["X", "I"], ["Y"], axis=0)],
"sample",
[],
[make_tensor_value_info("Y", TensorProto.INT64, [0])],
initializer=[
make_tensor("X", TensorProto.INT64, [0], np.array([], np.int64)),
make_tensor("I", TensorProto.INT64, [0], np.array([], np.int64))
]),
opset_imports=[onnx.helper.make_operatorsetid("", 13)])
print("check_model...")
onnx.checker.check_model(model)
print("infer_shapes...")
onnx.shape_inference.infer_shapes(model, strict_mode=True, data_prop=False)
print("infer_shapes w/ data_prop...")
onnx.shape_inference.infer_shapes(model, strict_mode=True, data_prop=True)
Traceback (most recent call last):
File "/home/avocado/github/onnx/sample.py", line 30, in <module>
onnx.shape_inference.infer_shapes(model, strict_mode=True, data_prop=True)
File "/home/avocado/github/onnx/onnx/shape_inference.py", line 46, in infer_shapes
inferred_model_str = C.infer_shapes(
onnx.onnx_cpp2py_export.shape_inference.InferenceError: [ShapeInferenceError] Inference error(s): (op_type:Gather): [ShapeInferenceError] axis must be in [-rank, rank-1]. |
I would like to try to solve this issue, can you assign it to me? |
@liwuhen Please feel free to create a pull request! |
I found that the source code part of this problem is caused by the logic not being written, I can use simple logic for this problem to solve it, but this part involves more code logic, do I need to discuss it? @justinchuby |
…alized empty onnx#6276 Signed-off-by: liwuhen <liwuhen5788@gmail.com>
### Description Fix issue #6276 (data propagation fails on Concat when first tensor is initialized empty). --------- Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Bug Report
Is the issue related to model conversion?
No
Describe the bug
My graph consists of a Concat node (with Axis=0) with two inputs with initializers. The first is initialized to
[]
and the second is[1,2,3]
. When I run shape inference withstrict_mode=True, data_prop=True
, it fails with the following errorSystem information
Reproduction instructions
model.onnx.zip
Expected behavior
The shape inference should succeed. The result of the concat should be a Tensor
[1,2,3]
Notes
The text was updated successfully, but these errors were encountered: