Skip to main content
Run a Loops script on your local machine to start. The local Python process submits training operations, waits for results, and requests samples. Baseten runs the trainer and sampler. For long or unattended runs, use baseten loops exec to run the same script on Baseten.

Prerequisites

Keep the same ServiceClient setup in the script for either location:
train_loops.py
ServiceClient() reads BASETEN_API_KEY and connects to https://api.baseten.co by default.

Run the Python script on your local machine

To run the script locally:
  1. From your project directory, export your workspace API key as BASETEN_API_KEY. Replace YOUR_API_KEY with your key:
  2. Run your training script:
    The quickstart script prints the session and run IDs, the reward of each step, sampled text, and checkpoint paths. Compare its output with Inspect the results.
Keep the local machine or third-party host awake and ensure it permits sustained outbound HTTPS connections to Baseten. Sandboxes and hosted notebooks can suspend processes or restrict network access even after a successful first request. The SDK retries transient connection failures, but it can’t keep a run going from a persistently unstable host or network.

Run the Python script on Baseten

baseten loops exec packages a project directory and runs your script as a Training Job, using your active Baseten CLI profile. The job supplies BASETEN_API_KEY from a team secret, which Truss creates on first use unless you supply your own credential. Use a CLI profile for the same workspace as your local API key. Baseten bills for the Training Job that runs your script. The Loops run bills separately according to its availability mode. To run the script on Baseten: From your project directory, run the same train_loops.py with its uv dependencies and stream its logs:
The submission result includes the job ID:
Output
By default, the job opens an SSH session you can connect to, which requires Training SSH for your workspace. This command disables SSH with --no-ssh. Omit it if you want an SSH session and your workspace has Training SSH enabled. Always pass --dir. Use . for the current project directory or pass another project path. The remote command runs from the uploaded directory. With --tail, the command writes the submission result to stdout and streams logs to stderr until the job finishes. It returns zero if the job completes successfully and a nonzero exit code if it fails. Press Ctrl+C to stop watching; the remote job keeps running. To submit the script and check it later:
  1. Run the following command to return a structured result after submission:
    Output
  2. Use job_id from the result to follow the job’s logs with baseten train job logs:
  3. Check that the job completed with baseten train job describe:
    Output
baseten loops exec has no Loops API equivalent because it uploads local source. For more information, see the baseten loops exec reference.

Deactivate the run

Closing the training client doesn’t deactivate the Loops run. Deactivate the run to end it and its paired sampler and to stop a dedicated run’s GPU billing.