-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e37d50
commit 31ca070
Showing
10 changed files
with
594 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
523 changes: 522 additions & 1 deletion
523
contrib/kaggle/distributed-pytorch-xla-basics-with-pjrt.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import os | ||
import sys | ||
import unittest | ||
|
||
import torch | ||
import torch_xla | ||
import torch_xla.core.xla_model as xm | ||
|
||
|
||
class InplaceUpdateTest(unittest.TestCase): | ||
|
||
def test_aten_op_after_full_update(self): | ||
device = xm.xla_device() | ||
t = torch.ones(2, 1, device=device) | ||
w = torch.ones(1, 2, device=device) | ||
t.zero_() | ||
y = torch.matmul(t, w) | ||
expected = torch.zeros(2, 2, device=device) | ||
xm.mark_step() | ||
self.assertTrue(torch.all(torch.eq(y, expected))) | ||
|
||
def test_aten_op_after_partial_update(self): | ||
device = xm.xla_device() | ||
t = torch.ones(2, 1, device=device) | ||
w = torch.ones(1, 2, device=device) | ||
t[0][0] = 0 | ||
y = torch.matmul(t, w) | ||
expected = torch.tensor([[0, 0], [1, 1]], device=device) | ||
xm.mark_step() | ||
self.assertTrue(torch.all(torch.eq(y, expected))) | ||
|
||
def test_non_aten_op_after_full_update(self): | ||
device = xm.xla_device() | ||
t = torch.ones(2, 1, device=device) | ||
w = torch.ones(1, 2, device=device) | ||
t.zero_() | ||
y = torch_xla._XLAC._xla_dot_general(t, w, (([1], [0]), ())) | ||
expected = torch.zeros(2, 2, device=device) | ||
xm.mark_step() | ||
self.assertTrue(torch.all(torch.eq(y, expected))) | ||
|
||
def test_non_aten_op_after_partial_update(self): | ||
device = xm.xla_device() | ||
t = torch.ones(2, 1, device=device) | ||
w = torch.ones(1, 2, device=device) | ||
t[0][0] = 0 | ||
y = torch_xla._XLAC._xla_dot_general(t, w, (([1], [0]), ())) | ||
expected = torch.tensor([[0, 0], [1, 1]], device=device) | ||
xm.mark_step() | ||
self.assertTrue(torch.all(torch.eq(y, expected))) | ||
|
||
|
||
if __name__ == '__main__': | ||
test = unittest.main() | ||
sys.exit(0 if test.result.wasSuccessful() else 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters