Repository navigation
Conversation
Without dim, torch returns the index into the flattened input (a scalar, or all-ones shape with keepdim). The converter reduced over the last axis instead, so a (2, 5, 7) input gave a (2, 5) output.
This branch has not been deployed
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.
torch.argmax(x)andtorch.argmin(x)withoutdimreturn the index into the flattened input (a scalar, or a tensor of ones withkeepdim=True). The converter reduced over the last axis instead, so for a (2, 5, 7) input it produced a (2, 5) output where torch returns a scalar. For a (1, N) input the result happens to match, which is why this goes unnoticed for single-sample logits.This flattens the input before reducing when
dimis None, and reshapes to all-ones whenkeepdimis set.Checks run (Mac, Core ML predictions vs torch, CPU_ONLY):
test_argmax_without_dim/test_argmin_without_dim(rank 1-3, keepdim True/False, float32 and int32 input, TorchScript and torch.export, neuralnetwork and mlprogram): 64 of the 96 new cases fail on main (the rank-1 cases already pass), all pass with this change.-k "TestArgmax or TestArgmin": 288 passed.