Skip to main content
Run LoRA training and generate samples on Baseten from Python.

Installation

Install baseten-loops with Python 3.12 or later:
Import the package as baseten.loops.

Authentication

Create a workspace API key for a workspace with Loops enabled, then set BASETEN_API_KEY:
ServiceClient reads the key from the environment:
Creating a ServiceClient starts a session. The client provisions trainers and samplers when you request them. See the ServiceClient reference to pass an API key, select a team, or connect to an existing run. After training, deactivate the run to stop GPU billing. Closing a Python client doesn’t deactivate the run.

Clients

  • ServiceClient: Create sessions, provision trainers and samplers, and retrieve checkpoints.
  • TrainingClient: Run forward and backward passes, apply optimizer steps, and save weights.
  • SamplingClient: Generate completions from current or version-pinned weights.

Commonly used methods

Reference

  • Types: Training inputs, configuration, and result handles.
  • Errors: SDK exception types and their causes.
  • Helpers: Functions such as attach_reference_logprobs and loops_log_kl_sample_train.