-
Notifications
You must be signed in to change notification settings - Fork 4k
Fix Shape→Gather→TopK regression: preserve rank-1 single-element index output in data propagation #29084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fix Shape→Gather→TopK regression: preserve rank-1 single-element index output in data propagation #29084
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
839dee9
Fix data propagation dropping rank for 1-D single-element shape values
titaiwangms 43c87ce
Drive decline regression tests via Model::Load + Graph::Resolve
titaiwangms 81c60a2
Assert (not expect) the decline tests' Range output rank
titaiwangms be364c9
Clarify Gather decline comments and remove dead unknown-rank branch
titaiwangms 3d2eb0e
Fold the two data-propagation decline tests into one shared model
titaiwangms 12df3c4
Collapse positive data-prop opt-loops to ORT_DISABLE_ALL to cut ASan …
titaiwangms be9aae8
Update stale decline-test reference in Unsqueeze data-propagation com…
titaiwangms a4a5b70
test: relocate data-propagation shape-inference tests to provider shard
titaiwangms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
67 changes: 67 additions & 0 deletions
67
onnxruntime/core/graph/data_propagation/data_propagation_value_utils.h
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| #include "core/graph/node_arg.h" | ||
|
|
||
| namespace onnxruntime { | ||
|
|
||
| // Data propagation carries a small "shape value" in one of two non-interchangeable channels | ||
| // on a NodeArg: a rank-0 scalar (inferred_scalar_value_) or a rank>=1 list of values | ||
| // (inferred_shape_values_). The helpers below let custom data-propagation ops read and write a | ||
| // single-element value while preserving its rank (rank-0 scalar vs rank-1 [1]), so a producer | ||
| // and its consumers cannot silently disagree on rank (e.g. Gather feeding Mul feeding TopK). | ||
|
|
||
| // Reads a single int64 shape value carried by a NodeArg's data propagation, accepting either a | ||
| // rank-0 scalar value or a rank-1 single-element value. On success, sets `value`, sets | ||
| // `is_rank1` to false for a scalar source or true for a rank-1 [1] source, and returns true. | ||
| // Returns false if the NodeArg carries no usable single-element shape value. | ||
| inline bool TryGetSinglePropagatedShapeValue(const NodeArg& input_def, int64_t& value, bool& is_rank1) { | ||
| if (input_def.GetInferredShapeScalarValue().has_value()) { | ||
| value = input_def.GetInferredShapeScalarValue().value(); | ||
| is_rank1 = false; | ||
| return true; | ||
| } | ||
|
|
||
| const auto& inferred_values = input_def.GetInferredShapeValues(); | ||
| if (inferred_values.has_value() && | ||
| inferred_values->dim_size() == 1 && | ||
| inferred_values->dim(0).has_dim_value()) { | ||
| value = inferred_values->dim(0).dim_value(); | ||
| is_rank1 = true; | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| // Stores a single int64 shape value on `output_def`, as a rank-0 scalar when `is_rank1` is false | ||
| // or as a rank-1 single-element value when `is_rank1` is true. The rank-1 representation mirrors | ||
| // how Graph::getInputData() reconstructs a TensorProto (dims=[1]) from inferred_shape_values_. | ||
| // The setter is correct-by-construction: it populates exactly one channel and clears the other, so | ||
| // the scalar-first reader (TryGetSinglePropagatedShapeValue) and the values-first getInputData() | ||
| // can never disagree on rank even if `output_def` carried a stale value from another channel. | ||
| inline void SetSinglePropagatedShapeValue(NodeArg& output_def, int64_t value, bool is_rank1) { | ||
| if (!is_rank1) { | ||
| output_def.SetInferredShapeScalarValue(value); | ||
| // Keep exactly one channel populated: drop any stale values channel that getInputData() would | ||
| // otherwise prefer over this scalar. | ||
| output_def.GetMutableInferredShapeValues().reset(); | ||
| return; | ||
| } | ||
|
|
||
| auto& inferred_values = output_def.GetMutableInferredShapeValues(); | ||
| if (!inferred_values.has_value()) { | ||
| inferred_values.emplace(); | ||
| } | ||
| inferred_values->clear_dim(); | ||
| inferred_values->add_dim()->set_dim_value(value); | ||
| // Keep exactly one channel populated: drop any stale scalar that the scalar-first reader would | ||
| // otherwise return ahead of this rank-1 value. | ||
| output_def.ClearInferredShapeScalarValue(); | ||
| } | ||
|
titaiwangms marked this conversation as resolved.
|
||
|
|
||
| } // namespace onnxruntime | ||
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.