Fallback _embedding_bag_backward and force sparse=false.#7584
Merged
Fallback _embedding_bag_backward and force sparse=false.#7584
_embedding_bag_backward and force sparse=false.#7584Conversation
JackCaoG
reviewed
Jun 27, 2024
| call(grad, indices_, offsets_, offset2bag, bag_size_, max_indices_, | ||
| num_weights, scale_grad_by_freq, mode, /*sparse=*/false, | ||
| per_sample_weights_opt, padding_idx); | ||
| } |
Collaborator
There was a problem hiding this comment.
can we add a test to test/test_operations.py, run the embedding bag fwd and bwd and make sure it doesn't crash? this way we can prevent it from regressing.
cf3a4a3 to
6e5131a
Compare
6e5131a to
5ffaadd
Compare
bhavya01
approved these changes
Jun 28, 2024
vanbasten23
reviewed
Jul 1, 2024
| fresh = tensor.clone() | ||
| # Make this tensor a leaf tensor by detaching and reseting its | ||
| # requires_grad property. | ||
| fresh = fresh.detach() |
Collaborator
There was a problem hiding this comment.
Very cool. I wonder why we need to make the tensor a leaf tensor. What would happen if we don't do it?
Collaborator
Author
There was a problem hiding this comment.
It's so we can grab its tensor.grad and compare.
vanbasten23
approved these changes
Jul 1, 2024
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.
Fix: #6008
This PR, in addition to pytorch/pytorch#129691, add support for embedding bag calls when its
sparseparameter is true.Problem: when
sparse=true,_embedding_bag_backwardcalledat::_sparse_coo_tensor_unsafe_symintfunction which returns a sparse tensor. Since PyTorch/XLA does not support sparse tensors, this resulted in a dispatch error (see the original issue).Solution: although, ideally we should support sparse tensors, in the short-term we decided (in an offline discussion) to fallback to the dense backwards function.
cc @miladm @JackCaoG