Expected behavior
The ONNX model should be successfully imported by the TVM Relax ONNX frontend.
The model contains dynamic shape calculation subgraphs before Reshape.
The shape graph operators, such as:
Shape
Gather
Slice
Unsqueeze
Concat
should be converted into Relax ShapeExpr / PrimValue instead of normal tensor operations.
Actual behavior
TVM Relax ONNX frontend fails during import.
Error:
InternalError:
Concat expects all input tensors to have same ndim.
However, the input contains tensors with ndim 3 and 2
The failure happens during Concat conversion.
The problematic Concat belongs to a dynamic shape construction subgraph, but it is handled as a normal tensor concatenation operation.
Environment
- TVM:
0.25.dev0 (local source tree)
- PyTorch:
2.12.0+cu130
- Python:
3.10.20
- OS:
Ubuntu 22.04 64-bit
- Target:
llvm (CPU)
- Frontend: from tvm.relax.frontend.onnx import from_onnx
Steps to reproduce
Load an ONNX model containing a dynamic reshape pattern:
import onnx
from tvm.relax.frontend.onnx import from_onnx
model = onnx.load("model.onnx")
mod = from_onnx(model)
The import fails during Concat conversion:
InternalError(
'Concat expects all input tensors to have same ndim.
However, the input contains tensors with ndim 3 and 2'
)
Analysis
The failure occurs for ONNX graphs containing dynamic reshape patterns.
Example pattern:
Input tensor
|
Shape
|
Gather / Slice
|
Unsqueeze
|
Concat
|
Reshape
The ONNX graph generates the target shape of Reshape dynamically.
These intermediate operators do not perform tensor computation. They only construct the shape argument required by Reshape.
The expected Relax representation is:
ShapeExpr
|
PrimValue
|
ShapeExpr
|
Concat
|
ShapeExpr
The current issue is that the shape graph Concat is incorrectly handled as tensor Concat, causing the dimension mismatch error.
Root cause
The same ONNX operators can appear in both tensor computation graphs and shape computation graphs.
Tensor graph example:
Shape graph example:
Shape
|
Gather
|
Unsqueeze
|
Concat
|
Reshape
The frontend needs data-flow based detection to distinguish these two cases.
Expected behavior
The ONNX model should be successfully imported by the TVM Relax ONNX frontend.
The model contains dynamic shape calculation subgraphs before
Reshape.The shape graph operators, such as:
ShapeGatherSliceUnsqueezeConcatshould be converted into Relax
ShapeExpr/PrimValueinstead of normal tensor operations.Actual behavior
TVM Relax ONNX frontend fails during import.
Error:
The failure happens during
Concatconversion.The problematic
Concatbelongs to a dynamic shape construction subgraph, but it is handled as a normal tensor concatenation operation.Environment
0.25.dev0(local source tree)2.12.0+cu1303.10.20Ubuntu 22.04 64-bitllvm(CPU)Steps to reproduce
Load an ONNX model containing a dynamic reshape pattern:
The import fails during
Concatconversion:Analysis
The failure occurs for ONNX graphs containing dynamic reshape patterns.
Example pattern:
The ONNX graph generates the target shape of
Reshapedynamically.These intermediate operators do not perform tensor computation. They only construct the shape argument required by
Reshape.The expected Relax representation is:
The current issue is that the shape graph
Concatis incorrectly handled as tensorConcat, causing the dimension mismatch error.Root cause
The same ONNX operators can appear in both tensor computation graphs and shape computation graphs.
Tensor graph example:
Shape graph example:
The frontend needs data-flow based detection to distinguish these two cases.