For f(*args, **kwargs), this supports gradients with respect to args or
kwargs, but kwargs are currently only supported in eager-mode.
Note that for keras layer and model objects, this is handled automatically.
Args
f
function f(*x) that returns a Tensor or sequence of Tensor outputs.
Returns
A function g that wraps f, but which recomputes f on the backwards
pass of a gradient call.
[null,null,["Last updated 2021-02-18 UTC."],[],[],null,["# tf.recompute_grad\n\n\u003cbr /\u003e\n\n|---------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/recompute_grad) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.4.0/tensorflow/python/ops/custom_gradient.py#L488-L558) |\n\nAn eager-compatible version of recompute_grad.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.recompute_grad`](https://www.tensorflow.org/api_docs/python/tf/recompute_grad)\n\n\u003cbr /\u003e\n\n tf.recompute_grad(\n f\n )\n\nFor f(\\*args, \\*\\*kwargs), this supports gradients with respect to args or\nkwargs, but kwargs are currently only supported in eager-mode.\nNote that for keras layer and model objects, this is handled automatically.\n| **Warning:** If `f` was originally a tf.keras Model or Layer object, `g` will not be able to access the member variables of that object, because `g` returns through the wrapper function `inner`. When recomputing gradients through objects that inherit from keras, we suggest keeping a reference to the underlying object around for the purpose of accessing these variables.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----|---------------------------------------------------------------------------|\n| `f` | function `f(*x)` that returns a `Tensor` or sequence of `Tensor` outputs. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A function `g` that wraps `f`, but which recomputes `f` on the backwards pass of a gradient call. ||\n\n\u003cbr /\u003e"]]