XLAShardedTensor.to_local() support#9505
Open
Hoomaaan wants to merge 13 commits into
Open
Conversation
f0c89b9 to
933a964
Compare
bfolie
reviewed
Aug 2, 2025
bfolie
reviewed
Aug 2, 2025
812a69a to
6dc2351
Compare
bfolie
approved these changes
Aug 14, 2025
rpsilva-aws
requested changes
Aug 15, 2025
| # Since global tensor is detached, add requires_grad and grad values back to the local tensor | ||
| if self.requires_grad: | ||
| result.requires_grad = self.requires_grad | ||
| result.grad = self.grad |
Collaborator
There was a problem hiding this comment.
The grad doesn't need to be cloned? Is it fine that we break the reference for the tensor, but not its grad? See if we can add a test that shows it is the case (e.g. both the prior and newer tensor updating the same grad).
Contributor
Author
There was a problem hiding this comment.
Updated to clone the self.grad if available
| result = self.global_tensor.clone() | ||
| # Since global tensor is detached, add requires_grad and grad values back to the local tensor | ||
| if self.requires_grad: | ||
| result.requires_grad = self.requires_grad |
Collaborator
There was a problem hiding this comment.
nit: result.requires_grad_(self.requires_grad) for in-place.
rpsilva-aws
approved these changes
Aug 15, 2025
…ure proper XLA support and maintain consistency with PyTorch/XLA SPMD integration.
3aaae84 to
b378a46
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The implementation adds a to_local() method to XLAShardedTensor class that converts a sharded tensor back to its local representation while preserving gradient information.
requires_grad property is preserved
gradients are properly calculated and maintained
backward pass works correctly through the local tensor
gradient values are accurately preserved