Commit 0ed5f23
Replace op_schema with op_signature (#2771)
This pull request refactors how operator schemas are handled throughout
the autocast, converter, and evaluator modules. The main change is
replacing direct usage of `OpSchema` with a new `_schemas.OpSignature`
abstraction, leading to more consistent and modular code when dealing
with operator signatures, especially for input casting and evaluation.
Several related methods are renamed and refactored for clarity and
encapsulation.
## Important changes
- The `Evaluator` interface now defines `eval_op` on onnx ops. The old
`eval` was removed in favor of a more flexible `eval_op`. The exporter's
eval will continue to function with a compatible logic in `class Op`
- `op_schema` properties from Functions are removed
**Operator signature abstraction and autocast refactor:**
* Replaced usage of `OpSchema` with `_schemas.OpSignature` in
`onnxscript/_internal/autocast.py`, updating all relevant function
signatures and internal logic to use the new abstraction. This includes
changing how input parameters are filtered and type constraints are
accessed.
**AST Converter integration:**
* Updated the converter (`onnxscript/_internal/converter.py`) to pass
`op_signature` instead of `op_schema` to autocast functions, ensuring
compatibility with the new signature abstraction.
**Evaluator refactor and encapsulation:**
* Refactored the evaluator (`onnxscript/_internal/evaluator.py`) to use
`_adapt_inputs`, `_adapt_attributes`, and `_adapt_outputs` methods,
encapsulating the logic for adapting inputs/outputs and removing unused
or redundant methods. Now, operator signatures are consistently adapted
from `OpSchema` using `_schemas.OpSignature`.
Addtionally:
* Clean up typing annotation utilities
* Now supply IR attrs directly when creating attributes to avoid proto
serialization and loss of subgraph references
---------
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>1 parent cd185e8 commit 0ed5f23
File tree
16 files changed
+254
-696
lines changed- docs/examples
- onnxscript
- _internal
- ir
- tests/function_libs/torch_lib
16 files changed
+254
-696
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | 10 | | |
13 | 11 | | |
| 12 | + | |
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
| |||
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | 22 | | |
32 | 23 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
40 | 31 | | |
41 | 32 | | |
42 | 33 | | |
| |||
45 | 36 | | |
46 | 37 | | |
47 | 38 | | |
48 | | - | |
49 | | - | |
| 39 | + | |
| 40 | + | |
50 | 41 | | |
51 | 42 | | |
52 | | - | |
53 | | - | |
54 | | - | |
| 43 | + | |
55 | 44 | | |
56 | 45 | | |
57 | 46 | | |
58 | 47 | | |
59 | 48 | | |
| 49 | + | |
60 | 50 | | |
61 | 51 | | |
62 | 52 | | |
63 | 53 | | |
64 | 54 | | |
65 | 55 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
71 | 59 | | |
72 | | - | |
73 | | - | |
74 | | - | |
| 60 | + | |
75 | 61 | | |
76 | 62 | | |
77 | 63 | | |
| |||
126 | 112 | | |
127 | 113 | | |
128 | 114 | | |
129 | | - | |
| 115 | + | |
130 | 116 | | |
131 | 117 | | |
132 | 118 | | |
| |||
140 | 126 | | |
141 | 127 | | |
142 | 128 | | |
143 | | - | |
| 129 | + | |
144 | 130 | | |
145 | 131 | | |
146 | 132 | | |
147 | 133 | | |
148 | | - | |
| 134 | + | |
| 135 | + | |
149 | 136 | | |
150 | 137 | | |
151 | 138 | | |
| |||
156 | 143 | | |
157 | 144 | | |
158 | 145 | | |
159 | | - | |
| 146 | + | |
160 | 147 | | |
161 | | - | |
| 148 | + | |
162 | 149 | | |
163 | 150 | | |
164 | 151 | | |
165 | 152 | | |
166 | 153 | | |
167 | 154 | | |
168 | 155 | | |
169 | | - | |
| 156 | + | |
170 | 157 | | |
171 | 158 | | |
172 | 159 | | |
| |||
177 | 164 | | |
178 | 165 | | |
179 | 166 | | |
180 | | - | |
| 167 | + | |
181 | 168 | | |
182 | 169 | | |
183 | 170 | | |
184 | 171 | | |
185 | 172 | | |
186 | | - | |
| 173 | + | |
187 | 174 | | |
188 | 175 | | |
189 | 176 | | |
190 | 177 | | |
191 | | - | |
| 178 | + | |
192 | 179 | | |
193 | 180 | | |
194 | 181 | | |
| |||
212 | 199 | | |
213 | 200 | | |
214 | 201 | | |
215 | | - | |
| 202 | + | |
0 commit comments