Skip to main content
The training cache keeps data between training jobs, so later jobs can skip downloads and preprocessing that earlier jobs already did.

Turn on the training cache

To turn on the cache, set cache_config on Runtime:
After a job writes to the cache, list the cached files to confirm they persisted.

Cache directory

By default, Baseten mounts the cache in two locations:
  • /root/.cache/user_artifacts, which can be accessed through the $BT_PROJECT_CACHE_DIR environment variable. This cache is shared by all jobs in a project.
  • /root/.cache/team_artifacts, which can be accessed through the $BT_TEAM_CACHE_DIR environment variable. A team’s jobs on the same cluster share this cache. (See Cache scope.)

Cache scope

Each cache lives on one cluster, so jobs reuse cached data when they run on that cluster. When you enable caching, your project pins to the cluster where its first cache-enabled job ran. New projects prefer their team’s existing cache location for the same GPU type. By default (cache_config.require_cache_affinity=true), requesting a GPU type the pinned cluster doesn’t offer fails the job. Set require_cache_affinity=false to allow another cluster, where you may need to re-seed the cache.

Prepare data on CPUs for GPU jobs

For CPU jobs that prepare cached data for GPU jobs, set TrainingProject.project_accelerator to the GPU type that consumes the data, such as Accelerator.H100.

Hugging Face cache mount

You can mount your cache to the Hugging Face cache directory by setting HF_HOME to one of the provided mount points plus /huggingface. For example, you can set HF_HOME=$BT_PROJECT_CACHE_DIR/huggingface to use the project cache directory. However, there are considerable technical pitfalls when trying to read from the cache with multiple processes, as Hugging Face doesn’t work well with distributed filesystems. To help enable this use case, ensure your dataset processors or process count is set to 1 to minimize the number of concurrent readers.

Cache seeding

Seeding the cache once avoids repeating a large download on every training job. See Seed large datasets into the cache for the seed job and download script.

Cache management

To list a project’s cached files, largest first, run:
<project_name> also accepts the project ID. The output starts with the cache’s total size, then lists each file’s path, type, size, permissions, and modification time:
The command only lists files. To delete files, delete them from inside a job that mounts the cache, for example from the job’s start_commands, and name them under $BT_PROJECT_CACHE_DIR or $BT_TEAM_CACHE_DIR:
config.py
When you delete a project, all data in the project’s training cache ($BT_PROJECT_CACHE_DIR) is permanently deleted with no archival or recovery option. See Delete a job or project for details.