-
Notifications
You must be signed in to change notification settings - Fork 109
Allow GraphBuilder to call script functions #2820
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
50ca21b
Add call function
gramalingam 255e747
Add test case
gramalingam ffddfd7
Cleanup
gramalingam 2786955
Add naming options to function call
gramalingam 5236801
Support OpBuilder in converter
gramalingam f66a197
Update documentation
gramalingam f053357
Potential fix for code scanning alert no. 22056: Unused import
gramalingam 8d8b2ea
Potential fix for code scanning alert no. 22055: Unused local variable
gramalingam c6692fa
Update onnxscript/_internal/builder.py
gramalingam 241ba42
Update onnxscript/_internal/_inliner.py
gramalingam d6d92f1
Update onnxscript/_internal/builder.py
gramalingam d2958f3
Address review feedback
gramalingam a35b8dd
Address PR feedback
gramalingam 85418f9
Fix import
gramalingam c29c923
Undo naming changes
gramalingam 11b7438
Fix pylint warning
gramalingam c9e2575
Run lint
gramalingam f4e0576
Merge with main
gramalingam 87ec5d9
Fix naming in test case
gramalingam 36da9f5
Address review comments
gramalingam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
|
|
||
| # Licensed under the MIT License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Mapping, Sequence | ||
|
|
||
| import onnx_ir as ir | ||
| from onnx_ir._cloner import Cloner | ||
|
gramalingam marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def instantiate( | ||
| function: ir.Function, | ||
| inputs: Sequence[ir.Value | None], | ||
| attributes: Mapping[str, ir.Attr], | ||
| *, | ||
| prefix: str = "", | ||
| ) -> tuple[list[ir.Node], list[ir.Value | None]]: | ||
| """Instantiate (inline) a function, substituting inputs and attributes. | ||
|
|
||
| Args: | ||
| function: The function to instantiate. | ||
| inputs: Actual input values to bind to the function's formal parameters. | ||
| attributes: Attribute values to substitute for reference attributes. | ||
| prefix: Optional prefix to prepend to node and output names. | ||
|
|
||
| Returns: | ||
| A tuple of (nodes, outputs) where nodes are the cloned function body | ||
| and outputs are the values corresponding to the function's outputs. | ||
| """ | ||
| formal_inputs = function.inputs | ||
| if len(inputs) > len(formal_inputs): | ||
| raise ValueError( | ||
| f"Too many inputs: got {len(inputs)}, " | ||
| f"but function has {len(formal_inputs)} parameters." | ||
| ) | ||
| value_map: dict[ir.Value, ir.Value | None] = dict(zip(formal_inputs, inputs)) | ||
|
|
||
| def rename(node: ir.Node) -> None: | ||
| if prefix: | ||
| if node.name: | ||
| node.name = prefix + node.name | ||
| for output in node.outputs: | ||
| if output is not None and output.name: | ||
| output.name = prefix + output.name | ||
|
|
||
| cloner = Cloner( | ||
| attr_map=attributes, | ||
| value_map=value_map, | ||
| metadata_props={}, | ||
| post_process=rename, | ||
| resolve_ref_attrs=True, | ||
| ) | ||
| nodes = [cloner.clone_node(n) for n in function] | ||
| outputs = [value_map.get(v) for v in function.outputs] | ||
| return nodes, outputs | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.