value_and_grad
Builtin index · REPL & diagnostics
value_and_grad(f, x)
Input: f, x · Output: no output
What it is
Takes a function f and a point x, and returns a two-element list [f(x), grad_f(x)] from a single forward pass, with the gradient shaped like x. The first element is the plain untracked result. Use this instead of computing f(x) and then separately re-evaluating for the gradient, which runs f twice; if you already hold a tracked loss, grad is the cheaper call because there is nothing left to save. Added in v0.3.0
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
value_and_grad(f, x) | f —not documented yetx —not documented yet | not documented yet | The first element is the plain untracked result. Added in v0.3.0. |
Examples
No documentation example calls this form yet. The REPL & diagnostics chapter is where one belongs.