Conversation
will-cromar
reviewed
Sep 5, 2024
| XLATensorPtr xmask = bridge::GetXlaTensor(mask); | ||
| auto masked_input = tensor_methods::mul(xinput, xmask); | ||
| auto result = tensor_methods::all_reduce(masked_input, AllReduceType::kSum, | ||
| 1.0, {}, true); |
Collaborator
There was a problem hiding this comment.
nit: name the non-obvious arguments at the end here. Assuming these two are scale and replica groups, /*scale=*/1, /*groups=*/{} (double check the names).
|
|
||
|
|
||
| @absltest.skipIf(lambda: tpu.num_logical_cores_per_chip() >= 2, | ||
| @absltest.skipIf(tpu.num_logical_cores_per_chip() >= 2, |
|
|
||
|
|
||
| # "broadcast(Tensor self, int src, str tag, int[] ranks, int group_size) -> Tensor", | ||
| @torch.library.impl("_c10d_functional::broadcast", "XLA") |
| at::Tensor mask; | ||
| const torch::lazy::BackendDevice& device = xinput->GetDevice(); | ||
| if (device.ordinal() == src) { | ||
| mask = at::ones_like(input); |
Collaborator
There was a problem hiding this comment.
Is there an equivalent to torch.no_grad() in C++? That's the only difference I see between the original python version and this one
Member
Author
There was a problem hiding this comment.
Searched the doc and we can use the following scope for tensor operation without grad:
{
at::NoGradGuard no_grad;
// tensor operations
}
Member
Author
There was a problem hiding this comment.
Anyone knows why we set no grad here:
@JackCaoG
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.
Support torch.distributed.broadcast for both dynamo and nondynamo.
This PR needs pytorch/pytorch#135171 to be merged first.