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

# The Cookbook

> Ready-to-run training recipes for GRPO, DPO, and SFT built on top of the Training API.

## What is the Cookbook?

The [Fireworks Cookbook](https://github.com/fw-ai/cookbook/tree/main/training) is a collection of training recipes and utilities built on top of the [Training API](/fine-tuning/training-api/introduction). It provides config-driven training loops that handle trainer provisioning, data loading, tokenization, gradient accumulation, checkpointing, and cleanup automatically.

The cookbook is **optional** — everything it does can be done with the API directly. Use the cookbook when you want a working training loop quickly; use the API when you need full control.

## Installation

```bash theme={null}
git clone https://github.com/fw-ai/cookbook.git
cd cookbook/training && pip install -e .
```

Set your credentials:

```bash theme={null}
export FIREWORKS_API_KEY="your-api-key"
```

## Available recipes

| Recipe                        | Module                           | Use case                                                                                                                                           |
| ----------------------------- | -------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| **RL**                        | `training.recipes.rl_loop`       | On-policy and off-policy reinforcement learning with GRPO, importance sampling, DAPO, DRO, GSPO, and CISPO                                         |
| **IGPO**                      | `training.recipes.igpo_loop`     | Information Gain-based Policy Optimization — turn-level IG rewards for multi-turn agent trajectories (extends GRPO)                                |
| **DPO**                       | `training.recipes.dpo_loop`      | Direct preference optimization from chosen/rejected pairs                                                                                          |
| **SFT**                       | `training.recipes.sft_loop`      | Supervised fine-tuning with cross-entropy loss                                                                                                     |
| **ORPO**                      | `training.recipes.orpo_loop`     | Odds ratio preference optimization                                                                                                                 |
| **Async RL** *(experimental)* | `training.recipes.async_rl_loop` | Asynchronous rollout / training overlap. **No backward-compatibility guarantee** — config fields and rollout protocol may change between releases. |

Each recipe follows the same pattern: import `Config` and `main`, set your config, and call `main(cfg)`.

All launch examples below use `infra=InfraConfig(training_shape_id=...)`. For cookbook users, that training shape ID is usually the only shape-specific input you need to set.

If you want field-level details about what a training shape controls and what stays configurable, see the API reference pages linked from [Training Shapes](/fine-tuning/training-api/training-shapes).

## Quick example: SFT

```python theme={null}
from training.recipes.sft_loop import Config, main
from training.utils import InfraConfig

cfg = Config(
    log_path="./sft_quickstart",
    base_model="accounts/fireworks/models/qwen3-8b",
    dataset="/path/to/training_data.jsonl",
    tokenizer_model="Qwen/Qwen3-8B",
    max_seq_len=4096,
    epochs=1,
    batch_size=4,
    infra=InfraConfig(
        training_shape_id="accounts/fireworks/trainingShapes/qwen3-8b-128k-h200",
    ),
)

main(cfg)
```

## Quick example: GRPO

```python theme={null}
from training.recipes.rl_loop import Config, main
from training.utils import DeployConfig, InfraConfig, WeightSyncConfig

cfg = Config(
    log_path="./grpo_quickstart",
    base_model="accounts/fireworks/models/qwen3-8b",
    dataset="/path/to/prompts.jsonl",
    max_rows=100,
    infra=InfraConfig(
        training_shape_id="accounts/fireworks/trainingShapes/qwen3-8b-128k-h200",
    ),
    deployment=DeployConfig(
        deployment_id="grpo-serving",
        tokenizer_model="Qwen/Qwen3-8B",
    ),
    weight_sync=WeightSyncConfig(weight_sync_interval=1),
)

main(cfg)
```

## W\&B logging

All cookbook recipes accept a `WandBConfig` to stream metrics to [Weights & Biases](https://wandb.ai):

```python theme={null}
from training.utils import WandBConfig

cfg = Config(
    # ... same config as above ...
    wandb=WandBConfig(
        entity="my-team",
        project="grpo-experiment",
        run_name="qwen3-8b-sft-v1",  # optional, auto-generated if omitted
    ),
)

main(cfg)
```

## Vision-language model support

All cookbook recipes support VLM fine-tuning. Use a VLM training shape and tokenizer, and provide multimodal datasets with `image_url` content. See [Vision Inputs](/fine-tuning/training-api/vision-inputs) for dataset format and examples.

## Next steps

* [Cookbook SFT](/fine-tuning/training-api/cookbook/sft) — supervised fine-tuning
* [Cookbook DPO](/fine-tuning/training-api/cookbook/dpo) — preference optimization with pairwise data
* [Cookbook RL (GRPO)](/fine-tuning/training-api/cookbook/rl) — full GRPO walkthrough with reward functions
* [Vision Inputs](/fine-tuning/training-api/vision-inputs) — fine-tune VLMs with image and text data
* [Cookbook Reference](/fine-tuning/training-api/cookbook/reference) — all config classes and parameters
