TensorPlay
latest (dev)
Copy
View Markdown

Latest development documentation · Updated 2026-10-08

tensorplay.func.grad_and_value

tensorplay.func.grad_and_value(func: Callable, argnums: int | tuple[int, ...] = 0, has_aux: bool = False) → Callable

Returns a function computing both the gradient of func and its value.

The value comes from the same forward pass the gradient needs, so this costs no more than grad() alone and saves evaluating func twice.

Returns a function producing (gradient, value), or (gradient, (value, aux)) when has_aux is set.

On this page

Ask DeepWiki