Skip to main content
Download data in your training script when you need a library’s own loader, such as datasets.load_dataset, or custom download logic. For read-only files in an hf://, s3://, gs://, r2://, or cw:// source, mount them with BDN instead. Each tab needs the source’s client library in the job’s image: boto3 for Amazon S3, datasets for Hugging Face, and google-cloud-storage for Google Cloud Storage. Use a base_image that includes it, or install it in start_commands before your code runs. The snippets that set Runtime environment variables go in your job’s config.py, alongside the rest of the job definition described in the quickstart. To read a bucket without storing a key, mount it with BDN and OIDC instead.
To load data from Amazon S3:
  1. Save your AWS credentials as Baseten secrets named aws_access_key_id and aws_secret_access_key.
  2. Add this to the job’s Runtime in config.py:
  3. Download from S3 in your training script:
    The script prints downloaded <bytes> bytes, where <bytes> is the size of the downloaded file.
To avoid re-downloading large datasets on each job, download to the training cache instead, and skip the download when the file is already there:

Next steps