Commit 43891bc
fix the fx tracer leaf module logic (#3487)
Summary:
# context
* in response to a TorchRec User Group [post](https://fb.workplace.com/groups/970281557043698/permalink/1984937168911460/)
* in torchrec.train_pipeline, the modified fx tracer
the algorithm is based on "named_modules()" API from torch.nn.Module, there
could be corner cases that a returned "leaf_module" is not actually called in the
forward pass. for example the umbrella_module would be considered as the top-level
leaf module but it actually won't appear in a fx-traced graph.
# example
* traced graph
```
opcode name target args kwargs
------------- ------------ ----------------------- ---------------------------- --------
placeholder x x () {}
call_module nested nested (x,) {}
call_module umbrella1_m1 umbrella1.m1 (x,) {}
call_module umbrella1_m2 umbrella1.m2 (x,) {}
call_function add <built-in function add> (umbrella1_m1, umbrella1_m2) {}
call_function add_1 <built-in function add> (nested, add) {}
call_module umbrella2_m1 umbrella2.m1 (x,) {}
call_function add_2 <built-in function add> (add_1, umbrella2_m1) {}
call_module umbrella2_m2 umbrella2.m2 (x,) {}
call_function add_3 <built-in function add> (add_2, umbrella2_m2) {}
call_module umbrella3 umbrella3 (x,) {}
call_function add_4 <built-in function add> (add_3, umbrella3) {}
call_module umbrella4_m1 umbrella4.m1 (x,) {}
call_function add_5 <built-in function add> (add_4, umbrella4_m1) {}
call_module umbrella4_m2 umbrella4.m2 (x,) {}
call_function add_6 <built-in function add> (add_5, umbrella4_m2) {}
output output output (add_6,) {}
```
Differential Revision: D808583791 parent 3a6cf2e commit 43891bc
File tree
2 files changed
+176
-2
lines changed- torchrec/distributed/train_pipeline
- tests
2 files changed
+176
-2
lines changedLines changed: 125 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| 25 | + | |
23 | 26 | | |
| 27 | + | |
24 | 28 | | |
25 | 29 | | |
26 | 30 | | |
| |||
110 | 114 | | |
111 | 115 | | |
112 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 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 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
514 | 514 | | |
515 | 515 | | |
516 | 516 | | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
517 | 540 | | |
518 | 541 | | |
519 | 542 | | |
| |||
573 | 596 | | |
574 | 597 | | |
575 | 598 | | |
576 | | - | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
577 | 612 | | |
578 | 613 | | |
| 614 | + | |
579 | 615 | | |
580 | 616 | | |
581 | 617 | | |
| |||
585 | 621 | | |
586 | 622 | | |
587 | 623 | | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
588 | 627 | | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
0 commit comments