@@ -44,14 +44,19 @@ values for the attributes ``start`` and ``end``.
44
44
45
45
.. literalinclude :: examples/firstdim.py
46
46
47
- In the translation of a call to an ONNX operator, keyword arguments (aka named arguments)
48
- of Python are translated into attribute parameters (of ONNX), while positional arguments
47
+ In the translation of a call to an ONNX operator, the translator makes use of the
48
+ ``OpSchema `` specification of the operator to map the actual parameters to appropriate input
49
+ parameters and attribute parameters. Since the ONNX specification does not indicate any
50
+ ordering for attribute parameters, it is recommended that attribute parameters be specified
51
+ using keyword arguments (aka named arguments).
52
+
53
+ If the translator does not have an opschema for the called op, it uses the following
54
+ strategy to map the actual parameters to appropriate input parameters and attribute parameters:
55
+ Keyword arguments of Python are translated into attribute parameters (of ONNX), while positional arguments
49
56
are translated into normal value-parameters.
50
- Thus, ``X `` is treated as a normal value-parameter (in ONNX) for this particular call, while
51
- ``start `` and ``end `` are treated as attribute-parameters.
52
- This is a limitation of the current converter and is proposed to be relaxed
53
- when schema information is available for the callee indicating which are
54
- value-parameters and which are attribute-parameters.
57
+ Thus, in the above example, ``X `` is treated as a normal value-parameter for this particular call, while
58
+ ``start `` and ``end `` are treated as attribute-parameters (when an opschema is unavailable).
59
+
55
60
56
61
**Specifying tensor-valued attributes **
57
62
@@ -106,13 +111,48 @@ The converter uses the type annotation on the formal input parameters to make th
106
111
Thus, in the example below, ``alpha `` is treated as an attribute parameter (because of its ``float ``
107
112
type annotation).
108
113
109
- .. literalinclude :: examples/leakyrelu.py
114
+ .. literalinclude :: examples/leaky_relu.py
115
+
116
+ The (ONNX) types of attributes supported and their corresponding (Python) type annotations are shown
117
+ in the table below. Other types of ONNX attributes are not yet supported.
118
+
119
+ ====================== ======================
120
+ ONNX Type Python Type Annotation
121
+ ====================== ======================
122
+ AttributeProto.FLOAT float
123
+ AttributeProto.INT int, bool
124
+ AttributeProto.STRING str
125
+ AttributeProto.FLOATS Sequence[float]
126
+ AttributeProto.INTS Sequence[int]
127
+ AttributeProto.STRINGS Sequence[str]
128
+ ====================== ======================
129
+
130
+ **Automatic promotion of attribute-parameters to values **
110
131
111
132
As illustrated in the above example, when an attribute-parameter is used in a context
112
133
requiring a value-parameter, the converter will automatically convert the attribute
113
134
into a tensor-value. Specifically, in the sub-expression ``alpha * X ``, the attribute
114
135
parameter ``alpha `` is used as a value-parameter of the call to the ``Mul `` op (denoted
115
- by the ``* ``) and is automatically converted.
136
+ by the ``* ``) and is automatically converted. Thus,
137
+
138
+ .. literalinclude :: examples/leaky_relu.py
139
+
140
+ is expanded to the following:
141
+
142
+ .. literalinclude :: examples/leaky_relu_attr_promoted.py
143
+
144
+ **Automatic casts for constant values **
145
+
146
+ The converter also automatically introduces casts (via the ONNX ``CastLike `` op)
147
+ when constants are used in a context where they are constrained to be of the
148
+ same type as some other (non-constant) operand. For example, the expression
149
+ ``2 * X `` is expanded to ``op.CastLike(2, X) * X ``, which allows the same
150
+ code to work for different types of ``X ``.
151
+
152
+ *Control-Flow *
153
+
154
+ The support for control-flow constructs in |onnxscript | is limited by
155
+ requirements of ONNX control-flow ops.
116
156
117
157
**Conditional statements **
118
158
0 commit comments