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

[NODE][IR] Introduce StructuralHash for the Unified IR. #5160

Merged
merged 4 commits into from
Mar 28, 2020

Conversation

tqchen
Copy link
Member

@tqchen tqchen commented Mar 28, 2020

This PR introduces a new way to handle structural hash for the unified IR.

  • Each object can now register an optional SEqualHash function, which
    describes how to reduce its structural equality to sequence of hash values.
  • Optionally, the object can choose to allow labeling of vars(e.g. function parameters)
    by calling DefHash
  • We implemented a non-recursive structural hasher that maintains its own stack
    to traverse te IR.

This PR also improves the hash value property from the previous relay's hash utility.
In particular, the graph node mode hashs a DAG differently from a tree
by attaching an unique occurence index to each graph node.

In all of the test cases so far, structural_hash is consistent with structural_equal.

  • if structrual(x, y) then structural_hash(x) == structural_hash(y)
  • if structural_hash(x) == structural_hash(y) then highly likely structural_equal(x, y)
    • hash no collison is found in our testcases.

Ideally we should work on automatically generating these functions in the future.

The new structural equal is intented to supersede AttrsHash and relay's StructuralHash function. Follow-up should be performed to redirect the existing usages, and removes
the corresponding implementation.

This PR introduces a new way to handle structural hash for the unified IR.

- Each object can now register an optional SEqualHash function, which
  describes how to reduce its structural equality to sequence of hash values.
- Optionally, the object can choose to allow labeling of vars(e.g. function parameters)
  by calling DefHash
- We implemented a non-recursive structural hasher that maintains its own stack
  to traverse te IR.

This PR also improves the hash value property from the previous relay's hash utility.
In particular, the graph node mode hashs a DAG differently from a tree
by attaching an unique occurence index to each graph node.

In all of the test cases so far, structural_hash is consistent with structural_equal.
- if structrual(x, y) then structural_hash(x) == structural_hash(y)
- if structural_hash(x) == structural_hash(y) then highly likely structural_equal(x, y)
  - hash no collison is found in our testcases.

Ideally we should work on automatically generating these functions in the future.
@tqchen
Copy link
Member Author

tqchen commented Mar 28, 2020

Copy link
Contributor

@MarisaKirisame MarisaKirisame left a comment

Choose a reason for hiding this comment

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

LGTM

src/node/structural_hash.cc Outdated Show resolved Hide resolved
Co-Authored-By: 雾雨魔理沙 <lolisa@marisa.moe>
@tqchen tqchen merged commit 497d01d into apache:master Mar 28, 2020
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Apr 16, 2020
* [NODE][IR] Introduce StructuralHash for the Unified IR.

This PR introduces a new way to handle structural hash for the unified IR.

- Each object can now register an optional SEqualHash function, which
  describes how to reduce its structural equality to sequence of hash values.
- Optionally, the object can choose to allow labeling of vars(e.g. function parameters)
  by calling DefHash
- We implemented a non-recursive structural hasher that maintains its own stack
  to traverse te IR.

This PR also improves the hash value property from the previous relay's hash utility.
In particular, the graph node mode hashs a DAG differently from a tree
by attaching an unique occurence index to each graph node.

In all of the test cases so far, structural_hash is consistent with structural_equal.
- if structrual(x, y) then structural_hash(x) == structural_hash(y)
- if structural_hash(x) == structural_hash(y) then highly likely structural_equal(x, y)
  - hash no collison is found in our testcases.

Ideally we should work on automatically generating these functions in the future.

* Fix cases for EnvFunc and Array dims

* fix testcase

* Update src/node/structural_hash.cc

Co-Authored-By: 雾雨魔理沙 <lolisa@marisa.moe>

Co-authored-by: 雾雨魔理沙 <lolisa@marisa.moe>
zhiics pushed a commit to neo-ai/tvm that referenced this pull request Apr 17, 2020
* [NODE][IR] Introduce StructuralHash for the Unified IR.

This PR introduces a new way to handle structural hash for the unified IR.

- Each object can now register an optional SEqualHash function, which
  describes how to reduce its structural equality to sequence of hash values.
- Optionally, the object can choose to allow labeling of vars(e.g. function parameters)
  by calling DefHash
- We implemented a non-recursive structural hasher that maintains its own stack
  to traverse te IR.

This PR also improves the hash value property from the previous relay's hash utility.
In particular, the graph node mode hashs a DAG differently from a tree
by attaching an unique occurence index to each graph node.

In all of the test cases so far, structural_hash is consistent with structural_equal.
- if structrual(x, y) then structural_hash(x) == structural_hash(y)
- if structural_hash(x) == structural_hash(y) then highly likely structural_equal(x, y)
  - hash no collison is found in our testcases.

Ideally we should work on automatically generating these functions in the future.

* Fix cases for EnvFunc and Array dims

* fix testcase

* Update src/node/structural_hash.cc

Co-Authored-By: 雾雨魔理沙 <lolisa@marisa.moe>

Co-authored-by: 雾雨魔理沙 <lolisa@marisa.moe>
@tqchen tqchen deleted the shash branch April 21, 2020 00:01
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.

3 participants