---
title: "GradOptions: interface in IR, TypeShade API reference"
description: "GradOptions, an interface in IR. Options for grad. The intermediate representation every backend reads: nodes, statements and declarations."
url: https://typeshade.dev/api/gradoptions/
language: en
---

# `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

```ts
interface GradOptions {
  readonly name?: string;
  readonly direction?: readonly number[];
  readonly mode?: 'forward' | 'reverse';
  readonly checkpoints?: number;
  readonly custom?: Readonly<Record<string, string>>;
}
```

## Instance properties

**`name` optional read only `string`**

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

**`direction` optional read 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.

**`mode` optional read 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.

**`checkpoints` optional read 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.

**`custom` optional read 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`](https://typeshade.dev/api/gradcheck/) holds it as it holds a generated adjoint.

## See also

- [`grad`](https://typeshade.dev/api/grad/)
- [`gradCheck`](https://typeshade.dev/api/gradcheck/)

## Source

[`src/core/passes/grad.ts`, line 13](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/passes/grad.ts#L13), at commit af54ddad5
