-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Reland Simplify handle indexing (#105006) #106357
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/106357
Note: Links to docs will display an error until the docs builds have been completed. ✅ 1 Unrelated FailureAs of commit be4c9a8: UNSTABLE - The following job failed but was likely due to flakiness present on trunk and has been marked as unstable:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This reverts commit a9a3c45. fixes [ghstack-poisoned]
| if not handle: | ||
| return | ||
| # Only record the first usage of a handles key | ||
| if handle in self.handles_to_post_forward_order_index: |
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 the test failures are real :/ |
yeah they are |
This reverts commit a9a3c45. fixes [ghstack-poisoned]
| self.handles_post_forward_order: List[FlatParamHandle] = [] | ||
| # Maps each handles key to its index in `handles_post_forward_order` | ||
| self.handles_to_post_forward_order_index: Dict[FlatParamHandle, int] = {} | ||
| self.handles_post_forward_order: List[Optional[FlatParamHandle]] = [] |
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.
nit: IIUC, this is actually a List[FlatParamHandle] now because we never append None into the list?
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.
LGTM!
| Returns the handle indices (i.e. indices into ``self.all_handles``) | ||
| corresponding to the handles in ``handle``. An entry in the | ||
| returned tuple is ``None`` if the handle is invalid. | ||
| """ |
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.
Before this PR (making note to myself):
pytorch/torch/distributed/fsdp/_exec_order_utils.py
Lines 193 to 201 in be4c9a8
| if self.is_first_iter: | |
| msg_prefix = "Forward order differs across ranks:" | |
| optional_local_indices: Tuple[ | |
| Optional[int], ... | |
| ] = self._get_handle_indices(handle) | |
| device = handle.device # guaranteed to be non-CPU | |
| num_valid_indices = sum( | |
| (index is not None) for index in optional_local_indices | |
| ) |
| local_indices = torch.tensor(optional_local_indices, **tensor_kwargs) # type: ignore[arg-type] |
The above looks buggy. If optional_local_indices has a None in it, we should not be able to pass it to torch.tensor().
|
@pytorchbot merge - Once more unto the breach |
|
❌ 🤖 pytorchbot command failed: Try |
|
@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):
This reverts commit a9a3c45.
This PR changes the following:
_ExecOrderData.handle_to_handle_index->FlatParamHandle._handle_index_ExecOrderData.handles_to_pre_forward_order_index->FlatParamHandle._pre_forward_order_index_ExecOrderData.handles_to_post_forward_order_index->FlatParamHandle._post_forward_index_FSDPState._needs_pre_forward_unshard->FlatParamHandle._needs_pre_forward_unshard_FSDPState._needs_pre_backward_unshard->FlatParamHandle._needs_pre_backward_unshard_FSDPState._handles_prefetched->FlatParamHandle._prefetched