-
Notifications
You must be signed in to change notification settings - Fork 767
Qualcomm AI Engine Direct - Support Debug Handle and Integrate IntermediateOutputCapturer #16316
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
Draft
winskuo-quic
wants to merge
1
commit into
pytorch:main
Choose a base branch
from
CodeLinaro:dev1/winskuo/debug_handle
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # Copyright (c) Qualcomm Innovation Center, Inc. | ||
| # All rights reserved | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
| import operator | ||
|
|
||
| import torch | ||
| from executorch.backends.qualcomm.utils.constants import QCOM_DEBUG_HANDLE | ||
| from executorch.exir.pass_base import ExportPass, PassResult | ||
|
|
||
|
|
||
| class ResolveDebugHandle(ExportPass): | ||
| """ | ||
| Caution: This pass is executed as the last of the edge_passes. | ||
| For any passes executed during qnn_preprocess, users will need to handle debug_handle ID themselves. | ||
|
|
||
| Description: During passes transformation, some passes might be copying some node's meta when creating a new node, | ||
| which means multiple nodes might be sharing the same debug_handle ID while it shouldn't. | ||
| This is critical as Intermediate Debugger uses debug handle as key. | ||
| debug_handle ID must be resolved so each op gets its own set of debug_handle ID and intermediate output. | ||
| """ | ||
|
|
||
| def __init__(self): | ||
| super(ResolveDebugHandle, self).__init__() | ||
|
|
||
| def call(self, graph_module: torch.fx.GraphModule): | ||
| handle_counter = 1 | ||
| visited = set() | ||
| for node in graph_module.graph.nodes: | ||
| # Assume node is traversed in topological order, adding a check here to be safe. | ||
| if node.target == operator.getitem: | ||
| source_node = node.args[0] | ||
| assert ( | ||
| source_node.name in visited | ||
| ), "Graph is not traversed in topological order, unexpected behavior." | ||
| node.meta[QCOM_DEBUG_HANDLE] = source_node.meta[QCOM_DEBUG_HANDLE] | ||
| elif node.op == "call_function": | ||
| node.meta[QCOM_DEBUG_HANDLE] = handle_counter | ||
| handle_counter += 1 | ||
| visited.add(node.name) | ||
|
|
||
| graph_module.recompile() | ||
| return PassResult(graph_module, True) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im not super understand here: if several nodes comes from one acient node (e..g doing decomposition on some op), they should have the same debug handle for tracing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the idea is that if we decompose the node but never assign a new handle ID, we are just saving the information for the last decomposed node rather than all decomposed node. I have draw an example below. Since edge and QNN has 1 to 1 mapping in this case, I think it would be better to gather all possible information rather than the last node's debug info. Since we reassign graph_handle, instead of only getting the output of node2, we can also get info for node1.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here im a little confused: when we see the qnn graph, how can we know that the qnn_node_1 and qnn_node2 here comes from a same super node? Or another q might be, which graph will play as the ground truth graph, when you doing intermediate comparsion?
We won't gather only the last node debug info, but all info.
In ExecuTorch normally we follow this rule:
if we transform {old_node_1, old_node_2, ..., old_node_n} into {new_node_1, new_node_2, ..., new_node_m}, where n and m can be arbitrary number starting from 1, then: eery new_node should have same debug handle, and the debug handle will be set(old_node_1.debug_handle + old_node_2.debug_handle, ..., old_node_n.debug_handle)
you can see if n is 1, this transform will be a operator decomposition; if m is 1, this transform will be a operator fusion, etc.
In this way whenever we see an arbitrary new_node, we will know its ancestor.
Not sure if that make sense to you?