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

xm.save() should not set sync_xla_data=True when sync'ing. #8484

Merged
merged 1 commit into from
Dec 17, 2024

Conversation

mcuiaws
Copy link
Contributor

@mcuiaws mcuiaws commented Dec 11, 2024

Setting sync_xla_data=True performs tensor graph sync as if it's a mark step, which triggers buffer aliasing to be performed. However, according to the comments in https://github.com/pytorch/xla/blame/v2.5.1/torch_xla/csrc/xla_graph_executor.cpp#L1336, it's not safe to do so unless all live tensors are being sync'd.

This fixes #8422

@mcuiaws mcuiaws force-pushed the fix_8422 branch 2 times, most recently from c2af6fa to 3d48f2a Compare December 11, 2024 22:18
Copy link
Collaborator

@tengyifei tengyifei left a comment

Choose a reason for hiding this comment

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

Need to resolve conflicts before merging.

@@ -143,6 +144,28 @@ def try_grad_accum(model, device, train_x, train_label, accum_steps):
alias_count == 1.0
), f"Expect 1 input-output alias pair for gradient accumulation, got {alias_count}"

def test_xm_save_no_aliasing(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this test is added in https://github.com/pytorch/xla/pull/8467/files already

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rebased.

Setting sync_xla_data=True performs tensor graph sync as if
it's a mark step, which triggers buffer aliasing to be performed.
However, it's not safe to do so unless all live tensors are
being sync'd.

Also fix torch_xla.utils.serialization.save() which has the same
issue.

This fixes pytorch#8422
@tengyifei tengyifei merged commit d3ed982 into pytorch:master Dec 17, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

xm.save() should not trigger buffer aliasing
3 participants