Conversation
The NeuralNetwork SoftmaxLayer applies axis=-1 for rank-3 inputs, so MIL softmax(axis=-3) must lower to SoftmaxND. Rank >= 4 is unchanged. Fixes apple#1714
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.
Summary
Rank-3 MIL
softmax(axis=-3)now lowers to NeuralNetworkSoftmaxNDinstead ofSoftmaxLayer. The runtime appliesSoftmaxLayeralong axis-1when rank is 3, so the converted model was numerically wrong (reporter's(2, 1, 1)example predicted all-ones instead of a 2-class softmax). Rank ≥ 4 is unchanged.Proto comment for
SoftmaxLayerParamsnow describes the rank-3 runtime exception.Fixes #1714.
Decision
Emit
SoftmaxNDwhen rank < 4; keepSoftmaxLayerfor rank ≥ 4 when the axis is-3/N-3. Document the rank-3 runtime inNeuralNetwork.proto.Alternative: always emit
SoftmaxND(neverSoftmaxLayer). The samerank >= 4gate is already used byconcatinop_mapping.py. Rank ≥ 4SoftmaxLayeris still the layer type on-device-update / CCE expects (#1705). Rank-3SoftmaxLayerwas numerically wrong, so it is not a usable updatable workaround.Can switch to always-
SoftmaxND, or drop the proto comment and keep the converter-only workaround.Test plan
(2, 1, 1)/axis=-3program withconvert_to="neuralnetwork": predict matchesscipy.special.softmax; spec usessoftmaxNDwithaxis == -3.(1, 1, 2)confirms pre-fixSoftmaxLayerwas axis-1; after the fix,axis=-3is a size-1 softmax (all-ones) as expected.axis=-3still emitsSoftmaxLayerand matches scipy.TestSoftmaxincluding the new cases (neuralnetwork + mlprogram). Tests fail on neuralnetwork if the mapping change is reverted.