Skip to main content
Loops is a Python SDK for LoRA fine-tuning, with supervised fine-tuning (SFT) and reinforcement learning (RL), on training and sampling infrastructure that Baseten manages. You write the training script, and Baseten runs the trainer and sampler. Use Training Jobs for full-parameter training or your own training framework.

What Loops provides

The SDK’s four core operations are forward_backward(), which computes the loss and accumulates gradients; optim_step(), which updates the adapter; sample(), which generates from the current or a saved policy; and save_state(), which saves training state you can resume. The API is compatible with Tinker, so a script that starts with import tinker runs on Loops without rewriting its calls. See Migrate from Tinker. The Loops cookbook packages ready-made SFT and RL recipes for the SDK, with examples for tool calling, sandboxed agents, and coding agents, and a loops command that checks and runs them.

How Loops works

Your training script sends each batch to the trainer, which computes the loss and gradients and then updates the LoRA adapter. The base model’s weights stay frozen. To generate with the updated adapter, for RL rollouts or for evaluation, the script publishes the adapter’s weights and samples from them. It can also save training state to resume a run, and save sampler weights to deploy as a model. Training and sampling run on separate resources. In synchronous RL, the script publishes weights and collects rollouts before each training step. Asynchronous RL samples while the trainer trains and limits how far behind the policy that generated a rollout can be. Both are patterns you write with the SDK; they’re separate from the SDK’s *_async methods, which integrate calls with a Python event loop. You can use Loops in two availability modes:
  • Serverless: shared capacity billed for the tokens you train and sample, for the models and configurations serverless supports. For more information, see Serverless Loops token pricing.
  • Dedicated: every supported model, billed for GPU time, with controls for replicas, warm reuse, and spot capacity.
Follow the quickstart to train and sample in the serverless mode.

Supported models

Loops trains LoRA adapters on open models from publishers including Qwen, Google, DeepSeek, Moonshot AI, NVIDIA, and Z.ai, including vision-language models. The model catalog lists every model with its availability modes, maximum sequence length, and vision support. Model access and sequence-length limits depend on your workspace. Check workspace access for the exact model IDs and sequence lengths your API key can use. Pass a returned model ID as base_model when you create a training client.

Request more access

To train a larger model or a model that isn’t listed, use longer sequences, or run more runs at once, fill out the Loops request form.

Where to go next

Reference

  • CLI reference: Manage runs and checkpoints, host the Python client, and inspect dedicated GPU allocations.
  • SDK reference: Train and sample from Python.
  • API reference: Manage Loops resources over HTTP.