Installation
Truss includes the training SDK:- uv (recommended)
- pip (macOS/Linux)
- pip (Windows)
uv is a fast Python package manager. Create a virtual environment and install Truss:
config.py). Import the SDK and accelerator config:
config.py
truss_train (for example, from truss_train import Compute, Runtime).
Complete example
Copy thisconfig.py as a starting point for your training project. It configures caching to persist pip packages between jobs, checkpointing to save model weights, and GPU compute on a single H200 node. Modify the start_commands, environment_variables, and accelerator fields for your use case. For more examples, see ml-cookbook.
config.py
push
Submits a training job to Baseten. Every config you define with the classes below does nothing until you callpush().
When you call push(), Baseten:
- Authenticates with your Baseten account.
- Creates the training project if one with the given name doesn’t already exist, or reuses the existing project.
- Archives your source directory (your training script, data files, and any other local files) and uploads it.
- Submits a new training job. Baseten provisions the hardware, pulls the container image, mounts any BDN weights, extracts your source files into the container, and runs your start_commands.
CREATED: Baseten has received the training configuration.DEPLOYING: Baseten is provisioning compute resources and installing dependencies.RUNNING: Your training code is actively executing.COMPLETED: The job has finished. Checkpoints and artifacts have been saved.DEPLOY_FAILED: The job failed to deploy, likely due to a bad image or resource allocation issue.FAILED: The job encountered an error. Check the logs for details.STOPPED: The job was manually stopped.
baseten train push --config config.py performs the same steps with additional options for team selection and flag overrides.
The push function accepts either a file path or a TrainingProject object.
config.py
Parameters
Path to a
config.py file or a TrainingProject instance. When you pass a Path, Baseten imports the module and scans for an instance of TrainingProject. The module must contain exactly one.Root directory whose contents Baseten uploads as the job’s working directory. Baseten archives this directory and extracts it into the container before running start_commands. Only applies when
config is a TrainingProject. Defaults to the current directory.ID of the team that owns the training project. Required for API keys that only have access to a non-default team. If omitted, the project uses the organization’s default team.
Return value
Returns a dictionary containing the created training job. Use theid and training_project.id values to monitor the job, stream logs, and list checkpoints.
Output
TrainingProject object to push():
submit_job.py
Output
After submitting
Oncepush() returns, Baseten queues your job and begins provisioning. Use the returned job ID to track progress:
- Stream logs:
baseten train job logs --job-id <job_id> --tail - Check status:
baseten train job describe --job-id <job_id> - List checkpoints: Use the get training job checkpoints API.
- Deploy a checkpoint: For more information, see deploy checkpoints.
config.py-based submission with the CLI, see the training getting started guide.
TrainingProject
Groups related training jobs under a single named project. When you push aTrainingProject, Baseten creates the project if it doesn’t exist, then submits the attached TrainingJob. All jobs in a project share the same project-level cache and appear together in the dashboard.
config.py
Parameters
Training job to submit. Defines the container image, compute resources, runtime commands, and optional weights. For more information, see TrainingJob.
GPU type that will use cached data prepared by CPU jobs, such as
Accelerator.H100 from truss.base.truss_config. Defaults to None; omitting it for an existing project keeps its current value. See Prepare data on CPUs for GPU jobs.TrainingJob
Represents a single training run. Baseten provisions the hardware specified in Compute, pulls the container Image, uploads your source directory, mounts any WeightsSource volumes, then executes the Runtime start commands. For more information, see the training lifecycle.config.py
Parameters
Docker image that provides the training environment, including the OS, CUDA drivers, and pre-installed libraries. For more information, see Image.
Hardware allocation for each node. Set the GPU type and count with
accelerator, and increase node_count for distributed training. Defaults to Compute(). For more information, see Compute.Controls container startup: shell commands to execute, environment variables to inject, and whether to enable caching or checkpointing. Defaults to
Runtime(). For more information, see Runtime.Queue priority for the job. Higher values run first when capacity becomes available. Defaults to
None, which leaves the platform default of 0. See queue priority.Opens a remote tunnel so you can attach VS Code or Cursor to the running container for live debugging. For more information, see InteractiveSession.
Controls which local files Baseten uploads to the container. Use this to exclude large directories, include files from outside the root, or change the root entirely. For more information, see Workspace.
Model weights that BDN mirrors and mounts read-only in the container. Supports Hugging Face, S3, GCS, Azure, R2, CoreWeave, and direct URLs. For more information, see WeightsSource.
When
True (default), Baseten uses /b10/workspace as the container’s working directory, extracting your source files and base image working directory contents there. The BT_WORKING_DIR environment variable points to /b10/workspace. When False, the Docker image’s default working directory is used and BT_WORKING_DIR is unset.WeightsSource
Mounts pre-trained model weights into the training container as a read-only volume. Baseten mirrors the weights through BDN before provisioning compute, so the data is on disk before yourstart_commands run.
On subsequent jobs, BDN serves the cached copy from a cluster- or node-local cache, which avoids re-downloading.
For the full delivery behavior, see how BDN serves training jobs.
- Hugging Face
- S3 with auth
- File filtering
config.py
Parameters
URI with scheme prefix.
For Hugging Face sources, pin to a specific revision with the
@revision suffix (branch, tag, or commit SHA).Authentication configuration. See the BDN configuration reference.
Image
Sets the Docker image that Baseten pulls to create the training container. The image provides the OS, CUDA drivers, Python version, and any pre-installed libraries your training code needs. Use a public image from Docker Hub or a private image with DockerAuth.config.py
Parameters
Credentials for pulling from private registries like AWS ECR or Google Container Registry. Store actual credentials as Baseten secrets. For more information, see DockerAuth.
DockerAuth
Provides credentials for pulling images from private Docker registries (AWS ECR, Google Container Registry, etc.). OIDC and AWS AssumeRole use short-lived credentials and do not require Baseten secrets. For setup instructions and complete examples, see private training images.IAM credentials for authenticating with AWS ECR. Requires
access_key_secret_ref and secret_access_key_secret_ref. For more information, see AWSIAMDockerAuth.AWS OIDC configuration for ECR. Requires
role_arn and region. For more information, see AWSOIDCDockerAuth.AWS AssumeRole configuration for ECR. Requires
role_arn and region. For more information, see AWSAssumeRoleDockerAuth.GCP OIDC configuration for Artifact Registry or Google Container Registry. Requires
service_account and workload_identity_provider. For more information, see GCPOIDCDockerAuth.Service account JSON credentials for authenticating with Google Container Registry. For more information, see GCPServiceAccountJSONDockerAuth.
Username/password credentials for authenticating with registries that support static credentials (Docker Hub, GHCR, NGC). Not compatible with AWS ECR or GCP Artifact Registry. For more information, see RegistrySecretDockerAuth.
AWSIAMDockerAuth
Authenticates with AWS ECR using IAM credentials.config.py
AWS access key ID, stored as a Baseten secret and referenced by name.
AWS secret access key, stored as a Baseten secret and referenced by name.
AWSOIDCDockerAuth
Authenticates with AWS ECR using short-lived OIDC credentials. Configure AWS trust and the completeImage object as shown in private training images.
AWSAssumeRoleDockerAuth
Authenticates with AWS ECR using short-lived AssumeRole credentials. Complete the AWS AssumeRole setup before using this configuration.GCPOIDCDockerAuth
Authenticates with Google Artifact Registry or Google Container Registry using short-lived OIDC credentials. Configure GCP and the completeImage object as
shown in private training images.
GCPServiceAccountJSONDockerAuth
Authenticates with Google Container Registry using service account JSON.config.py
GCP service account JSON, stored as a Baseten secret and referenced by name.
RegistrySecretDockerAuth
Authenticates with registries that support static username/password credentials, including Docker Hub, GHCR, and NGC. For AWS ECR or GCP Artifact Registry, use AWSIAMDockerAuth or GCPServiceAccountJSONDockerAuth instead.config.py
Registry credentials in
username:password format (plaintext, not Base64-encoded), stored as a Baseten secret and referenced by name.Compute
Defines the hardware Baseten allocates for each training job. Setnode_count above 1 for multi-node distributed training, which provisions multiple identical nodes and injects coordination environment variables (BT_LEADER_ADDR, BT_NODE_RANK, BT_GROUP_SIZE).
config.py
Parameters
Number of nodes to provision. Each node gets the full CPU, memory, and GPU allocation.
GPU type and count per node. For more information, see AcceleratorSpec.
Capacity guarantee the job is scheduled under.Available options:
AvailabilityModel.STANDARD: capacity that isn’t preempted.AvailabilityModel.SPOT: interruptible capacity that can be preempted at any time; you’re responsible for checkpointing your own progress.baseten train push --spotoverrides this field at push time.
AvailabilityModel.DEDICATED is the old name for STANDARD, and existing configs that set it still work.AcceleratorSpec
Selects the GPU type and count per node. Thecount determines how many GPUs are available to your training script on each node (exposed as $BT_NUM_GPUS).
Runtime
Controls what happens when the training container starts. Baseten executesstart_commands in order inside the container. Use them to install dependencies, set up data, and launch your training script. Baseten injects environment variables before the first command runs; use SecretReference for sensitive values like API keys so they aren’t stored in your config file.
config.py
Parameters
Key-value pairs that Baseten injects as env vars. Use SecretReference for sensitive values.
Enables writing model checkpoints to persistent storage. When enabled, Baseten mounts a volume and exports
$BT_CHECKPOINT_DIR. Defaults to CheckpointingConfig(). For more information, see CheckpointingConfig.Enables a persistent read-write cache that survives across jobs for pip packages, model downloads, and preprocessed datasets. For more information, see CacheConfig.
Downloads checkpoints from a previous job into the container before
start_commands run. Use this to resume training or initialize weights from an earlier experiment. For more information, see LoadCheckpointConfig.SecretReference
Injects a secret stored in your Baseten workspace as an environment variable at runtime. Baseten never writes the value to your config file or source code. Use this for API keys, tokens, and credentials.config.py
CheckpointingConfig
Enables persistent checkpoint storage for the training job. Whenenabled is true, Baseten mounts a persistent volume and exports $BT_CHECKPOINT_DIR as an environment variable pointing to it. Your training script writes model weights, optimizer state, or any artifacts to that directory.
A background process syncs the checkpoint directory to cloud storage on a recurring cycle. A checkpoint becomes durable only after it syncs, so keep each checkpoint on disk until it appears in your job’s checkpoint list. A checkpoint deleted before it syncs is lost, and errors aren’t raised. Synced checkpoints survive job termination and can be deployed to inference or loaded into future jobs. See the checkpointing guide for best practices.
config.py
CacheConfig
Enables a persistent read-write cache that survives across jobs. Use the cache for pip packages, downloaded model weights, preprocessed datasets, or any data you don’t want to re-download on every run. Whenenabled is true, Baseten mounts two shared directories into the container. When require_cache_affinity is true (the default), Baseten schedules the job on a node that already has cached data, which avoids cold starts. See the cache guide for usage patterns.
config.py
Contact support to enable it for your organization. Set to
true to place the job’s $HOME on the project cache at $BT_PROJECT_CACHE_DIR/homes/<job_id>, so files written there outlive the job. Requires enabled=True. Each job gets a new home directory; a later job doesn’t reuse an earlier job’s, but can read it at that path. Baseten deletes the home directory 7 days after the job ends. Use it to keep shell history, editor settings, and tool caches from an SSH workstation.LoadCheckpointConfig
Downloads checkpoints from previous training jobs into the container beforestart_commands run. Use this to resume training from a saved state or to initialize weights from an earlier experiment. Baseten downloads the specified checkpoints to download_folder (also exported as $BT_LOAD_CHECKPOINT_DIR) and your training script reads them at startup. For more information, see the loading checkpoints walkthrough.
config.py
One or more checkpoint references to download. Create references with
BasetenCheckpoint.from_latest_checkpoint(), BasetenCheckpoint.from_named_checkpoint(), or LoopsCheckpoint.from_checkpoint(). For more information, see BasetenCheckpoint and LoopsCheckpoint.Directory where Baseten downloads checkpoints. Exported as
$BT_LOAD_CHECKPOINT_DIR. Defaults to /tmp/loaded_checkpoints.BasetenCheckpoint
Creates references to checkpoints saved by previous training jobs. Pass these references to LoadCheckpointConfig to download checkpoint data into your container at job start. You can reference checkpoints by project name (gets the most recent), by job ID (gets the most recent from that job), or by exact checkpoint name and job ID.config.py
from_latest_checkpoint
Returns a reference to the most recent checkpoint from a project or job. At least one ofproject_name or job_id is required.
from_named_checkpoint
Returns a reference to a specific checkpoint by its name and job ID.LoopsCheckpoint
Creates references to checkpoints saved by Loops runs. Pass these references to LoadCheckpointConfig to download checkpoint data into your container at job start. Use this to load initial weights from a Loops run.config.py
from_checkpoint
Returns a reference to a specific Loops checkpoint by its run ID and checkpoint name.Checkpoint type to load.
trainer loads the full training state (default). sampler loads inference weights only.Workspace
Controls which local files Baseten uploads to the training container. By default, Baseten archives the directory containing yourconfig.py (or the source_dir you pass to push) and extracts it into the container’s working directory. Use Workspace to customize this behavior: exclude large data directories, include files from outside the root, or change the root entirely.
config.py
Parameters
Directories to exclude from the upload (for example,
"data", ".git", "__pycache__").InteractiveSession
Enables interactive access to the training container for live debugging. Configuresession_provider to choose between VS Code and Cursor remote tunnels and SSH, and trigger to control when the session starts.
- SSH
- VS Code & Cursor
config.py
Parameters
Controls when to activate the session. Defaults to
ON_DEMAND.Available options:ON_STARTUP: active from job start.ON_FAILURE: activates when training exits with a non-zero code.ON_DEMAND: activates when you connect (SSH) or authenticate through the device code flow (remote tunnel), or when you change the trigger on a running job.
Minutes before the session expires. Set to
-1 to extend the expiry to 10 years. For remote tunnel sessions, the expiry resets on every reconnect. For SSH, the expiry is set once at session start.Connection method for the interactive session. Defaults to
VS_CODE.Available options:VS_CODE: VS Code Remote Tunnels.CURSOR: Cursor Remote Tunnels.SSH: Direct SSH access from your terminal. See the SSH guide for setup.
Authentication provider for the remote tunnel device code flow. Defaults to
MICROSOFT. Ignored when session_provider=SSH.Available options:GITHUB: authenticate through GitHub.MICROSOFT: authenticate through Microsoft.
Environment variables
Baseten automatically injects these environment variables into every training container. Your training script can read them to discover job metadata, locate scratch, checkpoint, and cache directories, and coordinate across nodes in multi-node jobs.Standard variables
Multi-node variables
For distributed training across multiple nodes:Default HTTP timeout
Python HTTP requests in training containers time out after 300 seconds by default. Without a timeout, a request to a server that stops responding blocks forever, and your job hangs on billed GPU time until you notice and stop it. The timeout fires when the connection goes silent: the server doesn’t accept the connection, or stops sending data, for 300 seconds. It doesn’t limit total request duration, so a long download that’s still receiving data isn’t interrupted. When it fires, the request raises your HTTP library’s standard timeout or connection error, such asrequests.exceptions.ConnectionError. A stalled connection during training is almost always transient, so catch the error and retry; for large datasets and weights, skip in-script downloads entirely and mount them through BDN.
The default applies to standard-library and urllib3-based HTTP clients (including requests), and only to requests that don’t set their own timeout. A timeout passed in your code takes precedence.
To change the default, set BT_HTTP_DEFAULT_TIMEOUT_SEC in your job’s environment_variables. Raise it if you call servers that legitimately take longer than five minutes to start responding:
0 to remove the default entirely; requests without their own timeout can then hang indefinitely. Invalid values fall back to 300 seconds and log a warning to stderr.
Deploy checkpoints
Deploys trained model checkpoints from a completed training job to Baseten’s inference platform. Baseten downloads the checkpoint weights, packages them with a serving runtime, and creates a deployable model endpoint. See the deployment guide for the full workflow.Deploy with CLI wizard
Deploy checkpoints interactively with the CLI wizard:The
deploy_checkpoints command doesn’t support FSDP checkpoints. Configure these manually in the Truss config.For optimized inference with TensorRT-LLM, see Deploy with optimized inference engines.
Deploy with static configuration
Create a Python config file for repeatable deployments:DeployCheckpointsConfig
Defines how to deploy checkpoints from a completed training job to a Baseten inference endpoint. Baseten reads the checkpoint weights, selects the correct serving backend based on the model weights format (full, LoRA, or Whisper), and provisions the specified Compute resources.deploy_config.py
Parameters
Checkpoints to deploy, including the base model ID for LoRA and one or more checkpoint references. For more information, see CheckpointList.
Environment variables for the inference runtime, such as API keys or serving configuration. For more information, see DeployCheckpointsRuntime.
GPU and memory allocation for the inference endpoint. Uses the same Compute configuration as training jobs.
DeployCheckpointsRuntime
Sets environment variables for the deployed inference endpoint. Use this to inject API keys or configuration that the serving runtime needs.Key-value pairs that Baseten injects as env vars. Use SecretReference for sensitive values.
CheckpointList
Groups one or more checkpoints for deployment. For LoRA deployments, setbase_model_id to the Hugging Face model ID you trained the adapters on.
Directory where Baseten downloads checkpoint files during deployment. Defaults to
/tmp/training_checkpoints.One or more FullCheckpoint, LoRACheckpoint, or WhisperCheckpoint instances.
Loops checkpoint IDs to deploy. Mutually exclusive with
checkpoints: set one or the other, not both.Checkpoint types
Baseten supports three checkpoint types. Use the type that matches how your model was trained.FullCheckpoint
Deploys a complete set of model weights from a full fine-tune.LoRACheckpoint
Deploys LoRA adapter weights on top of the base model you specify in CheckpointList.LoRA adapter configuration. Set
rank to match the rank you used during training. Defaults to LoRADetails(). Valid values:- 8, 16, 32, 64, 128, 256, 320, 512.