1717
1818
1919class Builder (tape .Tape ):
20- """An extension of the tape that provides a more convenient API for constructing the IR."""
20+ """An extension of the tape that provides a more convenient API for constructing the IR.
21+
22+ Example:
23+ >>> from onnxscript import ir
24+ >>> from onnxscript.ir import _tape
25+ >>> op = _tape.Builder()
26+ >>> input = ir.Value(name="input", type=ir.TensorType(ir.DataType.FLOAT), shape=ir.Shape((1, 2)))
27+ >>> relu_val = op.Relu(input, _name="relu_node", _domain="", _version=18, _outputs=["relu_out"])
28+
29+ Note: When passing `_name`, ensure it is unique to avoid duplicate node names.
30+ """
2131
2232 def __getattr__ (self , op_type : str ) -> Any :
2333 return lambda * args , ** kwargs : self ._make_node (op_type , args , kwargs )
@@ -26,6 +36,8 @@ def _make_node(self, op_type: str, inputs: Sequence[ir.Value], kwargs: dict[str,
2636 domain = kwargs .pop ("_domain" , "" )
2737 version = kwargs .pop ("_version" , None )
2838 outputs = kwargs .pop ("_outputs" , 1 )
39+ name = kwargs .pop ("_name" , None )
40+
2941 if isinstance (outputs , Sequence ):
3042 num_outputs = len (outputs )
3143 else :
@@ -34,7 +46,12 @@ def _make_node(self, op_type: str, inputs: Sequence[ir.Value], kwargs: dict[str,
3446
3547 if num_outputs == 1 :
3648 value = super ().op (
37- op_type , inputs = inputs , attributes = kwargs , domain = domain , version = version
49+ op_type ,
50+ inputs = inputs ,
51+ attributes = kwargs ,
52+ domain = domain ,
53+ version = version ,
54+ name = name ,
3855 )
3956 if isinstance (outputs , Sequence ):
4057 value .name = outputs [0 ]
@@ -45,6 +62,7 @@ def _make_node(self, op_type: str, inputs: Sequence[ir.Value], kwargs: dict[str,
4562 attributes = kwargs ,
4663 domain = domain ,
4764 version = version ,
65+ name = name ,
4866 num_outputs = num_outputs ,
4967 )
5068 if isinstance (outputs , Sequence ):
0 commit comments