Skip to content

C++ gradient for Select - #14862

Merged
yifeif merged 5 commits into
tensorflow:masterfrom
facaiy:ENH/add_select_grad_on_c
Dec 20, 2017
Merged

yifeif merged 5 commits into
tensorflow:masterfrom
facaiy:ENH/add_select_grad_on_c

Conversation

@facaiy

@facaiy facaiy commented Nov 24, 2017 •

Copy link
Copy Markdown
Member

Fix #14845

migrate python implementation to c++ side, source:

@ops.RegisterGradient("Select")

How to test

  • add test case
  • pass all tests

@tensorflow-jenkins

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@facaiy

facaiy commented Nov 24, 2017 •

Copy link
Copy Markdown
Member Author

@suharshs Hi, since Select seems renamed to Where3, I'm a little confused about which op the gradient should be registered for, Select or Where3? Could you give an advice? Thank you.

@drpngx
drpngx requested review from skye and suharshs and removed request for skye December 4, 2017 03:13
@drpngx drpngx added the awaiting review Pull request awaiting review label Dec 4, 2017
@facaiy
facaiy force-pushed the ENH/add_select_grad_on_c branch from cd2bf45 to 88a2671 Compare December 10, 2017 07:20
@facaiy
facaiy force-pushed the ENH/add_select_grad_on_c branch from 88a2671 to 172dcec Compare December 10, 2017 07:22
@suharshs

Copy link
Copy Markdown

Sorry for the delay, was on vacation :)

I believe at the kernel level, the op is still "Select" so you should register it for that.

@suharshs suharshs left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

a couple minor comments. Thanks!

Comment thread tensorflow/cc/gradients/math_grad.cc Outdated
auto zeros = ZerosLike(scope, x);
auto grad = grad_inputs[0];

Scope grad_scope = scope.WithControlDependencies(grad);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why do you need this control dependency? Isn't there a data dependency with grad already?

}

TEST_F(NaryGradTest, Select) {
TensorShape x_shape({3, 4});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit: Since x_shape is the same as y_shape, maybe rename one to 'shape' and use that everywhere?

@facaiy

facaiy commented Dec 16, 2017

Copy link
Copy Markdown
Member Author

Welcome back, @suharshs . I have removed grad_scope, x_shape, y_shape as requested.

@suharshs suharshs removed the awaiting review Pull request awaiting review label Dec 18, 2017
@yifeif

yifeif commented Dec 20, 2017

Copy link
Copy Markdown
Contributor

@tensorflow-jenkins test this please

@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Dec 20, 2017
@yifeif yifeif added the kokoro:force-run Tests on submitted change label Dec 20, 2017
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Dec 20, 2017
@yifeif
yifeif merged commit dc355dc into tensorflow:master Dec 20, 2017
@facaiy
facaiy deleted the ENH/add_select_grad_on_c branch December 20, 2017 22:42
@gunan

gunan commented Jan 1, 2018

Copy link
Copy Markdown
Contributor

Correction, this is the cause of the flakes. reverting this PR instead.

drpngx pushed a commit that referenced this pull request Jan 1, 2018
TensorShape shape({3, 4});
auto x1 = Placeholder(scope_, DT_FLOAT, Placeholder::Shape(shape));
auto x2 = Placeholder(scope_, DT_FLOAT, Placeholder::Shape(shape));
auto y = Where3(scope_, Greater(scope_, x1, x2), x1, x2);

@facaiy facaiy Jan 2, 2018 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@gunan @drpngx There seems something wrong with the condition x1 > x2, which might be unstable for gradient calculation. I think that's why tests failed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@drpngx I want to confirm that: Is NaryGradTest.Select the only one failed test?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I can't remember on the top of my head. I thought there was another one. You can try bazel test --runs_per_test=100 and you should find it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fine, I'll look into it later. Thanks for your quick reply, @drpngx .

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have opened #15807 to fix the unstable test case. Might you take a look? Thanks.

facaiy added a commit to facaiy/tensorflow that referenced this pull request Jan 3, 2018
caisq pushed a commit that referenced this pull request Jan 4, 2018
* Revert "Revert "C++ gradient for Select (#14862)" (#15764)"

This reverts commit 4c19f77.
copybara-service Bot pushed a commit that referenced this pull request Jul 15, 2024
…her/scatter.

Imported from GitHub PR openxla/xla#14862

Issue #13304

In SPMD handling of gather/scatter the partition strategy is hardcoded to IndexParallel strategy. This is not optimal for all topology. This PR makes this option an SPMD config, but defaults to IndexParallel to maintain existing behavior.

Clang-format also fixed some formatting. Tests were added and all tests pass.
Copybara import of the project:

--
7f83c21573f24cd4e314b13ce2e349dd6194b451 by ptoulme-aws <[email protected]>:

Add SPMD config option to specify zero cost method for gather/scatter.

Merging this change closes #14862

FUTURE_COPYBARA_INTEGRATE_REVIEW=openxla/xla#14862 from ptoulme-aws:gather_scatter_config 7f83c21573f24cd4e314b13ce2e349dd6194b451
PiperOrigin-RevId: 652473292
copybara-service Bot pushed a commit that referenced this pull request Jul 15, 2024
…her/scatter.

Imported from GitHub PR openxla/xla#14862

Issue #13304

In SPMD handling of gather/scatter the partition strategy is hardcoded to IndexParallel strategy. This is not optimal for all topology. This PR makes this option an SPMD config, but defaults to IndexParallel to maintain existing behavior.

Clang-format also fixed some formatting. Tests were added and all tests pass.
Copybara import of the project:

--
7f83c21573f24cd4e314b13ce2e349dd6194b451 by ptoulme-aws <[email protected]>:

Add SPMD config option to specify zero cost method for gather/scatter.

Merging this change closes #14862

FUTURE_COPYBARA_INTEGRATE_REVIEW=openxla/xla#14862 from ptoulme-aws:gather_scatter_config 7f83c21573f24cd4e314b13ce2e349dd6194b451
PiperOrigin-RevId: 652473292
copybara-service Bot pushed a commit that referenced this pull request Jul 15, 2024
…her/scatter.

Imported from GitHub PR openxla/xla#14862

Issue #13304

In SPMD handling of gather/scatter the partition strategy is hardcoded to IndexParallel strategy. This is not optimal for all topology. This PR makes this option an SPMD config, but defaults to IndexParallel to maintain existing behavior.

Clang-format also fixed some formatting. Tests were added and all tests pass.
Copybara import of the project:

--
7f83c21573f24cd4e314b13ce2e349dd6194b451 by ptoulme-aws <[email protected]>:

Add SPMD config option to specify zero cost method for gather/scatter.

Merging this change closes #14862

FUTURE_COPYBARA_INTEGRATE_REVIEW=openxla/xla#14862 from ptoulme-aws:gather_scatter_config 7f83c21573f24cd4e314b13ce2e349dd6194b451
PiperOrigin-RevId: 652473292
copybara-service Bot pushed a commit that referenced this pull request Jul 15, 2024
…her/scatter.

Imported from GitHub PR openxla/xla#14862

Issue #13304

In SPMD handling of gather/scatter the partition strategy is hardcoded to IndexParallel strategy. This is not optimal for all topology. This PR makes this option an SPMD config, but defaults to IndexParallel to maintain existing behavior.

Clang-format also fixed some formatting. Tests were added and all tests pass.
Copybara import of the project:

--
7f83c21573f24cd4e314b13ce2e349dd6194b451 by ptoulme-aws <[email protected]>:

Add SPMD config option to specify zero cost method for gather/scatter.

Merging this change closes #14862

FUTURE_COPYBARA_INTEGRATE_REVIEW=openxla/xla#14862 from ptoulme-aws:gather_scatter_config 7f83c21573f24cd4e314b13ce2e349dd6194b451
PiperOrigin-RevId: 652514718
copybara-service Bot pushed a commit that referenced this pull request Jul 16, 2024
…her/scatter.

Imported from GitHub PR openxla/xla#14862

Issue #13304

In SPMD handling of gather/scatter the partition strategy is hardcoded to IndexParallel strategy. This is not optimal for all topology. This PR makes this option an SPMD config, but defaults to IndexParallel to maintain existing behavior.

Clang-format also fixed some formatting. Tests were added and all tests pass.
Copybara import of the project:

--
7f83c21573f24cd4e314b13ce2e349dd6194b451 by ptoulme-aws <[email protected]>:

Add SPMD config option to specify zero cost method for gather/scatter.

Merging this change closes #14862

FUTURE_COPYBARA_INTEGRATE_REVIEW=openxla/xla#14862 from ptoulme-aws:gather_scatter_config 7f83c21573f24cd4e314b13ce2e349dd6194b451
PiperOrigin-RevId: 652514718
copybara-service Bot pushed a commit that referenced this pull request Jul 16, 2024
…her/scatter.

Imported from GitHub PR openxla/xla#14862

Issue #13304

In SPMD handling of gather/scatter the partition strategy is hardcoded to IndexParallel strategy. This is not optimal for all topology. This PR makes this option an SPMD config, but defaults to IndexParallel to maintain existing behavior.

Clang-format also fixed some formatting. Tests were added and all tests pass.
Copybara import of the project:

--
7f83c21573f24cd4e314b13ce2e349dd6194b451 by ptoulme-aws <[email protected]>:

Add SPMD config option to specify zero cost method for gather/scatter.

Merging this change closes #14862

FUTURE_COPYBARA_INTEGRATE_REVIEW=openxla/xla#14862 from ptoulme-aws:gather_scatter_config 7f83c21573f24cd4e314b13ce2e349dd6194b451
PiperOrigin-RevId: 652473292
copybara-service Bot pushed a commit that referenced this pull request Jul 16, 2024
…her/scatter.

Imported from GitHub PR openxla/xla#14862

Issue #13304

In SPMD handling of gather/scatter the partition strategy is hardcoded to IndexParallel strategy. This is not optimal for all topology. This PR makes this option an SPMD config, but defaults to IndexParallel to maintain existing behavior.

Clang-format also fixed some formatting. Tests were added and all tests pass.
Copybara import of the project:

--
7f83c21573f24cd4e314b13ce2e349dd6194b451 by ptoulme-aws <[email protected]>:

Add SPMD config option to specify zero cost method for gather/scatter.

Merging this change closes #14862

PiperOrigin-RevId: 652736743
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants