Commit 1c4e18b
authored
[graph_trainer] Add CooR precompile support for aot_fx_trace compile mode (#2975)
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.14.0)
(oldest at bottom):
* __->__ #2975
Introduce aot_fx_trace as an alternate precompilation path alongside
the existing AOT joint graph export. aot_fx_trace uses make_fx to
trace the full fwd+loss+bwd step as a single FX graph, then serializes
the GraphModule for loading on all ranks during training. Because
cudagraphs is a default pass, we also include cudagraph composability
related changes in this PR to get to bitwise equivalence between
aot_fx_trace with and without precompile.
Changes:
- precompile_main.py: Refactor into _common_setup() + _precompile_aot()
+ _precompile_aot_fx_trace(), route by --compile.mode. Use Python
float for global_valid_tokens (matching dist_sum's return type) so
make_fx bakes it as a graph constant, identical to the runtime path.
- precompile.py: PrecompiledFxTraceArtifact dataclass, save/load fns.
Uses GraphPickler (not plain pickle) to preserve SymInt expressions
(_runtime_compute_coordinate_on_dim) through serialization — plain
pickle evaluates SymInts to concrete trace-time values, baking in
rank-specific embedding vocab offsets.
- compile.py: Mode-aware validation (aot_fx_trace doesn't need
serializable passes), logging for precompile load vs runtime trace
- trainer.py: _load_precompiled_fx_trace(), branching in
_make_fx_forward_backward_step()
- make_fx_tracer.py: Use set_multithreading_enabled(False) so backward
tracing runs on the calling thread, keeping the compile_on_one_rank
ContextVar visible
- cudagraph.py: Defer _input_indices_to_copy when example_inputs is
empty (precompile load path), accept opaque values (DeviceMesh) in
input validation, skip non-tensors in static address checks.
Squashed the separate cudagraph CooR PR into this one because
cudagraph activates automatically for aot_fx_trace graphs (all
inputs are desugared plain tensors + opaques, no HOPs), so bitwise
equivalence testing required both fixes together.
- passes.py: Guard cudagraph_pass against non-GraphModule inputs
## Test plan
- `pytest
torchtitan/experiments/graph_trainer/tests/test_bitwise_deterministic.py
-x` — 6 passed, 4 skipped (Llama3, DSv3 × {eager self-deterministic,
eager vs aot_fx_trace, precompile vs trace})
- `pytest torchtitan/experiments/graph_trainer/tests/test_precompile.py
-x` — all pass
- `pytest
torchtitan/experiments/graph_trainer/tests/test_trace_module.py -x` —
all pass
- 8-GPU integration tests via CI (ciflow/8gpu)1 parent ea6a1cd commit 1c4e18b
10 files changed
Lines changed: 867 additions & 122 deletions
File tree
- torchtitan/experiments/graph_trainer
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
249 | | - | |
| 249 | + | |
250 | 250 | | |
251 | 251 | | |
252 | | - | |
| 252 | + | |
| 253 | + | |
253 | 254 | | |
254 | 255 | | |
255 | 256 | | |
256 | | - | |
257 | | - | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
258 | 261 | | |
259 | 262 | | |
260 | 263 | | |
| |||
281 | 284 | | |
282 | 285 | | |
283 | 286 | | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
288 | 299 | | |
289 | 300 | | |
290 | 301 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| 127 | + | |
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
| |||
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
140 | 146 | | |
141 | 147 | | |
142 | 148 | | |
| |||
157 | 163 | | |
158 | 164 | | |
159 | 165 | | |
160 | | - | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
161 | 174 | | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
173 | 186 | | |
174 | 187 | | |
175 | 188 | | |
| |||
194 | 207 | | |
195 | 208 | | |
196 | 209 | | |
197 | | - | |
| 210 | + | |
198 | 211 | | |
199 | 212 | | |
200 | 213 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
307 | 307 | | |
308 | 308 | | |
309 | 309 | | |
| 310 | + | |
310 | 311 | | |
311 | 312 | | |
312 | 313 | | |
| |||
412 | 413 | | |
413 | 414 | | |
414 | 415 | | |
415 | | - | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
416 | 433 | | |
417 | 434 | | |
418 | 435 | | |
| |||
435 | 452 | | |
436 | 453 | | |
437 | 454 | | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
438 | 458 | | |
439 | 459 | | |
440 | 460 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
| 56 | + | |
61 | 57 | | |
62 | | - | |
63 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
64 | 61 | | |
65 | | - | |
66 | | - | |
| 62 | + | |
67 | 63 | | |
68 | 64 | | |
69 | 65 | | |
70 | | - | |
| 66 | + | |
71 | 67 | | |
72 | 68 | | |
73 | 69 | | |
| |||
93 | 89 | | |
94 | 90 | | |
95 | 91 | | |
96 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
97 | 106 | | |
98 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
99 | 113 | | |
100 | 114 | | |
101 | 115 | | |
102 | 116 | | |
103 | 117 | | |
104 | 118 | | |
105 | 119 | | |
| 120 | + | |
106 | 121 | | |
107 | 122 | | |
108 | | - | |
109 | 123 | | |
110 | 124 | | |
111 | 125 | | |
| |||
277 | 291 | | |
278 | 292 | | |
279 | 293 | | |
| 294 | + | |
280 | 295 | | |
281 | 296 | | |
282 | 297 | | |
| |||
295 | 310 | | |
296 | 311 | | |
297 | 312 | | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
298 | 317 | | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
299 | 325 | | |
300 | 326 | | |
301 | 327 | | |
| |||
305 | 331 | | |
306 | 332 | | |
307 | 333 | | |
308 | | - | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
309 | 340 | | |
310 | 341 | | |
311 | 342 | | |
| |||
0 commit comments