Skip to content

Commit c749a55

Browse files
committed
Improve message
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
1 parent 37a0c43 commit c749a55

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

onnxscript/optimizer/_constant_folding.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,16 @@ def identity(node: ir.Node, op, state: OptimizerState) -> ReturnValue:
602602
output = node.outputs[0]
603603
if input is not None and output is not None:
604604
# NOTE: backward shape inference
605-
input.shape = _merge_shapes(input.shape, output.shape)
605+
try:
606+
input.shape = _merge_shapes(input.shape, output.shape)
607+
except Exception as e:
608+
logger.warning(
609+
"[Constant folder] Cannot merge shapes on Identity node '%s' "
610+
"(folded from: %s) because of error: %s",
611+
node.name,
612+
input.meta.get(FOLDED_FROM_KEY, set()),
613+
e,
614+
)
606615
if input.type is None:
607616
input.type = output.type
608617
state.set_sym_value(output, input)
@@ -919,7 +928,9 @@ def merge_dims(dim1, dim2):
919928
if other_shape is None:
920929
return preferred_shape
921930
if len(preferred_shape) != len(other_shape):
922-
raise ValueError(f"Shapes must have the same rank, got preferred_shape={preferred_shape}, other_shape={other_shape}")
931+
raise ValueError(
932+
f"Shapes must have the same rank, got preferred_shape={preferred_shape}, other_shape={other_shape}"
933+
)
923934
return ir.Shape(
924935
[merge_dims(dim1, dim2) for dim1, dim2 in zip(preferred_shape, other_shape)]
925936
)

0 commit comments

Comments
 (0)