Calls the gradient function of the op. Args: op_name: the name of the op to be differentiated. attr_tuple: the attrs, as a tuple. num_inputs: the number of inputs to the op. inputs: inputs to the original operation. outputs: outputs to the original operation. out_grads: gr
(op_name, attr_tuple, num_inputs, inputs, outputs,
out_grads, skip_input_indices)
| 114 | |
| 115 | |
| 116 | def _gradient_function(op_name, attr_tuple, num_inputs, inputs, outputs, |
| 117 | out_grads, skip_input_indices): |
| 118 | """Calls the gradient function of the op. |
| 119 | |
| 120 | Args: |
| 121 | op_name: the name of the op to be differentiated. |
| 122 | attr_tuple: the attrs, as a tuple. |
| 123 | num_inputs: the number of inputs to the op. |
| 124 | inputs: inputs to the original operation. |
| 125 | outputs: outputs to the original operation. |
| 126 | out_grads: gradients of the operation wrt its outputs. |
| 127 | skip_input_indices: a tuple that is passed to the gradient function, |
| 128 | indicating which inputs to skip calculating the gradient for |
| 129 | |
| 130 | Returns: |
| 131 | The gradients with respect to the inputs of the function, as a list. |
| 132 | """ |
| 133 | mock_op = _MockOp(attr_tuple, inputs, outputs, op_name, skip_input_indices) |
| 134 | grad_fn = ops._gradient_registry.lookup(op_name) # pylint: disable=protected-access |
| 135 | if grad_fn is None: |
| 136 | return [None] * num_inputs |
| 137 | |
| 138 | return grad_fn(mock_op, *out_grads) |
| 139 | |
| 140 | |
| 141 | pywrap_tensorflow.TFE_Py_RegisterGradientFunction(_gradient_function) |