RepoBasetenBasetenpublished Nov 5, 2026seen 3w

basetenlabs/loops-cookbook

Python

Open original ↗

Captured source

source ↗
published Nov 5, 2026seen 3wcaptured 3whttp 200method plain

basetenlabs/loops-cookbook

Description: Baseten Loops example recipes and patterns

Language: Python

License: MIT

Stars: 0

Forks: 0

Open issues: 0

Created: 2026-11-05T23:34:53Z

Pushed: 2026-11-06T00:54:28Z

Default branch: main

Fork: no

Archived: no

README:

loops-cookbook

Post-train models on Baseten Loops. Loops runs the expensive half, a LoRA trainer and a paired sampler that hot-swaps to each new policy; the cookbook runs the rest. It comes with two recipes, and the loops command runs both: each config names its recipe with the recipe key.

| Recipe | Config key | Use it when | | --- | --- | --- | | [RL](#rl) | recipe = "rl" | your agent acts on tasks and a verifier rewards what it did | | [SFT](#sft) | recipe = "sft" | you have conversations for the model to imitate |

Install

You need uv, and a Baseten workspace with Loops enabled and its API key. Gated or private Hugging Face repos, including a tokenizer named by [model] tokenizer, also need HF_TOKEN.

As a dependency of your own project, from PyPI. Add ==X.Y.Z to pin a release.

uv add baseten-loops-cookbook # SFT, or RL with a custom runtime
uv add "baseten-loops-cookbook[harbor]" # RL with the Harbor runtime

The package ships the [examples](examples/), [patterns](patterns/) and [tasks](tasks/). Run one by its path in this repository, from any directory:

uv run loops check examples/terminal_bench/train.toml

A file at that path in your working directory wins over the installed one, so to change an example, copy its directory there; loops check prints where the installed one is. Copy it too for an example whose scripts write beside themselves, such as sft_toucan. The extras are the same as below: for example, uv add "baseten-loops-cookbook[harbor-blaxel]".

Or clone it to run the examples and hack on it:

uv sync # the core: SFT, and RL with a custom runtime
uv sync --extra harbor # + the Harbor runtime on Docker
uv sync --extra harbor-blaxel # + the Harbor runtime on Blaxel sandboxes
uv sync --extra harbor-daytona # + the Harbor runtime on Daytona sandboxes
uv sync --extra blaxel # + the Blaxel provider alone, for a custom runtime (likewise daytona)
uv sync --extra wandb # mirror metrics to Weights & Biases
uv sync --extra console # the rich live progress region (--output.console)
uv sync --extra vision # image inputs for vision models (brings torch)
uv sync --extra custom-loss # RL: your own loss through forward_backward_custom (brings torch)

The cookbook reaches Loops through the `baseten-loops` SDK, which it installs. Copy [.env.example](.env.example) to .env and fill in BASETEN_API_KEY. The CLIs load .env from the training config's directory or the working directory. Loops itself needs nothing local: the trainer and sampler run on Baseten.

Serverless or dedicated

Loops runs each model in one of two ways:

  • Serverless. The run trains and samples on a shared pool that Baseten keeps

ready, so the run starts in minutes.

  • Dedicated. The run gets its own trainer and sampler deployment. This takes

longer to start. The deployment stays provisioned, and you pay for it, until you deactivate the run.

The config does not choose between the two. The model and your workspace's access decide it. Qwen3.6-35B-A3B, GLM-5.3 and GLM-5.3-Flash have serverless pools. The quickstarts below train Qwen/Qwen3.6-35B-A3B. Some patterns and examples train other models. The [examples table](examples/README.md) gives the model of each example and how that model runs.

> [!NOTE] > Contact Baseten to get access to a serverless pool, to train a model that has no > pool, or to get dedicated capacity.

RL

Loops trains on what your agent did; the cookbook runs your agent on your tasks and turns each episode into training data with the exact tokens the model sampled.

How it works

1. The run schedules episodes on the runtime (Harbor, or a custom runtime). 2. The runtime runs your agent in its environment. 3. Every model call the agent makes goes through the cookbook's model client to the sampler. 4. The model client records the exact tokens the sampler returned. 5. The environment's verifier scores the episode, and the reward comes back through the runtime. 6. The run joins tokens and rewards into training batches for the LoRA trainer. 7. The trainer publishes the new policy to the sampler, and the next episodes use it.

So the responsibilities split cleanly:

  • You bring an environment (tasks, sandboxes, a verifier that produces rewards)

and an agent that decides what to do in it. The agent owns its prompts, tools, history, and stopping rules.

  • The cookbook brings the model client, which renders messages with the model's

own chat template and keeps the exact token IDs and logprobs; rollout scheduling across sampling and grading, sync or async; GRPO advantages (reward minus the group mean, not divided by its standard deviation) and datum packing; the Loops trainer transport, checkpoints, and metrics.

Pick a pattern

Where your agent runs decides most of what you write:

  • in-process: your agent is Python the runtime calls inside the training process,

such as a Harbor LoopsAgent class. It can call the model directly with llm().

  • local: your agent is its own program (a binary, a CLI, another language, code

you can't edit) that the runtime launches on the training machine. It reaches the model through the run's OpenAI-compatible endpoint.

  • remote: your agent runs inside the sandbox, such as an agent installed in the

environment. Not supported yet.

[patterns/README.md](patterns/README.md) defines the terms, then shows each placement with a diagram, what you write, when to use it, and who owns the sandbox on each environment backend. Every supported pattern is a runnable directory in [patterns/](patterns/), with a training config per backend; [examples/](examples/) builds settings and features on top of them.

Tasks with an environment also need an environment backend (see [environment backends](patterns/README.md#environment-backends)): a local Docker daemon is enough to start, and Blaxel or Daytona needs its extra and its credentials.

Quickstart

The smallest run needs only the core install and BASETEN_API_KEY: no Harbor,...

Excerpt shown — open the source for the full document.