Join us at TensorFlow World, Oct 28-31. Use code TF20 for 20% off select passes. Register now


TensorFlow 2.0 version View source on GitHub

Specifies that ops of type op_type is not differentiable.


  • tf.NoGradient
  • tf.NotDifferentiable
  • tf.compat.v1.NoGradient
  • tf.compat.v1.NotDifferentiable
  • tf.compat.v1.no_gradient
  • tf.compat.v2.no_gradient

This function should not be used for operations that have a well-defined gradient that is not yet implemented.

This function is only used when defining a new op type. It may be used for ops such as tf.size() that are not differentiable. For example:


The gradient computed for 'op_type' will then propagate zeros.

For ops that have a well-defined gradient but are not yet implemented, no declaration should be made, and an error must be thrown if an attempt to request its gradient is made.


  • op_type: The string type of an operation. This corresponds to the field for the proto that defines the operation.


  • TypeError: If op_type is not a string.