ML Community Day is November 9! Join us for updates from TensorFlow, JAX, and more Learn more


Assert the condition x > y holds element-wise.

Migrate to TF2

tf.compat.v1.assert_greater is compatible with eager execution and tf.function. Please use tf.debugging.assert_greater instead when migrating to TF2. Apart from data, all arguments are supported with the same argument name.

If you want to ensure the assert statements run before the potentially-invalid computation, please use tf.control_dependencies, as tf.function auto-control dependencies are insufficient for assert statements.

Structural Mapping to Native TF2


  x=x, y=y, data=data, summarize=summarize,
  message=message, name=name)


  x=x, y=y, message=message,
  summarize=summarize, name=name)

TF1 & TF2 Usage Example


g = tf.Graph()
with g.as_default():
  a = tf.compat.v1.placeholder(tf.float32, [2])
  b = tf.compat.v1.placeholder(tf.float32, [2])
  result = tf.compat.v1.assert_greater(a, b,
    message='"a > b" does not hold for the given inputs')
  with tf.compat.v1.control_dependencies([result]):
    sum_node = a + b
sess = tf.compat.v1.Session(graph=g)
val =, feed_dict={a: [1, 2], b:[0, 1]})


a = tf.Variable([1, 2], dtype=tf.float32)
b = tf.Variable([0, 1], dtype=tf.float32)
assert_op = tf.debugging.assert_greater(a, b, message=
  '"a > b" does not hold for the given inputs')
# When working with tf.control_dependencies
with tf.control_dependencies([assert_op]):
  val = a + b


This condition holds if for every pair of (possibly broadcast) elements x[i], y[i], we have x[i] > y[i]. If both x and y are empty, this is trivially satisfied.

When running in graph mode, you should add a dependency on this operation to ensure that it runs. Example of adding a dependency to an operation:

with tf.control_dependencies([tf.compat.v1.assert_greater(x, y)]):
  output = tf.reduce_sum(x)

x Numeric Tensor.