jax.custom_vjp.defremat#
- custom_vjp.defremat(fwd, rem, bwd)[source]#
Define custom rematerialization rules for this function.
The rules apply when this function is differentiated in reverse mode under
jax.remat(), where by default thefwdrule given todefvjp()is rematerialized according to the ambient checkpoint policy. Outside ofjax.remat(), unless a VJP is also defined withdefvjp, the rules define the VJP too, by runningremright afterfwdon the forward pass. Requires thejax_custom_vjp3andjax_remat3implementations.- Parameters:
fwd (Callable[..., tuple[ReturnValue, Any]]) – forward-pass rule, with the same signature as the
fwdrule ofdefvjp(): it takes the arguments of the primal function, and returns the primal output paired with residuals to save for the backward pass.rem (Callable[..., tuple[ReturnValue, Any]]) – rematerialization rule, of signature
rem(res, *args) -> (out, res2). On the backward pass it receives the residuals saved byfwdand the arguments of the primal function, and recomputes the primal output paired with the residualsres2forbwd.bwd (Callable[..., tuple[Any, ...]]) – backward-pass rule, as in
defvjp(), receivingres2as its residuals.
- Returns:
None.
- Return type:
None