-
Notifications
You must be signed in to change notification settings - Fork 8
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
Showing
6 changed files
with
58 additions
and
20 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
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import unittest | ||
import torch | ||
import torchacc as ta | ||
|
||
|
||
class PatchAutocastTest(unittest.TestCase): | ||
|
||
def _matmul_with_autocast(self, lhs, rhs, first_dtype, second_dtype): | ||
with torch.autocast(device_type=first_dtype, dtype=torch.bfloat16): | ||
first = torch.matmul(lhs, rhs) | ||
with torch.autocast(device_type=second_dtype, enabled=False): | ||
second = torch.matmul(lhs, rhs) | ||
return (first, second) | ||
|
||
def test_patch_autocast(self): | ||
device = ta.lazy_device() | ||
|
||
t1 = torch.rand([2,2], device=device) | ||
t2 = torch.rand([2,2], device=device) | ||
|
||
first, second = self._matmul_with_autocast(t1, t2, 'cuda', 'cuda') | ||
assert first.dtype==torch.bfloat16 | ||
assert second.dtype==torch.float32 | ||
|
||
first, second = self._matmul_with_autocast(t1, t2, 'xla', 'xla') | ||
assert first.dtype==torch.bfloat16 | ||
assert second.dtype==torch.float32 | ||
|
||
first, second = self._matmul_with_autocast(t1, t2, 'cuda', 'xla') | ||
assert first.dtype==torch.bfloat16 | ||
assert second.dtype==torch.float32 | ||
|
||
first, second = self._matmul_with_autocast(t1, t2, 'xla', 'cuda') | ||
assert first.dtype==torch.bfloat16 | ||
assert second.dtype==torch.float32 |
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 |
---|---|---|
|
@@ -133,5 +133,6 @@ def _set_env(): | |
|
||
|
||
patch.patch_fa() | ||
patch.patch_autocast() | ||
decompose.replace_decompose() | ||
_set_env() |
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