-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Ensure outer aliasing on DTensor matches inner aliasing #158954
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
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/158954
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 2a5fd23 with merge base f33ce40 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
torch/distributed/tensor/_api.py
Outdated
@@ -355,10 +356,15 @@ def __coerce_same_metadata_as_tangent__(self, flatten_spec, expected_type=None): | |||
# pyre-fixme[3]: Return type must be annotated. | |||
# pyre-fixme[2]: Parameter must be annotated. | |||
def __torch_dispatch__(cls, func, types, args=(), kwargs=None): # type: ignore[override] | |||
return DTensor._op_dispatcher.dispatch( | |||
return return_and_correct_aliasing( |
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.
so.. what does this actually do? is it basically mapping the aliasing metadata from the inner tensor to the outer wrapper?
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.
Yes. It will also make the "fake" storages match if needed such that our "standard" aliasing checks will pass.
torch/distributed/tensor/_api.py
Outdated
@@ -355,10 +356,15 @@ def __coerce_same_metadata_as_tangent__(self, flatten_spec, expected_type=None): | |||
# pyre-fixme[3]: Return type must be annotated. | |||
# pyre-fixme[2]: Parameter must be annotated. | |||
def __torch_dispatch__(cls, func, types, args=(), kwargs=None): # type: ignore[override] | |||
return DTensor._op_dispatcher.dispatch( | |||
return return_and_correct_aliasing( |
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.
Yes. It will also make the "fake" storages match if needed such that our "standard" aliasing checks will pass.
dang it, it makes some dtensor tests deadlock! Time for misery debugging |
Maybe it's unrelated? It doesn't repro locally |
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 1 mandatory check(s) failed. The first few are: Dig deeper by viewing the failures on hud |
It is not unrelated. It's actually this:
it only happens on two ranks and not on the other two. |
Signed-off-by: Edward Z. Yang <ezyangmeta.com> cc H-Huang awgu wanchaol fegin fduwjj wz337 wconstab d4l3k pragupta [ghstack-poisoned]
@wanchaol this potentially adds overhead |
I know how to fix this but I don't have the patience to do it right now. So here's the deal. So the root cause of the test failure here is that occasionally DTensor will put garbage in local tensor, specifically when a DTensor is not participating in a collective. I poked a bit to see if I could enforce a more uniform invariant on local tensor, but I eventually concluded that it is not so easy. So OK, let's just only fix aliases when we participated in ranks. So while I was writing this I started thinking about the performance overhead of doing this. So then I cracked open return_and_correct_aliasing and started reading the implementation. It looks... kind of expensive, actually? So then I started snooping around to see if I could do it in a simple way. Along the way I noticed that return_and_correct_aliasing probably doesn't handle split correctly? And I also noticed that it had already manually reimplemented the mutation/out aliasing behavior. So it's just storage left. But there's no way to easily tell if you ran a view op. And to do it fast you want to have pre-computed the alias relationship instead of doing a doubly nested iteration... |
Signed-off-by: Edward Z. Yang <ezyangmeta.com> cc H-Huang awgu wanchaol fegin fduwjj wz337 wconstab d4l3k pragupta [ghstack-poisoned]
Signed-off-by: Edward Z. Yang <ezyangmeta.com> cc H-Huang awgu wanchaol fegin fduwjj wz337 wconstab d4l3k pragupta [ghstack-poisoned]
I fixed it in an easier way |
@@ -164,7 +165,8 @@ def dispatch( | |||
assert output_sharding is not None, "output sharding should not be None" | |||
|
|||
mesh = op_info.compute_mesh | |||
if mesh.get_coordinate() is not None: | |||
participating = mesh.get_coordinate() is not None |
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.
When is this false? Is this due to h even sharding leaving one rank 'empty'?
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.
A DTensor is associated with a device mesh. The device mesh does NOT necessarily have to cover all of the GPUs that are actually known. We are still SPMD over everything, including things that are not in the mesh. Then those are not participating.
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.
hmm. this is kinda news to me.
i would like to see what example this happened in to understand it better. can you link to it?
usually, we partition the world gpus into various submeshes, but each 'op' still happens on each gpu. and each submesh dim is an orthogonal partitioning of the world mesh. Maybe just in some unit tests there are like 8gpus but the test case only initializes 4 of them?
@@ -450,6 +450,12 @@ def is_out_variant_op(self) -> bool: | |||
# be entirely correct, but it's good enough for now. | |||
return "out" in self.op._schema.overload_name | |||
|
|||
def is_view_op(self) -> bool: | |||
return any( | |||
a.alias_info is not None and not a.alias_info.is_write |
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.
what does 'not is_write' have to do with it being a view? would a modified view not set this?
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.
I'm being a little defensive here. Mutating ops have a write alias like mul_(Tensor(a!) self) -> Tensor(a!) self
. The logic I'm applying here would work in this case, but it is not necessary because these have already been handled by DTensor manually.
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.
it looks like you sidestepped the issue of dealing with the cpu tensor by just fixing up the real tensors, which seems good to me. asked a couple of questions but assuming you have good answers i'm happy with the change.
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Stack from ghstack (oldest at bottom):
Signed-off-by: Edward Z. Yang ezyang@meta.com
cc @H-Huang @awgu @wanchaol @fegin @fduwjj @wz337 @wconstab @d4l3k @pragupta