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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions python/hidet/drivers/build_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import List, Set, Dict
from typing import List, Dict
import os
import json
import shutil
Expand All @@ -34,15 +34,15 @@ def get_graph_weights(graph):
Get the weights of the graph. All constant tensors used by the operators in the graph, or returned directly by the
graph, are considered as weights.
"""
weights: Set[Tensor] = set()
weights: List[Tensor] = []
for node in graph.nodes:
for x in node.inputs:
if x.storage is not None:
weights.add(x)
weights.append(x)
for y in graph.outputs:
if y.storage is not None:
weights.add(y)
return list(weights)
weights.append(y)
return weights


def get_graph_intermediates(graph):
Expand Down Expand Up @@ -145,6 +145,7 @@ 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.

lines.append(str(space))

graph_hash = sha256('\n'.join(lines).encode('utf-8')).hexdigest()[:16]

return GraphMetaData(
Expand Down
8 changes: 5 additions & 3 deletions python/hidet/graph/impl/graph_impl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Tuple, Dict, Set, Optional, Union
from typing import List, Tuple, Dict, Optional, Union
from collections import defaultdict
import hidet.option
from hidet.graph.tensor import Tensor
Expand Down Expand Up @@ -39,10 +39,12 @@ def graph_analyze(
stop_tensors: List[Tensor] = stop_tensors or []

# find out all nodes
all_nodes: Set[Operator] = set()
# use dict for ordered set behaviour
# ordering needed for deterministic node ordering
all_nodes: Dict[Operator, bool] = {}

def find_all_nodes(u: Operator):
all_nodes.add(u)
all_nodes[u] = True
for x in u.inputs:
if x.op is None or x in stop_tensors:
continue
Expand Down
Loading