Computes the gradient of an EagerPyFunc.
(op, *dy)
| 325 | # TODO(akshayka): Implement higher-order derivatives. |
| 326 | @ops.RegisterGradient("EagerPyFunc") |
| 327 | def _EagerPyFuncGrad(op, *dy): |
| 328 | """Computes the gradient of an EagerPyFunc.""" |
| 329 | |
| 330 | token = op.get_attr("token") |
| 331 | |
| 332 | def eagerly_executed_grad(*dy): |
| 333 | tape, eager_inputs, eager_outputs = tape_cache.pop(compat.as_bytes(token)) |
| 334 | return tape.gradient(eager_outputs, eager_inputs, output_gradients=dy) |
| 335 | |
| 336 | with ops.control_dependencies(op.outputs): |
| 337 | return _internal_py_func( |
| 338 | func=eagerly_executed_grad, |
| 339 | inp=dy, |
| 340 | Tout=[tensor.dtype for tensor in op.inputs], |
| 341 | eager=True, |
| 342 | is_grad_func=True) |
| 343 | |
| 344 | |
| 345 | @tf_export("py_function") |
nothing calls this directly
no test coverage detected