Skip to content
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

[Fixbug] Fix graph metadata hash #428

Merged
merged 3 commits into from
Mar 4, 2024
Merged

Conversation

KTong821
Copy link
Contributor

Same graphs should have the same hash. Graph node traversal used in generating hash is non-deterministic, leading to different hashes for the same graph.

This can prevent graph runs from using the fast path, since dispatch tables cannot be found for the current (different) hash!

@yaoyaoding
Copy link
Member

Very interesting!

Is there any example to reproduce the behavior of producing different hashes?

@yaoyaoding yaoyaoding changed the title Fix graph metadata hash [Fixbug] Fix graph metadata hash Feb 21, 2024
@KTong821
Copy link
Contributor Author

KTong821 commented Feb 21, 2024

@yaoyaoding I am able to observe this on my resnet app branch, with >30 layers. Was not able to observe on smaller graphs.

graph_analyze in graph_impl.py runs a topological sort using iteration over unordered data structure (set, dict), causing this behaviour.

@@ -145,6 +145,11 @@ def get_graph_meta_data(graph: FlowGraph, num_kernels, space: int) -> GraphMetaD
lines.append(str(node.task))
lines.append(str(graph))
Copy link
Member

Choose a reason for hiding this comment

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

Will this line produce different string when the topological order is different?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think anything that relies on graph.nodes will cause this.

@vadiklyutiy
Copy link
Collaborator

@KTong821 What is the reason of Graph node traversal used in generating hash is non-deterministic?

@yaoyaoding
Copy link
Member

using iteration over unordered data structure (set, dict), causing this behaviour.

Good catch! We might need to avoid iterating set when we construct the topological order of nodes of flow graph.
Using dict is fine because "Dictionaries preserve insertion order." from https://docs.python.org/3/library/stdtypes.html#mapping-types-dict

@vadiklyutiy for your question, we used set and iterate it when we compute a topological order of our computation graph.

@KTong821
Copy link
Contributor Author

@yaoyaoding yes, making the topological ordering one-to-one is a better solution than sorting the hash input string. We might make different graphs have the same hash by sorting here. Will update PR.

@yaoyaoding
Copy link
Member

Thanks! @KTong821

@yaoyaoding yaoyaoding merged commit b7c9026 into hidet-org:main Mar 4, 2024
2 checks passed
KTong821 added a commit to KTong821/hidet that referenced this pull request Mar 5, 2024
Same graphs should have the same hash. Graph node traversal used in
generating hash is non-deterministic, leading to different hashes for
the same graph.

This can prevent graph runs from using the fast path, since dispatch
tables cannot be found for the current (different) hash!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants