Use the first dim of size 3 when torch.cross has no dim - #2810
Open
LeSingh1 wants to merge 1 commit into
Open
Conversation
dim is optional in aten::cross. Omitted, torch uses the first dimension of size 3, which is not dim 0 in general. The converter passed the argument straight to mb.gather, where a missing dim fell back to axis 0, so torch.cross(a, b) on a (2, 3) input gathered along the batch axis and produced a (3, 3) output where torch produces (2, 3) — a wrong shape and wrong values, with nothing raised. Resolve the default the way torch does, and raise if no dim has size 3 rather than silently gathering along a dim that cannot hold a cross product.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
dimis optional inaten::cross. Omitted, torch uses the first dimension of size 3, which is not dim 0 in general. The converter passed the argument straight tomb.gather, where the missingdimfell back to axis 0.torch returns shape
(2, 3); Core ML returns(3, 3)— wrong shape and wrong values, with nothing raised. Passingdim=1explicitly has always been correct, which is why the existingtest_cross(which always passesdim) never caught it.The fix resolves the default the way torch does, and raises when no dim has size 3 rather than gathering along a dim that cannot hold a cross product.
Testing
TestCross::test_cross_default_dimover shapes(2, 3),(3, 4),(3, 3),(2, 3, 4). The(2, 3)and(2, 3, 4)cases fail onmain;(3, 4)and(3, 3)pass either way and are there as controls, since for those the first dim of size 3 is dim 0. Existingtest_crossis unchanged and still passes.This machine has a broken scikit-learn install that makes every
TorchFrontend.TORCHEXPORTcase error out, including pre-existing ones, so I could only exercise the TorchScript frontend locally.