Skip to main content
Dedicated Loops runs your trainer and sampler on GPU deployments allocated to your run. Every supported base model trains in this mode, and it’s how you scale a run, such as asynchronous RL, beyond one trainer and one sampler replica. Loops chooses it by default for models and configurations serverless doesn’t serve; set scope to dedicated to choose it for any model. See choose a mode. Trainer and sampler deployments bill for GPU time while they run, including time between training operations. See How a dedicated run ends.

Scale the trainer

For more training throughput, run the trainer as multiple data-parallel replicas. Set the count when you create the trainer: the Python SDK takes a replicas argument (default 1) on create_lora_training_client(), the Baseten CLI takes --replicas, and the HTTP API takes a replicas field on POST /v1/loops/trainers.
To create a multi-replica trainer:Pass replicas when you create the training client:
To attach your training script to the trainer: Start your training script with LOOPS_REUSE_FROM_RUN_ID set to the run ID, so ServiceClient reuses that trainer instead of starting a new single-replica one:
Each replica is a full copy of the trainer with its own GPUs, so GPU time and cost scale with replicas: replicas=4 uses four times the GPUs of a single replica. Your training loop doesn’t change. Each forward_backward() batch is sharded across the replicas automatically, so batches don’t need to divide evenly: a batch of 3 on 2 replicas puts 2 examples on one worker and 1 on the other, and the result still has one entry per example, in order. Gradients synchronize across replicas at optim_step(), which advances policy_version once for the whole trainer. Size batches to at least the replica count; a smaller batch works but leaves the extra replicas idle for that step. Sampler replicas work the same way. Pass sampler_num_replicas to create_lora_training_client() to set the replica count for the run’s paired sampler, or num_replicas to ServiceClient.create_sampling_client() for a standalone sampler. The count sets both the minimum and maximum, and applies when the sampler is created.

Spot capacity

Spot capacity uses GPUs that Baseten can reclaim at any time, and a reclaim stops the run. Use it for interruptible training that can continue from a checkpoint. Deployments use non-preemptible capacity by default. To run on spot capacity, set scope to dedicated and set the capacity type to spot:
To allow spot capacity:Pass availability_model when you create the client:
If you set both, the ServiceClient argument takes precedence over LOOPS_AVAILABILITY_MODEL. Loops reuses a warm trainer only when it has the same capacity type; otherwise, it provisions a new trainer with the requested capacity. A paired sampler uses its run’s capacity type. Baseten can preempt spot trainers, so save checkpoints during training. Loops doesn’t restart a preempted run automatically, but you can create a new trainer from the latest checkpoint. See Checkpoints. Spot capacity must be enabled for your workspace. Contact us to enable it. For Training Jobs, see Spot capacity. If spot trainer creation fails, follow capacity and quota errors to distinguish unavailable GPUs from your organization’s trainer limit.

Reuse a warm run

Each new ServiceClient creates a session, and a new dedicated run starts its own trainer and sampler deployments and waits for them to come up. To skip that startup, reuse a prior run’s warm trainer and paired sampler. Multi-replica trainers always provision new deployments, so reuse doesn’t apply to them.
To reuse a warm run:Pass the earlier run’s ID when you create the client:
Session-based trainer reuse still works but is deprecated in favor of the run ID: ServiceClient(reuse_from_session_id=...), the LOOPS_REUSE_FROM_SESSION_ID environment variable, and the reuse_from_session_id field on POST /v1/loops/trainers. When both are set, the run ID takes precedence and the session ID is ignored. Reuse is best-effort: the run or session must belong to the same team, and Loops starts a new trainer if the earlier one is starting, stopped, or failed. Reuse affects deployment startup only; save and load checkpoints to preserve training state.

Overlap trainer and sampler startup

In the dedicated mode, an RL loop can reach its first rollout before the sampler has started. To bring both up at about the same time, start the first save_weights_and_get_sampling_client() call as an async task as soon as the trainer is ready, and train while the sampler provisions:
overlap_startup.py
Instead of the async task, pass with_sampler=True to create_lora_training_client(): the paired sampler starts with the trainer and serves the base model until the trainer publishes weights. By default, the sampler starts at the first sampling-client request, so a run that only trains doesn’t pay for sampler GPUs. Every long-running method has an *_async counterpart with the same arguments. See the note on TrainingClient.

Usage and logs

Use baseten loops usage to inspect dedicated GPU allocations. Deployment logs cover the run’s trainer and sampler deployments. See Loops troubleshooting for request errors and recovery.

How a dedicated run ends

A dedicated run bills for GPU time while its trainer and sampler deployments run, including idle time. Deactivate the run when you finish to shut down those deployments and stop billing. Closing the training client stops its keepalive but doesn’t deactivate the run. Without explicit deactivation, the run ends after a period of inactivity, 15 minutes by default. Saved checkpoints remain available after the run ends. See Deactivate a run for shutdown commands and status checks.

Configure the inactivity timeout

Set the timeout when you create a dedicated trainer with POST /v1/loops/trainers. The timeout starts when the run stops receiving requests or client keepalives.
integer
default:900
Inactivity period before the dedicated run ends, in seconds. Accepts values from 1 to 3600. Explicit deactivation ends the run without waiting for this timeout.
To create a run with a one-hour inactivity timeout:
  1. Install jq, set BASETEN_API_KEY to your workspace API key, then create a session:
  2. Create the dedicated trainer using the returned session ID:
    The response includes run.id. Keep it to attach your training script with LOOPS_REUSE_FROM_RUN_ID or to deactivate the run when you finish. This run bills for GPU time, including the inactivity period.