Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/pip/requirements/lintrunner/mypy-…
Browse files Browse the repository at this point in the history
…1.10.1
  • Loading branch information
justinchuby authored Jul 3, 2024
2 parents 41b7fd3 + 619f5ed commit 77f6e28
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions onnxscript/ir/_convenience.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,29 @@ def tensor(
doc_string=name,
)
return tensor_


def create_value_mapping(graph: _core.Graph) -> dict[str, _core.Value]:
"""Return a dictionary mapping names to values in the graph.
The mapping does not include values from subgraphs.
Args:
graph: The graph to extract the mapping from.
Returns:
A dictionary mapping names to values.
"""
values = {}
values.update(graph.initializers)
# The names of the values can be None or "", which we need to exclude
for input in graph.inputs:
if not input.name:
continue
values[input.name] = input
for node in graph:
for value in node.outputs:
if not value.name:
continue
values[value.name] = value
return values

0 comments on commit 77f6e28

Please sign in to comment.