Skip to content

Fix bugged gradients when combiner == 'MEAN' #2505

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

Merged
merged 6 commits into from
Jul 1, 2021

Conversation

Rocketknight1
Copy link
Contributor

Fixes #2502

@Rocketknight1
Copy link
Contributor Author

Wait hang on, I'm dumb. Fixing the PR!

weights = tf.ones_like(indices, dtype=params.dtype) / tf.cast(
tf.shape(indices)[1], params.dtype
)
combiner = "sum"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we have this combiner overriding?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a quick workaround, but the output and grads are correct, and performance is fine! Since combiner == "mean" does not support weights, we can get the right results by creating a dummy weight array (we do that anyway), then scaling it so that we get an unweighted mean instead of an unweighted sum.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should call tf.reduce_mean after custom op instead of integrating with it or combiner overriding.

@bhack
Copy link
Contributor

bhack commented Jun 19, 2021

The GPU test is failing.

@bhack bhack requested a review from fsx950223 June 19, 2021 17:47
@Rocketknight1
Copy link
Contributor Author

lol. This one is just a simple issue - the tolerances for the equality comparison are too tight for the float16 tests. Give me a sec and I'll fix it.

@fsx950223
Copy link
Member

fsx950223 commented Jun 20, 2021

Combiner is not used in


, which is different with cpu custom op.
Maybe you should call tf.reduce_mean after custom op instead of integrating with it.

@@ -49,8 +49,13 @@ def _embedding_bag(
Returns:
A `Tensor` of the format specified by `data_format`.
"""
if weights is None:
if weights is None and combiner == "sum":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use reduction instead of combiner

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The combiner is combining part of the layer and applies to the inputs/weights, not the output/loss! Is reduction still the right approach there?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add combiner document?

Copy link
Member

@seanpmorgan seanpmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to merge this as CI is broken without it. If there are any issues can we follow up in next PR. Cursory glance LGTM.

@seanpmorgan seanpmorgan merged commit 54a8720 into tensorflow:master Jul 1, 2021
@fsx950223
Copy link
Member

fsx950223 commented Jul 1, 2021

Going to merge this as CI is broken without it. If there are any issues can we follow up in next PR. Cursory glance LGTM.

I can't see ubuntu gpu CI report in the PR, could you check it?

@seanpmorgan
Copy link
Member

Going to merge this as CI is broken without it. If there are any issues can we follow up in next PR. Cursory glance LGTM.

I can't see ubuntu gpu CI report in the PR, could you check it?

Yeah landed on master (Shown by badge on central README): https://source.cloud.google.com/results/invocations/5a171fa3-3bad-4859-9a05-414e4c155851

@fsx950223
Copy link
Member

fsx950223 commented Jul 1, 2021

https://source.cloud.google.com/results/invocations/5a171fa3-3bad-4859-9a05-414e4c155851

How could I check it in the review process? Should I record the url? I could get the info in previous PRs.

@Rocketknight1
Copy link
Contributor Author

Hi, thanks for merging, and sorry for my slow replies! I've only been able to get to this at the weekends, but I am committed to maintaining it - it's unfortunate that we had to rush because of the broken CI, but I do think this PR should resolve most of the issues, and I see the follow-up PR is already open!

@seanpmorgan
Copy link
Member

Hi, thanks for merging, and sorry for my slow replies! I've only been able to get to this at the weekends, but I am committed to maintaining it - it's unfortunate that we had to rush because of the broken CI, but I do think this PR should resolve most of the issues, and I see the follow-up PR is already open!

Appreciate the maintainership @Rocketknight1 ! Its volunteer work so no need to apologize for slow responses :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Embedding Bag Fails GPU Testing
5 participants