GradOptions
On this page

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 only string

The name of the generated function. Defaults to <fn>_d_<param> in forward mode and <fn>_vjp in reverse mode.

directionoptionalread only readonly 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 of wrt at once: a function of the primal parameters and a seed dy of the result’s type, which returns a struct with one field for each name.

checkpointsoptionalread only number

Reverse mode: the number of checkpoint slots C each loop keeps in function memory. Defaults to 32. A loop of N iterations is saved every ceil(N / C) iterations, and for N up to C² its body runs about three times forward and once backward.

customoptionalread only Readonly<Record<string, string>>

Reverse mode: author-written adjoints, by function. { g: 'g_adjoint' } makes every call to g take its adjoint from g_adjoint(g's parameters…, dy), which returns a struct with a field of the same name and type for each float parameter of g. It is the escape hatch for a recurrence the author can invert. gradCheck holds it as it holds a generated adjoint.

See also

Source

src/core/passes/grad.ts, line 13, at commit af54ddad5

Edit this page Report a problem