W3cubDocs

/TensorFlow Python

tf.RegisterGradient

Class RegisterGradient

Defined in tensorflow/python/framework/ops.py.

See the guide: Building Graphs > Defining new operations

A decorator for registering the gradient function for an op type.

This decorator is only used when defining a new op type. For an op with m inputs and n outputs, the gradient function is a function that takes the original Operation and n Tensor objects (representing the gradients with respect to each output of the op), and returns m Tensor objects (representing the partial gradients with respect to each input of the op).

For example, assuming that operations of type "Sub" take two inputs x and y, and return a single output x - y, the following gradient function would be registered:

@tf.RegisterGradient("Sub")
def _sub_grad(unused_op, grad):
  return grad, tf.negative(grad)

The decorator argument op_type is the string type of an operation. This corresponds to the OpDef.name field for the proto that defines the operation.

Methods

__init__

__init__(op_type)

Creates a new decorator with op_type as the Operation type.

Args:

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

__call__

__call__(f)

Registers the function f as gradient function for op_type.

© 2018 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_docs/python/tf/RegisterGradient