Skip to content
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

Sync xla_args before computation. #5823

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions test/dynamo/test_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,17 @@ def foo(x):
x = torch.randint(0, 10, (10,), device=device)
foo(x)

def test_inputs_not_computed(self):

@torch.compile(backend="openxla")
def foo(x):
return x * 2

device = xm.xla_device()
x = torch.rand(5, device=device)
x = x.unsqueeze(dim=-1)
foo(x)


if __name__ == "__main__":
from torch._dynamo.test_case import run_tests
Expand Down
6 changes: 6 additions & 0 deletions torch_xla/core/dynamo_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,12 @@ def call_module(self, target, args, kwargs):


def extract_compiled_graph(xla_model: torch.fx.GraphModule, xla_args):
# Synchronize xla_args, so that each FunctionalTensorWrapper argument updates its
# value reference before actually computing it.
for a in xla_args:
if isinstance(a, torch.Tensor) and torch._is_functional_tensor(a):
torch._functionalize_sync(a)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first time learnt this api.. interesting.


# This call is critical to make sure xla_args' tensor id show up in graph_input_tensor_ids
xm.mark_step()

Expand Down