Cerebrium gives you access to persistent volumes to store model weights and files. This volume persists across your project, meaning that if you refer to model weights or files created in a different app (but in the same project), you’re able to access them.

This allows model weights to be loaded in more efficiently, as well as reduce the size of your App container image.

How it works

Every Cerebrium Project comes with a 50GB volume by default. This volume is mounted on all apps as /persistent-storage.

Uploading files

To upload files to your persistent volume, you can use the cerebrium cp local_path dest_path command. This command copies files from your local machine to the specified destination path in the volume. The dest_path is optional; if not provided, the files will be uploaded to the root of the persistent volume.

Usage: cerebrium cp [OPTIONS] LOCAL_PATH REMOTE_PATH (Optional)

  Copy contents to persistent volume.

Options:
  -h, --help          Show this message and exit.

Examples:
  # Copy a single file
  cerebrium cp src_file_name.txt # copies to /src_file_name.txt

  cerebrium cp src_file_name.txt dest_file_name.txt # copies to /dest_file_name.txt

  # Copy a directory
  cerebrium cp dir_name # copies to the root directory
  cerebrium cp dir_name sub_folder/ # copies to sub_folder/

Listing files

To list the files on your persistent volume, you can use the cerebrium ls [remote_path] command. This command lists all files and directories within the specified remote_path. If no remote_path is provided, it lists the contents of the root directory of the persistent volume.

Usage: cerebrium ls [OPTIONS] REMOTE_PATH (Optional)

  List contents of persistent volume.

Options:
  -h, --help          Show this message and exit.

Examples:
  # List all files in the root directory
  cerebrium ls

  # List all files in a specific folder
  cerebrium ls sub_folder/

Deleting files

To delete files or directories from your persistent volume, use the cerebrium rm remote_path command. This command removes the specified file or directory from the persistent volume. Be careful, as this operation is irreversible.

Usage: cerebrium rm [OPTIONS] REMOTE_PATH

  Remove a file or directory from persistent volume.

Options:
  -h, --help          Show this message and exit.

Examples:
  # Remove a specific file
  cerebrium rm /file_name.txt

  # Remove a directory and all its contents
  cerebrium rm /sub_folder/

Real world example

wget https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth
cerebrium cp sam_vit_h_4b8939.pth segment-anything/sam_vit_h_4b8939.pth

As a simple example, suppose you have an external SAM model that you want to use in your custom deployment. You can download it to a cache directory on your persistent volume. as such:

import os
import torch

file_path = "/persistent-storage/segment-anything/sam_vit_h_4b8939.pth"

# Load the model
model = torch.jit.load(file_path)
... # Continue with your initialization

Now, in later inference requests, the model loads from the persistent volume instead of downloading again.