-
Notifications
You must be signed in to change notification settings - Fork 480
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
support dist.broadcast #7956
base: master
Are you sure you want to change the base?
support dist.broadcast #7956
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -309,6 +309,28 @@ AllGatherResultCoalesced BuildAllGatherCoalesced( | |
return {result, token_handler.GetNewToken(result[0])}; | ||
} | ||
|
||
at::Tensor collective_broadcast(const at::Tensor& input, int64_t src, | ||
std::string) { | ||
XLATensorPtr xinput = bridge::GetXlaTensor(input); | ||
TORCH_LAZY_FN_COUNTER_TIMED_TRACING("xla::"); | ||
at::Tensor mask; | ||
const torch::lazy::BackendDevice& device = xinput->GetDevice(); | ||
if (device.ordinal() == src) { | ||
mask = at::ones_like(input); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there an equivalent to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Searched the doc and we can use the following scope for tensor operation without grad:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} else { | ||
mask = at::zeros_like(input); | ||
} | ||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: name the non-obvious arguments at the end here. Assuming these two are scale and replica groups, |
||
return bridge::AtenFromXlaTensor(result); | ||
} | ||
|
||
TORCH_LIBRARY_IMPL(_c10d_functional, XLA, m) { | ||
m.impl("broadcast", collective_broadcast); | ||
} | ||
|
||
CollectivePermuteResult BuildCollectivePermute( | ||
xla::XlaOp input, xla::XlaOp token, | ||
const std::vector<std::pair<int64_t, int64_t>>& source_target_pairs) { | ||
|
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.
🤦 thanks