Commit a477918
authored
Migrate OnnxDAG usage to onnx_ir + onnxscript rewriter and remove onnx_dag.py (microsoft#2558)
## Describe your changes
Replaces all `OnnxDAG` usage with `onnx_ir` (onnx-ir) and the
`onnxscript` rewriter, following the pattern from microsoft#2550, then deletes
the `onnx_dag.py` implementation.
**Production passes migrated to `onnx_ir`:**
- `vitis_ai/preprocess.py`, `static_llm.py`, `float16_conversion.py`,
`quantization.py`, `common.py`
- `mnb_to_qdq.py`
- `split.py` — `_run_for_config` rebuilt on ir; split graphs constructed
via per-split value maps, missing value-info resolved through
`SymbolicShapeInference`
- `compose.py` — `_get_composed_model` rebuilt on ir; merge-by-name with
`serde`-based node dedup and numpy shared-initializer equality
- `graph_surgeries.py` — `TieWordEmbeddings` moved from `ProtoSurgeon`
(proto/DAG) to `Surgeon` (`call_ir` on `ir.Model`); removed dead
`find_node` and the DAG-based base `add_reshape_node`
- `peephole_optimizer.py` — `fuse_reshape_operations` reimplemented on
`onnx_ir` (removing the `onnxruntime.transformers.onnx_model.OnnxModel`
dependency), replacing the previous stale OnnxDAG TODO
**onnx_ir idiom cleanups (from review feedback):**
- Use `ir_model.graphs()` (`common.py`), `ir_model.graph.all_nodes()`
(`mnb_to_qdq.py`), and `node.predecessors()` / `node.successors()`
(`split.py`) instead of hand-rolled helpers
- Use `ir.node` for node/attribute construction (`graph_surgeries.py`,
`mnb_to_qdq.py`, `vitis_ai/preprocess.py`)
- Use `ir.convenience.create_value_mapping` to build the value-info map
in `split.py`
- Use `value.dtype` directly in `compose.py`
- Moved the `onnx_ir` import to module top in `quantization.py`
**Correctness fixes for optional node names / opsets (from review
feedback):**
- `compose.py` — only dedup nodes by name when the name is non-empty, so
different unnamed nodes (`name=""`/`None`) no longer collide on the same
key and trigger false "Node mismatch" assertions
- `compose.py` — merge `opset_imports` across all component models (max
version per domain) instead of copying only from the first model, so
composing models with different domains/opset versions produces a valid
model
- `float16_conversion.py` — when `node_include_list` is set, raise a
clear error if the model contains unnamed nodes (which cannot be
included by name), preserving include-only semantics
**Tests:**
- `test_split_model.py`, `test_mnb_to_qdq.py` — migrated to ir idioms
- `test_graph_surgeries.py` — new read-only `GraphInspector` (ir-backed)
replaces `OnnxDAG` inspection sites; it reproduces OnnxDAG's
unique-naming of unnamed/duplicate nodes so name-based assertions stay
stable
**Cleanup:**
- Deleted `olive/passes/onnx/onnx_dag.py`
- No remaining `OnnxDAG` / `onnx_dag` references
Note: unlike OnnxDAG, ir does not auto-assign node names, so call sites
that keyed on names now guard against empty/`None` names (e.g.
`split.py`, `mnb_to_qdq.py`, `compose.py`, `float16_conversion.py`). The
quantized `TieWordEmbeddings` path is validated structurally only (no
ORT inference available offline).
## Checklist before requesting a review
- [x] Add unit tests for this change.
- [x] Make sure all tests can pass.
- [ ] Update documents if necessary.
- [x] Lint and apply fixes to your code by running `lintrunner -a`
- [ ] Is this a user-facing change? If yes, give a description of this
change to be included in the release notes.
## (Optional) Issue link
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>1 parent d9cc5e6 commit a477918
14 files changed
Lines changed: 782 additions & 1610 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
| |||
539 | 538 | | |
540 | 539 | | |
541 | 540 | | |
542 | | - | |
543 | | - | |
| 541 | + | |
| 542 | + | |
544 | 543 | | |
545 | 544 | | |
546 | | - | |
547 | | - | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
548 | 548 | | |
549 | 549 | | |
550 | 550 | | |
| |||
564 | 564 | | |
565 | 565 | | |
566 | 566 | | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
571 | 571 | | |
572 | 572 | | |
573 | 573 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
| |||
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
22 | | - | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| |||
109 | 111 | | |
110 | 112 | | |
111 | 113 | | |
112 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
113 | 125 | | |
114 | 126 | | |
115 | 127 | | |
116 | | - | |
117 | | - | |
118 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
119 | 131 | | |
120 | | - | |
121 | | - | |
| 132 | + | |
| 133 | + | |
122 | 134 | | |
123 | 135 | | |
124 | | - | |
125 | | - | |
| 136 | + | |
| 137 | + | |
126 | 138 | | |
127 | 139 | | |
128 | 140 | | |
129 | | - | |
130 | | - | |
| 141 | + | |
| 142 | + | |
131 | 143 | | |
132 | 144 | | |
133 | 145 | | |
134 | 146 | | |
135 | 147 | | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
152 | 175 | | |
153 | 176 | | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
168 | 191 | | |
169 | 192 | | |
170 | 193 | | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
180 | 206 | | |
181 | 207 | | |
182 | | - | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
183 | 212 | | |
184 | 213 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
193 | 269 | | |
194 | 270 | | |
195 | 271 | | |
196 | | - | |
| 272 | + | |
197 | 273 | | |
198 | 274 | | |
199 | 275 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
13 | | - | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
70 | | - | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | 73 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
84 | 92 | | |
85 | 93 | | |
86 | 94 | | |
| |||
0 commit comments