expr.h
45.4 KB
-
[NODE][IR] Introduce StructuralHash for the Unified IR. (#5160) · 497d01d3
* [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>
Tianqi Chen committed