> ## Documentation Index
> Fetch the complete documentation index at: https://staging.docs.trywhitney.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Algorithm cookbooks

> Implement training algorithms as loops over Whitney HTTP primitives.

Start with [SFT](/cookbooks/sft), [GRPO](/cookbooks/grpo), or
[evaluation](/cookbooks/evaluation). Use [More algorithms](/cookbooks/algorithms)
when you need a variant or distillation objective beyond those foundations.

| Goal                         | Start here                               |
| ---------------------------- | ---------------------------------------- |
| Supervised fine-tuning       | [SFT](/cookbooks/sft)                    |
| Group-relative RL            | [GRPO](/cookbooks/grpo)                  |
| Score generations locally    | [Evaluation](/cookbooks/evaluation)      |
| Algorithm-specific objective | [More algorithms](/cookbooks/algorithms) |

Every loop follows this safety envelope:

```text theme={null}
capabilities → session → run → ordered primitives
  → save/export → finish → close
```

On error or interruption:

```text theme={null}
cancel run → poll terminal state → close session
```

Implement algorithms as caller-owned loops over Whitney primitives. There is no
managed recipe submit endpoint and no Whitney SDK requirement for v1.

## Runnable reference implementations

Every loop on this page and on [More algorithms](/cookbooks/algorithms) has a
real, runnable counterpart in
[`examples/training/http/`](https://github.com/try-whitney/whitney/tree/main/examples/training/http) —
not pseudocode. `sl_loop.py` and `rl_loop.py` are the two foundational loops;
most algorithm variants are a single `build_loss(sample, cycle, request, ctx)`
callable plugged into `rl_loop.py`'s `--build-loss` flag, ported from
`tinker-cookbook==0.5.5` (the same version pinned in Whitney's own backend)
where an upstream implementation exists, and cited to it in the code.

| Algorithm              | File                               | Runnable?                                                 |
| ---------------------- | ---------------------------------- | --------------------------------------------------------- |
| SFT                    | `sl_loop.py`                       | yes                                                       |
| GRPO                   | `rl_loop.py`, `grpo_build_loss.py` | yes                                                       |
| GRPO no-std            | `grpo_nostd.py`                    | yes                                                       |
| GRPO length-normalized | `grpo_len_norm.py`                 | yes                                                       |
| Dr.GRPO                | `drgrpo.py`                        | yes                                                       |
| CISPO                  | `cispo.py`                         | yes                                                       |
| DAPO                   | `dapo.py`                          | yes                                                       |
| RLOO                   | `rloo.py`                          | yes                                                       |
| REINFORCE++            | `reinforce_pp.py`                  | yes                                                       |
| MaxRL                  | `maxrl.py`                         | yes                                                       |
| OPD                    | `opd.py`                           | yes                                                       |
| PPO                    | `ppo.py`                           | yes                                                       |
| GSPO                   | `gspo.py`                          | yes (Modal only)                                          |
| DPPO                   | `dppo.py`                          | yes (Modal only)                                          |
| OPSD                   | `opsd.py`                          | yes                                                       |
| SDPO                   | `sdpo.py`                          | yes                                                       |
| SAPO                   | `sapo.py`                          | stub — excluded by the provider's own wire-level API type |

`loss_config` values (PPO/GSPO/CISPO's clip range, DPPO's divergence
thresholds) reaching the provider at all needs a recent fix in Whitney's
Modal trainer bridge — see the note at the top of
[More algorithms](/cookbooks/algorithms).

Every stub file is still a real, non-allocating capability check
(`python <file>.py --provider ... --model ...`) with a docstring explaining
exactly what is missing — never a fabricated implementation.
