Skip to content
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

Add support for sparse_reduce_max and sparse_reduce_max_sparse #10056

Merged
merged 3 commits into from
Jun 22, 2017

Conversation

yongtang
Copy link
Member

This commit tries to address the issue raised in #10002 to have
the support for sparse_reduce_max and sparse_reduce_max_sparse.

Signed-off-by: Yong Tang yong.tang.github@outlook.com

@tensorflow-jenkins
Copy link
Collaborator

Can one of the admins verify this patch?

@concretevitamin
Copy link
Contributor

@yongtang I was imagining the code for sparse_reduce_sum_op.cc and sparse_reduce_max_op.cc can be mostly shared. A remotely related example is the ScatterUpdateOp, which has a template param on UpdateOp (ADD, etc.).

@maciekcc maciekcc added the stat:awaiting response Status - Awaiting response from author label May 22, 2017
@yongtang yongtang force-pushed the 10002-sparse_reduce_max branch from 3db0b00 to d509e10 Compare May 24, 2017 15:05
@yongtang
Copy link
Member Author

Thanks @concretevitamin for the review. The PR has been updated so that sparse_reduce_sum and sparse_reduce_max share the same code base. Please take a look.

Copy link
Contributor

@concretevitamin concretevitamin left a comment

Choose a reason for hiding this comment

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

This looks great! Left a few comments.

@@ -195,7 +209,7 @@ class SparseReduceSumOp : public OpKernel {
// g.group() provides the coordinates of a particular reduced value.
sp.Reorder<T>(reduction.reorder_dims);
for (const auto &g : sp.group(reduction.group_by_dims)) {
group_sum.device(ctx->eigen_cpu_device()) = g.template values<T>().sum();
Op::template Run<T>(ctx, group_sum, g.template values<T>());
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename group_sum? Something like reduced_val or something better.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @concretevitamin. The PR has been updated.

@@ -265,7 +286,7 @@ class SparseReduceSumSparseOp : public OpKernel {
auto group_sum = tmp_group_sum.scalar<T>();
int64 i = 0;
for (const auto &g : sp.group(reduction.group_by_dims)) {
group_sum.device(ctx->eigen_cpu_device()) = g.template values<T>().sum();
Op::template Run<T>(ctx, group_sum, g.template values<T>());
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@@ -0,0 +1,125 @@
/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer if you could leave out this file. The reason we originally had a C++ test file for SparseReduceSum was to ease debugging. Since now most of the kernels share the same logic, this is no longer needed. The functional correctness of the new op can be covered by the more lightweight Python unit tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. Done.

@@ -510,10 +510,86 @@ def testNoEmptyRows(self):
self.assertAllEqual(empty_row_indicator_out, np.zeros(2).astype(np.bool))


class SparseReduceMaxTest(test_util.TensorFlowTestCase):
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you refactor the existing SparseReduceSumTest to plumb through an extra bool argument, such as do_sum == True / False, so that we can share most of the existing test logic?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. Done.

@yongtang yongtang force-pushed the 10002-sparse_reduce_max branch 2 times, most recently from 9fa4189 to d23fd87 Compare May 25, 2017 02:39
@yongtang
Copy link
Member Author

@concretevitamin Thanks for the review. The PR has been updated. Please take.a look.

Copy link
Contributor

@concretevitamin concretevitamin left a comment

Choose a reason for hiding this comment

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

Great! Two final nits. Please address but I'm approving first ;)

static void Run(OpKernelContext *ctx, typename TTypes<T>::Scalar &s, const typename TTypes<T>::UnalignedVec &v) {
s.device(ctx->eigen_cpu_device()) = v.sum();
}
static const char * Name() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's do

StringPiece Name() {
    return "sum";
}

which is more succinct (and potentially safer).

static void Run(OpKernelContext *ctx, typename TTypes<T>::Scalar &s, const typename TTypes<T>::UnalignedVec &v) {
s.device(ctx->eigen_cpu_device()) = v.maximum();
}
static const char * Name() {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@yongtang yongtang force-pushed the 10002-sparse_reduce_max branch from d23fd87 to cdd89e2 Compare May 30, 2017 02:40
@yongtang
Copy link
Member Author

Thanks @concretevitamin. The PR has been updated.

@concretevitamin
Copy link
Contributor

Jenkins, test this please.

@andrewharp feel free to merge.

@jhseu jhseu added the API review API Review label Jun 7, 2017
@jhseu
Copy link
Contributor

jhseu commented Jun 7, 2017

This change will require API review.

@josh11b
Copy link
Contributor

josh11b commented Jun 12, 2017

Fine for API review.

@josh11b josh11b removed the API review API Review label Jun 12, 2017
@martinwicke
Copy link
Member

Can you rebase and fix the conflicts? I cannot fix things in this PR.

@yongtang yongtang force-pushed the 10002-sparse_reduce_max branch from cdd89e2 to 9f4c38a Compare June 14, 2017 17:15
@yongtang
Copy link
Member Author

Thanks @martinwicke. The PR has been rebased. Please take a look

@martinwicke
Copy link
Member

Jenkins, test this please.

@martinwicke martinwicke added awaiting testing (then merge) and removed stat:awaiting response Status - Awaiting response from author labels Jun 15, 2017
@martinwicke
Copy link
Member

Can you please run the API goldens updater as described in the error message of the failing Linux-CPU test?

@martinwicke martinwicke added the stat:awaiting response Status - Awaiting response from author label Jun 16, 2017
yongtang added 2 commits June 19, 2017 23:30
This commit tries to address the issue raised in 10002 to have
the support for sparse_reduce_max and sparse_reduce_max_sparse.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit moves sparse_reduce_sum_op.cc to sparse_reduce_op.cc
so that both `sparse_reduce_sum` and `sparse_reduce_max` share
the same code base.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
copybara-service bot pushed a commit that referenced this pull request Apr 18, 2024
Fixes #10056
Co-authored-by: pparuzel <paruzelp@google.com>
Co-authored-by: Adam-Banas <adambanas@google.com>
PiperOrigin-RevId: 615387700
copybara-service bot pushed a commit that referenced this pull request Apr 18, 2024
Fixes #10056
Co-authored-by: pparuzel <paruzelp@google.com>
Co-authored-by: Adam-Banas <adambanas@google.com>
PiperOrigin-RevId: 615387700
copybara-service bot pushed a commit that referenced this pull request Apr 18, 2024
Fixes #10056
Co-authored-by: pparuzel <paruzelp@google.com>
Co-authored-by: Adam-Banas <adambanas@google.com>
PiperOrigin-RevId: 615387700
copybara-service bot pushed a commit that referenced this pull request Apr 19, 2024
Fixes #10056
Co-authored-by: pparuzel <paruzelp@google.com>
Co-authored-by: Adam-Banas <adambanas@google.com>
PiperOrigin-RevId: 615387700
copybara-service bot pushed a commit that referenced this pull request Apr 19, 2024
Fixes #10056
Co-authored-by: pparuzel <paruzelp@google.com>
Co-authored-by: Adam-Banas <adambanas@google.com>
PiperOrigin-RevId: 615387700
copybara-service bot pushed a commit that referenced this pull request Apr 19, 2024
Fixes #10056
Co-authored-by: pparuzel <paruzelp@google.com>
Co-authored-by: Adam-Banas <adambanas@google.com>
PiperOrigin-RevId: 615387700
copybara-service bot pushed a commit that referenced this pull request Apr 19, 2024
Fixes #10056
Co-authored-by: pparuzel <paruzelp@google.com>
Co-authored-by: Adam-Banas <adambanas@google.com>
PiperOrigin-RevId: 615387700
copybara-service bot pushed a commit that referenced this pull request Apr 22, 2024
Fixes #10056
Co-authored-by: pparuzel <paruzelp@google.com>
Co-authored-by: Adam-Banas <adambanas@google.com>
PiperOrigin-RevId: 615387700
copybara-service bot pushed a commit that referenced this pull request Apr 22, 2024
Add test cases for handling nested tuples (given both as inputs and outputs) to CPU custom call typed FFI API tests.
Implements #10056.

PiperOrigin-RevId: 627008898
copybara-service bot pushed a commit that referenced this pull request Apr 22, 2024
Fixes #10056
Co-authored-by: pparuzel <paruzelp@google.com>
Co-authored-by: Adam-Banas <adambanas@google.com>
PiperOrigin-RevId: 615387700
copybara-service bot pushed a commit that referenced this pull request Apr 23, 2024
Add test cases for handling nested tuples (given both as inputs and outputs) to CPU custom call typed FFI API tests.
Implements #10056.

PiperOrigin-RevId: 627008898
copybara-service bot pushed a commit that referenced this pull request Apr 23, 2024
Add test cases for handling nested tuples (given both as inputs and outputs) to CPU custom call typed FFI API tests.
Implements #10056.

PiperOrigin-RevId: 627368299
copybara-service bot pushed a commit that referenced this pull request Apr 23, 2024
Fixes #10056
Co-authored-by: pparuzel <paruzelp@google.com>
Co-authored-by: Adam-Banas <adambanas@google.com>
PiperOrigin-RevId: 615387700
copybara-service bot pushed a commit that referenced this pull request Apr 25, 2024
Fixes #10056
Co-authored-by: pparuzel <paruzelp@google.com>
Co-authored-by: Adam-Banas <adambanas@google.com>
PiperOrigin-RevId: 615387700
copybara-service bot pushed a commit that referenced this pull request Apr 25, 2024
Fixes #10056
Co-authored-by: pparuzel <paruzelp@google.com>
Co-authored-by: Adam-Banas <adambanas@google.com>
PiperOrigin-RevId: 615387700
copybara-service bot pushed a commit that referenced this pull request Apr 25, 2024
Fixes #10056
Co-authored-by: pparuzel <paruzelp@google.com>
Co-authored-by: Adam-Banas <adambanas@google.com>
PiperOrigin-RevId: 615387700
copybara-service bot pushed a commit that referenced this pull request Apr 26, 2024
Fixes #10056
Co-authored-by: pparuzel <paruzelp@google.com>
Co-authored-by: Adam-Banas <adambanas@google.com>
PiperOrigin-RevId: 615387700
copybara-service bot pushed a commit that referenced this pull request Apr 26, 2024
Fixes #10056
Co-authored-by: pparuzel <paruzelp@google.com>
Co-authored-by: Adam-Banas <adambanas@google.com>
PiperOrigin-RevId: 615387700
copybara-service bot pushed a commit that referenced this pull request Apr 29, 2024
Fixes #10056
Co-authored-by: pparuzel <paruzelp@google.com>
Co-authored-by: Adam-Banas <adambanas@google.com>
PiperOrigin-RevId: 615387700
copybara-service bot pushed a commit that referenced this pull request Apr 30, 2024
…d FFI

Part of #10056

Co-authored-by: pparuzel paruzelp@google.com
Co-authored-by: Adam-Banas adambanas@google.com
PiperOrigin-RevId: 629372087
copybara-service bot pushed a commit that referenced this pull request Apr 30, 2024
Fixes #10056
Co-authored-by: pparuzel <paruzelp@google.com>
Co-authored-by: Adam-Banas <adambanas@google.com>
PiperOrigin-RevId: 615387700
copybara-service bot pushed a commit that referenced this pull request May 2, 2024
Fixes #10056
Co-authored-by: pparuzel <paruzelp@google.com>
Co-authored-by: Adam-Banas <adambanas@google.com>
PiperOrigin-RevId: 615387700
copybara-service bot pushed a commit that referenced this pull request May 2, 2024
…d FFI

Part of #10056

Co-authored-by: pparuzel paruzelp@google.com
Co-authored-by: Adam-Banas adambanas@google.com
PiperOrigin-RevId: 629372087
copybara-service bot pushed a commit that referenced this pull request May 2, 2024
Fixes #10056
Co-authored-by: pparuzel <paruzelp@google.com>
Co-authored-by: Adam-Banas <adambanas@google.com>
PiperOrigin-RevId: 615387700
copybara-service bot pushed a commit that referenced this pull request May 2, 2024
Fixes #10056
Co-authored-by: pparuzel <paruzelp@google.com>
Co-authored-by: Adam-Banas <adambanas@google.com>
PiperOrigin-RevId: 615387700
copybara-service bot pushed a commit that referenced this pull request May 3, 2024
Fixes #10056
Co-authored-by: pparuzel <paruzelp@google.com>
Co-authored-by: Adam-Banas <adambanas@google.com>
PiperOrigin-RevId: 615387700
copybara-service bot pushed a commit that referenced this pull request May 3, 2024
Fixes #10056
Co-authored-by: pparuzel <paruzelp@google.com>
Co-authored-by: Adam-Banas <adambanas@google.com>
PiperOrigin-RevId: 630339013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes stat:awaiting response Status - Awaiting response from author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants