-
Notifications
You must be signed in to change notification settings - Fork 489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable passing down dynamic dimensions from torch to XLA #5790
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
56f698d
port sandeep unbounded dynamism change
24f42c4
format
lsy323 4acf02d
fix linter
lsy323 495f844
remove set tag
af14415
Enable unbounded dynamism using env var, add more guards for unbounde…
73ec1c5
remove unused util
f2e65aa
Get unbounded dynamism flag from function
lsy323 6b8072d
add test
07d2b43
rename unbounded dynamism private number, and str serializaiton
lsy323 7c0ac9b
recover WORKSPACE
lsy323 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,58 @@ | ||
import sys | ||
import unittest | ||
|
||
import torch | ||
import torch_xla | ||
import torch_xla.core.xla_model as xm | ||
from torch_xla.stablehlo import exported_program_to_stablehlo | ||
|
||
# Note: Unbounded dynamism is under development. It works with unmerged | ||
# XLA changes. Experimental XLA branch: https://github.com/lsy323/openxla-xla/tree/lsiyuan/sandeep-dynamism-rebased | ||
|
||
device = xm.xla_device() | ||
|
||
|
||
class UnboundedDynamismExportTest(unittest.TestCase): | ||
|
||
def test_simply_add(self): | ||
a = torch.tensor([[1, 2], [2, 4]], device=device) | ||
torch_xla._XLAC._xla_mark_dynamic(a, 0) | ||
b = torch.tensor([[1, 2], [2, 4]], device=device) | ||
torch_xla._XLAC._xla_mark_dynamic(b, 0) | ||
c = a * b | ||
hlo_content = torch_xla._XLAC._get_xla_tensors_hlo([c]) | ||
self.assertTrue( | ||
"(p0.1: s64[?,2], p1.2: s64[?,2]) -> (s64[?,2])" in hlo_content) | ||
|
||
def test_export_dynamism(self): | ||
|
||
class M(torch.nn.Module): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
def forward(self, x, y): | ||
return x * y | ||
|
||
example_args = (torch.tensor([[1, 2], [2, 4]], device=device), | ||
torch.tensor([[1, 2], [2, 4]], device=device)) | ||
constraints = [ | ||
# First dimension of each input is a dynamic batch size | ||
torch.export.dynamic_dim(example_args[0], 0), | ||
torch.export.dynamic_dim(example_args[1], 0), | ||
# The dynamic batch size between the inputs are equal | ||
torch.export.dynamic_dim(example_args[0], | ||
0) == torch.export.dynamic_dim( | ||
example_args[1], 0), | ||
] | ||
ep = torch.export.export(M(), args=example_args, constraints=constraints) | ||
shlo_module = exported_program_to_stablehlo(ep) | ||
shlo_text = shlo_module.get_stablehlo_text("forward") | ||
self.assertTrue( | ||
"(%arg0: tensor<?x2xi64>, %arg1: tensor<?x2xi64>) -> tensor<?x2xi64>" in | ||
shlo_text) | ||
|
||
|
||
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please prepare an opset issue to track supporting this mode of dynamism?
Similar work example: #5764
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I think we have a list internally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it work to maintain the list on GH?