Commit f8a2ce3
Fix inplace ops on Partial DTensors to preserve aliasing semantics (pytorch#164729)
Fixes pytorch#163374.
Here is the output from reproducible code:
```
W1006 09:09:26.329000 2457 /home/fedora/github/pytorch/torch/distributed/run.py:811]
W1006 09:09:26.329000 2457 /home/fedora/github/pytorch/torch/distributed/run.py:811] *****************************************
W1006 09:09:26.329000 2457 /home/fedora/github/pytorch/torch/distributed/run.py:811] Setting OMP_NUM_THREADS environment variable for each process to be 1 in default, to avoid your system being overloaded, please further tune the variable for optimal performance in your application as needed.
W1006 09:09:26.329000 2457 /home/fedora/github/pytorch/torch/distributed/run.py:811] *****************************************
aten::clamp_(dt: f32[][R], None, 2)
redistribute_input(0, [P] -> [R])
redistribute_input(t: f32[], [P] -> [R])
_c10d_functional::all_reduce(t: f32[], sum, 0)
_c10d_functional::wait_tensor(t: f32[])
aten::clamp_(t: f32[], None, 2)
aten::view(t: f32[], [])
(Replicate(),)
tensor(2., device='cuda:0')
```
The behavior is now matching what you were expecting in issue pytorch#163374:
Expected behavior (from the issue):
1. Placement should change from Partial(sum) to Replicate()
2. Value should be tensor(2.) instead of tensor(144.)
Actual output from this build:
1. (Replicate(),) - placement is correct
2. tensor(2., device='cuda:0') - value is correct
so the inplace operation now properly redistributes the partial DTensor to replicate before performing the clamp snd maintains the correct aliasing semantics. It also produces the expected clamped value.
Pull Request resolved: pytorch#164729
Approved by: https://github.com/ezyang1 parent e2c6834 commit f8a2ce3
File tree
2 files changed
+37
-3
lines changed- test/distributed/tensor
- torch/distributed/tensor
2 files changed
+37
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
331 | 331 | | |
332 | 332 | | |
333 | 333 | | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
334 | 353 | | |
335 | 354 | | |
336 | 355 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
340 | 344 | | |
341 | 345 | | |
342 | 346 | | |
343 | 347 | | |
344 | 348 | | |
345 | | - | |
346 | | - | |
347 | | - | |
| 349 | + | |
348 | 350 | | |
349 | 351 | | |
350 | 352 | | |
351 | 353 | | |
352 | 354 | | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
353 | 368 | | |
354 | 369 | | |
355 | 370 | | |
| |||
0 commit comments