-
Notifications
You must be signed in to change notification settings - Fork 103
Add input() and add_output() methods to GraphBuilder #2828
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
Open
justinchuby
wants to merge
4
commits into
main
Choose a base branch
from
input-output
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
|
|
@@ -541,6 +541,65 @@ def test_output_names_are_unique_for_same_op_type(self): | |
| names = [t1.name, t2.name, t3.name] | ||
| self.assertEqual(len(set(names)), 3) | ||
|
|
||
| def test_input_creates_and_registers_graph_input(self): | ||
| """Test that GraphBuilder.input creates and appends a graph input value.""" | ||
| graph = ir.Graph( | ||
| name="test_model", | ||
| inputs=[], | ||
| outputs=[], | ||
| nodes=[], | ||
| opset_imports={"": _default_opset_version}, | ||
| ) | ||
| graph_builder = builder.GraphBuilder(graph) | ||
|
|
||
| value = graph_builder.input("data", dtype=ir.DataType.FLOAT, shape=[2, 3]) | ||
|
|
||
| self.assertEqual(value.name, "data") | ||
| self.assertEqual(value.type.dtype, ir.DataType.FLOAT) | ||
| self.assertEqual(list(value.shape), [2, 3]) | ||
| self.assertEqual(len(graph.inputs), 1) | ||
| self.assertIs(graph.inputs[0], value) | ||
|
|
||
justinchuby marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def test_add_output_renames_and_registers_output(self): | ||
| """Test that GraphBuilder.add_output renames (optionally) and appends outputs.""" | ||
| graph = ir.Graph( | ||
| name="test_model", | ||
| inputs=[], | ||
| outputs=[], | ||
| nodes=[], | ||
| opset_imports={"": _default_opset_version}, | ||
| ) | ||
| graph_builder = builder.GraphBuilder(graph) | ||
|
|
||
| output = ir.Value(name="old_name") | ||
| graph_builder.add_output(output, "new_name") | ||
|
|
||
| self.assertEqual(output.name, "new_name") | ||
| self.assertEqual(len(graph.outputs), 1) | ||
| self.assertIs(graph.outputs[0], output) | ||
|
Comment on lines
+600
to
+616
|
||
|
|
||
justinchuby marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def test_initializer_qualification_behavior(self): | ||
| """Test that GraphBuilder.initializer qualifies names unless explicitly disabled.""" | ||
| graph = ir.Graph( | ||
| name="test_model", | ||
| inputs=[], | ||
| outputs=[], | ||
| nodes=[], | ||
| opset_imports={"": _default_opset_version}, | ||
| ) | ||
| graph_builder = builder.GraphBuilder(graph) | ||
|
|
||
| graph_builder.push_module("layer1") | ||
| qualified = graph_builder.initializer(ir.tensor([1.0], name="w"), name="weight") | ||
| unqualified = graph_builder.initializer( | ||
| ir.tensor([2.0], name="b"), name="bias", qualify=False | ||
| ) | ||
|
|
||
| self.assertEqual(qualified.name, "layer1.weight") | ||
| self.assertEqual(unqualified.name, "bias") | ||
| self.assertIn("layer1.weight", graph.initializers) | ||
| self.assertIn("bias", graph.initializers) | ||
|
|
||
| def test_multi_output_names_are_unique(self): | ||
| """Test that multi-output ops produce unique names with counter suffix.""" | ||
| op, x, y = _create_builder_with_inputs() | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about this too. I think if we could accommodate something like
FLOAT['N', 1024]as a way of compactly specifying type and shape, it would help. Like it is done here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hesitant to pass in generic-looking type objects around. The behavior of generic type classes tend to be a bit unstable across different python versions (where things are stored, how data can be accessed, when something is evaluated, etc.). So I am not preferring it for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is unstable? Maybe we can fix it. Or support something like
(dtype, ('N', 1024))There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In summary: the suggestions are