-
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.
Torch functional tensors needs sync'ing before transferring to CPU.
This patch fixes #8482.
- Loading branch information
Showing
3 changed files
with
43 additions
and
0 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
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,39 @@ | ||
import io | ||
import os | ||
|
||
os.environ["XLA_DISABLE_FUNCTIONALIZATION"] = "0" | ||
os.environ["XLA_ENABLE_PARAM_ALIASING"] = "0" | ||
|
||
import torch | ||
import torch_xla | ||
import torch_xla.core.xla_model as xm | ||
import unittest | ||
|
||
|
||
class TestFunctionalization(unittest.TestCase): | ||
|
||
def test_xm_save(self): | ||
""" | ||
Test that xm.save() does torch._functionalize_sync() | ||
""" | ||
xla_device = xm.xla_device() | ||
t1 = torch.tensor([1], device=xla_device) | ||
t2 = t1.detach() | ||
xm.mark_step() | ||
|
||
t2.add_(t2) | ||
xm.mark_step() | ||
|
||
# mark_step() causes t1 and t2 to be out of sync on the XLA side. | ||
# _functionalize_sync() is needed to get them back in sync. | ||
|
||
fobj = io.BytesIO() | ||
xm.save({'t1': t1}, fobj) | ||
fobj.seek(0) | ||
saved = torch.load(fobj) | ||
|
||
self.assertEqual(t1.item(), saved['t1'].item()) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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