# tf.no_gradient

<br />

|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 2 version](https://www.tensorflow.org/api_docs/python/tf/no_gradient) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/framework/ops.py#L2490-L2522) |

Specifies that ops of type `op_type` is not differentiable.

#### View aliases


**Main aliases**

\`tf.NoGradient\`, \`tf.NotDifferentiable\`
**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.NoGradient`](https://www.tensorflow.org/api_docs/python/tf/no_gradient), [`tf.compat.v1.NotDifferentiable`](https://www.tensorflow.org/api_docs/python/tf/no_gradient), [`tf.compat.v1.no_gradient`](https://www.tensorflow.org/api_docs/python/tf/no_gradient), \`tf.compat.v2.no_gradient\`

<br />

    tf.no_gradient(
        op_type
    )

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()`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/size) that are not differentiable. For
example:

    tf.no_gradient("Size")

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.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `op_type` | The string type of an operation. This corresponds to the `OpDef.name` field for the proto that defines the operation. |

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `TypeError` | If `op_type` is not a string. |

<br />