> ## Documentation Index
> Fetch the complete documentation index at: https://docs.baseten.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Load weights and data with BDN

> Mount model weights and training data from Hugging Face, S3, GCS, R2, CoreWeave, or Azure into a training container through the Baseten Delivery Network (BDN).

Use the [`weights`](https://docs.baseten.co/reference/sdk/training#param-weights) parameter on
[`TrainingJob`](https://docs.baseten.co/reference/sdk/training#trainingjob) to mount model weights and
training data into your container through the [Baseten Delivery Network (BDN)](https://docs.baseten.co/development/model/bdn.md). BDN mirrors your data once and
serves it from multi-tier caches, so subsequent jobs start faster.

Each weight source specifies a remote URI and a local mount path. When your
container starts, the data is already available at the [`mount_location`](https://docs.baseten.co/reference/sdk/training#param-mount-location).

> [!NOTE]
>
> BDN mirrors your weights to Baseten storage during the `CREATED` state, before any compute is provisioned. Once your job is scheduled on a node, BDN places the weights on local disk before your [`start_commands`](https://docs.baseten.co/reference/sdk/training#param-start-commands) run. Weight delivery never overlaps with workload execution, so BDN has no effect on training throughput. The only difference between a cache hit and a cache miss is how long the deploy phase takes.

## Mount weights and a dataset

Add [`WeightsSource`](https://docs.baseten.co/reference/sdk/training#weightssource) entries to the `weights` list of an existing `TrainingJob` in your job's `config.py`. To create the file from scratch, see [the quickstart](https://docs.baseten.co/training/getting-started.md).

This example mounts model weights from Hugging Face and training data from S3 into the container before your code runs:

```python config.py theme={"system"}
from truss_train import TrainingProject, TrainingJob, Image, Compute, Runtime, WeightsSource
from truss.base.truss_config import AcceleratorSpec

training_job = TrainingJob(
    image=Image(base_image="pytorch/pytorch:2.7.0-cuda12.8-cudnn9-runtime"),
    compute=Compute(
        accelerator=AcceleratorSpec(accelerator="H200", count=1),
    ),
    runtime=Runtime(
        start_commands=["python train.py"],
    ),
    weights=[
        WeightsSource(
            source="hf://Qwen/Qwen3-0.6B",
            mount_location="/app/models/Qwen/Qwen3-0.6B",
        ),
        WeightsSource(
            source="s3://my-bucket/training-data",
            mount_location="/app/data/training-data",
        ),
    ],
)

training_project = TrainingProject(name="qwen3-finetune", job=training_job)
```

In your training script, read the mount paths directly:

```python train.py theme={"system"}
import os

from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained("/app/models/Qwen/Qwen3-0.6B")
tokenizer = AutoTokenizer.from_pretrained("/app/models/Qwen/Qwen3-0.6B")

print("data files:", os.listdir("/app/data/training-data"))
```

Push the job once the script is in place:

```bash theme={"system"}
baseten train push --config config.py
```

The job's logs show the files BDN mounted from the S3 prefix under `data files:`.

## Supported sources

BDN supports these URI schemes:

| Scheme | Example | Source |
| - | - | - |
| `hf://` | `hf://meta-llama/Llama-3.1-8B@main` | Hugging Face Hub |
| `s3://` | `s3://my-bucket/path/to/data` | Amazon S3 |
| `gs://` | `gs://my-bucket/path/to/data` | Google Cloud Storage |
| `r2://` | `r2://<account_id>.<bucket>/path/to/data` | Cloudflare R2 |
| `cw://` | `cw://my-bucket/path/to/data` | CoreWeave AI Object Storage |
| `azure://` | `azure://<account>/<container>/path/to/data` | Azure Blob Storage |

For Hugging Face sources, pin to a specific revision with the `@revision` suffix (branch, tag, or commit SHA).

For R2, add the jurisdiction between the account ID and the bucket when your bucket isn't in the default one: `r2://<account_id>.<jurisdiction>.<bucket>/path/to/data`.

## Authentication

Private or gated sources require authentication. Add an [`auth`](https://docs.baseten.co/reference/sdk/training#param-auth) block to your
`WeightsSource`. For AWS, use [OIDC](https://docs.baseten.co/organization/oidc.md) (recommended) or
[AWS AssumeRole](https://docs.baseten.co/organization/aws-assume-role.md) to avoid storing long-lived
credentials in Baseten.

The role ARN, region, service account, and workload identity provider values aren't credentials, so you can commit them to your repository.

> [tab] Hugging Face
>
> **To read a private or gated repository**:
>
> 1. Store a [Hugging Face access token](https://huggingface.co/settings/tokens) as a [Baseten secret](https://docs.baseten.co/organization/secrets.md) named `hf_access_token`.
>
> 2. Add this source to the job's `weights` list:
>
>    ```python theme={"system"}
>    WeightsSource(
>        source="hf://meta-llama/Llama-3.1-8B@main",
>        mount_location="/app/models/llama",
>        auth={"auth_method": "CUSTOM_SECRET", "auth_secret_name": "hf_access_token"},
>    )
>    ```

> [tab] S3 (AWS OIDC)
>
> **To read a private S3 bucket with AWS OIDC**:
>
> 1. [Configure AWS to trust the Baseten OIDC provider](https://docs.baseten.co/organization/oidc.md#aws), then create an IAM role with read access to your bucket.
>
> 2. Add this source to the job's `weights` list:
>
>    ```python theme={"system"}
>    WeightsSource(
>        source="s3://my-bucket/training-data",
>        mount_location="/app/data/training-data",
>        auth={
>            "auth_method": "AWS_OIDC",
>            "aws_oidc_role_arn": "arn:aws:iam::<aws-account-id>:role/baseten-s3-access",
>            "aws_oidc_region": "us-west-2",
>        },
>    )
>    ```

> [tab] S3 (AWS AssumeRole)
>
> **To read a private S3 bucket with AWS AssumeRole**:
>
> 1. Complete the [AWS AssumeRole setup](https://docs.baseten.co/organization/aws-assume-role.md#set-up-aws-assumerole) and attach S3 read permissions to the role in your AWS account.
>
> 2. Add this source to the job's `weights` list:
>
>    ```python theme={"system"}
>    WeightsSource(
>        source="s3://my-bucket/training-data",
>        mount_location="/app/data/training-data",
>        auth={
>            "auth_method": "AWS_ASSUME_ROLE",
>            "aws_assume_role_arn": "arn:aws:iam::<aws-account-id>:role/baseten-s3-access",
>            "aws_assume_role_region": "us-west-2",
>        },
>    )
>    ```

> [tab] S3 (IAM credentials)
>
> **To read a private S3 bucket with IAM credentials**:
>
> 1. Store the credentials as a JSON [Baseten secret](https://docs.baseten.co/organization/secrets.md) named `aws_credentials`. The value must contain `aws_access_key_id`, `aws_secret_access_key`, and `aws_region`.
>
> 2. Add this source to the job's `weights` list:
>
>    ```python theme={"system"}
>    WeightsSource(
>        source="s3://my-bucket/training-data",
>        mount_location="/app/data/training-data",
>        auth={"auth_method": "CUSTOM_SECRET", "auth_secret_name": "aws_credentials"},
>    )
>    ```

> [tab] GCS (GCP OIDC)
>
> **To read a private GCS bucket with GCP OIDC**:
>
> 1. [Configure Workload Identity Federation for Baseten](https://docs.baseten.co/organization/oidc.md#gcp) and grant the service account read access to your bucket.
>
> 2. Add this source to the job's `weights` list:
>
>    ```python theme={"system"}
>    WeightsSource(
>        source="gs://my-bucket/training-data",
>        mount_location="/app/data/training-data",
>        auth={
>            "auth_method": "GCP_OIDC",
>            "gcp_oidc_service_account": "baseten-training@my-project.iam.gserviceaccount.com",
>            "gcp_oidc_workload_id_provider": "projects/123456789/locations/global/workloadIdentityPools/baseten/providers/baseten",
>        },
>    )
>    ```

For the full list of authentication options and source-specific configuration, see the [BDN configuration reference](https://docs.baseten.co/development/model/bdn.md#configuration-reference).

## Filter files

[`allow_patterns`](https://docs.baseten.co/reference/sdk/training#param-allow-patterns) and [`ignore_patterns`](https://docs.baseten.co/reference/sdk/training#param-ignore-patterns) take glob patterns. A pattern such as `*.safetensors` matches only files at the top level of the source, so use `**/*.safetensors` to match files in subdirectories.

Add both lists to a source in the job's `weights`:

```python theme={"system"}
WeightsSource(
    source="hf://meta-llama/Llama-3.1-8B@main",
    mount_location="/app/models/llama",
    allow_patterns=["*.safetensors", "config.json", "tokenizer.*"],
    ignore_patterns=["*.md", "*.txt"],
)
```

## How BDN serves training jobs

When you submit a training job, BDN compares your `weights` config to what's already in Baseten storage and pulls anything missing from the upstream source. It then stages the full set on the node before your `start_commands` run.
Data delivery happens entirely during the `CREATED` and `DEPLOYING` phases.

Two cache tiers sit in front of Baseten's mirror:

* **Cluster-local cache:** shared across nodes in a GPU cluster. Populated the first time a job in that cluster pulls a given set of files.
* **Node-local cache:** lives on the node itself. Populated when a job lands on that node.

Both caches evict with LRU. On a **node-local hit**, the node mounts the data directly and your job starts almost immediately. On a **cluster-local hit**, BDN transfers the data from the cluster cache to the node, which adds a small amount of deploy time. On a **full miss**, BDN pulls from its mirror, which adds more deploy time.

## Weight access across jobs

A training job reads only the weight sources it declares in its config. Private sources like S3, GCS, R2, and CoreWeave stay within your organization.

Within your organization, jobs that reference the same unchanged source pull from the upstream once instead of once per job. For example, running many jobs against the same S3 dataset egresses from your bucket a single time, regardless of which user launched them.

## Next steps

* [BDN configuration reference](https://docs.baseten.co/development/model/bdn.md#configuration-reference): Every weight source option, authentication method, and URI scheme.
* [Download data in your training script](https://docs.baseten.co/training/download-data.md): Load data with a library's own loader or custom code.
* [Storage overview](https://docs.baseten.co/training/concepts/storage.md): Compare BDN with the training cache, checkpoints, and scratch space.
