-
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
Fallback _embedding_bag_backward
and force sparse=false
.
#7584
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
516228c
Fallback on `_embedding_bag_backward`.
ysiraichi 5ffaadd
Add torch_pin.
ysiraichi dc6ab01
Add test.
ysiraichi b59e5b0
Warn only if sparse.
ysiraichi 46371e5
Remove torch_pin.
ysiraichi a35b53a
Propagate fallback function name change.
ysiraichi 6c3f778
Fix lint issues.
ysiraichi 9f05200
Add path for `XLA_DISABLE_FUNCTIONALIZATION=1`.
ysiraichi e85be64
Fix fallback function rename.
ysiraichi c87e76a
Fix lint issues.
ysiraichi 8d61cc1
Fix lint issues.
ysiraichi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
#include <ATen/native/BinaryOps.h> | ||
#include <ATen/native/CPUFallback.h> | ||
#include <ATen/native/TypeProperties.h> | ||
#include <ATen/ops/_embedding_bag_backward_native.h> | ||
#include <ATen/ops/expand_copy.h> | ||
#include <c10/core/Contiguity.h> | ||
#include <torch/csrc/lazy/core/shape_inference.h> | ||
|
@@ -1489,6 +1490,32 @@ XLANativeFunctions::_embedding_bag_forward_only( | |
bridge::AtenFromXlaTensor(std::get<3>(result))); | ||
} | ||
|
||
at::Tensor XLANativeFunctions::_embedding_bag_backward( | ||
const at::Tensor& grad, const at::Tensor& indices_, | ||
const at::Tensor& offsets_, const at::Tensor& offset2bag, | ||
const at::Tensor& bag_size_, const at::Tensor& max_indices_, | ||
int64_t num_weights, bool scale_grad_by_freq, int64_t mode, bool sparse, | ||
const std::optional<at::Tensor>& per_sample_weights_opt, | ||
int64_t padding_idx) { | ||
TORCH_LAZY_FN_COUNTER_TIMED_TRACING("xla::"); | ||
if (sparse) { | ||
TORCH_WARN( | ||
"XLA does not support EmbeddingBag sparse backward function. " | ||
"Falling back to the dense function."); | ||
} | ||
if (runtime::sys_util::GetEnvBool("XLA_DISABLE_FUNCTIONALIZATION", false)) { | ||
return at::native::_embedding_bag_backward_symint( | ||
grad, indices_, offsets_, offset2bag, bag_size_, max_indices_, | ||
num_weights, scale_grad_by_freq, mode, /*sparse=*/false, | ||
per_sample_weights_opt, padding_idx); | ||
} | ||
return at::native:: | ||
call_fallback_fn<&xla_fallback, ATEN_OP(_embedding_bag_backward)>::call( | ||
grad, indices_, offsets_, offset2bag, bag_size_, max_indices_, | ||
num_weights, scale_grad_by_freq, mode, /*sparse=*/false, | ||
per_sample_weights_opt, padding_idx); | ||
} | ||
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. can we add a test to |
||
|
||
at::Tensor XLANativeFunctions::empty_symint( | ||
at::SymIntArrayRef sym_size, std::optional<at::ScalarType> dtype, | ||
std::optional<at::Layout> layout, std::optional<at::Device> device, | ||
|
Oops, something went wrong.
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.
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.
Very cool. I wonder why we need to make the tensor a leaf tensor. What would happen if we don't do it?
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's so we can grab its
tensor.grad
and compare.