Skip to content

tf.reduce_sum with multiple negative axes and tf.RaggedTensor bugged #27497

@jackd

Description

@jackd

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): ubuntu 16.04
  • TensorFlow installed from (source or binary): pip
  • TensorFlow version (use command below):
  • Python version: ('v1.13.1-0-g6612da8951', '1.13.1')
  • GPU model and memory: quadro k620 2gb

Current behaviour

Multiple axes passed to tf.reduce_sum with first argument being a ragged tensor results in incorrect behaviour.

import tensorflow as tf

x_values = tf.random.normal(shape=(100, 5, 6))
x_row_lengths = tf.constant([20, 30, 50], dtype=tf.int64)
x_ragged = tf.RaggedTensor.from_row_lengths(x_values, x_row_lengths)
print(x_ragged.shape)
# [3, ?, 5, 6]

# wrong shape
print(tf.reduce_sum(x_ragged, axis=(-2, -3)).shape)
# [50, 6]

# positive axes work
print(tf.reduce_sum(x_ragged, axis=(1, 2)).shape)
# [3, 6]

# separate reductions work
print(tf.reduce_sum(tf.reduce_sum(x_ragged, axis=-3), axis=-2).shape)
# [3, 6]

Expected behaviour

Same result as corresponding positive indices/separate reductions.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions