ServiceClient is the entry point for every session. It calls the Baseten control plane to create a session, then provisions trainers and samplers within that session on demand. It returns the TrainingClient and SamplingClient you drive for the rest of a run.
Provision a trainer and get a TrainingClient:
ServiceClient
Construct a
ServiceClient and create a new TrainerSession on the Baseten control plane. All arguments are keyword-only. api_key defaults to the BASETEN_API_KEY environment variable, and base_url to LOOPS_BASE_URL (falling back to https://app.baseten.co).Pass reuse_from_session_id to reuse a prior session’s trainer and sampler for create_lora_training_client and create_sampling_client calls instead of provisioning fresh. The named session must belong to the same team. ServiceClient reads the LOOPS_REUSE_FROM_SESSION_ID environment variable when no kwarg is passed; the kwarg wins when both are set. Reuse is best-effort: if the prior deployment is stopped, failed, or unhealthy, a fresh one is provisioned and the call still succeeds. See Reuse infrastructure across sessions.ServiceClient
Bind to already-running local trainer and sampler processes without contacting the control plane. Pass
trainer_url and sampler_url as the base URLs of local server processes. Useful for end-to-end testing.TrainingClient
Provision a trainer for the given Hugging Face
base_model and return a connected TrainingClient. Blocks until the trainer’s HTTP server is up, so you can use the returned client immediately. The trainer comes up without a sampler; one is provisioned the first time you request a sampling client from the returned TrainingClient. Pass a WandbConfig instance to stream training metrics to a Weights & Biases run.replicas sets the number of data-parallel copies of the trainer to run. More copies raise throughput (larger effective batch, faster weight updates) at proportionally more GPUs; they don’t change model size or sequence length. Must be at least 1. Values above 1 provision fresh capacity and bypass session reuse. See Scale the trainer for how batches shard across replicas.TrainingClient
Return a
TrainingClient initialized with the weights saved at path. The optimizer starts fresh. Use this to resume from a saved checkpoint when you do not need the prior optimizer state. replicas works as in create_lora_training_client.TrainingClient
Return a
TrainingClient that resumes from path with the optimizer state and step count intact. Use this to continue a run exactly where it left off. replicas works as in create_lora_training_client.SamplingClient
Provision a standalone sampler and return a connected
SamplingClient. A standalone sampler has no trainer or run behind it and receives no weight syncs. Pass exactly one of base_model or model_path (a bt://loops:<run_id>/sampler_weights/<name> checkpoint URI to serve); passing both or neither raises ValueError. Blocks until the sampler’s deployment is active.To sample from a live run’s latest weights, use TrainingClient.save_weights_and_get_sampling_client instead. ServiceClient.local clients don’t support model_path.ServerCapabilities
Return the control plane’s view of supported base models and the GPU classes it can provision them on. Useful for confirming a base model is available before calling
create_lora_training_client. Returns ServerCapabilities.list[Checkpoint]
List checkpoints saved by the run identified by
run_id. Calls the list checkpoints API, not the trainer directly. Returns a list of Checkpoint.CheckpointFilesResponse
Return presigned URLs for every file in the specified checkpoint folder. Checkpoint IDs are globally unique, so no run scoping is required. The Loops stack writes checkpoints as unzipped directories rather than archives, so this returns a file list instead of a single archive URL. If the checkpoint files live in S3, export
S3_REGION to that bucket’s AWS region before calling this method. Wraps the get checkpoint files API.str
Property. The session ID assigned by the control plane. Available after construction.