Installation
Installbaseten-loops with Python 3.12 or later:
baseten.loops.
Authentication
Create a workspace API key for a workspace with Loops enabled, then setBASETEN_API_KEY:
ServiceClient reads the key from the environment:
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
create_lora_training_client(): Provision a trainer and get aTrainingClient.forward_backward()andoptim_step(): Run one training step.save_state(): Save a checkpoint.save_weights_and_get_sampling_client(): Publish weights and get a pinnedSamplingClient.sample(): Generate from the trained model.list_checkpoints(): List a run’s checkpoints.download_checkpoint(): Download a checkpoint to a local directory.
Reference
- Types: Training inputs, configuration, and result handles.
- Errors: SDK exception types and their causes.
- Helpers: Functions such as
attach_reference_logprobsandloops_log_kl_sample_train.
Related documentation
- Loops quickstart: Train one step, generate a sample, and shut down the run.
- Programmatic training: Run training and evaluation from your application.
- Loops API: Manage runs, trainers, samplers, and checkpoints over HTTP.
- Loops run commands: Inspect and deactivate runs from your terminal.