GradOptions
Interface in IR
Options for grad.
import type { GradOptions } from 'typeshade'
The signature, the description and the examples come from the compiler's own source at commit af54ddad5.
Syntax
interface GradOptions { readonly name?: string; readonly direction?: readonly number[]; readonly mode?: 'forward' | 'reverse'; readonly checkpoints?: number; readonly custom?: Readonly<Record<string, string>>;}Instance properties
nameoptionalread onlystringThe name of the generated function. Defaults to
<fn>_d_<param>in forward mode and<fn>_vjpin reverse mode.directionoptionalread onlyreadonly number[]The direction to differentiate along when the parameter is a vector: the generated function returns the directional derivative, the Jacobian times this vector. Required for a vector parameter in forward mode, refused for a scalar one and in reverse mode.
modeoptionalread only'forward' | 'reverse''forward'(the default) adds the derivative along one parameter, the Jacobian times a tangent.'reverse'adds the vector-Jacobian product with respect to every name ofwrtat once: a function of the primal parameters and a seeddyof the result’s type, which returns a struct with one field for each name.checkpointsoptionalread onlynumberReverse mode: the number of checkpoint slots
Ceach loop keeps in function memory. Defaults to 32. A loop ofNiterations is saved everyceil(N / C)iterations, and forNup toC²its body runs about three times forward and once backward.customoptionalread onlyReadonly<Record<string, string>>Reverse mode: author-written adjoints, by function.
{ g: 'g_adjoint' }makes every call togtake its adjoint fromg_adjoint(g's parameters…, dy), which returns a struct with a field of the same name and type for each float parameter ofg. It is the escape hatch for a recurrence the author can invert.gradCheckholds it as it holds a generated adjoint.
See also
Source
src/core/passes/grad.ts, line 13, at commit af54ddad5