Skip to content

Clean up SegmentReduction Ops #7362

Closed
Closed

Description

@PhilJd

The segment reduction ops are currently inconsistent, they include different ops for sorted/unsorted/ and sparse/dense tensors.
I guess it would make sense to provide the same reduction ops for these - I'd be happy to work on this and build on nikste's work.

For similar previous issues @andydavis1, @drpngx were responsible for reviewing, so I link you here.

Things to possibly consider:

  • Replace the sorted segment options by the more general unsorted options. I did a quick, non-extensive benchmark for unsorted_segment_max vs segment_max, the processing time is about the same (with the unsorted op even being a bit faster sometimes).
    The drawback would be, that num_segments needs to be specified or needs to be computed before the reduction.
  • Include the feature request "Extend tf.unsorted_segment_sum to allow 'rejecting' entries" Extend tf.unsorted_segment_sum to allow 'rejecting' entries #478
  • Address the ToDo in UnsortedSegmentMax: // todo: Remove duplicate code in UnsortedSegmentSumFunctor and UnsortedSegmentMaxFunctor.
    To sum up, I'd suggest to replace and extend the currently provided functions
tf.segment_sum(data, segment_ids, name=None)
tf.segment_prod(data, segment_ids, name=None)
tf.segment_min(data, segment_ids, name=None)
tf.segment_max(data, segment_ids, name=None)
tf.segment_mean(data, segment_ids, name=None)
tf.unsorted_segment_sum(data, segment_ids, num_segments, name=None)
tf.sparse_segment_sum(data, indices, segment_ids, name=None)
tf.sparse_segment_mean(data, indices, segment_ids, name=None)
tf.sparse_segment_sqrt_n(data, indices, segment_ids, name=None)

with

# all dense/sparse ops support unsorted segments
tf.segment_sum(data, segment_ids, num_segements=None, name=None) 
tf.segment_prod(data, segment_ids, num_segements=None, name=None)
tf.segment_min(data, segment_ids, num_segements=None, name=None)
tf.segment_max(data, segment_ids, num_segements=None, name=None) 
tf.segment_mean(data, segment_ids, num_segements=None, name=None)
tf.segment_sqrt_n(data, segment_ids, num_segements=None, name=None)  # new

tf.sparse_segment_sum(data, indices, segment_ids, name=None)
tf.sparse_segment_prod(data, indices, segment_ids, name=None)  # new
tf.sparse_segment_min(data, indices, segment_ids, name=None)  # new
tf.sparse_segment_max(data, indices, segment_ids, name=None)  # new
tf.sparse_segment_mean(data, indices, segment_ids, name=None)
tf.sparse_segment_sqrt_n(data, indices, segment_ids, name=None)

(Or tf.unsorted_segment_reduce_op instead of tf.segement_reduceop to not break backward compability)

Activity

  1. girving commented on Feb 9, 2017

    @girving
    Contributor

    I don't think we'll replace the sorted versions with unsorted versions. The feature requested in #478 is covered by #478, so we don't need to ask for it twice here. The remaining new bits are adding missing ops and fixing the TODO, both of which we would be happy to accept PRs for.

  2. girving commented on Feb 9, 2017

    @girving
    Contributor

    However, it would be better to have targeted feature requests rather than this grab bag mixing things we don't want and things we do, so I'm going to close this issue for now. Would you be willing to file more specific issues for the two aspects I mentioned?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions