Commit b79d74a
Re-initialize autograd engine in child processes (#4158)
* Re-initialize autograd engine in child processes
The autograd engine uses threads for backwards. These don't exist after
forks and they were not being re-initialized because the
Engine::start_threads_flag was already set. This re-initializes the
engine in child processes, which will cause it to re-create threads when
backwards() is called in the child process.
Note that we only attempt to handle the common case where fork() is
called while the backwards threads are idle.
Fixes #3966
* Avoid non-async-signal-safe functions in fork handler1 parent 5c46427 commit b79d74a
File tree
2 files changed
+46
-0
lines changed- test
- torch/csrc/autograd
2 files changed
+46
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
53 | 58 | | |
54 | 59 | | |
55 | 60 | | |
| |||
417 | 422 | | |
418 | 423 | | |
419 | 424 | | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
420 | 433 | | |
421 | 434 | | |
422 | 435 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
10 | 14 | | |
11 | 15 | | |
12 | 16 | | |
| |||
130 | 134 | | |
131 | 135 | | |
132 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
133 | 153 | | |
134 | 154 | | |
135 | 155 | | |
136 | 156 | | |
| 157 | + | |
137 | 158 | | |
138 | 159 | | |
139 | 160 | | |
| |||
263 | 284 | | |
264 | 285 | | |
265 | 286 | | |
| 287 | + | |
| 288 | + | |
266 | 289 | | |
267 | 290 | | |
268 | 291 | | |
| |||
271 | 294 | | |
272 | 295 | | |
273 | 296 | | |
| 297 | + | |
274 | 298 | | |
275 | 299 | | |
276 | 300 | | |
| |||
326 | 350 | | |
327 | 351 | | |
328 | 352 | | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
329 | 357 | | |
330 | 358 | | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
331 | 364 | | |
332 | 365 | | |
333 | 366 | | |
| |||
0 commit comments