OmarAzizi opened a new pull request, #19966: URL: https://github.com/apache/tvm/pull/19966
## Summary Before opset 13, ONNX `Squeeze` specifies `axes` as a node attribute rather than a tensor input. The Relax ONNX importer only implemented `_impl_v13`, which reads axes from the second input, so for opset < 13 models, the attribute was silently ignored (`axis` defaulted to `None`) and the importer squeezed every size-1 dimension instead of only the requested one. This produced tensors with the wrong rank, breaking downstream ops like `Transpose` whose `perm` no longer matched the input's actual rank. Added `_impl_v1` to read `axes` from the node attribute for opset < 13, and factored the existing squeeze logic into a shared `_squeeze` helper used by both `_impl_v1` and `_impl_v13`. ## Test plan - Added `test_squeeze_axes_attribute` to `tests/python/relax/test_frontend_onnx.py`, covering an opset-11 `Squeeze` node with `axes` as an attribute. - Ran `pytest tests/python/relax/test_frontend_onnx.py -k squeeze`. All 21 tests pass. - Verified against the real-world model that triggers this bug, [PaddlePaddle/PP-OCRv6_tiny_rec_onnx](https://huggingface.co/PaddlePaddle/PP-OCRv6_tiny_rec_onnx) (opset 11, uses attribute-based `Squeeze`): import fails on `main` with `Transpose: number of axes in perm attribute (3) must equal the number of input tensor dimensions (-1)`, and succeeds with this fix. ## Real-world reproduction ```python import urllib.request import onnx from tvm.relax.frontend.onnx import from_onnx # PaddlePaddle/PP-OCRv6_tiny_rec_onnx (opset 11, uses attribute-based Squeeze) url = "https://huggingface.co/PaddlePaddle/PP-OCRv6_tiny_rec_onnx/resolve/main/inference.onnx" path = "pp_ocrv6_tiny_rec.onnx" urllib.request.urlretrieve(url, path) model = onnx.load(path) print("opset:", [(o.domain, o.version) for o in model.opset_import]) for node in model.graph.node: if node.op_type == "Squeeze": axes_attr = [a for a in node.attribute if a.name == "axes"] print(node.name, "inputs=", list(node.input), "axes_attr=", axes_attr) # Fails on main with: # ValueError: Transpose: number of axes in perm attribute (3) must equal the number of input tensor dimensions (-1) # Succeeds with this fix. mod = from_onnx(model) print("Import succeeded") ``` Fixes (partially) #19965. The shape-Gather and dynamic-TopK issues reported in that issue are separate and not addressed here. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
