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 team to create the session, trainers, and samplers inside a specific Baseten team instead of your organization’s default team. Give the team’s name, not its ID. ServiceClient resolves the name against your available teams when you construct it, and raises ValueError listing the teams you can use when none match. ServiceClient reads the LOOPS_TEAM environment variable when you don’t pass the kwarg. See Choose a team.Pass reuse_from_run_id to attach create_lora_training_client calls to a prior run’s warm trainer and paired sampler instead of provisioning fresh. ServiceClient reads the LOOPS_REUSE_FROM_RUN_ID environment variable when you don’t pass the kwarg; the kwarg wins when you set both.reuse_from_session_id (environment variable LOOPS_REUSE_FROM_SESSION_ID) is the deprecated session-based equivalent; when both are set, the run ID wins and the session ID is ignored. Standalone samplers from create_sampling_client reuse through the session ID only.The named run or session must belong to the same team. Reuse is best-effort: if the prior trainer or sampler is stopped, failed, or unhealthy, the backend provisions a fresh one 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. By default 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 run and session reuse. See Scale the trainer for how batches shard across replicas.max_seq_len sets the longest sequence in tokens the run must handle. Omit it and the backend picks the default for the model and the accelerators available to you. The run’s paired sampler serves at this length too.with_sampler provisions the run’s paired sampler up front so it boots alongside the trainer, instead of waiting for your first sampling request. Use it when you know you’ll sample, so you don’t pay the sampler cold start mid-loop. Leave it off for train-only workloads so no sampler GPU is provisioned. If the sampler create fails, the run continues and the sampler falls back to being created on first use.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 is ACTIVE.max_seq_len sets the longest prompt in tokens the sampler must handle. Omit it and the backend picks the default for the model and the accelerators available to you.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.