Skip to content

feat: Add DrawGraph tool for graph visualization #7172

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 1 commit into from
Dec 6, 2024

Conversation

Nick-Wei
Copy link
Contributor

@Nick-Wei Nick-Wei commented Dec 4, 2024

  • Implemented the DrawGraph tool to visualize graphs.
  • Added test cases to validate the correctness of the generated graphs.

Copy link

pytorch-bot bot commented Dec 4, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/7172

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure

As of commit 938d8f2 with merge base 8861b9a (image):

NEW FAILURE - The following job has failed:

  • pull / unittest-arm / linux-job (gh)
    RuntimeError: Command docker exec -t 83c41ba4f094be30cb613fa9c3cbe0f59f03168483594426fc47c376699ddcdf /exec failed with exit code 1

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 4, 2024
@Nick-Wei
Copy link
Contributor Author

Nick-Wei commented Dec 4, 2024

Hi @haowhsu-quic , this PR enables to draw graphs in the C++ backend. During preprocessing, we can obtain the op wrapper list, which can then be used to generate corresponding graphs. Hopefully we could have this merged, thanks.
Below are the generated graphs and the excel file containing scale data and offset data.
image
image

@dbort dbort requested review from cccclai and haowhsu-quic December 4, 2024 21:57
@dbort dbort added the partner: qualcomm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Qualcomm label Dec 4, 2024
.def(
"GetInputTensors",
&OpWrapper::GetInputTensors,
"A function which get input tensors")
Copy link
Collaborator

Choose a reason for hiding this comment

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

gets. Ditto for followings.

);

py::enum_<Qnn_Definition_t>(m, "QnnDefinition")
.value("IMPL_GENERATED", Qnn_Definition_t::QNN_DEFINITION_IMPL_GENERATED)
Copy link
Collaborator

Choose a reason for hiding this comment

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

"IMPL_GENERATED" -> "QNN_DEFINITION_IMPL_GENERATED" to align the style. Ditto for followings.

@@ -1079,3 +1079,19 @@ def forward(self, x, y):
x = x.view(new_shape)
x = x.permute(0, 2, 1, 3)
return torch.matmul(x, y.transpose(-1, -2))

class draw_graph_model(torch.nn.Module):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Camel form on class name would be better, please also put this in alphabetical order.

@@ -989,3 +995,135 @@ def tag_quant_io(gm: torch.fx.GraphModule, get_quant_io_dtype_fn: Callable):
for node in gm.graph.nodes:
if dtype := get_quant_io_dtype_fn(node):
node.meta[QCOM_QUANTIZED_IO] = dtype


class DrawGraph:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you put class definition to the below of _AnnotationSkipper? thanks.

if input_node_name not in node_list:
node_list[input_node_name] = {"node" : input_node, "input_list" : []}
input_list.append(input_node_name)
# ToDo: tensor v2
Copy link
Collaborator

Choose a reason for hiding this comment

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

#TODO

input_list.append(input_node_name)
# ToDo: tensor v2
elif (op_wrapper.GetOpConfig()["outputTensors"][j].version == 2):
pass
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we raise an exception here to prevent drawing the wrong graph?

node_list[node_name]["input_list"] = input_list
# TODO: tensor v2
elif (op_wrapper.GetOpConfig()["outputTensors"][i].version == 2):
pass
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto.

Copy link
Collaborator

@haowhsu-quic haowhsu-quic left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution, I think this is definitely a great tool for us to debug real graph in QNN.

node_name = node.name
input_list = []
for j in range(op_wrapper.GetOpConfig()["numOfInputs"]):
if(op_wrapper.GetOpConfig()["inputTensors"][j].version == 1):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like wrong indentation here.

@Nick-Wei
Copy link
Contributor Author

Nick-Wei commented Dec 5, 2024

@pytorchbot label "feature"

@pytorch-bot pytorch-bot bot added the feature label Dec 5, 2024
@@ -93,6 +93,12 @@
from torch.fx import passes
from torch.fx.passes.operator_support import OperatorSupportBase
from torch.library import Library
from graphviz import Digraph
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you create a debugger folder under backends/qualcomm and move this implementation to there. Then we could get rid of dependency of python package in utils.py.

- Implemented the DrawGraph tool to visualize graphs.
- Added test cases to validate the correctness of the generated graphs.
@Nick-Wei
Copy link
Contributor Author

Nick-Wei commented Dec 5, 2024

@pytorchbot label "feature"

@Nick-Wei
Copy link
Contributor Author

Nick-Wei commented Dec 5, 2024

@haowhsu-quic The above modifications have been completed. Please help confirm, thanks.

Copy link
Collaborator

@haowhsu-quic haowhsu-quic left a comment

Choose a reason for hiding this comment

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

Looks good to me, thank you for contribution!
Hi @cccclai, it would be great to have this & #6591, mind taking a look? Thank you.

@Nick-Wei
Copy link
Contributor Author

Nick-Wei commented Dec 5, 2024

Thank you for taking the time to review it.

@facebook-github-bot
Copy link
Contributor

@cccclai has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@cccclai cccclai added the release notes: backends [DO NOT USE] Changes to any of the backend delegates label Dec 5, 2024
Copy link
Contributor

@cccclai cccclai left a comment

Choose a reason for hiding this comment

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

Thank you for contributing!

@cccclai cccclai merged commit be0bd75 into pytorch:main Dec 6, 2024
41 of 44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. partner: qualcomm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Qualcomm release notes: backends [DO NOT USE] Changes to any of the backend delegates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants