Skip to content

Commit aa0039e

Browse files
authored
Deprecate ir.Input in favor of ir.val (#185)
Deprecate `ir.Input` in favor of the clearer `ir.val`, since `ir.Input` doesn't really create "Inputs" but instead is a convenience for creating a value. --------- Signed-off-by: Justin Chu <[email protected]>
1 parent 7acc4bf commit aa0039e

File tree

10 files changed

+116
-172
lines changed

10 files changed

+116
-172
lines changed

docs/getting_started.ipynb

Lines changed: 81 additions & 138 deletions
Large diffs are not rendered by default.

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ An in-memory IR that supports the full ONNX spec, designed for graph constructio
1515
## Get started
1616

1717
```{toctree}
18-
:maxdepth: 1
18+
:maxdepth: 2
1919
2020
Overview <self>
2121
getting_started

src/onnx_ir/_convenience/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def replace_all_uses_with(
293293
We want to replace the node A with a new node D::
294294
295295
>>> import onnx_ir as ir
296-
>>> input = ir.Input("input")
296+
>>> input = ir.val("input")
297297
>>> node_a = ir.Node("", "A", [input])
298298
>>> node_b = ir.Node("", "B", node_a.outputs)
299299
>>> node_c = ir.Node("", "C", node_a.outputs)

src/onnx_ir/_convenience/_constructors.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,16 @@ def node(
159159
doc_string: str | None = None,
160160
metadata_props: dict[str, str] | None = None,
161161
) -> ir.Node:
162-
"""Create an :class:`~onnx_ir.Node`.
162+
"""Create a :class:`~onnx_ir.Node`.
163163
164164
This is a convenience constructor for creating a Node that supports Python
165165
objects as attributes.
166166
167167
Example::
168168
169169
>>> import onnx_ir as ir
170-
>>> input_a = ir.Input("A", shape=ir.Shape([1, 2]), type=ir.TensorType(ir.DataType.INT32))
171-
>>> input_b = ir.Input("B", shape=ir.Shape([1, 2]), type=ir.TensorType(ir.DataType.INT32))
170+
>>> input_a = ir.val("A", shape=[1, 2], type=ir.TensorType(ir.DataType.INT32))
171+
>>> input_b = ir.val("B", shape=[1, 2], type=ir.TensorType(ir.DataType.INT32))
172172
>>> node = ir.node(
173173
... "SomeOp",
174174
... inputs=[input_a, input_b],
@@ -218,7 +218,7 @@ def node(
218218

219219

220220
def val(
221-
name: str,
221+
name: str | None,
222222
dtype: ir.DataType | None = None,
223223
shape: ir.Shape | Sequence[int | str | None] | None = None,
224224
*,
@@ -255,7 +255,7 @@ def val(
255255
when you want to create an initializer. The type and shape can be obtained from the tensor.
256256
257257
Returns:
258-
A value with the given name and type.
258+
A Value object.
259259
"""
260260
if const_value is not None:
261261
const_tensor_type = _core.TensorType(const_value.dtype)

src/onnx_ir/_core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
import ml_dtypes
4747
import numpy as np
48-
from typing_extensions import TypeIs
48+
from typing_extensions import TypeIs, deprecated
4949

5050
import onnx_ir
5151
from onnx_ir import (
@@ -2275,6 +2275,7 @@ def is_initializer(self) -> bool:
22752275
return self._is_initializer
22762276

22772277

2278+
@deprecated("Input is deprecated since 0.1.9. Use ir.val(...) instead.")
22782279
def Input(
22792280
name: str | None = None,
22802281
shape: Shape | None = None,

src/onnx_ir/external_data_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def _simple_model(self) -> ir.Model:
166166
node_0 = ir.Node(
167167
"",
168168
"Op_0",
169-
inputs=[ir.Input("input_0"), ir.Input("input_1")],
169+
inputs=[ir.val("input_0"), ir.val("input_1")],
170170
num_outputs=2,
171171
name="node_0",
172172
)

src/onnx_ir/passes/common/identity_elimination_test.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class TestIdentityEliminationPass(unittest.TestCase):
1616
def test_eliminate_identity_not_graph_output(self):
1717
"""Test: y = Identity(x) where y is not a graph output."""
1818
# Create a simple model: input -> Identity -> Add -> output
19-
input_value = ir.Input(
19+
input_value = ir.val(
2020
"input", shape=ir.Shape([2, 2]), type=ir.TensorType(ir.DataType.FLOAT)
2121
)
2222

@@ -110,7 +110,7 @@ def test_eliminate_identity_with_output_renaming(self):
110110
def test_keep_identity_when_both_input_and_output_are_graph_boundaries(self):
111111
"""Test: y = Identity(x) where y is graph output AND x is graph input."""
112112
# Create graph input
113-
input_value = ir.Input(
113+
input_value = ir.val(
114114
"graph_input", shape=ir.Shape([2, 2]), type=ir.TensorType(ir.DataType.FLOAT)
115115
)
116116

@@ -150,7 +150,7 @@ def test_keep_identity_when_both_input_and_output_are_graph_boundaries(self):
150150
def test_multiple_identity_nodes(self):
151151
"""Test elimination of multiple Identity nodes in different scenarios."""
152152
# Create graph input
153-
input_value = ir.Input(
153+
input_value = ir.val(
154154
"input", shape=ir.Shape([2, 2]), type=ir.TensorType(ir.DataType.FLOAT)
155155
)
156156

@@ -203,7 +203,7 @@ def test_multiple_identity_nodes(self):
203203

204204
def test_invalid_identity_node_skipped(self):
205205
"""Test that invalid Identity nodes are skipped."""
206-
input_value = ir.Input(
206+
input_value = ir.val(
207207
"input", shape=ir.Shape([2, 2]), type=ir.TensorType(ir.DataType.FLOAT)
208208
)
209209

@@ -261,7 +261,7 @@ def test_identity_with_none_input_skipped(self):
261261

262262
def test_no_identity_nodes(self):
263263
"""Test pass on a graph with no Identity nodes."""
264-
input_value = ir.Input(
264+
input_value = ir.val(
265265
"input", shape=ir.Shape([2, 2]), type=ir.TensorType(ir.DataType.FLOAT)
266266
)
267267

@@ -311,7 +311,7 @@ def test_empty_graph(self):
311311

312312
def test_chain_of_identities(self):
313313
"""Test elimination of a chain of Identity nodes."""
314-
input_value = ir.Input(
314+
input_value = ir.val(
315315
"input", shape=ir.Shape([2, 2]), type=ir.TensorType(ir.DataType.FLOAT)
316316
)
317317

@@ -362,7 +362,7 @@ def test_chain_of_identities(self):
362362

363363
def test_non_standard_domain_identity_skipped(self):
364364
"""Test that Identity nodes with non-standard domain are skipped."""
365-
input_value = ir.Input(
365+
input_value = ir.val(
366366
"input", shape=ir.Shape([2, 2]), type=ir.TensorType(ir.DataType.FLOAT)
367367
)
368368

@@ -404,7 +404,7 @@ def test_non_standard_domain_identity_skipped(self):
404404

405405
def test_non_identity_node_skipped(self):
406406
"""Test that non-Identity nodes are skipped (covers line 55)."""
407-
input_value = ir.Input(
407+
input_value = ir.val(
408408
"input", shape=ir.Shape([2, 2]), type=ir.TensorType(ir.DataType.FLOAT)
409409
)
410410

@@ -438,7 +438,7 @@ def test_non_identity_node_skipped(self):
438438
def test_function_with_identity_elimination(self):
439439
"""Test that Identity nodes in functions are processed."""
440440
# Create function with Identity node
441-
func_input = ir.Input(
441+
func_input = ir.val(
442442
"func_input", shape=ir.Shape([2, 2]), type=ir.TensorType(ir.DataType.FLOAT)
443443
)
444444

@@ -470,7 +470,7 @@ def test_function_with_identity_elimination(self):
470470
)
471471

472472
# Create a main graph
473-
main_input = ir.Input(
473+
main_input = ir.val(
474474
"main_input", shape=ir.Shape([2, 2]), type=ir.TensorType(ir.DataType.FLOAT)
475475
)
476476

@@ -508,7 +508,7 @@ def test_function_with_identity_elimination(self):
508508

509509
def test_multiple_graph_outputs_with_identity(self):
510510
"""Test case where graph has multiple outputs and only one is the Identity output."""
511-
input_value = ir.Input(
511+
input_value = ir.val(
512512
"input", shape=ir.Shape([2, 2]), type=ir.TensorType(ir.DataType.FLOAT)
513513
)
514514

src/onnx_ir/passes/common/naming_test.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class TestNameFixPass(unittest.TestCase):
1616
def test_assign_names_to_unnamed_values(self):
1717
"""Test ensuring all values have names even if IR auto-assigned them."""
1818
# Create a simple model with auto-assigned names
19-
input_value = ir.Input(
19+
input_value = ir.val(
2020
None, shape=ir.Shape([2, 2]), type=ir.TensorType(ir.DataType.FLOAT)
2121
) # Will get auto-assigned name when added to graph
2222

@@ -53,7 +53,7 @@ def test_assign_names_to_unnamed_values(self):
5353
def test_assign_names_to_unnamed_nodes(self):
5454
"""Test ensuring all nodes have names even if IR auto-assigned them."""
5555
# Create a simple model
56-
input_value = ir.Input(
56+
input_value = ir.val(
5757
"input", shape=ir.Shape([2, 2]), type=ir.TensorType(ir.DataType.FLOAT)
5858
)
5959

@@ -88,7 +88,7 @@ def test_assign_names_to_unnamed_nodes(self):
8888
def test_assigns_names_when_truly_unnamed(self):
8989
"""Test that the pass assigns names when values/nodes are created without names and manually cleared."""
9090
# Create a model and manually clear names to test assignment
91-
input_value = ir.Input(
91+
input_value = ir.val(
9292
"input", shape=ir.Shape([2, 2]), type=ir.TensorType(ir.DataType.FLOAT)
9393
)
9494

@@ -124,13 +124,13 @@ def test_assigns_names_when_truly_unnamed(self):
124124
def test_handles_global_uniqueness_across_subgraphs(self):
125125
"""Test that names are unique globally, including across subgraphs."""
126126
# Create main graph input
127-
main_input = ir.Input(
127+
main_input = ir.val(
128128
"main_input", shape=ir.Shape([2, 2]), type=ir.TensorType(ir.DataType.FLOAT)
129129
)
130130

131131
# Create a simple subgraph for an If node
132132
# Subgraph input and output (with potential name conflicts)
133-
sub_input = ir.Input(
133+
sub_input = ir.val(
134134
"main_input", shape=ir.Shape([2, 2]), type=ir.TensorType(ir.DataType.FLOAT)
135135
) # Same name as main input - should cause conflict
136136

@@ -147,7 +147,7 @@ def test_handles_global_uniqueness_across_subgraphs(self):
147147
)
148148

149149
# Create condition input for If node
150-
condition_input = ir.Input(
150+
condition_input = ir.val(
151151
"condition", shape=ir.Shape([]), type=ir.TensorType(ir.DataType.BOOL)
152152
)
153153

@@ -236,10 +236,10 @@ def test_handles_global_uniqueness_across_subgraphs(self):
236236
def test_handle_duplicate_value_names(self):
237237
"""Test handling duplicate value names by making them unique."""
238238
# Create values with duplicate names
239-
input1 = ir.Input(
239+
input1 = ir.val(
240240
"duplicate_name", shape=ir.Shape([2, 2]), type=ir.TensorType(ir.DataType.FLOAT)
241241
)
242-
input2 = ir.Input(
242+
input2 = ir.val(
243243
"duplicate_name", shape=ir.Shape([2, 2]), type=ir.TensorType(ir.DataType.FLOAT)
244244
)
245245

@@ -276,7 +276,7 @@ def test_handle_duplicate_value_names(self):
276276

277277
def test_handle_duplicate_node_names(self):
278278
"""Test handling duplicate node names by making them unique."""
279-
input_value = ir.Input(
279+
input_value = ir.val(
280280
"input", shape=ir.Shape([2, 2]), type=ir.TensorType(ir.DataType.FLOAT)
281281
)
282282

@@ -321,7 +321,7 @@ def test_handle_duplicate_node_names(self):
321321

322322
def test_no_modification_when_all_names_unique(self):
323323
"""Test that the pass doesn't modify anything when all names are already unique."""
324-
input_value = ir.Input(
324+
input_value = ir.val(
325325
"unique_input", shape=ir.Shape([2, 2]), type=ir.TensorType(ir.DataType.FLOAT)
326326
)
327327

@@ -359,7 +359,7 @@ def test_no_modification_when_all_names_unique(self):
359359
def test_graph_inputs_outputs_have_precedence(self):
360360
"""Test that graph inputs and outputs keep their names when there are conflicts."""
361361
# Create an input with a specific name
362-
input_value = ir.Input(
362+
input_value = ir.val(
363363
"important_input", shape=ir.Shape([2, 2]), type=ir.TensorType(ir.DataType.FLOAT)
364364
)
365365

src/onnx_ir/serde.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ def _deserialize_graph(
711711

712712
# Create values for initializers and inputs
713713
initializer_tensors = [deserialize_tensor(tensor) for tensor in proto.initializer]
714-
inputs = [_core.Input(info.name) for info in proto.input]
714+
inputs = [_core.Value(name=info.name) for info in proto.input]
715715
for info, value in zip(proto.input, inputs):
716716
deserialize_value_info_proto(info, value)
717717

@@ -869,7 +869,7 @@ def deserialize_function(proto: onnx.FunctionProto) -> _core.Function:
869869
Returns:
870870
An IR Function object representing the ONNX function.
871871
"""
872-
inputs = [_core.Input(name) for name in proto.input]
872+
inputs = [_core.Value(name=name) for name in proto.input]
873873
values: dict[str, _core.Value] = {v.name: v for v in inputs} # type: ignore[misc]
874874
value_info = {info.name: info for info in getattr(proto, "value_info", [])}
875875

src/onnx_ir/serde_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ def test_deserialize_graph_handles_unsorted_graph(self):
447447
node_0 = ir.Node(
448448
"",
449449
"Op_0",
450-
inputs=[ir.Input("input_0"), ir.Input("input_1")],
450+
inputs=[ir.val("input_0"), ir.val("input_1")],
451451
num_outputs=2,
452452
name="node_0",
453453
)

0 commit comments

Comments
 (0)