Skip to content

graph: utils: pm: correctly handle empty optional subgraph and multi-consumer one #3282

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 2 commits into from
Jun 19, 2025

Conversation

ShanSimu
Copy link
Contributor

@ShanSimu ShanSimu commented May 16, 2025

Description

During pattern matching, we found a bug that occurs when two optional subgraphs are connected: if the first one is empty and the second one's input has multi-consumers, it leads to incorrect behavior. This PR is intended to fix that bug.

Fixes MFDNN-13660

@ShanSimu ShanSimu self-assigned this May 16, 2025
@ShanSimu ShanSimu requested a review from a team as a code owner May 16, 2025 03:23
@ShanSimu ShanSimu added the component:graph-api Codeowner: @oneapi-src/onednn-graph label May 16, 2025
@ShanSimu ShanSimu force-pushed the shaojiec/fix_causal_mask branch from b897dbd to cf1adcc Compare May 16, 2025 03:54
if (rep_node->get_body()->get_inner_consumer(0)->size()
== 1)
continue;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please elaborate the code above? Especially what is the for and if functions doing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The for loop is used to iterate over all sorted_consumers and check whether their corresponding ops exist in updated_op_map_. If any op hasn't been processed (i.e., all_ops_in_map == false), it further checks whether the out_node (output node) is a multi-consumer. If it's not, the subsequent processing is skipped using continue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the for loop, it seems redundant as the outer loop (L368) already iterates all the consumers, can you just consider that specific consumer?
And when all_ops_in_map = true, why do we still need to match them again in L411? If I understand correctly, in the map means it's already matched?

Copy link
Contributor Author

@ShanSimu ShanSimu May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for commenting. I have removed for loop and just consider the specific op.
Add an else branch to set consumer_matched to true and then break.

continue;
if (rep_node->get_body()->get_inner_consumer(0)->size() == 1)
continue;
// For repetition case, check if multi consumers have been matched
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a UT to verify the code here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

@ShanSimu ShanSimu force-pushed the shaojiec/fix_causal_mask branch from cf1adcc to 5def59f Compare May 21, 2025 03:13
@github-actions github-actions bot added the component:tests Codeowner: @oneapi-src/onednn-arch label May 21, 2025
@ShanSimu ShanSimu requested a review from ElaineBao May 22, 2025 02:50
@ShanSimu ShanSimu force-pushed the shaojiec/fix_causal_mask branch 2 times, most recently from 6178727 to 94af97e Compare May 26, 2025 02:25
@ShanSimu
Copy link
Contributor Author

make test
set test_scope=NIGHTLY
disable benchdnn_all
enable benchdnn_graph

@ShanSimu ShanSimu force-pushed the shaojiec/fix_causal_mask branch from 94af97e to f3ecaea Compare May 27, 2025 05:50
@ShanSimu
Copy link
Contributor Author

make test
set test_scope=NIGHTLY
disable benchdnn_all
enable benchdnn_graph

@ShanSimu ShanSimu force-pushed the shaojiec/fix_causal_mask branch from f3ecaea to 36fa6a6 Compare June 4, 2025 05:29
@ShanSimu ShanSimu force-pushed the shaojiec/fix_causal_mask branch from 36fa6a6 to 51f7fb2 Compare June 17, 2025 01:39
@ShanSimu
Copy link
Contributor Author

make test
set test_scope=NIGHTLY
disable benchdnn_all
enable benchdnn_graph

@TaoLv TaoLv merged commit d77eb19 into main Jun 19, 2025
23 of 24 checks passed
@TaoLv TaoLv deleted the shaojiec/fix_causal_mask branch June 19, 2025 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:graph-api Codeowner: @oneapi-src/onednn-graph component:tests Codeowner: @oneapi-src/onednn-arch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants