onnxruntime
093a5f4c - Respect Shape start/end in symbolic shape inference (#33157)

Commit
4 days ago
Respect Shape start/end in symbolic shape inference (#33157) ### Description `SymbolicShapeInference._infer_Shape` stored the full input shape as the node's value and ignored the `start`/`end` attributes added in opset 15. The output type of the Shape node was right (it comes from ONNX shape inference), but every downstream consumer of the value (ConstantOfShape, Reshape, Expand, Concat, ...) got the wrong dims. Example: for an input of shape `[b, s, 8]`, `Shape(start=1)` was propagated as `[b, s, 8]` instead of `[s, 8]`, so a following `ConstantOfShape` was inferred as rank 3 while ORT produces rank 2. The fix slices the symbolic shape with `start`/`end`. Python slicing already clamps negative and out-of-range values the same way the ONNX spec does. Added `test_shape_start_end` to `onnxruntime_test_python_symbolic_shape_infer.py`. I also checked `start`/`end` combinations (`1`, `-2`, `end=-1`, `1..3`, `-10..10`, `3..1`) against the shapes ORT returns at runtime and they all match now. ### Motivation and Context The PyTorch dynamo exporter emits `Shape` with `start`/`end` often, so symbolic shape inference (used by the transformers optimizer and `quant_pre_process`) gives wrong shapes on those models.
Author
Parents
Loading